From 071d0259293c260804b4bd25860dcd22b5fbaf59 Mon Sep 17 00:00:00 2001 From: Yves Gerey Date: Tue, 28 Jan 2020 20:07:19 +0100 Subject: [PATCH] Activate event tracing for unit tests. For good! The --trace_event=file.json option allows to log events, for further inspection in chromium event viewer. Previous handling of this option was broken, closing the logger before the tests were even run. Bug: webrtc:10926 Change-Id: I9123d12666b5f254feeaef685def96eb8ba1c7f8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167720 Reviewed-by: Mirko Bonadei Reviewed-by: Artem Titov Commit-Queue: Yves Gerey Cr-Commit-Position: refs/heads/master@{#30401} --- test/test_main_lib.cc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/test/test_main_lib.cc b/test/test_main_lib.cc index df74182850..efa11282b0 100644 --- a/test/test_main_lib.cc +++ b/test/test_main_lib.cc @@ -122,13 +122,6 @@ class TestMainImpl : public TestMain { rtc::LogMessage::SetLogToStderr(absl::GetFlag(FLAGS_logs) || absl::GetFlag(FLAGS_verbose)); - std::string trace_event_path = absl::GetFlag(FLAGS_trace_event); - const bool capture_events = !trace_event_path.empty(); - if (capture_events) { - rtc::tracing::SetupInternalTracer(); - rtc::tracing::StartInternalCapture(trace_event_path.c_str()); - } - // InitFieldTrialsFromString stores the char*, so the char array must // outlive the application. field_trials_ = absl::GetFlag(FLAGS_force_fieldtrials); @@ -152,18 +145,22 @@ class TestMainImpl : public TestMain { rtc::ThreadManager::Instance()->WrapCurrentThread(); RTC_CHECK(rtc::Thread::Current()); - if (capture_events) { - rtc::tracing::StopInternalCapture(); - } return 0; } int Run(int argc, char* argv[]) override { + std::string trace_event_path = absl::GetFlag(FLAGS_trace_event); + const bool capture_events = !trace_event_path.empty(); + if (capture_events) { + rtc::tracing::SetupInternalTracer(); + rtc::tracing::StartInternalCapture(trace_event_path.c_str()); + } + #if defined(WEBRTC_IOS) rtc::test::InitTestSuite(RUN_ALL_TESTS, argc, argv, absl::GetFlag(FLAGS_save_chartjson_result)); rtc::test::RunTestsFromIOSApp(); - return 0; + int exit_code = 0; #else int exit_code = RUN_ALL_TESTS(); @@ -188,17 +185,21 @@ class TestMainImpl : public TestMain { result_file << "{\"version\": 3}"; result_file.close(); } +#endif + + if (capture_events) { + rtc::tracing::StopInternalCapture(); + } #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ defined(UNDEFINED_SANITIZER) // We want the test flagged as failed only for sanitizer defects, // in which case the sanitizer will override exit code with 66. - return 0; + exit_code = 0; #endif return exit_code; -#endif } ~TestMainImpl() override = default;