make all bionic death tests not dumpable
Bug: 18067305
Change-Id: Ia1ecacf47eddecc9bc58aaac779e0c218f463179
diff --git a/tests/BionicDeathTest.h b/tests/BionicDeathTest.h
new file mode 100644
index 0000000..31d2d6e
--- /dev/null
+++ b/tests/BionicDeathTest.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BIONIC_TESTS_BIONIC_DEATH_TEST_H_
+#define BIONIC_TESTS_BIONIC_DEATH_TEST_H_
+
+#include <gtest/gtest.h>
+
+#include <sys/prctl.h>
+
+class BionicDeathTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ // Suppress debuggerd stack traces. Too slow.
+ old_dumpable_ = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
+ prctl(PR_SET_DUMPABLE, 0, 0, 0, 0);
+ ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+ }
+
+ virtual void TearDown() {
+ prctl(PR_SET_DUMPABLE, old_dumpable_, 0, 0, 0, 0);
+ }
+
+ private:
+ int old_dumpable_;
+};
+
+#endif // BIONIC_TESTS_BIONIC_DEATH_TEST_H_
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index 352cac6..48764aa 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -15,38 +15,24 @@
*/
#include <gtest/gtest.h>
-#include <signal.h>
-#include <string.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <malloc.h>
-#include <fcntl.h>
-#include <sys/prctl.h>
+#include "BionicDeathTest.h"
-// We have to say "DeathTest" here so gtest knows to run this test (which exits)
-// in its own process. Unfortunately, the C preprocessor doesn't give us an
-// easy way to concatenate strings, so we need to use the complicated method
-// below. *sigh*
+#include <fcntl.h>
+#include <malloc.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+// Fortify test code needs to run multiple times, so TEST_NAME macro is used to
+// distinguish different tests. TEST_NAME is defined in compilation command.
#define DEATHTEST_PASTER(name) name##_DeathTest
#define DEATHTEST_EVALUATOR(name) DEATHTEST_PASTER(name)
#define DEATHTEST DEATHTEST_EVALUATOR(TEST_NAME)
-class DEATHTEST : public testing::Test {
- protected:
- virtual void SetUp() {
- old_dumpable_ = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
- // Suppress debuggerd stack traces. Too slow.
- prctl(PR_SET_DUMPABLE, 0, 0, 0, 0);
- }
-
- virtual void TearDown() {
- prctl(PR_SET_DUMPABLE, old_dumpable_, 0, 0, 0, 0);
- }
- private:
- int old_dumpable_;
-};
+class DEATHTEST : public BionicDeathTest {};
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE == 2
struct foo {
@@ -60,7 +46,6 @@
// This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, stpncpy_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
int copy_amt = atoi("11");
ASSERT_EXIT(stpncpy(myfoo.a, "01234567890", copy_amt),
@@ -72,7 +57,6 @@
// This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, stpncpy2_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
memset(&myfoo, 0, sizeof(myfoo));
myfoo.one[0] = 'A'; // not null terminated string
@@ -85,7 +69,6 @@
// This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strncpy_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
int copy_amt = atoi("11");
ASSERT_EXIT(strncpy(myfoo.a, "01234567890", copy_amt),
@@ -97,7 +80,6 @@
// This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strncpy2_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
memset(&myfoo, 0, sizeof(myfoo));
myfoo.one[0] = 'A'; // not null terminated string
@@ -110,7 +92,6 @@
// This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, sprintf_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
char source_buf[15];
memcpy(source_buf, "12345678901234", 15);
@@ -123,7 +104,6 @@
// This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, sprintf2_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
ASSERT_EXIT(sprintf(myfoo.a, "0123456789"),
testing::KilledBySignal(SIGABRT), "");
@@ -145,12 +125,10 @@
}
TEST_F(DEATHTEST, vsprintf_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(vsprintf_helper2("%s", "0123456789"), testing::KilledBySignal(SIGABRT), "");
}
TEST_F(DEATHTEST, vsprintf2_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(vsprintf_helper2("0123456789"), testing::KilledBySignal(SIGABRT), "");
}
#endif
@@ -171,12 +149,10 @@
}
TEST_F(DEATHTEST, vsnprintf_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(vsnprintf_helper2("%s", "0123456789"), testing::KilledBySignal(SIGABRT), "");
}
TEST_F(DEATHTEST, vsnprintf2_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(vsnprintf_helper2("0123456789"), testing::KilledBySignal(SIGABRT), "");
}
#endif
@@ -187,7 +163,6 @@
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, stpcpy_fortified2) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
char* src = strdup("");
ASSERT_EXIT(stpcpy(myfoo.empty, src),
@@ -205,7 +180,6 @@
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strcpy_fortified2) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
char* src = strdup("");
ASSERT_EXIT(strcpy(myfoo.empty, src),
@@ -223,7 +197,6 @@
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strcpy2_fortified2) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
char* src = strdup("1");
ASSERT_EXIT(strcpy(myfoo.empty, src),
@@ -241,7 +214,6 @@
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strcpy3_fortified2) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
char* src = strdup("12");
ASSERT_EXIT(strcpy(myfoo.one, src),
@@ -258,7 +230,6 @@
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strchr_fortified2) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
memcpy(myfoo.a, "0123456789", sizeof(myfoo.a));
myfoo.b[0] = '\0';
@@ -275,7 +246,6 @@
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strrchr_fortified2) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
memcpy(myfoo.a, "0123456789", 10);
memcpy(myfoo.b, "01234", 6);
@@ -292,7 +262,6 @@
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strlcpy_fortified2) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
strcpy(myfoo.a, "01");
size_t n = strlen(myfoo.a);
@@ -309,7 +278,6 @@
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strlcat_fortified2) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
strcpy(myfoo.a, "01");
myfoo.one[0] = '\0';
@@ -326,7 +294,6 @@
// This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strncat_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
size_t n = atoi("10"); // avoid compiler optimizations
strncpy(myfoo.a, "012345678", n);
@@ -338,7 +305,6 @@
// This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strncat2_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
myfoo.a[0] = '\0';
size_t n = atoi("10"); // avoid compiler optimizations
@@ -347,7 +313,6 @@
#endif
TEST_F(DEATHTEST, strncat3_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); // unterminated string
myfoo.b[0] = '\0';
@@ -359,7 +324,6 @@
// This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, strcat_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char src[11];
strcpy(src, "0123456789");
foo myfoo;
@@ -369,7 +333,6 @@
#endif
TEST_F(DEATHTEST, strcat2_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
memcpy(myfoo.a, "0123456789", sizeof(myfoo.a)); // unterminated string
myfoo.b[0] = '\0';
@@ -377,7 +340,6 @@
}
TEST_F(DEATHTEST, snprintf_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
strcpy(myfoo.a, "012345678");
size_t n = strlen(myfoo.a) + 2;
@@ -385,7 +347,6 @@
}
TEST_F(DEATHTEST, bzero_fortified2) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
foo myfoo;
memcpy(myfoo.b, "0123456789", sizeof(myfoo.b));
size_t n = atoi("11");
@@ -397,7 +358,6 @@
// multibyte target where we over fill (should fail)
TEST_F(DEATHTEST, strcpy_fortified) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
char *orig = strdup("0123456789");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
@@ -410,7 +370,6 @@
// zero sized target with "\0" source (should fail)
TEST_F(DEATHTEST, strcpy2_fortified) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[0];
char *orig = strdup("");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
@@ -423,7 +382,6 @@
// zero sized target with longer source (should fail)
TEST_F(DEATHTEST, strcpy3_fortified) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[0];
char *orig = strdup("1");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
@@ -436,7 +394,6 @@
// one byte target with longer source (should fail)
TEST_F(DEATHTEST, strcpy4_fortified) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[1];
char *orig = strdup("12");
ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
@@ -448,7 +405,6 @@
TEST_F(DEATHTEST, strlen_fortified) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
memcpy(buf, "0123456789", sizeof(buf));
ASSERT_EXIT(printf("%zd", strlen(buf)), testing::KilledBySignal(SIGABRT), "");
@@ -459,7 +415,6 @@
TEST_F(DEATHTEST, strchr_fortified) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
memcpy(buf, "0123456789", sizeof(buf));
ASSERT_EXIT(printf("%s", strchr(buf, 'a')), testing::KilledBySignal(SIGABRT), "");
@@ -470,7 +425,6 @@
TEST_F(DEATHTEST, strrchr_fortified) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
memcpy(buf, "0123456789", sizeof(buf));
ASSERT_EXIT(printf("%s", strrchr(buf, 'a')), testing::KilledBySignal(SIGABRT), "");
@@ -481,7 +435,6 @@
TEST_F(DEATHTEST, strlcpy_fortified) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char bufa[15];
char bufb[10];
strcpy(bufa, "01234567890123");
@@ -494,7 +447,6 @@
TEST_F(DEATHTEST, strlcat_fortified) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char bufa[15];
char bufb[10];
bufb[0] = '\0';
@@ -507,7 +459,6 @@
}
TEST_F(DEATHTEST, sprintf_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
char source_buf[15];
memcpy(source_buf, "12345678901234", 15);
@@ -518,7 +469,6 @@
// This test is disabled in clang because clang doesn't properly detect
// this buffer overflow. TODO: Fix clang.
TEST_F(DEATHTEST, sprintf_malloc_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char* buf = (char *) malloc(10);
char source_buf[11];
memcpy(source_buf, "1234567890", 11);
@@ -528,7 +478,6 @@
#endif
TEST_F(DEATHTEST, sprintf2_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[5];
ASSERT_EXIT(sprintf(buf, "aaaaa"), testing::KilledBySignal(SIGABRT), "");
}
@@ -545,12 +494,10 @@
}
TEST_F(DEATHTEST, vsprintf_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(vsprintf_helper("%s", "0123456789"), testing::KilledBySignal(SIGABRT), "");
}
TEST_F(DEATHTEST, vsprintf2_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(vsprintf_helper("0123456789"), testing::KilledBySignal(SIGABRT), "");
}
@@ -567,17 +514,14 @@
}
TEST_F(DEATHTEST, vsnprintf_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(vsnprintf_helper("%s", "0123456789"), testing::KilledBySignal(SIGABRT), "");
}
TEST_F(DEATHTEST, vsnprintf2_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(vsnprintf_helper("0123456789"), testing::KilledBySignal(SIGABRT), "");
}
TEST_F(DEATHTEST, strncat_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
size_t n = atoi("10"); // avoid compiler optimizations
strncpy(buf, "012345678", n);
@@ -585,7 +529,6 @@
}
TEST_F(DEATHTEST, strncat2_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
buf[0] = '\0';
size_t n = atoi("10"); // avoid compiler optimizations
@@ -593,7 +536,6 @@
}
TEST_F(DEATHTEST, strcat_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char src[11];
strcpy(src, "0123456789");
char buf[10];
@@ -602,7 +544,6 @@
}
TEST_F(DEATHTEST, memmove_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[20];
strcpy(buf, "0123456789");
size_t n = atoi("10");
@@ -610,7 +551,6 @@
}
TEST_F(DEATHTEST, memcpy_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char bufa[10];
char bufb[10];
strcpy(bufa, "012345678");
@@ -619,7 +559,6 @@
}
TEST_F(DEATHTEST, stpncpy_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char bufa[15];
char bufb[10];
strcpy(bufa, "01234567890123");
@@ -628,7 +567,6 @@
}
TEST_F(DEATHTEST, stpncpy2_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char dest[11];
char src[10];
memcpy(src, "0123456789", sizeof(src)); // src is not null terminated
@@ -636,7 +574,6 @@
}
TEST_F(DEATHTEST, strncpy_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char bufa[15];
char bufb[10];
strcpy(bufa, "01234567890123");
@@ -646,7 +583,6 @@
TEST_F(DEATHTEST, strncpy2_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char dest[11];
char src[10];
memcpy(src, "0123456789", sizeof(src)); // src is not null terminated
@@ -654,7 +590,6 @@
}
TEST_F(DEATHTEST, snprintf_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char bufa[15];
char bufb[10];
strcpy(bufa, "0123456789");
@@ -663,7 +598,6 @@
}
TEST_F(DEATHTEST, bzero_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
memcpy(buf, "0123456789", sizeof(buf));
size_t n = atoi("11");
@@ -671,13 +605,11 @@
}
TEST_F(DEATHTEST, umask_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
mode_t mask = atoi("1023"); // 01777 in octal
ASSERT_EXIT(umask(mask), testing::KilledBySignal(SIGABRT), "");
}
TEST_F(DEATHTEST, recv_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
size_t data_len = atoi("11"); // suppress compiler optimizations
char buf[10];
ASSERT_EXIT(recv(0, buf, data_len, 0), testing::KilledBySignal(SIGABRT), "");
@@ -685,7 +617,6 @@
TEST_F(DEATHTEST, FD_ISSET_fortified) {
#if defined(__BIONIC__) // glibc catches this at compile-time.
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
fd_set set;
memset(&set, 0, sizeof(set));
ASSERT_EXIT(FD_ISSET(-1, &set), testing::KilledBySignal(SIGABRT), "");
@@ -693,7 +624,6 @@
}
TEST_F(DEATHTEST, FD_ISSET_2_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[1];
fd_set* set = (fd_set*) buf;
ASSERT_EXIT(FD_ISSET(0, set), testing::KilledBySignal(SIGABRT), "");
@@ -703,14 +633,12 @@
static void FD_ZERO_function(fd_set* s) { FD_ZERO(s); }
TEST_F(DEATHTEST, FD_ZERO_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[1];
fd_set* set = (fd_set*) buf;
ASSERT_EXIT(FD_ZERO_function(set), testing::KilledBySignal(SIGABRT), "");
}
TEST_F(DEATHTEST, read_fortified) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[1];
size_t ct = atoi("2"); // prevent optimizations
int fd = open("/dev/null", O_RDONLY);
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 61641e4..379e495 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -16,6 +16,10 @@
#include <gtest/gtest.h>
+#include "private/ScopeGuard.h"
+#include "BionicDeathTest.h"
+#include "ScopedSignalHandler.h"
+
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
@@ -27,8 +31,6 @@
#include <time.h>
#include <unistd.h>
-#include "private/ScopeGuard.h"
-#include "ScopedSignalHandler.h"
TEST(pthread, pthread_key_create) {
pthread_key_t key;
@@ -302,9 +304,11 @@
// Even though this isn't really a death test, we have to say "DeathTest" here so gtest knows to
// run this test (which exits normally) in its own process.
-TEST(pthread_DeathTest, pthread_bug_37410) {
+
+class pthread_DeathTest : public BionicDeathTest {};
+
+TEST_F(pthread_DeathTest, pthread_bug_37410) {
// http://code.google.com/p/android/issues/detail?id=37410
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(TestBug37410::main(), ::testing::ExitedWithCode(0), "");
}
diff --git a/tests/stack_protector_test.cpp b/tests/stack_protector_test.cpp
index fea24d8..aad51ec 100644
--- a/tests/stack_protector_test.cpp
+++ b/tests/stack_protector_test.cpp
@@ -19,6 +19,7 @@
*/
#include <gtest/gtest.h>
+#include "BionicDeathTest.h"
#include <pthread.h>
#include <stdint.h>
@@ -120,9 +121,10 @@
#endif // TEST_STACK_CHK_GUARD
}
-TEST(stack_protector_DeathTest, modify_stack_protector) {
+class stack_protector_DeathTest : public BionicDeathTest {};
+
+TEST_F(stack_protector_DeathTest, modify_stack_protector) {
#if defined(TEST_STACK_CHK_GUARD)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(do_modify_stack_chk_guard(), testing::KilledBySignal(SIGABRT), "");
#else // TEST_STACK_CHK_GUARD
GTEST_LOG_(INFO) << "This test does nothing.\n";
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index ea88f39..421cd82 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -15,6 +15,7 @@
*/
#include <gtest/gtest.h>
+#include "BionicDeathTest.h"
#include "TemporaryFile.h"
#include <errno.h>
@@ -168,9 +169,11 @@
// Even though this isn't really a death test, we have to say "DeathTest" here so gtest knows to
// run this test (which exits normally) in its own process.
-TEST(stdlib_DeathTest, getenv_after_main_thread_exits) {
+
+class stdlib_DeathTest : public BionicDeathTest {};
+
+TEST_F(stdlib_DeathTest, getenv_after_main_thread_exits) {
// https://code.google.com/p/android/issues/detail?id=57421
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_EXIT(TestBug57421_main(), ::testing::ExitedWithCode(0), "");
}
diff --git a/tests/system_properties_test.cpp b/tests/system_properties_test.cpp
index bfd5854..c7bfee6 100644
--- a/tests/system_properties_test.cpp
+++ b/tests/system_properties_test.cpp
@@ -15,8 +15,10 @@
*/
#include <gtest/gtest.h>
-#include <sys/wait.h>
+#include "BionicDeathTest.h"
+
#include <errno.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <string>
@@ -398,9 +400,10 @@
WTERMSIG(exit_status) == SIGABRT);
}
-TEST(properties_DeathTest, read_only) {
+class properties_DeathTest : public BionicDeathTest {};
+
+TEST_F(properties_DeathTest, read_only) {
#if defined(__BIONIC__)
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
// This test only makes sense if we're talking to the real system property service.
struct stat sb;
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 21c14f4..7232ae2 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -15,6 +15,7 @@
*/
#include <gtest/gtest.h>
+#include "BionicDeathTest.h"
#include "ScopedSignalHandler.h"
#include "TemporaryFile.h"
@@ -22,10 +23,11 @@
#include <fcntl.h>
#include <limits.h>
#include <stdint.h>
-#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <unistd.h>
+
TEST(unistd, sysconf_SC_MONOTONIC_CLOCK) {
ASSERT_GT(sysconf(_SC_MONOTONIC_CLOCK), 0);
@@ -463,7 +465,8 @@
ASSERT_EQ(NULL, result);
}
-TEST(unistd_DeathTest, abort) {
- ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+class unistd_DeathTest : public BionicDeathTest {};
+
+TEST_F(unistd_DeathTest, abort) {
ASSERT_EXIT(abort(), testing::KilledBySignal(SIGABRT), "");
}