brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · 514837d Raw
97 lines · cpp
1//===-- report_test.cpp -----------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "tests/scudo_unit_test.h"10 11#include "chunk.h"12#include "report.h"13 14TEST(ScudoReportDeathTest, Check) {15  CHECK_LT(-1, 1);16  EXPECT_DEATH(CHECK_GT(-1, 1),17               "\\(-1\\) > \\(1\\) \\(\\(u64\\)op1=18446744073709551615, "18               "\\(u64\\)op2=1");19}20 21TEST(ScudoReportDeathTest, Generic) {22  // Potentially unused if EXPECT_DEATH isn't defined.23  UNUSED void *P = reinterpret_cast<void *>(0x42424242U);24  UNUSED scudo::Chunk::PackedHeader Header = {};25  EXPECT_DEATH(scudo::reportError("TEST123"), "Scudo ERROR.*TEST123");26  EXPECT_DEATH(scudo::reportInvalidFlag("ABC", "DEF"), "Scudo ERROR.*ABC.*DEF");27  EXPECT_DEATH(scudo::reportHeaderCorruption(&Header, P),28               "Scudo ERROR.*42424242");29  EXPECT_DEATH(scudo::reportSanityCheckError("XYZ"), "Scudo ERROR.*XYZ");30  EXPECT_DEATH(scudo::reportAlignmentTooBig(123, 456), "Scudo ERROR.*123.*456");31  EXPECT_DEATH(scudo::reportAllocationSizeTooBig(123, 456, 789),32               "Scudo ERROR.*123.*456.*789");33  EXPECT_DEATH(scudo::reportOutOfMemory(4242), "Scudo ERROR.*4242");34  EXPECT_DEATH(35      scudo::reportInvalidChunkState(scudo::AllocatorAction::Recycling, P),36      "Scudo ERROR.*recycling.*42424242");37  EXPECT_DEATH(38      scudo::reportInvalidChunkState(scudo::AllocatorAction::Sizing, P),39      "Scudo ERROR.*sizing.*42424242");40  EXPECT_DEATH(41      scudo::reportMisalignedPointer(scudo::AllocatorAction::Deallocating, P),42      "Scudo ERROR.*deallocating.*42424242");43  EXPECT_DEATH(scudo::reportDeallocTypeMismatch(44                   scudo::AllocatorAction::Reallocating, P, 0, 1),45               "Scudo ERROR.*reallocating.*42424242");46  EXPECT_DEATH(scudo::reportDeleteSizeMismatch(P, 123, 456),47               "Scudo ERROR.*42424242.*123.*456");48}49 50TEST(ScudoReportDeathTest, CSpecific) {51  EXPECT_DEATH(scudo::reportAlignmentNotPowerOfTwo(123), "Scudo ERROR.*123");52  EXPECT_DEATH(scudo::reportCallocOverflow(123, 456), "Scudo ERROR.*123.*456");53  EXPECT_DEATH(scudo::reportInvalidPosixMemalignAlignment(789),54               "Scudo ERROR.*789");55  EXPECT_DEATH(scudo::reportPvallocOverflow(123), "Scudo ERROR.*123");56  EXPECT_DEATH(scudo::reportInvalidAlignedAllocAlignment(123, 456),57               "Scudo ERROR.*123.*456");58}59 60TEST(ScudoReportDeathTest, HeaderCorruption) {61  UNUSED void *P = reinterpret_cast<void *>(0x42424242U);62  UNUSED scudo::Chunk::PackedHeader Header = {};63  EXPECT_DEATH(scudo::reportHeaderCorruption(&Header, P),64               "Scudo ERROR.*corrupted chunk header at address 0x.*42424242: "65               "chunk header is zero and might indicate memory "66               "corruption or a double free");67  Header = 10U;68  EXPECT_DEATH(scudo::reportHeaderCorruption(&Header, P),69               "Scudo ERROR.*corrupted chunk header at address 0x.*42424242: "70               "most likely due to memory corruption");71}72 73#if SCUDO_LINUX || SCUDO_TRUSTY || SCUDO_ANDROID74#include "report_linux.h"75 76#include <errno.h>77#include <sys/mman.h>78 79TEST(ScudoReportDeathTest, Linux) {80  errno = ENOMEM;81  EXPECT_DEATH(scudo::reportMapError(),82               "Scudo ERROR:.*internal map failure \\(error desc=.*\\)");83  errno = ENOMEM;84  EXPECT_DEATH(scudo::reportMapError(1024U),85               "Scudo ERROR:.*internal map failure \\(error desc=.*\\) "86               "requesting 1KB");87  errno = ENOMEM;88  EXPECT_DEATH(scudo::reportUnmapError(0x1000U, 100U),89               "Scudo ERROR:.*internal unmap failure \\(error desc=.*\\) Addr "90               "0x1000 Size 100");91  errno = ENOMEM;92  EXPECT_DEATH(scudo::reportProtectError(0x1000U, 100U, PROT_READ),93               "Scudo ERROR:.*internal protect failure \\(error desc=.*\\) "94               "Addr 0x1000 Size 100 Prot 1");95}96#endif97