Fix SignalHandlerTest with ASAN
[folly.git] / folly / experimental / symbolizer / test / SignalHandlerTest.cpp
index 89f8159106b025721eef09af289d73e18123a6f5..1a8fae6b18bc56955e60684c8fef5335c5d48b21 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
-#include "folly/experimental/symbolizer/test/SignalHandlerTest.h"
-#include "folly/experimental/symbolizer/SignalHandler.h"
+#include <folly/experimental/symbolizer/test/SignalHandlerTest.h>
+#include <folly/experimental/symbolizer/SignalHandler.h>
 
-#include <gtest/gtest.h>
+#include <folly/CPortability.h>
+#include <folly/FileUtil.h>
+#include <folly/Range.h>
+#include <folly/portability/GTest.h>
 
-#include "folly/FileUtil.h"
-#include "folly/Range.h"
-
-namespace folly { namespace symbolizer { namespace test {
+namespace folly {
+namespace symbolizer {
+namespace test {
 
 namespace {
 
@@ -30,7 +32,6 @@ void print(StringPiece sp) {
   writeFull(STDERR_FILENO, sp.data(), sp.size());
 }
 
-
 void callback1() {
   print("Callback1\n");
 }
@@ -39,29 +40,40 @@ void callback2() {
   print("Callback2\n");
 }
 
-}  // namespace
+} // namespace
 
 TEST(SignalHandler, Simple) {
   addFatalSignalCallback(callback1);
   addFatalSignalCallback(callback2);
   installFatalSignalHandler();
+  installFatalSignalCallbacks();
 
   EXPECT_DEATH(
       failHard(),
       "^\\*\\*\\* Aborted at [0-9]+ \\(Unix time, try 'date -d @[0-9]+'\\) "
       "\\*\\*\\*\n"
       "\\*\\*\\* Signal 11 \\(SIGSEGV\\) \\(0x2a\\) received by PID [0-9]+ "
-      "\\(TID 0x[0-9a-f]+\\), stack trace: \\*\\*\\*\n"
+      "\\(pthread TID 0x[0-9a-f]+\\) \\(linux TID [0-9]+\\) "
+      "\\(maybe from PID [0-9]+, UID [0-9]+\\) "
+      "\\(code: address not mapped to object\\), "
+      "stack trace: \\*\\*\\*\n"
       ".*\n"
-      "    @ [0-9a-f]+ folly::symbolizer::test::SignalHandler_Simple_Test"
-      "::TestBody\\(\\)\n"
+      ".*    @ [0-9a-f]+.* folly::symbolizer::test::SignalHandler_Simple_Test"
+      "::TestBody\\(\\).*\n"
       ".*\n"
-      "    @ [0-9a-f]+ main\n"
+      ".*    @ [0-9a-f]+.* main.*\n"
       ".*\n"
       "Callback1\n"
       "Callback2\n"
-      );
+      ".*");
 }
+} // namespace test
+} // namespace symbolizer
+} // namespace folly
 
-
-}}}  // namespaces
+// Can't use initFacebookLight since that would install its own signal handlers
+// Can't use initFacebookNoSignals since we cannot depend on common
+int main(int argc, char** argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+  return RUN_ALL_TESTS();
+}