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