summaryrefslogtreecommitdiff
path: root/gnu/llvm/compiler-rt/lib/gwp_asan/tests/harness.h
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/llvm/compiler-rt/lib/gwp_asan/tests/harness.h')
-rw-r--r--gnu/llvm/compiler-rt/lib/gwp_asan/tests/harness.h41
1 files changed, 37 insertions, 4 deletions
diff --git a/gnu/llvm/compiler-rt/lib/gwp_asan/tests/harness.h b/gnu/llvm/compiler-rt/lib/gwp_asan/tests/harness.h
index ed91e642de7..c8f643dbab9 100644
--- a/gnu/llvm/compiler-rt/lib/gwp_asan/tests/harness.h
+++ b/gnu/llvm/compiler-rt/lib/gwp_asan/tests/harness.h
@@ -14,9 +14,11 @@
#if defined(__Fuchsia__)
#include <zxtest/zxtest.h>
using Test = ::zxtest::Test;
+template <typename T> using TestWithParam = ::zxtest::TestWithParam<T>;
#else
#include "gtest/gtest.h"
using Test = ::testing::Test;
+template <typename T> using TestWithParam = ::testing::TestWithParam<T>;
#endif
#include "gwp_asan/guarded_pool_allocator.h"
@@ -39,6 +41,11 @@ bool OnlyOnce();
}; // namespace test
}; // namespace gwp_asan
+char *AllocateMemory(gwp_asan::GuardedPoolAllocator &GPA);
+void DeallocateMemory(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr);
+void DeallocateMemory2(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr);
+void TouchMemory(void *Ptr);
+
class DefaultGuardedPoolAllocator : public Test {
public:
void SetUp() override {
@@ -81,7 +88,8 @@ protected:
MaxSimultaneousAllocations;
};
-class BacktraceGuardedPoolAllocator : public Test {
+class BacktraceGuardedPoolAllocator
+ : public TestWithParam</* Recoverable */ bool> {
public:
void SetUp() override {
gwp_asan::options::Options Opts;
@@ -91,10 +99,19 @@ public:
Opts.InstallForkHandlers = gwp_asan::test::OnlyOnce();
GPA.init(Opts);
+ // In recoverable mode, capture GWP-ASan logs to an internal buffer so that
+ // we can search it in unit tests. For non-recoverable tests, the default
+ // buffer is fine, as any tests should be EXPECT_DEATH()'d.
+ Recoverable = GetParam();
+ gwp_asan::Printf_t PrintfFunction = PrintfToBuffer;
+ GetOutputBuffer().clear();
+ if (!Recoverable)
+ PrintfFunction = gwp_asan::test::getPrintfFunction();
+
gwp_asan::segv_handler::installSignalHandlers(
- &GPA, gwp_asan::test::getPrintfFunction(),
- gwp_asan::backtrace::getPrintBacktraceFunction(),
- gwp_asan::backtrace::getSegvBacktraceFunction());
+ &GPA, PrintfFunction, gwp_asan::backtrace::getPrintBacktraceFunction(),
+ gwp_asan::backtrace::getSegvBacktraceFunction(),
+ /* Recoverable */ Recoverable);
}
void TearDown() override {
@@ -103,7 +120,23 @@ public:
}
protected:
+ static std::string &GetOutputBuffer() {
+ static std::string Buffer;
+ return Buffer;
+ }
+
+ __attribute__((format(printf, 1, 2))) static void
+ PrintfToBuffer(const char *Format, ...) {
+ va_list AP;
+ va_start(AP, Format);
+ char Buffer[8192];
+ vsnprintf(Buffer, sizeof(Buffer), Format, AP);
+ GetOutputBuffer() += Buffer;
+ va_end(AP);
+ }
+
gwp_asan::GuardedPoolAllocator GPA;
+ bool Recoverable;
};
// https://github.com/google/googletest/blob/master/docs/advanced.md#death-tests-and-threads