8183004: Remove code related to gtest death tests from assert macro
authorstuefe
Thu, 14 Feb 2019 19:48:57 +0100
changeset 53757 e31f39e088b7
parent 53756 adfb1c71f52c
child 53758 026e1ea616c8
8183004: Remove code related to gtest death tests from assert macro Reviewed-by: shade, kbarrett, iignatyev
src/hotspot/share/utilities/debug.cpp
src/hotspot/share/utilities/debug.hpp
test/hotspot/gtest/unittest.hpp
--- a/src/hotspot/share/utilities/debug.cpp	Thu Feb 14 09:38:19 2019 -0800
+++ b/src/hotspot/share/utilities/debug.cpp	Thu Feb 14 19:48:57 2019 +0100
@@ -61,6 +61,7 @@
 #include "utilities/vmError.hpp"
 
 #include <stdio.h>
+#include <stdarg.h>
 
 // Support for showing register content on asserts/guarantees.
 #ifdef CAN_SHOW_REGISTERS_ON_ASSERT
@@ -244,6 +245,22 @@
     context = g_assertion_context;
   }
 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
+
+#ifdef ASSERT
+  if (detail_fmt != NULL && ExecutingUnitTests) {
+    // Special handling for the sake of gtest death tests which expect the assert
+    // message to be printed in one short line to stderr (see TEST_VM_ASSERT_MSG) and
+    // cannot be tweaked to accept our normal assert message.
+    va_list detail_args_copy;
+    va_copy(detail_args_copy, detail_args);
+    ::fputs("assert failed: ", stderr);
+    ::vfprintf(stderr, detail_fmt, detail_args_copy);
+    ::fputs("\n", stderr);
+    ::fflush(stderr);
+    va_end(detail_args_copy);
+  }
+#endif
+
   VMError::report_and_die(Thread::current_or_null(), context, file, line, error_msg, detail_fmt, detail_args);
   va_end(detail_args);
 }
@@ -293,21 +310,6 @@
   report_vm_error(file, line, "Unimplemented()");
 }
 
-#ifdef ASSERT
-bool is_executing_unit_tests() {
-  return ExecutingUnitTests;
-}
-
-void report_assert_msg(const char* msg, ...) {
-  va_list ap;
-  va_start(ap, msg);
-
-  fprintf(stderr, "assert failed: %s\n", err_msg(FormatBufferDummy(), msg, ap).buffer());
-
-  va_end(ap);
-}
-#endif // ASSERT
-
 void report_untested(const char* file, int line, const char* message) {
 #ifndef PRODUCT
   warning("Untested: %s in %s: %d\n", message, file, line);
--- a/src/hotspot/share/utilities/debug.hpp	Thu Feb 14 09:38:19 2019 -0800
+++ b/src/hotspot/share/utilities/debug.hpp	Thu Feb 14 19:48:57 2019 +0100
@@ -54,9 +54,6 @@
 do {                                                                           \
   if (!(p)) {                                                                  \
     TOUCH_ASSERT_POISON;                                                       \
-    if (is_executing_unit_tests()) {                                           \
-      report_assert_msg(__VA_ARGS__);                                          \
-    }                                                                          \
     report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", __VA_ARGS__); \
     BREAKPOINT;                                                                \
   }                                                                            \
@@ -157,16 +154,10 @@
 // ATTRIBUTE_PRINTF works with gcc >= 4.8 and any other compiler.
 void report_vm_error(const char* file, int line, const char* error_msg,
                      const char* detail_fmt, ...) ATTRIBUTE_PRINTF(4, 5);
-#ifdef ASSERT
-void report_assert_msg(const char* msg, ...) ATTRIBUTE_PRINTF(1, 2);
-#endif // ASSERT
 #else
 // GCC < 4.8 warns because of empty format string.  Warning can not be switched off selectively.
 void report_vm_error(const char* file, int line, const char* error_msg,
                      const char* detail_fmt, ...);
-#ifdef ASSERT
-void report_assert_msg(const char* msg, ...);
-#endif // ASSERT
 #endif
 void report_vm_status_error(const char* file, int line, const char* error_msg,
                             int status, const char* detail);
@@ -178,11 +169,6 @@
 void report_unimplemented(const char* file, int line);
 void report_untested(const char* file, int line, const char* message);
 
-#ifdef ASSERT
-// unit test support
-bool is_executing_unit_tests();
-#endif // ASSERT
-
 void warning(const char* format, ...) ATTRIBUTE_PRINTF(1, 2);
 
 // Compile-time asserts.  Cond must be a compile-time constant expression that
--- a/test/hotspot/gtest/unittest.hpp	Thu Feb 14 09:38:19 2019 -0800
+++ b/test/hotspot/gtest/unittest.hpp	Thu Feb 14 19:48:57 2019 +0100
@@ -105,7 +105,7 @@
   TEST(category, CONCAT(name, _vm_assert)) {                        \
     ASSERT_EXIT(child_ ## category ## _ ## name ## _(),             \
                 ::testing::ExitedWithCode(1),                       \
-                "assert failed: " msg);                             \
+                "^assert failed: " msg);                             \
   }                                                                 \
                                                                     \
   void test_ ## category ## _ ## name ## _()