| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/test/unit_test_launcher.h" | 5 #include "base/test/unit_test_launcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "base/threading/thread_checker.h" | 24 #include "base/threading/thread_checker.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 namespace base { | 27 namespace base { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // This constant controls how many tests are run in a single batch by default. | 31 // This constant controls how many tests are run in a single batch by default. |
| 32 const size_t kDefaultTestBatchLimit = 10; | 32 const size_t kDefaultTestBatchLimit = 10; |
| 33 | 33 |
| 34 const char kHelpFlag[] = "help"; |
| 35 |
| 34 // Flag to enable the new launcher logic. | 36 // Flag to enable the new launcher logic. |
| 35 // TODO(phajdan.jr): Remove it, http://crbug.com/236893 . | 37 // TODO(phajdan.jr): Remove it, http://crbug.com/236893 . |
| 36 const char kBraveNewTestLauncherFlag[] = "brave-new-test-launcher"; | 38 const char kBraveNewTestLauncherFlag[] = "brave-new-test-launcher"; |
| 37 | 39 |
| 38 // Flag to run all tests in a single process. | 40 // Flag to run all tests in a single process. |
| 39 const char kSingleProcessTestsFlag[] = "single-process-tests"; | 41 const char kSingleProcessTestsFlag[] = "single-process-tests"; |
| 40 | 42 |
| 43 void PrintUsage() { |
| 44 fprintf(stdout, |
| 45 "Runs tests using the gtest framework, each batch of tests being\n" |
| 46 "run in their own process. Supported command-line flags:\n" |
| 47 "\n" |
| 48 " --single-process-tests\n" |
| 49 " Runs the tests and the launcher in the same process. Useful\n" |
| 50 " for debugging a specific test in a debugger.\n" |
| 51 " --test-launcher-jobs=N\n" |
| 52 " Sets the number of parallel test jobs to N.\n" |
| 53 " --test-launcher-batch-limit=N\n" |
| 54 " Sets the limit of test batch to run in a single process to N.\n" |
| 55 " --gtest_filter=...\n" |
| 56 " Runs a subset of tests (see --gtest_help for more info).\n" |
| 57 " --help\n" |
| 58 " Shows this message.\n" |
| 59 " --gtest_help\n" |
| 60 " Shows the gtest help message.\n"); |
| 61 fflush(stdout); |
| 62 } |
| 63 |
| 41 // Returns command line for child GTest process based on the command line | 64 // Returns command line for child GTest process based on the command line |
| 42 // of current process. |test_names| is a vector of test full names | 65 // of current process. |test_names| is a vector of test full names |
| 43 // (e.g. "A.B"), |output_file| is path to the GTest XML output file. | 66 // (e.g. "A.B"), |output_file| is path to the GTest XML output file. |
| 44 CommandLine GetCommandLineForChildGTestProcess( | 67 CommandLine GetCommandLineForChildGTestProcess( |
| 45 const std::vector<std::string>& test_names, | 68 const std::vector<std::string>& test_names, |
| 46 const base::FilePath& output_file) { | 69 const base::FilePath& output_file) { |
| 47 CommandLine new_cmd_line(*CommandLine::ForCurrentProcess()); | 70 CommandLine new_cmd_line(*CommandLine::ForCurrentProcess()); |
| 48 | 71 |
| 49 new_cmd_line.AppendSwitchPath(switches::kTestLauncherOutput, output_file); | 72 new_cmd_line.AppendSwitchPath(switches::kTestLauncherOutput, output_file); |
| 50 new_cmd_line.AppendSwitchASCII(kGTestFilterFlag, JoinString(test_names, ":")); | 73 new_cmd_line.AppendSwitchASCII(kGTestFilterFlag, JoinString(test_names, ":")); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 328 |
| 306 return true; | 329 return true; |
| 307 } | 330 } |
| 308 | 331 |
| 309 } // namespace | 332 } // namespace |
| 310 | 333 |
| 311 int LaunchUnitTests(int argc, | 334 int LaunchUnitTests(int argc, |
| 312 char** argv, | 335 char** argv, |
| 313 const RunTestSuiteCallback& run_test_suite) { | 336 const RunTestSuiteCallback& run_test_suite) { |
| 314 CommandLine::Init(argc, argv); | 337 CommandLine::Init(argc, argv); |
| 315 if (CommandLine::ForCurrentProcess()->HasSwitch(kSingleProcessTestsFlag) || | 338 if (CommandLine::ForCurrentProcess()->HasSwitch(kGTestHelpFlag) || |
| 339 CommandLine::ForCurrentProcess()->HasSwitch(kSingleProcessTestsFlag) || |
| 316 !CommandLine::ForCurrentProcess()->HasSwitch(kBraveNewTestLauncherFlag)) { | 340 !CommandLine::ForCurrentProcess()->HasSwitch(kBraveNewTestLauncherFlag)) { |
| 317 return run_test_suite.Run(); | 341 return run_test_suite.Run(); |
| 318 } | 342 } |
| 319 | 343 |
| 344 if (CommandLine::ForCurrentProcess()->HasSwitch(kHelpFlag)) { |
| 345 PrintUsage(); |
| 346 return 0; |
| 347 } |
| 348 |
| 320 base::TimeTicks start_time(base::TimeTicks::Now()); | 349 base::TimeTicks start_time(base::TimeTicks::Now()); |
| 321 | 350 |
| 322 testing::InitGoogleTest(&argc, argv); | 351 testing::InitGoogleTest(&argc, argv); |
| 323 TestTimeouts::Initialize(); | 352 TestTimeouts::Initialize(); |
| 324 | 353 |
| 325 int jobs = SysInfo::NumberOfProcessors(); | 354 int jobs = SysInfo::NumberOfProcessors(); |
| 326 if (!GetSwitchValueAsInt(switches::kTestLauncherJobs, &jobs)) | 355 if (!GetSwitchValueAsInt(switches::kTestLauncherJobs, &jobs)) |
| 327 return 1; | 356 return 1; |
| 328 | 357 |
| 329 int batch_limit = kDefaultTestBatchLimit; | 358 int batch_limit = kDefaultTestBatchLimit; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 345 | 374 |
| 346 fprintf(stdout, | 375 fprintf(stdout, |
| 347 "Tests took %" PRId64 " seconds.\n", | 376 "Tests took %" PRId64 " seconds.\n", |
| 348 (base::TimeTicks::Now() - start_time).InSeconds()); | 377 (base::TimeTicks::Now() - start_time).InSeconds()); |
| 349 fflush(stdout); | 378 fflush(stdout); |
| 350 | 379 |
| 351 return exit_code; | 380 return exit_code; |
| 352 } | 381 } |
| 353 | 382 |
| 354 } // namespace base | 383 } // namespace base |
| OLD | NEW |