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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "tests/scudo_unit_test.h" 10 11 #include "report.h" 12 13 TEST(ScudoReportDeathTest, Check) { 14 CHECK_LT(-1, 1); 15 EXPECT_DEATH(CHECK_GT(-1, 1), 16 "\\(-1\\) > \\(1\\) \\(\\(u64\\)op1=18446744073709551615, " 17 "\\(u64\\)op2=1"); 18 } 19 20 TEST(ScudoReportDeathTest, Generic) { 21 // Potentially unused if EXPECT_DEATH isn't defined. 22 UNUSED void *P = reinterpret_cast<void *>(0x42424242U); 23 EXPECT_DEATH(scudo::reportError("TEST123"), "Scudo ERROR.*TEST123"); 24 EXPECT_DEATH(scudo::reportInvalidFlag("ABC", "DEF"), "Scudo ERROR.*ABC.*DEF"); 25 EXPECT_DEATH(scudo::reportHeaderCorruption(P), "Scudo ERROR.*42424242"); 26 EXPECT_DEATH(scudo::reportHeaderRace(P), "Scudo ERROR.*42424242"); 27 EXPECT_DEATH(scudo::reportSanityCheckError("XYZ"), "Scudo ERROR.*XYZ"); 28 EXPECT_DEATH(scudo::reportAlignmentTooBig(123, 456), "Scudo ERROR.*123.*456"); 29 EXPECT_DEATH(scudo::reportAllocationSizeTooBig(123, 456, 789), 30 "Scudo ERROR.*123.*456.*789"); 31 EXPECT_DEATH(scudo::reportOutOfMemory(4242), "Scudo ERROR.*4242"); 32 EXPECT_DEATH( 33 scudo::reportInvalidChunkState(scudo::AllocatorAction::Recycling, P), 34 "Scudo ERROR.*recycling.*42424242"); 35 EXPECT_DEATH( 36 scudo::reportInvalidChunkState(scudo::AllocatorAction::Sizing, P), 37 "Scudo ERROR.*sizing.*42424242"); 38 EXPECT_DEATH( 39 scudo::reportMisalignedPointer(scudo::AllocatorAction::Deallocating, P), 40 "Scudo ERROR.*deallocating.*42424242"); 41 EXPECT_DEATH(scudo::reportDeallocTypeMismatch( 42 scudo::AllocatorAction::Reallocating, P, 0, 1), 43 "Scudo ERROR.*reallocating.*42424242"); 44 EXPECT_DEATH(scudo::reportDeleteSizeMismatch(P, 123, 456), 45 "Scudo ERROR.*42424242.*123.*456"); 46 } 47 48 TEST(ScudoReportDeathTest, CSpecific) { 49 EXPECT_DEATH(scudo::reportAlignmentNotPowerOfTwo(123), "Scudo ERROR.*123"); 50 EXPECT_DEATH(scudo::reportCallocOverflow(123, 456), "Scudo ERROR.*123.*456"); 51 EXPECT_DEATH(scudo::reportInvalidPosixMemalignAlignment(789), 52 "Scudo ERROR.*789"); 53 EXPECT_DEATH(scudo::reportPvallocOverflow(123), "Scudo ERROR.*123"); 54 EXPECT_DEATH(scudo::reportInvalidAlignedAllocAlignment(123, 456), 55 "Scudo ERROR.*123.*456"); 56 } 57