From 343a3e1fbc19a44d6f6fdfc6cae38ccc7f32e790 Mon Sep 17 00:00:00 2001 From: Caslyn Tonelli Date: Thu, 30 Mar 2023 00:03:05 +0000 Subject: [gwp_asan] Employ EXPECT_DEATH for zxtest compatibility Employ a similar tactic introduced by https://reviews.llvm.org/D94362 for gwp_asan tests. zxtest `ASSERT_DEATH` syntax differs from gtest in that it expects a lambda. zxtest does not have `EXPECT_DEATH`, so it introduced for Fuchsia builds and wraps the expression with a lambda to create a compatible syntax between zxtest and gtest for death tests. An example of where this compatiblity is needed is in `never_allocated.cpp`. Differential Revision: https://reviews.llvm.org/D147189 GitOrigin-RevId: f2a1726d2199150918430a84f29cf8835bfe8e5a Change-Id: I36a4ddde3fd55ae61bf731dc439762d7157dfa7d --- gwp_asan/tests/harness.h | 7 +++++++ gwp_asan/tests/never_allocated.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gwp_asan/tests/harness.h b/gwp_asan/tests/harness.h index 3e85935..ae39a44 100644 --- a/gwp_asan/tests/harness.h +++ b/gwp_asan/tests/harness.h @@ -15,6 +15,13 @@ #define ZXTEST_USE_STREAMABLE_MACROS #include namespace testing = zxtest; +// zxtest defines a different ASSERT_DEATH, taking a lambda and an error message +// if death didn't occur, versus gtest taking a statement and a string to search +// for in the dying process. zxtest doesn't define an EXPECT_DEATH, so we use +// that in the tests below (which works as intended for gtest), and we define +// EXPECT_DEATH as a wrapper for zxtest's ASSERT_DEATH. Note that zxtest drops +// the functionality for checking for a particular message in death. +#define EXPECT_DEATH(X, Y) ASSERT_DEATH(([&] { X; }), "") #else #include "gtest/gtest.h" #endif diff --git a/gwp_asan/tests/never_allocated.cpp b/gwp_asan/tests/never_allocated.cpp index bd43b22..2f695b4 100644 --- a/gwp_asan/tests/never_allocated.cpp +++ b/gwp_asan/tests/never_allocated.cpp @@ -25,7 +25,7 @@ TEST_P(BacktraceGuardedPoolAllocatorDeathTest, NeverAllocated) { // in the posix crash handler. char *volatile NeverAllocatedPtr = static_cast(Ptr) + 0x3000; if (!Recoverable) { - ASSERT_DEATH(*NeverAllocatedPtr = 0, DeathNeedle); + EXPECT_DEATH(*NeverAllocatedPtr = 0, DeathNeedle); return; } -- cgit v1.2.3