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(ScudoReportTest, Generic) { 14 // Potentially unused if EXPECT_DEATH isn't defined. 15 UNUSED void *P = reinterpret_cast<void *>(0x42424242U); 16 EXPECT_DEATH(scudo::reportError("TEST123"), "Scudo ERROR.*TEST123"); 17 EXPECT_DEATH(scudo::reportInvalidFlag("ABC", "DEF"), "Scudo ERROR.*ABC.*DEF"); 18 EXPECT_DEATH(scudo::reportHeaderCorruption(P), "Scudo ERROR.*42424242"); 19 EXPECT_DEATH(scudo::reportHeaderRace(P), "Scudo ERROR.*42424242"); 20 EXPECT_DEATH(scudo::reportSanityCheckError("XYZ"), "Scudo ERROR.*XYZ"); 21 EXPECT_DEATH(scudo::reportAlignmentTooBig(123, 456), "Scudo ERROR.*123.*456"); 22 EXPECT_DEATH(scudo::reportAllocationSizeTooBig(123, 456, 789), 23 "Scudo ERROR.*123.*456.*789"); 24 EXPECT_DEATH(scudo::reportOutOfMemory(4242), "Scudo ERROR.*4242"); 25 EXPECT_DEATH( 26 scudo::reportInvalidChunkState(scudo::AllocatorAction::Recycling, P), 27 "Scudo ERROR.*recycling.*42424242"); 28 EXPECT_DEATH( 29 scudo::reportInvalidChunkState(scudo::AllocatorAction::Sizing, P), 30 "Scudo ERROR.*sizing.*42424242"); 31 EXPECT_DEATH( 32 scudo::reportMisalignedPointer(scudo::AllocatorAction::Deallocating, P), 33 "Scudo ERROR.*deallocating.*42424242"); 34 EXPECT_DEATH(scudo::reportDeallocTypeMismatch( 35 scudo::AllocatorAction::Reallocating, P, 0, 1), 36 "Scudo ERROR.*reallocating.*42424242"); 37 EXPECT_DEATH(scudo::reportDeleteSizeMismatch(P, 123, 456), 38 "Scudo ERROR.*42424242.*123.*456"); 39 } 40 41 TEST(ScudoReportTest, CSpecific) { 42 EXPECT_DEATH(scudo::reportAlignmentNotPowerOfTwo(123), "Scudo ERROR.*123"); 43 EXPECT_DEATH(scudo::reportCallocOverflow(123, 456), "Scudo ERROR.*123.*456"); 44 EXPECT_DEATH(scudo::reportInvalidPosixMemalignAlignment(789), 45 "Scudo ERROR.*789"); 46 EXPECT_DEATH(scudo::reportPvallocOverflow(123), "Scudo ERROR.*123"); 47 EXPECT_DEATH(scudo::reportInvalidAlignedAllocAlignment(123, 456), 48 "Scudo ERROR.*123.*456"); 49 } 50