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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « sandbox/linux/system_headers/x86_64_linux_syscalls.h ('k') | services/gles2/gpu_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/test/test_suite.h" 11 #include "base/test/test_suite.h"
12 #include "build/build_config.h"
10 #include "sandbox/linux/tests/test_utils.h" 13 #include "sandbox/linux/tests/test_utils.h"
11 #include "sandbox/linux/tests/unit_tests.h" 14 #include "sandbox/linux/tests/unit_tests.h"
12 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/multiprocess_func_list.h" 16 #include "testing/multiprocess_func_list.h"
14 17
15 namespace sandbox { 18 namespace sandbox {
16 namespace { 19 namespace {
17 20
18 // Check for leaks in our tests. 21 // Check for leaks in our tests.
19 void RunPostTestsChecks() { 22 void RunPostTestsChecks(const base::FilePath& orig_cwd) {
20 if (TestUtils::CurrentProcessHasChildren()) { 23 if (TestUtils::CurrentProcessHasChildren()) {
21 LOG(ERROR) << "One of the tests created a child that was not waited for. " 24 LOG(FATAL) << "One of the tests created a child that was not waited for. "
22 << "Please, clean-up after your tests!"; 25 << "Please, clean up after your tests!";
26 }
27
28 base::FilePath cwd;
29 CHECK(GetCurrentDirectory(&cwd));
30 if (orig_cwd != cwd) {
31 LOG(FATAL) << "One of the tests changed the current working directory. "
32 << "Please, clean up after your tests!";
23 } 33 }
24 } 34 }
25 35
26 } // namespace 36 } // namespace
27 } // namespace sandbox 37 } // namespace sandbox
28 38
29 #if defined(OS_ANDROID) 39 #if defined(OS_ANDROID)
30 void UnitTestAssertHandler(const std::string& str) { 40 void UnitTestAssertHandler(const std::string& str) {
31 _exit(1); 41 _exit(1);
32 } 42 }
33 #endif 43 #endif
34 44
35 int main(int argc, char* argv[]) { 45 int main(int argc, char* argv[]) {
36 base::CommandLine::Init(argc, argv); 46 base::CommandLine::Init(argc, argv);
37 std::string client_func = 47 std::string client_func =
38 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 48 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
39 switches::kTestChildProcess); 49 switches::kTestChildProcess);
40 if (!client_func.empty()) { 50 if (!client_func.empty()) {
41 base::AtExitManager exit_manager; 51 base::AtExitManager exit_manager;
42 return multi_process_function_list::InvokeChildProcessTest(client_func); 52 return multi_process_function_list::InvokeChildProcessTest(client_func);
43 } 53 }
44 54
55 base::FilePath orig_cwd;
56 CHECK(GetCurrentDirectory(&orig_cwd));
57
45 #if defined(OS_ANDROID) 58 #if defined(OS_ANDROID)
46 // The use of Callbacks requires an AtExitManager. 59 // The use of Callbacks requires an AtExitManager.
47 base::AtExitManager exit_manager; 60 base::AtExitManager exit_manager;
48 testing::InitGoogleTest(&argc, argv); 61 testing::InitGoogleTest(&argc, argv);
49 // Death tests rely on LOG(FATAL) triggering an exit (the default behavior is 62 // Death tests rely on LOG(FATAL) triggering an exit (the default behavior is
50 // SIGABRT). The normal test launcher does this at initialization, but since 63 // SIGABRT). The normal test launcher does this at initialization, but since
51 // we still do not use this on Android, we must install the handler ourselves. 64 // we still do not use this on Android, we must install the handler ourselves.
52 logging::SetLogAssertHandler(UnitTestAssertHandler); 65 logging::SetLogAssertHandler(UnitTestAssertHandler);
53 #endif 66 #endif
54 // Always go through re-execution for death tests. 67 // Always go through re-execution for death tests.
55 // This makes gtest only marginally slower for us and has the 68 // This makes gtest only marginally slower for us and has the
56 // additional side effect of getting rid of gtest warnings about fork() 69 // additional side effect of getting rid of gtest warnings about fork()
57 // safety. 70 // safety.
58 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; 71 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
59 #if defined(OS_ANDROID) 72 #if defined(OS_ANDROID)
60 int tests_result = RUN_ALL_TESTS(); 73 int tests_result = RUN_ALL_TESTS();
61 #else 74 #else
62 int tests_result = base::RunUnitTestsUsingBaseTestSuite(argc, argv); 75 int tests_result = base::RunUnitTestsUsingBaseTestSuite(argc, argv);
63 #endif 76 #endif
64 77
65 sandbox::RunPostTestsChecks(); 78 sandbox::RunPostTestsChecks(orig_cwd);
66 return tests_result; 79 return tests_result;
67 } 80 }
OLDNEW
« no previous file with comments | « sandbox/linux/system_headers/x86_64_linux_syscalls.h ('k') | services/gles2/gpu_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698