diff options
author | Christopher Ferris <cferris@google.com> | 2017-09-06 14:15:28 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2017-09-06 17:08:44 -0700 |
commit | edccd84763c96fedb88b66f413de534fd302d882 (patch) | |
tree | 1ab630e5a8a041710198bd3b0c4a030e33f61348 /libunwindstack/tests/MemoryRemoteTest.cpp | |
parent | 18149b6764437eeb88d0ab78e565ec9cb2384779 (diff) |
Fix UnwindTest repeatability.
- Rewrite some of the UnwindTest tests to properly wait for the process
to be ready.
- Add a TestScopedPidReaper to make sure that fork process get killed even
if the test fails. Add this to all tests that fail.
- Create a quiesce function to be used by all of the tests that will
wait after attaching to a process.
Bug: 65287279
Test: Ran unit tests on hikey960 board and on host repeatedly.
Change-Id: I57084120396f34d8dfb852f3d814bef2056f1b54
Diffstat (limited to 'libunwindstack/tests/MemoryRemoteTest.cpp')
-rw-r--r-- | libunwindstack/tests/MemoryRemoteTest.cpp | 31 |
1 files changed, 5 insertions, 26 deletions
diff --git a/libunwindstack/tests/MemoryRemoteTest.cpp b/libunwindstack/tests/MemoryRemoteTest.cpp index f8965b2ce..a66d0c550 100644 --- a/libunwindstack/tests/MemoryRemoteTest.cpp +++ b/libunwindstack/tests/MemoryRemoteTest.cpp @@ -22,7 +22,6 @@ #include <sys/mman.h> #include <sys/ptrace.h> #include <sys/types.h> -#include <time.h> #include <unistd.h> #include <vector> @@ -34,32 +33,18 @@ #include <unwindstack/Memory.h> #include "MemoryFake.h" +#include "TestUtils.h" namespace unwindstack { class MemoryRemoteTest : public ::testing::Test { protected: - static uint64_t NanoTime() { - struct timespec t = { 0, 0 }; - clock_gettime(CLOCK_MONOTONIC, &t); - return static_cast<uint64_t>(t.tv_sec * NS_PER_SEC + t.tv_nsec); - } - static bool Attach(pid_t pid) { if (ptrace(PTRACE_ATTACH, pid, 0, 0) == -1) { return false; } - uint64_t start = NanoTime(); - siginfo_t si; - while (TEMP_FAILURE_RETRY(ptrace(PTRACE_GETSIGINFO, pid, 0, &si)) < 0 && errno == ESRCH) { - if ((NanoTime() - start) > 10 * NS_PER_SEC) { - printf("%d: Failed to stop after 10 seconds.\n", pid); - return false; - } - usleep(30); - } - return true; + return TestQuiescePid(pid); } static bool Detach(pid_t pid) { @@ -79,6 +64,7 @@ TEST_F(MemoryRemoteTest, read) { exit(1); } ASSERT_LT(0, pid); + TestScopedPidReaper reap(pid); ASSERT_TRUE(Attach(pid)); @@ -91,9 +77,6 @@ TEST_F(MemoryRemoteTest, read) { } ASSERT_TRUE(Detach(pid)); - - kill(pid, SIGKILL); - ASSERT_EQ(pid, wait(nullptr)); } TEST_F(MemoryRemoteTest, read_fail) { @@ -111,6 +94,7 @@ TEST_F(MemoryRemoteTest, read_fail) { exit(1); } ASSERT_LT(0, pid); + TestScopedPidReaper reap(pid); ASSERT_TRUE(Attach(pid)); @@ -132,9 +116,6 @@ TEST_F(MemoryRemoteTest, read_fail) { ASSERT_EQ(0, munmap(src, pagesize)); ASSERT_TRUE(Detach(pid)); - - kill(pid, SIGKILL); - ASSERT_EQ(pid, wait(nullptr)); } TEST_F(MemoryRemoteTest, read_overflow) { @@ -152,6 +133,7 @@ TEST_F(MemoryRemoteTest, read_illegal) { exit(1); } ASSERT_LT(0, pid); + TestScopedPidReaper reap(pid); ASSERT_TRUE(Attach(pid)); @@ -162,9 +144,6 @@ TEST_F(MemoryRemoteTest, read_illegal) { ASSERT_FALSE(remote.Read(0, dst.data(), 100)); ASSERT_TRUE(Detach(pid)); - - kill(pid, SIGKILL); - ASSERT_EQ(pid, wait(nullptr)); } } // namespace unwindstack |