xref: /openbsd-src/gnu/llvm/compiler-rt/lib/scudo/standalone/tests/report_test.cpp (revision d89ec533011f513df1010f142a111086a0785f09)
13cab2bb3Spatrick //===-- report_test.cpp -----------------------------------------*- C++ -*-===//
23cab2bb3Spatrick //
33cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
43cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information.
53cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63cab2bb3Spatrick //
73cab2bb3Spatrick //===----------------------------------------------------------------------===//
83cab2bb3Spatrick 
93cab2bb3Spatrick #include "tests/scudo_unit_test.h"
103cab2bb3Spatrick 
113cab2bb3Spatrick #include "report.h"
123cab2bb3Spatrick 
TEST(ScudoReportDeathTest,Check)13*d89ec533Spatrick TEST(ScudoReportDeathTest, Check) {
14*d89ec533Spatrick   CHECK_LT(-1, 1);
15*d89ec533Spatrick   EXPECT_DEATH(CHECK_GT(-1, 1),
16*d89ec533Spatrick                "\\(-1\\) > \\(1\\) \\(\\(u64\\)op1=18446744073709551615, "
17*d89ec533Spatrick                "\\(u64\\)op2=1");
18*d89ec533Spatrick }
19*d89ec533Spatrick 
TEST(ScudoReportDeathTest,Generic)20*d89ec533Spatrick TEST(ScudoReportDeathTest, Generic) {
213cab2bb3Spatrick   // Potentially unused if EXPECT_DEATH isn't defined.
223cab2bb3Spatrick   UNUSED void *P = reinterpret_cast<void *>(0x42424242U);
233cab2bb3Spatrick   EXPECT_DEATH(scudo::reportError("TEST123"), "Scudo ERROR.*TEST123");
243cab2bb3Spatrick   EXPECT_DEATH(scudo::reportInvalidFlag("ABC", "DEF"), "Scudo ERROR.*ABC.*DEF");
253cab2bb3Spatrick   EXPECT_DEATH(scudo::reportHeaderCorruption(P), "Scudo ERROR.*42424242");
263cab2bb3Spatrick   EXPECT_DEATH(scudo::reportHeaderRace(P), "Scudo ERROR.*42424242");
273cab2bb3Spatrick   EXPECT_DEATH(scudo::reportSanityCheckError("XYZ"), "Scudo ERROR.*XYZ");
283cab2bb3Spatrick   EXPECT_DEATH(scudo::reportAlignmentTooBig(123, 456), "Scudo ERROR.*123.*456");
293cab2bb3Spatrick   EXPECT_DEATH(scudo::reportAllocationSizeTooBig(123, 456, 789),
303cab2bb3Spatrick                "Scudo ERROR.*123.*456.*789");
313cab2bb3Spatrick   EXPECT_DEATH(scudo::reportOutOfMemory(4242), "Scudo ERROR.*4242");
323cab2bb3Spatrick   EXPECT_DEATH(
333cab2bb3Spatrick       scudo::reportInvalidChunkState(scudo::AllocatorAction::Recycling, P),
343cab2bb3Spatrick       "Scudo ERROR.*recycling.*42424242");
353cab2bb3Spatrick   EXPECT_DEATH(
363cab2bb3Spatrick       scudo::reportInvalidChunkState(scudo::AllocatorAction::Sizing, P),
373cab2bb3Spatrick       "Scudo ERROR.*sizing.*42424242");
383cab2bb3Spatrick   EXPECT_DEATH(
393cab2bb3Spatrick       scudo::reportMisalignedPointer(scudo::AllocatorAction::Deallocating, P),
403cab2bb3Spatrick       "Scudo ERROR.*deallocating.*42424242");
413cab2bb3Spatrick   EXPECT_DEATH(scudo::reportDeallocTypeMismatch(
423cab2bb3Spatrick                    scudo::AllocatorAction::Reallocating, P, 0, 1),
433cab2bb3Spatrick                "Scudo ERROR.*reallocating.*42424242");
443cab2bb3Spatrick   EXPECT_DEATH(scudo::reportDeleteSizeMismatch(P, 123, 456),
453cab2bb3Spatrick                "Scudo ERROR.*42424242.*123.*456");
463cab2bb3Spatrick }
473cab2bb3Spatrick 
TEST(ScudoReportDeathTest,CSpecific)48*d89ec533Spatrick TEST(ScudoReportDeathTest, CSpecific) {
493cab2bb3Spatrick   EXPECT_DEATH(scudo::reportAlignmentNotPowerOfTwo(123), "Scudo ERROR.*123");
503cab2bb3Spatrick   EXPECT_DEATH(scudo::reportCallocOverflow(123, 456), "Scudo ERROR.*123.*456");
513cab2bb3Spatrick   EXPECT_DEATH(scudo::reportInvalidPosixMemalignAlignment(789),
523cab2bb3Spatrick                "Scudo ERROR.*789");
533cab2bb3Spatrick   EXPECT_DEATH(scudo::reportPvallocOverflow(123), "Scudo ERROR.*123");
543cab2bb3Spatrick   EXPECT_DEATH(scudo::reportInvalidAlignedAllocAlignment(123, 456),
553cab2bb3Spatrick                "Scudo ERROR.*123.*456");
563cab2bb3Spatrick }
57