OSDN Git Service

Don't use PR_SET_DUMPABLE to prevent crash dumping in death tests.
authorJosh Gao <jmgao@google.com>
Thu, 12 Oct 2017 20:32:45 +0000 (13:32 -0700)
committerJosh Gao <jmgao@google.com>
Tue, 17 Oct 2017 04:31:37 +0000 (21:31 -0700)
Bug: http://b/27833000
Test: bionic-unit-tests are way faster
Change-Id: I6ae029edcd4c4b4b0dfaf613fc17c208d3cb24d1

tests/BionicDeathTest.h

index 31d2d6e..3e8d7b2 100644 (file)
 #ifndef BIONIC_TESTS_BIONIC_DEATH_TEST_H_
 #define BIONIC_TESTS_BIONIC_DEATH_TEST_H_
 
-#include <gtest/gtest.h>
+#include <signal.h>
 
-#include <sys/prctl.h>
+#include <gtest/gtest.h>
 
 class BionicDeathTest : public testing::Test {
  protected:
   virtual void SetUp() {
     // Suppress debuggerd stack traces. Too slow.
-    old_dumpable_ = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
-    prctl(PR_SET_DUMPABLE, 0, 0, 0, 0);
-    ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+    for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) {
+      struct sigaction action = {};
+      action.sa_handler = SIG_DFL;
+      sigaction(signo, &action, &previous_);
+    }
   }
 
   virtual void TearDown() {
-    prctl(PR_SET_DUMPABLE, old_dumpable_, 0, 0, 0, 0);
+    for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) {
+      sigaction(signo, &previous_, nullptr);
+    }
   }
 
  private:
-  int old_dumpable_;
+  struct sigaction previous_;
 };
 
 #endif // BIONIC_TESTS_BIONIC_DEATH_TEST_H_