OLD | NEW |
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" | |
8 #include "base/command_line.h" | 7 #include "base/command_line.h" |
9 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/test/test_suite.h" | 11 #include "base/test/test_suite.h" |
13 #include "build/build_config.h" | 12 #include "build/build_config.h" |
14 #include "sandbox/linux/tests/test_utils.h" | 13 #include "sandbox/linux/tests/test_utils.h" |
15 #include "sandbox/linux/tests/unit_tests.h" | 14 #include "sandbox/linux/tests/unit_tests.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "testing/multiprocess_func_list.h" | 16 #include "testing/multiprocess_func_list.h" |
(...skipping 13 matching lines...) Expand all Loading... |
31 if (orig_cwd != cwd) { | 30 if (orig_cwd != cwd) { |
32 LOG(FATAL) << "One of the tests changed the current working directory. " | 31 LOG(FATAL) << "One of the tests changed the current working directory. " |
33 << "Please, clean up after your tests!"; | 32 << "Please, clean up after your tests!"; |
34 } | 33 } |
35 } | 34 } |
36 | 35 |
37 } // namespace | 36 } // namespace |
38 } // namespace sandbox | 37 } // namespace sandbox |
39 | 38 |
40 #if !defined(SANDBOX_USES_BASE_TEST_SUITE) | 39 #if !defined(SANDBOX_USES_BASE_TEST_SUITE) |
41 void UnitTestAssertHandler(const char* file, | 40 void UnitTestAssertHandler(const std::string& str) { |
42 int line, | |
43 const base::StringPiece message, | |
44 const base::StringPiece stack_trace) { | |
45 _exit(1); | 41 _exit(1); |
46 } | 42 } |
47 #endif | 43 #endif |
48 | 44 |
49 int main(int argc, char* argv[]) { | 45 int main(int argc, char* argv[]) { |
50 base::CommandLine::Init(argc, argv); | 46 base::CommandLine::Init(argc, argv); |
51 std::string client_func; | 47 std::string client_func; |
52 #if defined(SANDBOX_USES_BASE_TEST_SUITE) | 48 #if defined(SANDBOX_USES_BASE_TEST_SUITE) |
53 client_func = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 49 client_func = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
54 switches::kTestChildProcess); | 50 switches::kTestChildProcess); |
55 #endif | 51 #endif |
56 if (!client_func.empty()) { | 52 if (!client_func.empty()) { |
57 base::AtExitManager exit_manager; | 53 base::AtExitManager exit_manager; |
58 return multi_process_function_list::InvokeChildProcessTest(client_func); | 54 return multi_process_function_list::InvokeChildProcessTest(client_func); |
59 } | 55 } |
60 | 56 |
61 base::FilePath orig_cwd; | 57 base::FilePath orig_cwd; |
62 CHECK(GetCurrentDirectory(&orig_cwd)); | 58 CHECK(GetCurrentDirectory(&orig_cwd)); |
63 | 59 |
64 #if !defined(SANDBOX_USES_BASE_TEST_SUITE) | 60 #if !defined(SANDBOX_USES_BASE_TEST_SUITE) |
65 // The use of Callbacks requires an AtExitManager. | 61 // The use of Callbacks requires an AtExitManager. |
66 base::AtExitManager exit_manager; | 62 base::AtExitManager exit_manager; |
67 testing::InitGoogleTest(&argc, argv); | 63 testing::InitGoogleTest(&argc, argv); |
68 // Death tests rely on LOG(FATAL) triggering an exit (the default behavior is | 64 // Death tests rely on LOG(FATAL) triggering an exit (the default behavior is |
69 // SIGABRT). The normal test launcher does this at initialization, but since | 65 // SIGABRT). The normal test launcher does this at initialization, but since |
70 // we still do not use this on Android, we must install the handler ourselves. | 66 // we still do not use this on Android, we must install the handler ourselves. |
71 logging::ScopedLogAssertHandler scoped_assert_handler( | 67 logging::SetLogAssertHandler(UnitTestAssertHandler); |
72 base::Bind(UnitTestAssertHandler)); | |
73 #endif | 68 #endif |
74 // Always go through re-execution for death tests. | 69 // Always go through re-execution for death tests. |
75 // This makes gtest only marginally slower for us and has the | 70 // This makes gtest only marginally slower for us and has the |
76 // additional side effect of getting rid of gtest warnings about fork() | 71 // additional side effect of getting rid of gtest warnings about fork() |
77 // safety. | 72 // safety. |
78 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; | 73 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
79 #if !defined(SANDBOX_USES_BASE_TEST_SUITE) | 74 #if !defined(SANDBOX_USES_BASE_TEST_SUITE) |
80 int tests_result = RUN_ALL_TESTS(); | 75 int tests_result = RUN_ALL_TESTS(); |
81 #else | 76 #else |
82 int tests_result = base::RunUnitTestsUsingBaseTestSuite(argc, argv); | 77 int tests_result = base::RunUnitTestsUsingBaseTestSuite(argc, argv); |
83 #endif | 78 #endif |
84 | 79 |
85 sandbox::RunPostTestsChecks(orig_cwd); | 80 sandbox::RunPostTestsChecks(orig_cwd); |
86 return tests_result; | 81 return tests_result; |
87 } | 82 } |
OLD | NEW |