Commit 040aca7a authored by Mike West's avatar Mike West Committed by Commit Bot

Revert "Reland "[base] Cleanup StackTraceTest.OutputToStream #ifdef soup.""

This reverts commit 06b27c6f.

Reason for revert: 

This consistently fails under MSan with:

```
[ RUN      ] StackTraceTest.OutputToStream
../../base/debug/stack_trace_unittest.cc:82: Failure
Value of: backtrace_message.find("testing::Test::Run") != std::string::npos
  Actual: false
Expected: true
Expected a demangled symbol in backtrace:
    #0 0x5608768c4adb in backtrace /b/swarming/w/ir/cache/builder/src/third_party/llvm/compiler-rt/lib/msan/../sanitizer_common/sanitizer_common_interceptors.inc:4101:13
    #1 0x56087a80709b in base::debug::CollectStackTrace(void**, unsigned long) ./../../base/debug/stack_trace_posix.cc:840:39
    #2 0x56087a45d4da in StackTrace ./../../base/debug/stack_trace.cc:206:12
    #3 0x56087a45d4da in base::debug::StackTrace::StackTrace() ./../../base/debug/stack_trace.cc:203:28
    #4 0x5608770e0c0f in base::debug::StackTraceTest_OutputToStream_Test::TestBody() ./../../base/debug/stack_trace_unittest.cc:39:14
    #5 0x56087a2470c5 in HandleExceptionsInMethodIfSupported<testing::Test, void> ./../../third_party/googletest/src/googletest/src/gtest.cc:0:0
    #6 0x56087a2470c5 in testing::Test::Run() ./../../third_party/googletest/src/googletest/src/gtest.cc:2508:5
    #7 0x56087a24abde in testing::TestInfo::Run() ./../../third_party/googletest/src/googletest/src/gtest.cc:2684:11
    #8 0x56087a24c81a in testing::TestSuite::Run() ./../../third_party/googletest/src/googletest/src/gtest.cc:2816:28
    #9 0x56087a28aa4a in testing::internal::UnitTestImpl::RunAllTests() ./../../third_party/googletest/src/googletest/src/gtest.cc:5338:44
    #10 0x56087a288cae in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> ./../../third_party/googletest/src/googletest/src/gtest.cc:0:0
    #11 0x56087a288cae in testing::UnitTest::Run() ./../../third_party/googletest/src/googletest/src/gtest.cc:4925:10
    #12 0x56087a9047a5 in RUN_ALL_TESTS ./../../third_party/googletest/src/googletest/include/gtest/gtest.h:2473:46
    #13 0x56087a9047a5 in base::TestSuite::Run() ./../../base/test/test_suite.cc:394:16
    #14 0x56087a98ce2a in Run ./../../base/callback.h:98:12
    #15 0x56087a98ce2a in base::(anonymous namespace)::LaunchUnitTestsInternal(base::OnceCallback<int ()>, unsigned long, int, unsigned long, bool, base::OnceCallback<void ()>) ./../../base/test/launcher/unit_test_launcher.cc:158:38
    #16 0x56087a98c8bf in base::LaunchUnitTests(int, char**, base::OnceCallback<int ()>, unsigned long) ./../../base/test/launcher/unit_test_launcher.cc:228:10
    #17 0x56087a8b39a0 in main ./../../base/test/run_all_base_unittests.cc:12:10
    #18 0x7f4d99e7d830 in __libc_start_main ??:0:0
    #19 0x56087688a67a in _start ??:0:0

Stack trace:
    #0 0x56087a45d4da in StackTrace ./../../base/debug/stack_trace.cc:206:12
    #1 0x56087a45d4da in base::debug::StackTrace::StackTrace() ./../../base/debug/stack_trace.cc:203:28
    #2 0x56087a1f22de in StackTraceGetter::CurrentStackTrace(int, int) ./../../third_party/googletest/custom/gtest/internal/custom/stack_trace_getter.cc:22:27
    #3 0x56087a226149 in testing::internal::UnitTestImpl::CurrentOsStackTraceExceptTop(int) ./../../third_party/googletest/src/googletest/src/gtest.cc:820:35
```

 (see https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8896945774609420288/+/steps/base_unittests/0/logs/Deterministic_failure:_StackTraceTest.OutputToStream__status_FAILURE_/0)

Original change's description:
> Reland "[base] Cleanup StackTraceTest.OutputToStream #ifdef soup."
> 
> This was most recently reverted in
> https://chromium-review.googlesource.com/c/chromium/src/+/1906545
> due to failures on some ChromeOS platforms, which lack the necessary
> tables to allow stack-trace unwinding.
> 
> Bug: 999737, 706728
> Change-Id: I7889416cd2ae9b6a09caf9eebb68a5ccf8bf4ca3
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1911680
> Auto-Submit: Wez <wez@chromium.org>
> Commit-Queue: Albert J. Wong <ajwong@chromium.org>
> Reviewed-by: Albert J. Wong <ajwong@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#714735}

TBR=ajwong@chromium.org,wez@chromium.org

