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

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

Issue 1147463003: Linux sandbox: support build configuration without base test framework (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 18 matching lines...) Expand all
29 CHECK(GetCurrentDirectory(&cwd)); 29 CHECK(GetCurrentDirectory(&cwd));
30 if (orig_cwd != cwd) { 30 if (orig_cwd != cwd) {
31 LOG(FATAL) << "One of the tests changed the current working directory. " 31 LOG(FATAL) << "One of the tests changed the current working directory. "
32 << "Please, clean up after your tests!"; 32 << "Please, clean up after your tests!";
33 } 33 }
34 } 34 }
35 35
36 } // namespace 36 } // namespace
37 } // namespace sandbox 37 } // namespace sandbox
38 38
39 #if defined(OS_ANDROID) 39 #if !defined(SANDBOX_USES_BASE_TEST_SUITE)
40 void UnitTestAssertHandler(const std::string& str) { 40 void UnitTestAssertHandler(const std::string& str) {
41 _exit(1); 41 _exit(1);
42 } 42 }
43 #endif 43 #endif
44 44
45 int main(int argc, char* argv[]) { 45 int main(int argc, char* argv[]) {
46 base::CommandLine::Init(argc, argv); 46 base::CommandLine::Init(argc, argv);
47 std::string client_func = 47 std::string client_func;
48 #if defined(SANDBOX_USES_BASE_TEST_SUITE)
49 client_func =
48 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 50 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
49 switches::kTestChildProcess); 51 switches::kTestChildProcess);
52 #endif
50 if (!client_func.empty()) { 53 if (!client_func.empty()) {
51 base::AtExitManager exit_manager; 54 base::AtExitManager exit_manager;
52 return multi_process_function_list::InvokeChildProcessTest(client_func); 55 return multi_process_function_list::InvokeChildProcessTest(client_func);
53 } 56 }
54 57
55 base::FilePath orig_cwd; 58 base::FilePath orig_cwd;
56 CHECK(GetCurrentDirectory(&orig_cwd)); 59 CHECK(GetCurrentDirectory(&orig_cwd));
57 60
58 #if defined(OS_ANDROID) 61 #if !defined(SANDBOX_USES_BASE_TEST_SUITE)
59 // The use of Callbacks requires an AtExitManager. 62 // The use of Callbacks requires an AtExitManager.
60 base::AtExitManager exit_manager; 63 base::AtExitManager exit_manager;
61 testing::InitGoogleTest(&argc, argv); 64 testing::InitGoogleTest(&argc, argv);
62 // Death tests rely on LOG(FATAL) triggering an exit (the default behavior is 65 // Death tests rely on LOG(FATAL) triggering an exit (the default behavior is
63 // SIGABRT). The normal test launcher does this at initialization, but since 66 // SIGABRT). The normal test launcher does this at initialization, but since
64 // we still do not use this on Android, we must install the handler ourselves. 67 // we still do not use this on Android, we must install the handler ourselves.
65 logging::SetLogAssertHandler(UnitTestAssertHandler); 68 logging::SetLogAssertHandler(UnitTestAssertHandler);
66 #endif 69 #endif
67 // Always go through re-execution for death tests. 70 // Always go through re-execution for death tests.
68 // This makes gtest only marginally slower for us and has the 71 // This makes gtest only marginally slower for us and has the
69 // additional side effect of getting rid of gtest warnings about fork() 72 // additional side effect of getting rid of gtest warnings about fork()
70 // safety. 73 // safety.
71 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; 74 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
72 #if defined(OS_ANDROID) 75 #if !defined(SANDBOX_USES_BASE_TEST_SUITE)
73 int tests_result = RUN_ALL_TESTS(); 76 int tests_result = RUN_ALL_TESTS();
74 #else 77 #else
75 int tests_result = base::RunUnitTestsUsingBaseTestSuite(argc, argv); 78 int tests_result = base::RunUnitTestsUsingBaseTestSuite(argc, argv);
76 #endif 79 #endif
77 80
78 sandbox::RunPostTestsChecks(orig_cwd); 81 sandbox::RunPostTestsChecks(orig_cwd);
79 return tests_result; 82 return tests_result;
80 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698