GTTF: Add command-line switches for number of jobs and batch limit.

BUG=236893
R=sky@chromium.org

Review URL: https://codereview.chromium.org/23760003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221315 0039d316-1c4b-4281-b951-d872f2087c98
parent b32ae166
...@@ -8,6 +8,12 @@ ...@@ -8,6 +8,12 @@
// TODO(phajdan.jr): Clean up the switch names. // TODO(phajdan.jr): Clean up the switch names.
const char switches::kTestLargeTimeout[] = "test-large-timeout"; const char switches::kTestLargeTimeout[] = "test-large-timeout";
// Maximum number of tests to run in a single batch.
const char switches::kTestLauncherBatchLimit[] = "test-launcher-batch-limit";
// Number of parallel test launcher jobs.
const char switches::kTestLauncherJobs[] = "test-launcher-jobs";
// Path to test results file in our custom test launcher format. // Path to test results file in our custom test launcher format.
const char switches::kTestLauncherOutput[] = "test-launcher-output"; const char switches::kTestLauncherOutput[] = "test-launcher-output";
......
...@@ -10,6 +10,8 @@ namespace switches { ...@@ -10,6 +10,8 @@ namespace switches {
// All switches in alphabetical order. The switches should be documented // All switches in alphabetical order. The switches should be documented
// alongside the definition of their values in the .cc file. // alongside the definition of their values in the .cc file.
extern const char kTestLargeTimeout[]; extern const char kTestLargeTimeout[];
extern const char kTestLauncherBatchLimit[];
extern const char kTestLauncherJobs[];
extern const char kTestLauncherOutput[]; extern const char kTestLauncherOutput[];
extern const char kTestTinyTimeout[]; extern const char kTestTinyTimeout[];
extern const char kUiTestActionTimeout[]; extern const char kUiTestActionTimeout[];
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/sys_info.h"
#include "base/test/gtest_xml_util.h" #include "base/test/gtest_xml_util.h"
#include "base/test/parallel_test_launcher.h" #include "base/test/parallel_test_launcher.h"
#include "base/test/test_launcher.h" #include "base/test/test_launcher.h"
...@@ -26,8 +28,8 @@ namespace base { ...@@ -26,8 +28,8 @@ namespace base {
namespace { namespace {
// This constant controls how many tests are run in a single batch. // This constant controls how many tests are run in a single batch by default.
const size_t kTestBatchLimit = 10; const size_t kDefaultTestBatchLimit = 10;
// Flag to enable the new launcher logic. // Flag to enable the new launcher logic.
// TODO(phajdan.jr): Remove it, http://crbug.com/236893 . // TODO(phajdan.jr): Remove it, http://crbug.com/236893 .
...@@ -54,7 +56,9 @@ CommandLine GetCommandLineForChildGTestProcess( ...@@ -54,7 +56,9 @@ CommandLine GetCommandLineForChildGTestProcess(
class UnitTestLauncherDelegate : public TestLauncherDelegate { class UnitTestLauncherDelegate : public TestLauncherDelegate {
public: public:
explicit UnitTestLauncherDelegate(size_t jobs) : parallel_launcher_(jobs) { UnitTestLauncherDelegate(size_t jobs, size_t batch_limit)
: parallel_launcher_(jobs),
batch_limit_(batch_limit) {
} }
virtual ~UnitTestLauncherDelegate() { virtual ~UnitTestLauncherDelegate() {
...@@ -92,7 +96,7 @@ class UnitTestLauncherDelegate : public TestLauncherDelegate { ...@@ -92,7 +96,7 @@ class UnitTestLauncherDelegate : public TestLauncherDelegate {
tests_.push_back(launch_info); tests_.push_back(launch_info);
// Run tests in batches no larger than the limit. // Run tests in batches no larger than the limit.
if (tests_.size() >= kTestBatchLimit) if (tests_.size() >= batch_limit_)
RunRemainingTests(); RunRemainingTests();
} }
...@@ -280,11 +284,28 @@ class UnitTestLauncherDelegate : public TestLauncherDelegate { ...@@ -280,11 +284,28 @@ class UnitTestLauncherDelegate : public TestLauncherDelegate {
ParallelTestLauncher parallel_launcher_; ParallelTestLauncher parallel_launcher_;
// Maximum number of tests to run in a single batch.
size_t batch_limit_;
std::vector<TestLaunchInfo> tests_; std::vector<TestLaunchInfo> tests_;
ThreadChecker thread_checker_; ThreadChecker thread_checker_;
}; };
bool GetSwitchValueAsInt(const std::string& switch_name, int* result) {
if (!CommandLine::ForCurrentProcess()->HasSwitch(switch_name))
return true;
std::string switch_value =
CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name);
if (!StringToInt(switch_value, result) || *result < 1) {
LOG(ERROR) << "Invalid value for " << switch_name << ": " << switch_value;
return false;
}
return true;
}
} // namespace } // namespace
int LaunchUnitTests(int argc, int LaunchUnitTests(int argc,
...@@ -298,22 +319,28 @@ int LaunchUnitTests(int argc, ...@@ -298,22 +319,28 @@ int LaunchUnitTests(int argc,
base::TimeTicks start_time(base::TimeTicks::Now()); base::TimeTicks start_time(base::TimeTicks::Now());
fprintf(stdout,
"Starting tests...\n"
"IMPORTANT DEBUGGING NOTE: batches of tests are run inside their own \n"
"process. For debugging a test inside a debugger, use the\n"
"--gtest_filter=<your_test_name> flag along with \n"
"--single-process-tests.\n");
fflush(stdout);
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
TestTimeouts::Initialize(); TestTimeouts::Initialize();
int jobs = SysInfo::NumberOfProcessors();
if (!GetSwitchValueAsInt(switches::kTestLauncherJobs, &jobs))
return 1;
int batch_limit = kDefaultTestBatchLimit;
if (!GetSwitchValueAsInt(switches::kTestLauncherBatchLimit, &batch_limit))
return 1;
fprintf(stdout,
"Starting tests (using %d parallel jobs)...\n"
"IMPORTANT DEBUGGING NOTE: batches of tests are run inside their\n"
"own process. For debugging a test inside a debugger, use the\n"
"--gtest_filter=<your_test_name> flag along with\n"
"--single-process-tests.\n", jobs);
fflush(stdout);
MessageLoop message_loop; MessageLoop message_loop;
// TODO(phajdan.jr): Provide an option to adjust jobs, default to number base::UnitTestLauncherDelegate delegate(jobs, batch_limit);
// of CPU cores.
base::UnitTestLauncherDelegate delegate(4);
int exit_code = base::LaunchTests(&delegate, argc, argv); int exit_code = base::LaunchTests(&delegate, argc, argv);
fprintf(stdout, fprintf(stdout,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment