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/launcher/test_launcher.h" | 5 #include "base/test/launcher/test_launcher.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 bool TestLauncher::Init() { | 545 bool TestLauncher::Init() { |
546 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 546 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
547 | 547 |
548 if (command_line->HasSwitch(kGTestListTestsFlag)) { | 548 if (command_line->HasSwitch(kGTestListTestsFlag)) { |
549 // Child gtest processes would list tests instead of running tests. | 549 // Child gtest processes would list tests instead of running tests. |
550 // TODO(phajdan.jr): Restore support for the flag. | 550 // TODO(phajdan.jr): Restore support for the flag. |
551 LOG(ERROR) << kGTestListTestsFlag << " is not supported."; | 551 LOG(ERROR) << kGTestListTestsFlag << " is not supported."; |
552 return false; | 552 return false; |
553 } | 553 } |
554 | 554 |
555 if (!TakeInt32FromEnvironment(kTestTotalShards, &total_shards_)) | 555 // Initialize sharding. Command line takes precedence over legacy environment |
556 return false; | 556 // variables. |
557 if (!TakeInt32FromEnvironment(kTestShardIndex, &shard_index_)) | 557 if (command_line->HasSwitch(switches::kTestLauncherTotalShards) && |
558 return false; | 558 command_line->HasSwitch(switches::kTestLauncherShardIndex)) { |
| 559 if (!StringToInt( |
| 560 command_line->GetSwitchValueASCII( |
| 561 switches::kTestLauncherTotalShards), |
| 562 &total_shards_)) { |
| 563 LOG(ERROR) << "Invalid value for " << switches::kTestLauncherTotalShards; |
| 564 return false; |
| 565 } |
| 566 if (!StringToInt( |
| 567 command_line->GetSwitchValueASCII( |
| 568 switches::kTestLauncherShardIndex), |
| 569 &shard_index_)) { |
| 570 LOG(ERROR) << "Invalid value for " << switches::kTestLauncherShardIndex; |
| 571 return false; |
| 572 } |
| 573 fprintf(stdout, |
| 574 "Using sharding settings from command line. This is shard %d/%d\n", |
| 575 shard_index_, total_shards_); |
| 576 fflush(stdout); |
| 577 } else { |
| 578 if (!TakeInt32FromEnvironment(kTestTotalShards, &total_shards_)) |
| 579 return false; |
| 580 if (!TakeInt32FromEnvironment(kTestShardIndex, &shard_index_)) |
| 581 return false; |
| 582 fprintf(stdout, |
| 583 "Using sharding settings from environment. This is shard %d/%d\n", |
| 584 shard_index_, total_shards_); |
| 585 fflush(stdout); |
| 586 } |
559 if (shard_index_ < 0 || | 587 if (shard_index_ < 0 || |
560 total_shards_ < 0 || | 588 total_shards_ < 0 || |
561 shard_index_ >= total_shards_) { | 589 shard_index_ >= total_shards_) { |
562 LOG(ERROR) << "Invalid environment variables: we require 0 <= " | 590 LOG(ERROR) << "Invalid sharding settings: we require 0 <= " |
563 << kTestShardIndex << " < " << kTestTotalShards | 591 << kTestShardIndex << " < " << kTestTotalShards |
564 << ", but you have " << kTestShardIndex << "=" << shard_index_ | 592 << ", but you have " << kTestShardIndex << "=" << shard_index_ |
565 << ", " << kTestTotalShards << "=" << total_shards_ << ".\n"; | 593 << ", " << kTestTotalShards << "=" << total_shards_ << ".\n"; |
566 return false; | 594 return false; |
567 } | 595 } |
568 | 596 |
569 if (command_line->HasSwitch(kGTestRepeatFlag) && | 597 if (command_line->HasSwitch(kGTestRepeatFlag) && |
570 !StringToInt(command_line->GetSwitchValueASCII(kGTestRepeatFlag), | 598 !StringToInt(command_line->GetSwitchValueASCII(kGTestRepeatFlag), |
571 &cycles_)) { | 599 &cycles_)) { |
572 LOG(ERROR) << "Invalid value for " << kGTestRepeatFlag; | 600 LOG(ERROR) << "Invalid value for " << kGTestRepeatFlag; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 | 896 |
869 g_live_processes.Get().erase(process_handle); | 897 g_live_processes.Get().erase(process_handle); |
870 } | 898 } |
871 | 899 |
872 base::CloseProcessHandle(process_handle); | 900 base::CloseProcessHandle(process_handle); |
873 | 901 |
874 return exit_code; | 902 return exit_code; |
875 } | 903 } |
876 | 904 |
877 } // namespace base | 905 } // namespace base |
OLD | NEW |