Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: sandbox/linux/tests/main.cc

Issue 2638763004: Report CHECK/DCHECK to test launcher summary output. (Closed)
Patch Set: Fix review issues. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/base_switches.h" 6 #include "base/base_switches.h"
7 #include "base/bind.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
8 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/test/logging_utils.h"
11 #include "base/test/test_suite.h" 13 #include "base/test/test_suite.h"
12 #include "build/build_config.h" 14 #include "build/build_config.h"
13 #include "sandbox/linux/tests/test_utils.h" 15 #include "sandbox/linux/tests/test_utils.h"
14 #include "sandbox/linux/tests/unit_tests.h" 16 #include "sandbox/linux/tests/unit_tests.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/multiprocess_func_list.h" 18 #include "testing/multiprocess_func_list.h"
17 19
18 namespace sandbox { 20 namespace sandbox {
19 namespace { 21 namespace {
20 22
21 // Check for leaks in our tests. 23 // Check for leaks in our tests.
22 void RunPostTestsChecks(const base::FilePath& orig_cwd) { 24 void RunPostTestsChecks(const base::FilePath& orig_cwd) {
23 if (TestUtils::CurrentProcessHasChildren()) { 25 if (TestUtils::CurrentProcessHasChildren()) {
24 LOG(FATAL) << "One of the tests created a child that was not waited for. " 26 LOG(FATAL) << "One of the tests created a child that was not waited for. "
25 << "Please, clean up after your tests!"; 27 << "Please, clean up after your tests!";
26 } 28 }
27 29
28 base::FilePath cwd; 30 base::FilePath cwd;
29 CHECK(GetCurrentDirectory(&cwd)); 31 CHECK(GetCurrentDirectory(&cwd));
30 if (orig_cwd != cwd) { 32 if (orig_cwd != cwd) {
31 LOG(FATAL) << "One of the tests changed the current working directory. " 33 LOG(FATAL) << "One of the tests changed the current working directory. "
32 << "Please, clean up after your tests!"; 34 << "Please, clean up after your tests!";
33 } 35 }
34 } 36 }
35 37
36 } // namespace 38 } // namespace
37 } // namespace sandbox 39 } // namespace sandbox
38 40
39 #if !defined(SANDBOX_USES_BASE_TEST_SUITE) 41 #if !defined(SANDBOX_USES_BASE_TEST_SUITE)
40 void UnitTestAssertHandler(const std::string& str) { 42 void UnitTestAssertHandler(const char* file, int line, size_t message_start,
Paweł Hajdan Jr. 2017/02/13 17:17:24 This seems to still use the old signature.
alex-ac 2017/02/14 10:34:28 Done.
43 size_t stack_start, const std::string& str) {
41 _exit(1); 44 _exit(1);
42 } 45 }
43 #endif 46 #endif
44 47
45 int main(int argc, char* argv[]) { 48 int main(int argc, char* argv[]) {
46 base::CommandLine::Init(argc, argv); 49 base::CommandLine::Init(argc, argv);
47 std::string client_func; 50 std::string client_func;
48 #if defined(SANDBOX_USES_BASE_TEST_SUITE) 51 #if defined(SANDBOX_USES_BASE_TEST_SUITE)
49 client_func = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 52 client_func = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
50 switches::kTestChildProcess); 53 switches::kTestChildProcess);
51 #endif 54 #endif
52 if (!client_func.empty()) { 55 if (!client_func.empty()) {
53 base::AtExitManager exit_manager; 56 base::AtExitManager exit_manager;
54 return multi_process_function_list::InvokeChildProcessTest(client_func); 57 return multi_process_function_list::InvokeChildProcessTest(client_func);
55 } 58 }
56 59
57 base::FilePath orig_cwd; 60 base::FilePath orig_cwd;
58 CHECK(GetCurrentDirectory(&orig_cwd)); 61 CHECK(GetCurrentDirectory(&orig_cwd));
59 62
60 #if !defined(SANDBOX_USES_BASE_TEST_SUITE) 63 #if !defined(SANDBOX_USES_BASE_TEST_SUITE)
61 // The use of Callbacks requires an AtExitManager. 64 // The use of Callbacks requires an AtExitManager.
62 base::AtExitManager exit_manager; 65 base::AtExitManager exit_manager;
63 testing::InitGoogleTest(&argc, argv); 66 testing::InitGoogleTest(&argc, argv);
64 // Death tests rely on LOG(FATAL) triggering an exit (the default behavior is 67 // Death tests rely on LOG(FATAL) triggering an exit (the default behavior is
65 // SIGABRT). The normal test launcher does this at initialization, but since 68 // SIGABRT). The normal test launcher does this at initialization, but since
66 // we still do not use this on Android, we must install the handler ourselves. 69 // we still do not use this on Android, we must install the handler ourselves.
67 logging::SetLogAssertHandler(UnitTestAssertHandler); 70 logging::ScopedLogAssertHandler scoped_assert_handler(
71 base::Bind(UnitTestAssertHandler));
68 #endif 72 #endif
69 // Always go through re-execution for death tests. 73 // Always go through re-execution for death tests.
70 // This makes gtest only marginally slower for us and has the 74 // This makes gtest only marginally slower for us and has the
71 // additional side effect of getting rid of gtest warnings about fork() 75 // additional side effect of getting rid of gtest warnings about fork()
72 // safety. 76 // safety.
73 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; 77 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
74 #if !defined(SANDBOX_USES_BASE_TEST_SUITE) 78 #if !defined(SANDBOX_USES_BASE_TEST_SUITE)
75 int tests_result = RUN_ALL_TESTS(); 79 int tests_result = RUN_ALL_TESTS();
76 #else 80 #else
77 int tests_result = base::RunUnitTestsUsingBaseTestSuite(argc, argv); 81 int tests_result = base::RunUnitTestsUsingBaseTestSuite(argc, argv);
78 #endif 82 #endif
79 83
80 sandbox::RunPostTestsChecks(orig_cwd); 84 sandbox::RunPostTestsChecks(orig_cwd);
81 return tests_result; 85 return tests_result;
82 } 86 }
OLDNEW
« base/test/test_suite.cc ('K') | « net/tools/stress_cache/stress_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698