summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/test/launcher/test_launcher.cc38
-rw-r--r--base/test/test_switches.cc9
-rw-r--r--base/test/test_switches.h2
3 files changed, 44 insertions, 5 deletions
diff --git a/base/test/launcher/test_launcher.cc b/base/test/launcher/test_launcher.cc
index 0076634..1d0c8fe 100644
--- a/base/test/launcher/test_launcher.cc
+++ b/base/test/launcher/test_launcher.cc
@@ -552,14 +552,42 @@ bool TestLauncher::Init() {
return false;
}
- if (!TakeInt32FromEnvironment(kTestTotalShards, &total_shards_))
- return false;
- if (!TakeInt32FromEnvironment(kTestShardIndex, &shard_index_))
- return false;
+ // Initialize sharding. Command line takes precedence over legacy environment
+ // variables.
+ if (command_line->HasSwitch(switches::kTestLauncherTotalShards) &&
+ command_line->HasSwitch(switches::kTestLauncherShardIndex)) {
+ if (!StringToInt(
+ command_line->GetSwitchValueASCII(
+ switches::kTestLauncherTotalShards),
+ &total_shards_)) {
+ LOG(ERROR) << "Invalid value for " << switches::kTestLauncherTotalShards;
+ return false;
+ }
+ if (!StringToInt(
+ command_line->GetSwitchValueASCII(
+ switches::kTestLauncherShardIndex),
+ &shard_index_)) {
+ LOG(ERROR) << "Invalid value for " << switches::kTestLauncherShardIndex;
+ return false;
+ }
+ fprintf(stdout,
+ "Using sharding settings from command line. This is shard %d/%d\n",
+ shard_index_, total_shards_);
+ fflush(stdout);
+ } else {
+ if (!TakeInt32FromEnvironment(kTestTotalShards, &total_shards_))
+ return false;
+ if (!TakeInt32FromEnvironment(kTestShardIndex, &shard_index_))
+ return false;
+ fprintf(stdout,
+ "Using sharding settings from environment. This is shard %d/%d\n",
+ shard_index_, total_shards_);
+ fflush(stdout);
+ }
if (shard_index_ < 0 ||
total_shards_ < 0 ||
shard_index_ >= total_shards_) {
- LOG(ERROR) << "Invalid environment variables: we require 0 <= "
+ LOG(ERROR) << "Invalid sharding settings: we require 0 <= "
<< kTestShardIndex << " < " << kTestTotalShards
<< ", but you have " << kTestShardIndex << "=" << shard_index_
<< ", " << kTestTotalShards << "=" << total_shards_ << ".\n";
diff --git a/base/test/test_switches.cc b/base/test/test_switches.cc
index 18b4881..50b4513 100644
--- a/base/test/test_switches.cc
+++ b/base/test/test_switches.cc
@@ -26,6 +26,15 @@ const char switches::kTestLauncherSummaryOutput[] =
const char switches::kTestLauncherPrintTestStdio[] =
"test-launcher-print-test-stdio";
+// Index of the test shard to run, starting from 0 (first shard) to total shards
+// minus one (last shard).
+const char switches::kTestLauncherShardIndex[] =
+ "test-launcher-shard-index";
+
+// Total number of shards. Must be the same for all shards.
+const char switches::kTestLauncherTotalShards[] =
+ "test-launcher-total-shards";
+
// Time (in milliseconds) that the tests should wait before timing out.
const char switches::kTestLauncherTimeout[] = "test-launcher-timeout";
// TODO(phajdan.jr): Clean up the switch names.
diff --git a/base/test/test_switches.h b/base/test/test_switches.h
index 330b925..a492058 100644
--- a/base/test/test_switches.h
+++ b/base/test/test_switches.h
@@ -15,6 +15,8 @@ extern const char kTestLauncherJobs[];
extern const char kTestLauncherOutput[];
extern const char kTestLauncherSummaryOutput[];
extern const char kTestLauncherPrintTestStdio[];
+extern const char kTestLauncherShardIndex[];
+extern const char kTestLauncherTotalShards[];
extern const char kTestLauncherTimeout[];
extern const char kTestTinyTimeout[];
extern const char kUiTestActionTimeout[];