Change-Id: I94bb1c35c8a8b205b72f4a7705996276453f9c2a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 999737, 706728
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1912704Reviewed-by: default avatarMike West <mkwst@chromium.org>
Commit-Queue: Mike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714858}
parent ebce384d
......@@ -31,11 +31,25 @@ typedef MultiProcessTest StackTraceTest;
typedef testing::Test StackTraceTest;
#endif
#if !defined(__UCLIBC__) && !defined(_AIX)
// StackTrace::OutputToStream() is not implemented under uclibc, nor AIX.
// See https://crbug.com/706728
// TODO(https://crbug.com/999737): Rewrite this test for better clarity and
// correctness.
// Note: On Linux, this test currently only fully works on Debug builds.
// See comments in the #ifdef soup if you intend to change this.
#if defined(OS_WIN)
// Always fails on Windows: crbug.com/32070
#define MAYBE_OutputToStream DISABLED_OutputToStream
#elif defined(OS_FUCHSIA) && defined(OFFICIAL_BUILD)
TEST_F(StackTraceTest, OutputToStream) {
// Backtraces aren't supported by Fuchsia release-optimized builds.
#define MAYBE_OutputToStream DISABLED_OutputToStream
#else
#define MAYBE_OutputToStream OutputToStream
#endif
#if !defined(__UCLIBC__) && !defined(_AIX)
TEST_F(StackTraceTest, MAYBE_OutputToStream) {
StackTrace trace;
// Dump the trace into a string.
......@@ -46,53 +60,76 @@ TEST_F(StackTraceTest, OutputToStream) {
// ToString() should produce the same output.
EXPECT_EQ(backtrace_message, trace.ToString());
size_t frames_found = 0;
const void* const* addresses = trace.Addresses(&frames_found);
#if defined(OFFICIAL_BUILD) && defined(OS_POSIX) && !defined(OS_MACOSX)
#if defined(OS_POSIX) && !defined(OS_MACOSX) && NDEBUG
// Stack traces require an extra data table that bloats our binaries,
// so they're turned off for official builds. Stop the test here, so
// it at least verifies that StackTrace calls don't crash.
return;
#endif // defined(OFFICIAL_BUILD) && defined(OS_POSIX) && !defined(OS_MACOSX)
ASSERT_TRUE(addresses);
ASSERT_GT(frames_found, 5u) << "Too few frames found.";
#if defined(OS_FUCHSIA) || defined(OS_ANDROID)
// Under Fuchsia and Android, StackTrace emits executable build-Ids and
// address offsets which are symbolized on the test host system, rather than
// being symbolized in-process.
// so they're turned off for release builds. We stop the test here,
// at least letting us verify that the calls don't crash.
return;
#endif // defined(OS_FUCHSIA) || defined(OS_ANDROID)
#endif // defined(OS_POSIX) && !defined(OS_MACOSX) && NDEBUG
#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER)
// Configurations such as ASAN and TSan emit unsymbolized stacks.
return;
#endif // defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER)
size_t frames_found = 0;
trace.Addresses(&frames_found);
ASSERT_GE(frames_found, 5u) <<
"No stack frames found. Skipping rest of test.";
// Check if the output has symbol initialization warning. If it does, fail.
ASSERT_EQ(backtrace_message.find("Dumping unresolved backtrace"),
std::string::npos)
<< "Unable to resolve symbols.";
std::string::npos) <<
"Unable to resolve symbols. Skipping rest of test.";
#if defined(OS_MACOSX)
#if 0
// Disabled due to -fvisibility=hidden in build config.
// Symbol resolution via the backtrace_symbol function does not work well
// in OS X.
// See this thread:
//
// http://lists.apple.com/archives/darwin-dev/2009/Mar/msg00111.html
//
// Just check instead that we find our way back to the "start" symbol
// which should be the first symbol in the trace.
//
// TODO(port): Find a more reliable way to resolve symbols.
// Expect to at least find main.
EXPECT_TRUE(backtrace_message.find("start") != std::string::npos)
<< "Expected to find start in backtrace:\n"
<< backtrace_message;
#endif
#elif defined(USE_SYMBOLIZE)
// This branch is for gcc-compiled code, but not Mac due to the
// above #if.
// Expect a demangled symbol.
// Note that Windows Release builds omit the function parameters from the
// demangled stack output, otherwise this could be "testing::Test::Run()".
EXPECT_TRUE(backtrace_message.find("testing::Test::Run") != std::string::npos)
EXPECT_TRUE(backtrace_message.find("testing::Test::Run()") !=
std::string::npos)
<< "Expected a demangled symbol in backtrace:\n"
<< backtrace_message;
#elif 0
// This is the fall-through case; it used to cover Windows.
// But it's disabled because of varying buildbot configs;
// some lack symbols.
// Expect to at least find main.
EXPECT_TRUE(backtrace_message.find("main") != std::string::npos)
<< "Expected to find main in backtrace:\n"
<< backtrace_message;
#if defined(OS_WIN)
// MSVC doesn't allow the use of C99's __func__ within C++, so we fake it with
// MSVC's __FUNCTION__ macro.
#define __func__ __FUNCTION__
#endif
// Expect to find this function as well.
// Note: This will fail if not linked with -rdynamic (aka -export_dynamic)
EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos)
<< "Expected to find " << __func__ << " in backtrace:\n"
<< backtrace_message;
#endif // define(OS_MACOSX)
}
#if !defined(OFFICIAL_BUILD) && !defined(NO_UNWIND_TABLES)
......@@ -109,7 +146,7 @@ TEST_F(StackTraceTest, TruncatedTrace) {
truncated.Addresses(&count);
EXPECT_EQ(2u, count);
}
#endif // !defined(OFFICIAL_BUILD) && !defined(NO_UNWIND_TABLES)
#endif // !defined(OFFICIAL_BUILD)
// The test is used for manual testing, e.g., to see the raw output.
TEST_F(StackTraceTest, DebugOutputToStream) {
......@@ -157,7 +194,7 @@ TEST_F(StackTraceTest, DebugOutputToStreamWithNullPrefix) {
trace.ToStringWithPrefix(nullptr);
}
#endif // !defined(__UCLIBC__) && !defined(_AIX)
#endif // !defined(__UCLIBC__)
#if defined(OS_POSIX) && !defined(OS_ANDROID)
#if !defined(OS_IOS)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment