diff options
author | Elliott Hughes <enh@google.com> | 2021-04-09 17:13:09 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2021-04-12 10:01:20 -0700 |
commit | 141b917018048c5fda567785740dfaaf38e66f1e (patch) | |
tree | 144416c96d8e3d1406ed78d8221a72a174317d80 /tests | |
parent | 999d82e51d8b96c622ecb63c69b56e7e7753e47d (diff) |
Switch to libbase SilentDeathTest.
Bug: http://b/184955378
Test: treehugger
Change-Id: Ie0849224074da92203340a741a86a24a4a3702c2
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Android.bp | 7 | ||||
-rw-r--r-- | tests/BionicDeathTest.h | 45 | ||||
-rw-r--r-- | tests/assert_test.cpp | 4 | ||||
-rw-r--r-- | tests/cfi_test.cpp | 7 | ||||
-rw-r--r-- | tests/clang_fortify_tests.cpp | 4 | ||||
-rw-r--r-- | tests/error_test.cpp | 4 | ||||
-rw-r--r-- | tests/fdsan_test.cpp | 7 | ||||
-rw-r--r-- | tests/fortify_test.cpp | 5 | ||||
-rw-r--r-- | tests/pidfd_test.cpp | 9 | ||||
-rw-r--r-- | tests/pthread_test.cpp | 4 | ||||
-rw-r--r-- | tests/semaphore_test.cpp | 7 | ||||
-rw-r--r-- | tests/setjmp_test.cpp | 5 | ||||
-rw-r--r-- | tests/stack_protector_test.cpp | 5 | ||||
-rw-r--r-- | tests/stdio_test.cpp | 6 | ||||
-rw-r--r-- | tests/stdlib_test.cpp | 4 | ||||
-rw-r--r-- | tests/system_properties_test.cpp | 4 | ||||
-rw-r--r-- | tests/threads_test.cpp | 5 | ||||
-rw-r--r-- | tests/unistd_test.cpp | 6 |
18 files changed, 52 insertions, 86 deletions
diff --git a/tests/Android.bp b/tests/Android.bp index 02a33eec4..476b8f5fb 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -567,6 +567,9 @@ cc_defaults { "-Wno-strlcpy-strlcat-size", "-Wno-strncat-size", ], + static_libs: [ + "libbase", + ], } cc_defaults { @@ -575,6 +578,9 @@ cc_defaults { "-U_FORTIFY_SOURCE", ], srcs: ["fortify_test_main.cpp"], + static_libs: [ + "libbase", + ], tidy: false, target: { host: { @@ -839,7 +845,6 @@ cc_defaults { ], static_libs: [ // The order of these libraries matters, do not shuffle them. - "libbase", "libmeminfo", "libziparchive", "libz", diff --git a/tests/BionicDeathTest.h b/tests/BionicDeathTest.h deleted file mode 100644 index f70839a0f..000000000 --- a/tests/BionicDeathTest.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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. - */ - -#pragma once - -#include <signal.h> - -#include <gtest/gtest.h> - -#if !defined(__BIONIC__) -#define sigaction64 sigaction -#endif - -class BionicDeathTest : public testing::Test { - protected: - virtual void SetUp() { - // Suppress debuggerd stack traces. Too slow. - for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) { - struct sigaction64 action = { .sa_handler = SIG_DFL }; - sigaction64(signo, &action, &previous_); - } - } - - virtual void TearDown() { - for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) { - sigaction64(signo, &previous_, nullptr); - } - } - - private: - struct sigaction64 previous_; -}; diff --git a/tests/assert_test.cpp b/tests/assert_test.cpp index 714e22a59..769852abf 100644 --- a/tests/assert_test.cpp +++ b/tests/assert_test.cpp @@ -19,9 +19,9 @@ #undef NDEBUG #include <assert.h> -#include "BionicDeathTest.h" +#include <android-base/silent_death_test.h> -using assert_DeathTest = BionicDeathTest; +using assert_DeathTest = SilentDeathTest; TEST(assert, assert_true) { assert(true); diff --git a/tests/cfi_test.cpp b/tests/cfi_test.cpp index d3cd8d1b8..9a6ed9ac6 100644 --- a/tests/cfi_test.cpp +++ b/tests/cfi_test.cpp @@ -15,12 +15,13 @@ */ #include <dlfcn.h> -#include <gtest/gtest.h> #include <sys/stat.h> #include <vector> -#include "BionicDeathTest.h" +#include <android-base/silent_death_test.h> +#include <gtest/gtest.h> + #include "gtest_globals.h" #include "utils.h" @@ -35,7 +36,7 @@ void __cfi_slowpath_diag(uint64_t CallSiteTypeId, void* Ptr, void* DiagData); size_t __cfi_shadow_size(); } -using cfi_test_DeathTest = BionicDeathTest; +using cfi_test_DeathTest = SilentDeathTest; static void f() {} diff --git a/tests/clang_fortify_tests.cpp b/tests/clang_fortify_tests.cpp index 035517083..5768f1fb3 100644 --- a/tests/clang_fortify_tests.cpp +++ b/tests/clang_fortify_tests.cpp @@ -94,14 +94,14 @@ #include <wchar.h> #ifndef COMPILATION_TESTS +#include <android-base/silent_death_test.h> #include <gtest/gtest.h> -#include "BionicDeathTest.h" #define CONCAT2(x, y) x##y #define CONCAT(x, y) CONCAT2(x, y) #define FORTIFY_TEST_NAME CONCAT(CONCAT(clang_fortify_test_, _FORTIFY_SOURCE), _DeathTest) -using FORTIFY_TEST_NAME = BionicDeathTest; +using FORTIFY_TEST_NAME = SilentDeathTest; template <typename Fn> __attribute__((noreturn)) static void ExitAfter(Fn&& f) { diff --git a/tests/error_test.cpp b/tests/error_test.cpp index e03c8d44f..e114f064c 100644 --- a/tests/error_test.cpp +++ b/tests/error_test.cpp @@ -30,7 +30,9 @@ #include <error.h> -#include "BionicDeathTest.h" +#include <android-base/silent_death_test.h> + +using error_DeathTest = SilentDeathTest; static size_t g_test_error_print_progname_invocation_count; diff --git a/tests/fdsan_test.cpp b/tests/fdsan_test.cpp index c294ff353..016970ffb 100644 --- a/tests/fdsan_test.cpp +++ b/tests/fdsan_test.cpp @@ -16,8 +16,6 @@ #include <gtest/gtest.h> -#include "BionicDeathTest.h" - #include <dirent.h> #include <errno.h> #include <fcntl.h> @@ -32,6 +30,7 @@ #include <unordered_map> +#include <android-base/silent_death_test.h> #include <android-base/unique_fd.h> #define FDSAN_TEST(test_name) TEST_F(FdsanTest, test_name) @@ -49,12 +48,12 @@ struct fdsan : public ::testing::Test { } }; -struct fdsan_DeathTest : public BionicDeathTest { +struct fdsan_DeathTest : public SilentDeathTest { #if defined(__BIONIC__) void SetUp() override { android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_FATAL); signal(BIONIC_SIGNAL_DEBUGGER, SIG_DFL); // Disable debuggerd. - BionicDeathTest::SetUp(); + SilentDeathTest::SetUp(); } #endif }; diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp index 3ca0223b2..4abee67dc 100644 --- a/tests/fortify_test.cpp +++ b/tests/fortify_test.cpp @@ -15,7 +15,6 @@ */ #include <gtest/gtest.h> -#include "BionicDeathTest.h" #include <fcntl.h> #include <malloc.h> @@ -28,6 +27,8 @@ #include <sys/types.h> #include <time.h> +#include <android-base/silent_death_test.h> + #if __BIONIC__ #define ASSERT_FORTIFY(expr) ASSERT_EXIT(expr, testing::KilledBySignal(SIGABRT), "FORTIFY") #else @@ -40,7 +41,7 @@ #define DEATHTEST_EVALUATOR(name) DEATHTEST_PASTER(name) #define DEATHTEST DEATHTEST_EVALUATOR(TEST_NAME) -class DEATHTEST : public BionicDeathTest {}; +using DEATHTEST = SilentDeathTest; #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE == 2 struct foo { diff --git a/tests/pidfd_test.cpp b/tests/pidfd_test.cpp index 7c691ef16..b9fadb4a0 100644 --- a/tests/pidfd_test.cpp +++ b/tests/pidfd_test.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include <gtest/gtest.h> + #include <errno.h> #include <fcntl.h> #include <signal.h> @@ -24,16 +26,13 @@ #include <sys/pidfd.h> #endif +#include <android-base/silent_death_test.h> #include <android-base/unique_fd.h> -#include <gtest/gtest.h> - -#include "BionicDeathTest.h" - using android::base::unique_fd; using namespace std::chrono_literals; -using pidfd_DeathTest = BionicDeathTest; +using pidfd_DeathTest = SilentDeathTest; TEST(pidfd, pidfd_open) { #if defined(__BIONIC__) diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp index 1cbe3de35..1a00460bc 100644 --- a/tests/pthread_test.cpp +++ b/tests/pthread_test.cpp @@ -38,14 +38,14 @@ #include <android-base/macros.h> #include <android-base/parseint.h> #include <android-base/scopeguard.h> +#include <android-base/silent_death_test.h> #include <android-base/strings.h> #include "private/bionic_constants.h" -#include "BionicDeathTest.h" #include "SignalUtils.h" #include "utils.h" -using pthread_DeathTest = BionicDeathTest; +using pthread_DeathTest = SilentDeathTest; TEST(pthread, pthread_key_create) { pthread_key_t key; diff --git a/tests/semaphore_test.cpp b/tests/semaphore_test.cpp index ed0fcf17e..f3f60208d 100644 --- a/tests/semaphore_test.cpp +++ b/tests/semaphore_test.cpp @@ -17,17 +17,18 @@ #include <semaphore.h> #include <errno.h> -#include <gtest/gtest.h> #include <limits.h> #include <pthread.h> #include <time.h> #include <unistd.h> -#include "BionicDeathTest.h" +#include <android-base/silent_death_test.h> +#include <gtest/gtest.h> + #include "SignalUtils.h" #include "private/bionic_constants.h" -using semaphore_DeathTest = BionicDeathTest; +using semaphore_DeathTest = SilentDeathTest; TEST(semaphore, sem_init) { sem_t s; diff --git a/tests/setjmp_test.cpp b/tests/setjmp_test.cpp index ec1badcf2..ee126eb11 100644 --- a/tests/setjmp_test.cpp +++ b/tests/setjmp_test.cpp @@ -21,10 +21,11 @@ #include <sys/syscall.h> #include <unistd.h> -#include "BionicDeathTest.h" +#include <android-base/silent_death_test.h> + #include "SignalUtils.h" -using setjmp_DeathTest = BionicDeathTest; +using setjmp_DeathTest = SilentDeathTest; TEST(setjmp, setjmp_smoke) { int value; diff --git a/tests/stack_protector_test.cpp b/tests/stack_protector_test.cpp index 9fe7bb105..a95e0373c 100644 --- a/tests/stack_protector_test.cpp +++ b/tests/stack_protector_test.cpp @@ -19,7 +19,6 @@ */ #include <gtest/gtest.h> -#include "BionicDeathTest.h" #include <pthread.h> #include <stdint.h> @@ -27,6 +26,8 @@ #include <unistd.h> #include <set> +#include <android-base/silent_death_test.h> + #include "private/bionic_tls.h" extern "C" pid_t gettid(); // glibc defines this but doesn't declare it anywhere. @@ -99,7 +100,7 @@ TEST(stack_protector, global_guard) { #endif } -class stack_protector_DeathTest : public BionicDeathTest {}; +using stack_protector_DeathTest = SilentDeathTest; TEST_F(stack_protector_DeathTest, modify_stack_protector) { // In another file to prevent inlining, which removes stack protection. diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 5491589a5..5736e1787 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -33,10 +33,10 @@ #include <vector> #include <android-base/file.h> +#include <android-base/silent_death_test.h> #include <android-base/test_utils.h> #include <android-base/unique_fd.h> -#include "BionicDeathTest.h" #include "utils.h" // This #include is actually a test too. We have to duplicate the @@ -56,8 +56,8 @@ using namespace std::string_literals; -using stdio_DeathTest = BionicDeathTest; -using stdio_nofortify_DeathTest = BionicDeathTest; +using stdio_DeathTest = SilentDeathTest; +using stdio_nofortify_DeathTest = SilentDeathTest; static void SetFileTo(const char* path, const char* content) { FILE* fp; diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp index 90ef8619f..6c7966d72 100644 --- a/tests/stdlib_test.cpp +++ b/tests/stdlib_test.cpp @@ -31,9 +31,9 @@ #include <android-base/file.h> #include <android-base/macros.h> +#include <android-base/silent_death_test.h> #include <gtest/gtest.h> -#include "BionicDeathTest.h" #include "math_data_test.h" #include "utils.h" @@ -447,7 +447,7 @@ static void TestBug57421_main() { // 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. -class stdlib_DeathTest : public BionicDeathTest {}; +using stdlib_DeathTest = SilentDeathTest; TEST_F(stdlib_DeathTest, getenv_after_main_thread_exits) { // https://code.google.com/p/android/issues/detail?id=57421 diff --git a/tests/system_properties_test.cpp b/tests/system_properties_test.cpp index 6d696c79f..aa8fef4dc 100644 --- a/tests/system_properties_test.cpp +++ b/tests/system_properties_test.cpp @@ -15,7 +15,6 @@ */ #include <gtest/gtest.h> -#include "BionicDeathTest.h" #include <errno.h> #include <sys/wait.h> @@ -25,6 +24,7 @@ #include <thread> #include <android-base/file.h> +#include <android-base/silent_death_test.h> using namespace std::literals; @@ -425,7 +425,7 @@ bool KilledByFault::operator()(int exit_status) const { WTERMSIG(exit_status) == SIGABRT); } -class properties_DeathTest : public BionicDeathTest {}; +using properties_DeathTest = SilentDeathTest; TEST_F(properties_DeathTest, read_only) { #if defined(__BIONIC__) diff --git a/tests/threads_test.cpp b/tests/threads_test.cpp index 5fafff38d..c1e9b123a 100644 --- a/tests/threads_test.cpp +++ b/tests/threads_test.cpp @@ -60,7 +60,8 @@ static int exit_arg(void* arg) { #include <thread> -#include "BionicDeathTest.h" +#include <android-base/silent_death_test.h> + #include "SignalUtils.h" TEST(threads, call_once) { @@ -361,7 +362,7 @@ TEST(threads, thrd_create__thrd_exit) { #endif } -class threads_DeathTest : public BionicDeathTest {}; +using threads_DeathTest = SilentDeathTest; TEST(threads_DeathTest, thrd_exit_main_thread) { #if !defined(HAVE_THREADS_H) diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp index 595ba90c4..7d1e6128b 100644 --- a/tests/unistd_test.cpp +++ b/tests/unistd_test.cpp @@ -16,7 +16,6 @@ #include <gtest/gtest.h> -#include "BionicDeathTest.h" #include "SignalUtils.h" #include "utils.h" @@ -37,6 +36,7 @@ #include <chrono> #include <android-base/file.h> +#include <android-base/silent_death_test.h> #include <android-base/strings.h> #include "private/get_cpu_count_from_string.h" @@ -53,6 +53,8 @@ #define UNISTD_DEATHTEST unistd_DeathTest #endif +using UNISTD_DEATHTEST = SilentDeathTest; + using namespace std::chrono_literals; static void* get_brk() { @@ -711,8 +713,6 @@ TEST(UNISTD_TEST, hwasan_vfork) { } } -class UNISTD_DEATHTEST : public BionicDeathTest {}; - TEST_F(UNISTD_DEATHTEST, abort) { ASSERT_EXIT(abort(), testing::KilledBySignal(SIGABRT), ""); } |