From 61d070650780e13f2e9326d1b8f40f6968ea5de3 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 18 Feb 2021 17:17:27 -0800 Subject: [PATCH] Use death tests correctly. The existing attempt at a death test wrapper wasn't functional (because the tests were TEST rather than TEST_F), and the code in that class doesn't work anyway. Since I don't understand the intent behind the failing dup2() calls, I've just removed this and replaced it with BionicDeathTest which we do need to suppress all the debuggerd work which caused this bug to be filed. Bug: http://b/180605583 Test: treehugger Change-Id: I7717f7ae2620452656cf07db299774dadef55766 --- tests/clang_fortify_tests.cpp | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/tests/clang_fortify_tests.cpp b/tests/clang_fortify_tests.cpp index 0d17284fb..035517083 100644 --- a/tests/clang_fortify_tests.cpp +++ b/tests/clang_fortify_tests.cpp @@ -99,37 +99,9 @@ #define CONCAT2(x, y) x##y #define CONCAT(x, y) CONCAT2(x, y) -#define FORTIFY_TEST_NAME CONCAT(clang_fortify_test_, _FORTIFY_SOURCE) +#define FORTIFY_TEST_NAME CONCAT(CONCAT(clang_fortify_test_, _FORTIFY_SOURCE), _DeathTest) -namespace { -struct FORTIFY_TEST_NAME : BionicDeathTest { - protected: - void SetUp() override { - stdin_saved = dup(STDIN_FILENO); - if (stdin_saved < 0) err(1, "failed to dup stdin"); - - int devnull = open("/dev/null", O_RDONLY); - if (devnull < 0) err(1, "failed to open /dev/null"); - - if (!dup2(devnull, STDIN_FILENO)) err(1, "failed to overwrite stdin"); - static_cast(close(devnull)); - - BionicDeathTest::SetUp(); - } - - void TearDown() override { - if (stdin_saved == -1) return; - if (!dup2(stdin_saved, STDIN_FILENO)) warn("failed to restore stdin"); - - static_cast(close(stdin_saved)); - - BionicDeathTest::TearDown(); - } - - private: - int stdin_saved = -1; -}; -} // namespace +using FORTIFY_TEST_NAME = BionicDeathTest; template __attribute__((noreturn)) static void ExitAfter(Fn&& f) { @@ -153,7 +125,7 @@ __attribute__((noreturn)) static void ExitAfter(Fn&& f) { #define EXPECT_FORTIFY_DEATH_STRUCT EXPECT_NO_DEATH #endif -#define FORTIFY_TEST(test_name) TEST(FORTIFY_TEST_NAME, test_name) +#define FORTIFY_TEST(test_name) TEST_F(FORTIFY_TEST_NAME, test_name) #else // defined(COMPILATION_TESTS)