Merge "Switch to libbase SilentDeathTest." am: 27cf254193 am: d6aabe9294

Original change: https://android-review.googlesource.com/c/platform/bionic/+/1671973

Change-Id: If6a9955cafba68100d4d867a0a3558445d5b8c99
This commit is contained in:
Elliott Hughes 2021-04-12 19:27:29 +00:00 committed by Automerger Merge Worker
commit ce0d14734b
18 changed files with 52 additions and 86 deletions

View file

@ -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",

View file

@ -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_;
};

View file

@ -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);

View file

@ -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() {}

View file

@ -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) {

View file

@ -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;

View file

@ -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
};

View file

@ -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 {

View file

@ -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__)

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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.

View file

@ -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;

View file

@ -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

View file

@ -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__)

View file

@ -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)

View file

@ -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), "");
}