| 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 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/environment.h" | 14 #include "base/environment.h" |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/files/scoped_file.h" | 17 #include "base/files/scoped_file.h" |
| 18 #include "base/format_macros.h" | 18 #include "base/format_macros.h" |
| 19 #include "base/hash.h" |
| 19 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
| 20 #include "base/logging.h" | 21 #include "base/logging.h" |
| 21 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
| 22 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 23 #include "base/process/kill.h" | 24 #include "base/process/kill.h" |
| 24 #include "base/process/launch.h" | 25 #include "base/process/launch.h" |
| 25 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 26 #include "base/strings/string_split.h" | 27 #include "base/strings/string_split.h" |
| 27 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
| 28 #include "base/strings/stringize_macros.h" | 29 #include "base/strings/stringize_macros.h" |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 #if defined(ARCH_CPU_64_BITS) | 749 #if defined(ARCH_CPU_64_BITS) |
| 749 results_tracker_.AddGlobalTag("CPU_64_BITS"); | 750 results_tracker_.AddGlobalTag("CPU_64_BITS"); |
| 750 #endif | 751 #endif |
| 751 | 752 |
| 752 return true; | 753 return true; |
| 753 } | 754 } |
| 754 | 755 |
| 755 void TestLauncher::RunTests() { | 756 void TestLauncher::RunTests() { |
| 756 testing::UnitTest* const unit_test = testing::UnitTest::GetInstance(); | 757 testing::UnitTest* const unit_test = testing::UnitTest::GetInstance(); |
| 757 | 758 |
| 758 int num_runnable_tests = 0; | |
| 759 | |
| 760 std::vector<std::string> test_names; | 759 std::vector<std::string> test_names; |
| 761 | 760 |
| 762 for (int i = 0; i < unit_test->total_test_case_count(); ++i) { | 761 for (int i = 0; i < unit_test->total_test_case_count(); ++i) { |
| 763 const testing::TestCase* test_case = unit_test->GetTestCase(i); | 762 const testing::TestCase* test_case = unit_test->GetTestCase(i); |
| 764 for (int j = 0; j < test_case->total_test_count(); ++j) { | 763 for (int j = 0; j < test_case->total_test_count(); ++j) { |
| 765 const testing::TestInfo* test_info = test_case->GetTestInfo(j); | 764 const testing::TestInfo* test_info = test_case->GetTestInfo(j); |
| 766 std::string test_name = test_info->test_case_name(); | 765 std::string test_name = test_info->test_case_name(); |
| 767 test_name.append("."); | 766 test_name.append("."); |
| 768 test_name.append(test_info->name()); | 767 test_name.append(test_info->name()); |
| 769 | 768 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 797 excluded = true; | 796 excluded = true; |
| 798 break; | 797 break; |
| 799 } | 798 } |
| 800 } | 799 } |
| 801 if (excluded) | 800 if (excluded) |
| 802 continue; | 801 continue; |
| 803 | 802 |
| 804 if (!launcher_delegate_->ShouldRunTest(test_case, test_info)) | 803 if (!launcher_delegate_->ShouldRunTest(test_case, test_info)) |
| 805 continue; | 804 continue; |
| 806 | 805 |
| 807 if (num_runnable_tests++ % total_shards_ != shard_index_) | 806 if (base::Hash(test_name) % total_shards_ != |
| 807 static_cast<uint32>(shard_index_)) { |
| 808 continue; | 808 continue; |
| 809 } |
| 809 | 810 |
| 810 test_names.push_back(test_name); | 811 test_names.push_back(test_name); |
| 811 } | 812 } |
| 812 } | 813 } |
| 813 | 814 |
| 814 test_started_count_ = launcher_delegate_->RunTests(this, test_names); | 815 test_started_count_ = launcher_delegate_->RunTests(this, test_names); |
| 815 | 816 |
| 816 if (test_started_count_ == 0) { | 817 if (test_started_count_ == 0) { |
| 817 fprintf(stdout, "0 tests run\n"); | 818 fprintf(stdout, "0 tests run\n"); |
| 818 fflush(stdout); | 819 fflush(stdout); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 | 1077 |
| 1077 g_live_processes.Get().erase(process_handle); | 1078 g_live_processes.Get().erase(process_handle); |
| 1078 } | 1079 } |
| 1079 | 1080 |
| 1080 base::CloseProcessHandle(process_handle); | 1081 base::CloseProcessHandle(process_handle); |
| 1081 | 1082 |
| 1082 return exit_code; | 1083 return exit_code; |
| 1083 } | 1084 } |
| 1084 | 1085 |
| 1085 } // namespace base | 1086 } // namespace base |
| OLD | NEW |