summaryrefslogtreecommitdiffstats
path: root/debuggerd/debuggerd_test.cpp
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-05-08 20:18:33 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-05-08 20:18:34 +0000
commit2bc6196faa38e0d5a4bd0bf6ca962dcfa60248a4 (patch)
treef4f5678c211a570ef824efdeaca955f2e8818bd2 /debuggerd/debuggerd_test.cpp
parentee9e5d098191cf1fa0932db7498963de3d6dcf1b (diff)
parent2e7b8e2d1aff139895127a93c020bddb98a0f26e (diff)
downloadsystem_core-2bc6196faa38e0d5a4bd0bf6ca962dcfa60248a4.tar.gz
system_core-2bc6196faa38e0d5a4bd0bf6ca962dcfa60248a4.tar.bz2
system_core-2bc6196faa38e0d5a4bd0bf6ca962dcfa60248a4.zip
Merge "debuggerd_handler: use syscall(__NR_get[pt]id) instead of get[pt]id."
Diffstat (limited to 'debuggerd/debuggerd_test.cpp')
-rw-r--r--debuggerd/debuggerd_test.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp
index 568879ed5..0b4bbfb60 100644
--- a/debuggerd/debuggerd_test.cpp
+++ b/debuggerd/debuggerd_test.cpp
@@ -29,6 +29,7 @@
#include <android-base/file.h>
#include <android-base/logging.h>
+#include <android-base/macros.h>
#include <android-base/parseint.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
@@ -149,7 +150,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 StartProcess(std::function<void()> function, std::function<pid_t()> forker = fork);
void StartCrasher(const std::string& crash_type);
void FinishCrasher();
void AssertDeath(int signo);
@@ -195,14 +196,14 @@ void CrasherTest::FinishIntercept(int* result) {
}
}
-void CrasherTest::StartProcess(std::function<void()> function) {
+void CrasherTest::StartProcess(std::function<void()> function, std::function<pid_t()> forker) {
unique_fd read_pipe;
unique_fd crasher_read_pipe;
if (!Pipe(&crasher_read_pipe, &crasher_pipe)) {
FAIL() << "failed to create pipe: " << strerror(errno);
}
- crasher_pid = fork();
+ crasher_pid = forker();
if (crasher_pid == -1) {
FAIL() << "fork failed: " << strerror(errno);
} else if (crasher_pid == 0) {
@@ -527,6 +528,37 @@ TEST_F(CrasherTest, capabilities) {
ASSERT_MATCH(result, R"(#00 pc [0-9a-f]+\s+ /system/lib)" ARCH_SUFFIX R"(/libc.so \(tgkill)");
}
+TEST_F(CrasherTest, fake_pid) {
+ int intercept_result;
+ unique_fd output_fd;
+
+ // Prime the getpid/gettid caches.
+ UNUSED(getpid());
+ UNUSED(gettid());
+
+ std::function<pid_t()> clone_fn = []() {
+ return syscall(__NR_clone, SIGCHLD, nullptr, nullptr, nullptr, nullptr);
+ };
+ StartProcess(
+ []() {
+ ASSERT_NE(getpid(), syscall(__NR_getpid));
+ ASSERT_NE(gettid(), syscall(__NR_gettid));
+ raise(SIGSEGV);
+ },
+ clone_fn);
+
+ StartIntercept(&output_fd);
+ FinishCrasher();
+ AssertDeath(SIGSEGV);
+ FinishIntercept(&intercept_result);
+
+ ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";
+
+ std::string result;
+ 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(crash_dump, zombie) {
pid_t forkpid = fork();