diff options
Diffstat (limited to 'debuggerd/debuggerd_test.cpp')
-rw-r--r-- | debuggerd/debuggerd_test.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp index 3b2419365..e7503e97e 100644 --- a/debuggerd/debuggerd_test.cpp +++ b/debuggerd/debuggerd_test.cpp @@ -17,6 +17,7 @@ #include <err.h> #include <fcntl.h> #include <unistd.h> +#include <sys/prctl.h> #include <sys/types.h> #include <chrono> @@ -90,6 +91,7 @@ class CrasherTest : public ::testing::Test { // Returns -1 if we fail to read a response from tombstoned, otherwise the received return code. void FinishIntercept(int* result); + void StartProcess(std::function<void()> function); void StartCrasher(const std::string& crash_type); void FinishCrasher(); void AssertDeath(int signo); @@ -166,9 +168,8 @@ void CrasherTest::FinishIntercept(int* result) { } } -void CrasherTest::StartCrasher(const std::string& crash_type) { - std::string type = "wait-" + crash_type; - +void CrasherTest::StartProcess(std::function<void()> function) { + unique_fd read_pipe; unique_fd crasher_read_pipe; if (!Pipe(&crasher_read_pipe, &crasher_pipe)) { FAIL() << "failed to create pipe: " << strerror(errno); @@ -182,9 +183,17 @@ void CrasherTest::StartCrasher(const std::string& crash_type) { dup2(crasher_read_pipe.get(), STDIN_FILENO); dup2(devnull.get(), STDOUT_FILENO); dup2(devnull.get(), STDERR_FILENO); + function(); + _exit(0); + } +} + +void CrasherTest::StartCrasher(const std::string& crash_type) { + std::string type = "wait-" + crash_type; + StartProcess([type]() { execl(CRASHER_PATH, CRASHER_PATH, type.c_str(), nullptr); err(1, "exec failed"); - } + }); } void CrasherTest::FinishCrasher() { @@ -379,3 +388,20 @@ TEST_F(CrasherTest, backtrace) { ConsumeFd(std::move(output_fd), &result); ASSERT_MATCH(result, R"(#00 pc [0-9a-f]+\s+ /system/lib)" ARCH_SUFFIX R"(/libc.so \(tgkill)"); } + +TEST_F(CrasherTest, PR_SET_DUMPABLE_0_crash) { + StartProcess([]() { + prctl(PR_SET_DUMPABLE, 0); + volatile char* null = static_cast<char*>(nullptr); + *null = '\0'; + }); + AssertDeath(SIGSEGV); +} + +TEST_F(CrasherTest, PR_SET_DUMPABLE_0_raise) { + StartProcess([]() { + prctl(PR_SET_DUMPABLE, 0); + raise(SIGUSR1); + }); + AssertDeath(SIGUSR1); +} |