| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 099ded5 commit fa46c90
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,6 +137,10 @@ GTEST_DECLARE_int32_(repeat); | |||
| 137 | 137 | // only torn down once, for the last. | |
| 138 | 138 | GTEST_DECLARE_bool_(recreate_environments_when_repeating); | |
| 139 | 139 | ||
| 140 | + // Together these flags determine which tests are run if the test is sharded. | ||
| 141 | + GTEST_DECLARE_int32_(shard_index); | ||
| 142 | + GTEST_DECLARE_int32_(total_shards); | ||
| 143 | + | ||
| 140 | 144 | // This flag controls whether Google Test includes Google Test internal | |
| 141 | 145 | // stack frames in failure stack traces. | |
| 142 | 146 | GTEST_DECLARE_bool_(show_internal_stack_frames); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -246,15 +246,12 @@ GTEST_API_ std::string WideStringToUtf8(const wchar_t* str, int num_chars); | |||
| 246 | 246 | // be created, prints an error and exits. | |
| 247 | 247 | void WriteToShardStatusFileIfNeeded(); | |
| 248 | 248 | ||
| 249 | - // Checks whether sharding is enabled by examining the relevant | ||
| 250 | - // environment variable values. If the variables are present, | ||
| 251 | - // but inconsistent (e.g., shard_index >= total_shards), prints | ||
| 252 | - // an error and exits. If in_subprocess_for_death_test, sharding is | ||
| 249 | + // Checks whether sharding is enabled by examining the relevant flag values. | ||
| 250 | + // If the flags are set, but inconsistent (e.g., shard_index >= total_shards), | ||
| 251 | + // prints an error and exits. If in_subprocess_for_death_test, sharding is | ||
| 253 | 252 | // disabled because it must only be applied to the original test | |
| 254 | 253 | // process. Otherwise, we could filter out death tests we intended to execute. | |
| 255 | - GTEST_API_ bool ShouldShard(const char* total_shards_str, | ||
| 256 | - const char* shard_index_str, | ||
| 257 | - bool in_subprocess_for_death_test); | ||
| 254 | + GTEST_API_ bool ShouldShard(bool in_subprocess_for_death_test); | ||
| 258 | 255 | ||
| 259 | 256 | // Parses the environment variable var as a 32-bit integer. If it is unset, | |
| 260 | 257 | // returns default_val. If it is not a 32-bit integer, prints an error and | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -407,6 +407,18 @@ GTEST_DEFINE_bool_( | |||
| 407 | 407 | "if exceptions are enabled or exit the program with a non-zero code " | |
| 408 | 408 | "otherwise. For use with an external test framework."); | |
| 409 | 409 | ||
| 410 | + GTEST_DEFINE_int32_( | ||
| 411 | + shard_index, | ||
| 412 | + testing::internal::Int32FromEnvOrDie(testing::kTestShardIndex, -1), | ||
| 413 | + "The zero-based index of the shard to run. A value of -1 " | ||
| 414 | + "(the default) indicates that sharding is disabled."); | ||
| 415 | + | ||
| 416 | + GTEST_DEFINE_int32_( | ||
| 417 | + total_shards, | ||
| 418 | + testing::internal::Int32FromEnvOrDie(testing::kTestTotalShards, -1), | ||
| 419 | + "The total number of shards to use when running tests in parallel. " | ||
| 420 | + "A value of -1 (the default) indicates that sharding is disabled."); | ||
| 421 | + | ||
| 410 | 422 | #if GTEST_USE_OWN_FLAGFILE_FLAG_ | |
| 411 | 423 | GTEST_DEFINE_string_( | |
| 412 | 424 | flagfile, testing::internal::StringFromGTestEnv("flagfile", ""), | |
@@ -3475,11 +3487,11 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart( | |||
| 3475 | 3487 | filter); | |
| 3476 | 3488 | } | |
| 3477 | 3489 | ||
| 3478 | - if (internal::ShouldShard(kTestTotalShards, kTestShardIndex, false)) { | ||
| 3479 | - const int32_t shard_index = Int32FromEnvOrDie(kTestShardIndex, -1); | ||
| 3480 | - ColoredPrintf(GTestColor::kYellow, "Note: This is test shard %d of %s.\n", | ||
| 3490 | + if (internal::ShouldShard(false)) { | ||
| 3491 | + const int32_t shard_index = GTEST_FLAG_GET(shard_index); | ||
| 3492 | + ColoredPrintf(GTestColor::kYellow, "Note: This is test shard %d of %d.\n", | ||
| 3481 | 3493 | static_cast<int>(shard_index) + 1, | |
| 3482 | - internal::posix::GetEnv(kTestTotalShards)); | ||
| 3494 | + GTEST_FLAG_GET(total_shards)); | ||
| 3483 | 3495 | } | |
| 3484 | 3496 | ||
| 3485 | 3497 | if (GTEST_FLAG_GET(shuffle)) { | |
@@ -5983,8 +5995,7 @@ bool UnitTestImpl::RunAllTests() { | |||
| 5983 | 5995 | #endif // defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) | |
| 5984 | 5996 | #endif // GTEST_HAS_DEATH_TEST | |
| 5985 | 5997 | ||
| 5986 | - const bool should_shard = ShouldShard(kTestTotalShards, kTestShardIndex, | ||
| 5987 | - in_subprocess_for_death_test); | ||
| 5998 | + const bool should_shard = ShouldShard(in_subprocess_for_death_test); | ||
| 5988 | 5999 | ||
| 5989 | 6000 | // Compares the full test names with the filter to decide which | |
| 5990 | 6001 | // tests to run. | |
@@ -6196,45 +6207,44 @@ void WriteToShardStatusFileIfNeeded() { | |||
| 6196 | 6207 | } | |
| 6197 | 6208 | #endif // GTEST_HAS_FILE_SYSTEM | |
| 6198 | 6209 | ||
| 6199 | - // Checks whether sharding is enabled by examining the relevant | ||
| 6200 | - // environment variable values. If the variables are present, | ||
| 6201 | - // but inconsistent (i.e., shard_index >= total_shards), prints | ||
| 6202 | - // an error and exits. If in_subprocess_for_death_test, sharding is | ||
| 6203 | - // disabled because it must only be applied to the original test | ||
| 6204 | - // process. Otherwise, we could filter out death tests we intended to execute. | ||
| 6205 | - bool ShouldShard(const char* total_shards_env, const char* shard_index_env, | ||
| 6206 | - bool in_subprocess_for_death_test) { | ||
| 6210 | + // Checks whether sharding is enabled by examining the relevant command line | ||
| 6211 | + // arguments. If the arguments are present, but inconsistent | ||
| 6212 | + // (i.e., shard_index >= total_shards), prints an error and exits. | ||
| 6213 | + // If in_subprocess_for_death_test, sharding is disabled because it must only | ||
| 6214 | + // be applied to the original test process. Otherwise, we could filter out death | ||
| 6215 | + // tests we intended to execute. | ||
| 6216 | + bool ShouldShard(bool in_subprocess_for_death_test) { | ||
| 6207 | 6217 | if (in_subprocess_for_death_test) { | |
| 6208 | 6218 | return false; | |
| 6209 | 6219 | } | |
| 6210 | 6220 | ||
| 6211 | - const int32_t total_shards = Int32FromEnvOrDie(total_shards_env, -1); | ||
| 6212 | - const int32_t shard_index = Int32FromEnvOrDie(shard_index_env, -1); | ||
| 6221 | + const int32_t total_shards = GTEST_FLAG_GET(total_shards); | ||
| 6222 | + const int32_t shard_index = GTEST_FLAG_GET(shard_index); | ||
| 6213 | 6223 | ||
| 6214 | 6224 | if (total_shards == -1 && shard_index == -1) { | |
| 6215 | 6225 | return false; | |
| 6216 | 6226 | } else if (total_shards == -1 && shard_index != -1) { | |
| 6217 | - const Message msg = Message() << "Invalid environment variables: you have " | ||
| 6218 | - << kTestShardIndex << " = " << shard_index | ||
| 6219 | - << ", but have left " << kTestTotalShards | ||
| 6220 | - << " unset.\n"; | ||
| 6227 | + const Message msg = Message() | ||
| 6228 | + << "Invalid sharding: you have " << kTestShardIndex | ||
| 6229 | + << " = " << shard_index << ", but have left " | ||
| 6230 | + << kTestTotalShards << " unset.\n"; | ||
| 6221 | 6231 | ColoredPrintf(GTestColor::kRed, "%s", msg.GetString().c_str()); | |
| 6222 | 6232 | fflush(stdout); | |
| 6223 | 6233 | exit(EXIT_FAILURE); | |
| 6224 | 6234 | } else if (total_shards != -1 && shard_index == -1) { | |
| 6225 | 6235 | const Message msg = Message() | |
| 6226 | - << "Invalid environment variables: you have " | ||
| 6227 | - << kTestTotalShards << " = " << total_shards | ||
| 6228 | - << ", but have left " << kTestShardIndex << " unset.\n"; | ||
| 6236 | + << "Invalid sharding: you have " << kTestTotalShards | ||
| 6237 | + << " = " << total_shards << ", but have left " | ||
| 6238 | + << kTestShardIndex << " unset.\n"; | ||
| 6229 | 6239 | ColoredPrintf(GTestColor::kRed, "%s", msg.GetString().c_str()); | |
| 6230 | 6240 | fflush(stdout); | |
| 6231 | 6241 | exit(EXIT_FAILURE); | |
| 6232 | 6242 | } else if (shard_index < 0 || shard_index >= total_shards) { | |
| 6233 | 6243 | const Message msg = | |
| 6234 | - Message() << "Invalid environment variables: we require 0 <= " | ||
| 6235 | - << kTestShardIndex << " < " << kTestTotalShards | ||
| 6236 | - << ", but you have " << kTestShardIndex << "=" << shard_index | ||
| 6237 | - << ", " << kTestTotalShards << "=" << total_shards << ".\n"; | ||
| 6244 | + Message() << "Invalid sharding: we require 0 <= " << kTestShardIndex | ||
| 6245 | + << " < " << kTestTotalShards << ", but you have " | ||
| 6246 | + << kTestShardIndex << "=" << shard_index << ", " | ||
| 6247 | + << kTestTotalShards << "=" << total_shards << ".\n"; | ||
| 6238 | 6248 | ColoredPrintf(GTestColor::kRed, "%s", msg.GetString().c_str()); | |
| 6239 | 6249 | fflush(stdout); | |
| 6240 | 6250 | exit(EXIT_FAILURE); | |
@@ -6277,11 +6287,10 @@ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) { | |||
| 6277 | 6287 | // . Returns the number of tests that should run. | |
| 6278 | 6288 | int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { | |
| 6279 | 6289 | const int32_t total_shards = shard_tests == HONOR_SHARDING_PROTOCOL | |
| 6280 | - ? Int32FromEnvOrDie(kTestTotalShards, -1) | ||
| 6290 | + ? GTEST_FLAG_GET(total_shards) | ||
| 6281 | 6291 | : -1; | |
| 6282 | - const int32_t shard_index = shard_tests == HONOR_SHARDING_PROTOCOL | ||
| 6283 | - ? Int32FromEnvOrDie(kTestShardIndex, -1) | ||
| 6284 | - : -1; | ||
| 6292 | + const int32_t shard_index = | ||
| 6293 | + shard_tests == HONOR_SHARDING_PROTOCOL ? GTEST_FLAG_GET(shard_index) : -1; | ||
| 6285 | 6294 | ||
| 6286 | 6295 | const PositiveAndNegativeUnitTestFilter gtest_flag_filter( | |
| 6287 | 6296 | GTEST_FLAG_GET(filter)); | |
@@ -6810,6 +6819,8 @@ static bool ParseGoogleTestFlag(const char* const arg) { | |||
| 6810 | 6819 | GTEST_INTERNAL_PARSE_FLAG(print_utf8); | |
| 6811 | 6820 | GTEST_INTERNAL_PARSE_FLAG(random_seed); | |
| 6812 | 6821 | GTEST_INTERNAL_PARSE_FLAG(repeat); | |
| 6822 | + GTEST_INTERNAL_PARSE_FLAG(shard_index); | ||
| 6823 | + GTEST_INTERNAL_PARSE_FLAG(total_shards); | ||
| 6813 | 6824 | GTEST_INTERNAL_PARSE_FLAG(recreate_environments_when_repeating); | |
| 6814 | 6825 | GTEST_INTERNAL_PARSE_FLAG(shuffle); | |
| 6815 | 6826 | GTEST_INTERNAL_PARSE_FLAG(stack_trace_depth); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments