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
3 // found in the LICENSE file.
5 #include "base/at_exit.h"
6 #include "base/base_switches.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/logging.h"
11 #include "base/test/test_suite.h"
12 #include "build/build_config.h"
13 #include "sandbox/linux/tests/test_utils.h"
14 #include "sandbox/linux/tests/unit_tests.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/multiprocess_func_list.h"
21 // Check for leaks in our tests.
22 void RunPostTestsChecks(const base::FilePath
& orig_cwd
) {
23 if (TestUtils::CurrentProcessHasChildren()) {
24 LOG(FATAL
) << "One of the tests created a child that was not waited for. "
25 << "Please, clean up after your tests!";
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!";
37 } // namespace sandbox
39 #if defined(OS_ANDROID)
40 void UnitTestAssertHandler(const std::string
& str
) {
45 int main(int argc
, char* argv
[]) {
46 base::CommandLine::Init(argc
, argv
);
47 std::string client_func
=
48 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
49 switches::kTestChildProcess
);
50 if (!client_func
.empty()) {
51 base::AtExitManager exit_manager
;
52 return multi_process_function_list::InvokeChildProcessTest(client_func
);
55 base::FilePath orig_cwd
;
56 CHECK(GetCurrentDirectory(&orig_cwd
));
58 #if defined(OS_ANDROID)
59 // The use of Callbacks requires an AtExitManager.
60 base::AtExitManager exit_manager
;
61 testing::InitGoogleTest(&argc
, argv
);
62 // 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
64 // we still do not use this on Android, we must install the handler ourselves.
65 logging::SetLogAssertHandler(UnitTestAssertHandler
);
67 // Always go through re-execution for death tests.
68 // This makes gtest only marginally slower for us and has the
69 // additional side effect of getting rid of gtest warnings about fork()
71 ::testing::FLAGS_gtest_death_test_style
= "threadsafe";
72 #if defined(OS_ANDROID)
73 int tests_result
= RUN_ALL_TESTS();
75 int tests_result
= base::RunUnitTestsUsingBaseTestSuite(argc
, argv
);
78 sandbox::RunPostTestsChecks(orig_cwd
);