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
diff --git a/tests/clang_fortify_tests.cpp b/tests/clang_fortify_tests.cpp
index 0d17284..0355170 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<void>(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<void>(close(stdin_saved));
-
- BionicDeathTest::TearDown();
- }
-
- private:
- int stdin_saved = -1;
-};
-} // namespace
+using FORTIFY_TEST_NAME = BionicDeathTest;
template <typename Fn>
__attribute__((noreturn)) static void ExitAfter(Fn&& f) {
@@ -153,7 +125,7 @@
#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)