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 11 matching lines...) Expand all Loading... |
22 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
23 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
24 #include "base/process/kill.h" | 24 #include "base/process/kill.h" |
25 #include "base/process/launch.h" | 25 #include "base/process/launch.h" |
26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/string_split.h" | 27 #include "base/strings/string_split.h" |
28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
29 #include "base/strings/stringize_macros.h" | 29 #include "base/strings/stringize_macros.h" |
30 #include "base/strings/stringprintf.h" | 30 #include "base/strings/stringprintf.h" |
31 #include "base/strings/utf_string_conversions.h" | 31 #include "base/strings/utf_string_conversions.h" |
| 32 #include "base/test/gtest_util.h" |
32 #include "base/test/launcher/test_results_tracker.h" | 33 #include "base/test/launcher/test_results_tracker.h" |
33 #include "base/test/sequenced_worker_pool_owner.h" | 34 #include "base/test/sequenced_worker_pool_owner.h" |
34 #include "base/test/test_switches.h" | 35 #include "base/test/test_switches.h" |
35 #include "base/test/test_timeouts.h" | 36 #include "base/test/test_timeouts.h" |
36 #include "base/threading/thread_checker.h" | 37 #include "base/threading/thread_checker.h" |
37 #include "base/time/time.h" | 38 #include "base/time/time.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
39 | 40 |
40 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
41 #include "base/mac/scoped_nsautorelease_pool.h" | 42 #include "base/mac/scoped_nsautorelease_pool.h" |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 #endif | 894 #endif |
894 | 895 |
895 #if defined(ARCH_CPU_64_BITS) | 896 #if defined(ARCH_CPU_64_BITS) |
896 results_tracker_.AddGlobalTag("CPU_64_BITS"); | 897 results_tracker_.AddGlobalTag("CPU_64_BITS"); |
897 #endif | 898 #endif |
898 | 899 |
899 return true; | 900 return true; |
900 } | 901 } |
901 | 902 |
902 void TestLauncher::RunTests() { | 903 void TestLauncher::RunTests() { |
903 testing::UnitTest* const unit_test = testing::UnitTest::GetInstance(); | 904 std::vector<SplitTestName> tests(GetCompiledInTests()); |
904 | 905 |
905 std::vector<std::string> test_names; | 906 std::vector<std::string> test_names; |
906 | 907 |
907 for (int i = 0; i < unit_test->total_test_case_count(); ++i) { | 908 for (size_t i = 0; i < tests.size(); i++) { |
908 const testing::TestCase* test_case = unit_test->GetTestCase(i); | 909 std::string test_name = FormatFullTestName(tests[i].first, tests[i].second); |
909 for (int j = 0; j < test_case->total_test_count(); ++j) { | |
910 const testing::TestInfo* test_info = test_case->GetTestInfo(j); | |
911 std::string test_name = FormatFullTestName( | |
912 test_info->test_case_name(), test_info->name()); | |
913 | 910 |
914 results_tracker_.AddTest(test_name); | 911 results_tracker_.AddTest(test_name); |
915 | 912 |
916 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 913 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
917 if (test_name.find("DISABLED") != std::string::npos) { | 914 if (test_name.find("DISABLED") != std::string::npos) { |
918 results_tracker_.AddDisabledTest(test_name); | 915 results_tracker_.AddDisabledTest(test_name); |
919 | 916 |
920 // Skip disabled tests unless explicitly requested. | 917 // Skip disabled tests unless explicitly requested. |
921 if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag)) | 918 if (!command_line->HasSwitch(kGTestRunDisabledTestsFlag)) |
922 continue; | 919 continue; |
923 } | 920 } |
924 | 921 |
925 if (!launcher_delegate_->ShouldRunTest(test_case, test_info)) | 922 if (!launcher_delegate_->ShouldRunTest(tests[i].first, tests[i].second)) |
926 continue; | 923 continue; |
927 | 924 |
928 // Skip the test that doesn't match the filter (if given). | 925 // Skip the test that doesn't match the filter (if given). |
929 if (!positive_test_filter_.empty()) { | 926 if (!positive_test_filter_.empty()) { |
930 bool found = false; | 927 bool found = false; |
931 for (size_t k = 0; k < positive_test_filter_.size(); ++k) { | 928 for (size_t k = 0; k < positive_test_filter_.size(); ++k) { |
932 if (MatchPattern(test_name, positive_test_filter_[k])) { | 929 if (MatchPattern(test_name, positive_test_filter_[k])) { |
933 found = true; | 930 found = true; |
934 break; | |
935 } | |
936 } | |
937 | |
938 if (!found) | |
939 continue; | |
940 } | |
941 bool excluded = false; | |
942 for (size_t k = 0; k < negative_test_filter_.size(); ++k) { | |
943 if (MatchPattern(test_name, negative_test_filter_[k])) { | |
944 excluded = true; | |
945 break; | 931 break; |
946 } | 932 } |
947 } | 933 } |
948 if (excluded) | 934 |
| 935 if (!found) |
949 continue; | 936 continue; |
| 937 } |
| 938 bool excluded = false; |
| 939 for (size_t k = 0; k < negative_test_filter_.size(); ++k) { |
| 940 if (MatchPattern(test_name, negative_test_filter_[k])) { |
| 941 excluded = true; |
| 942 break; |
| 943 } |
| 944 } |
| 945 if (excluded) |
| 946 continue; |
950 | 947 |
951 if (base::Hash(test_name) % total_shards_ != | 948 if (base::Hash(test_name) % total_shards_ != |
952 static_cast<uint32>(shard_index_)) { | 949 static_cast<uint32>(shard_index_)) { |
953 continue; | 950 continue; |
954 } | 951 } |
955 | 952 |
956 test_names.push_back(test_name); | 953 test_names.push_back(test_name); |
957 } | |
958 } | 954 } |
959 | 955 |
960 test_started_count_ = launcher_delegate_->RunTests(this, test_names); | 956 test_started_count_ = launcher_delegate_->RunTests(this, test_names); |
961 | 957 |
962 if (test_started_count_ == 0) { | 958 if (test_started_count_ == 0) { |
963 fprintf(stdout, "0 tests run\n"); | 959 fprintf(stdout, "0 tests run\n"); |
964 fflush(stdout); | 960 fflush(stdout); |
965 | 961 |
966 // No tests have actually been started, so kick off the next iteration. | 962 // No tests have actually been started, so kick off the next iteration. |
967 MessageLoop::current()->PostTask( | 963 MessageLoop::current()->PostTask( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 } | 1084 } |
1089 | 1085 |
1090 std::string snippet(full_output.substr(run_pos)); | 1086 std::string snippet(full_output.substr(run_pos)); |
1091 if (end_pos != std::string::npos) | 1087 if (end_pos != std::string::npos) |
1092 snippet = full_output.substr(run_pos, end_pos - run_pos); | 1088 snippet = full_output.substr(run_pos, end_pos - run_pos); |
1093 | 1089 |
1094 return snippet; | 1090 return snippet; |
1095 } | 1091 } |
1096 | 1092 |
1097 } // namespace base | 1093 } // namespace base |
OLD | NEW |