| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/test/test_launcher.h" | 5 #include "content/public/test/test_launcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 TestLauncherDelegate* g_launcher_delegate; | 62 TestLauncherDelegate* g_launcher_delegate; |
| 63 } | 63 } |
| 64 | 64 |
| 65 // The environment variable name for the total number of test shards. | 65 // The environment variable name for the total number of test shards. |
| 66 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; | 66 const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; |
| 67 // The environment variable name for the test shard index. | 67 // The environment variable name for the test shard index. |
| 68 const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; | 68 const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; |
| 69 | 69 |
| 70 // The default output file for XML output. | 70 // The default output file for XML output. |
| 71 const FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( | 71 const base::FilePath::CharType kDefaultOutputFile[] = FILE_PATH_LITERAL( |
| 72 "test_detail.xml"); | 72 "test_detail.xml"); |
| 73 | 73 |
| 74 // Quit test execution after this number of tests has timed out. | 74 // Quit test execution after this number of tests has timed out. |
| 75 const int kMaxTimeouts = 5; // 45s timeout * (5 + 1) = 270s max run time. | 75 const int kMaxTimeouts = 5; // 45s timeout * (5 + 1) = 270s max run time. |
| 76 | 76 |
| 77 namespace { | 77 namespace { |
| 78 | 78 |
| 79 // Parses the environment variable var as an Int32. If it is unset, returns | 79 // Parses the environment variable var as an Int32. If it is unset, returns |
| 80 // default_val. If it is set, unsets it then converts it to Int32 before | 80 // default_val. If it is set, unsets it then converts it to Int32 before |
| 81 // returning it. If unsetting or converting to an Int32 fails, print an | 81 // returning it. If unsetting or converting to an Int32 fails, print an |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 FILE* out_; | 159 FILE* out_; |
| 160 | 160 |
| 161 DISALLOW_COPY_AND_ASSIGN(ResultsPrinter); | 161 DISALLOW_COPY_AND_ASSIGN(ResultsPrinter); |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 ResultsPrinter::ResultsPrinter(const CommandLine& command_line) : out_(NULL) { | 164 ResultsPrinter::ResultsPrinter(const CommandLine& command_line) : out_(NULL) { |
| 165 if (!command_line.HasSwitch(kGTestOutputFlag)) | 165 if (!command_line.HasSwitch(kGTestOutputFlag)) |
| 166 return; | 166 return; |
| 167 std::string flag = command_line.GetSwitchValueASCII(kGTestOutputFlag); | 167 std::string flag = command_line.GetSwitchValueASCII(kGTestOutputFlag); |
| 168 size_t colon_pos = flag.find(':'); | 168 size_t colon_pos = flag.find(':'); |
| 169 FilePath path; | 169 base::FilePath path; |
| 170 if (colon_pos != std::string::npos) { | 170 if (colon_pos != std::string::npos) { |
| 171 FilePath flag_path = command_line.GetSwitchValuePath(kGTestOutputFlag); | 171 base::FilePath flag_path = |
| 172 FilePath::StringType path_string = flag_path.value(); | 172 command_line.GetSwitchValuePath(kGTestOutputFlag); |
| 173 path = FilePath(path_string.substr(colon_pos + 1)); | 173 base::FilePath::StringType path_string = flag_path.value(); |
| 174 path = base::FilePath(path_string.substr(colon_pos + 1)); |
| 174 // If the given path ends with '/', consider it is a directory. | 175 // If the given path ends with '/', consider it is a directory. |
| 175 // Note: This does NOT check that a directory (or file) actually exists | 176 // Note: This does NOT check that a directory (or file) actually exists |
| 176 // (the behavior is same as what gtest does). | 177 // (the behavior is same as what gtest does). |
| 177 if (file_util::EndsWithSeparator(path)) { | 178 if (file_util::EndsWithSeparator(path)) { |
| 178 FilePath executable = command_line.GetProgram().BaseName(); | 179 base::FilePath executable = command_line.GetProgram().BaseName(); |
| 179 path = path.Append(executable.ReplaceExtension( | 180 path = path.Append(executable.ReplaceExtension( |
| 180 FilePath::StringType(FILE_PATH_LITERAL("xml")))); | 181 base::FilePath::StringType(FILE_PATH_LITERAL("xml")))); |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 if (path.value().empty()) | 184 if (path.value().empty()) |
| 184 path = FilePath(kDefaultOutputFile); | 185 path = base::FilePath(kDefaultOutputFile); |
| 185 FilePath dir_name = path.DirName(); | 186 base::FilePath dir_name = path.DirName(); |
| 186 if (!file_util::DirectoryExists(dir_name)) { | 187 if (!file_util::DirectoryExists(dir_name)) { |
| 187 LOG(WARNING) << "The output directory does not exist. " | 188 LOG(WARNING) << "The output directory does not exist. " |
| 188 << "Creating the directory: " << dir_name.value(); | 189 << "Creating the directory: " << dir_name.value(); |
| 189 // Create the directory if necessary (because the gtest does the same). | 190 // Create the directory if necessary (because the gtest does the same). |
| 190 file_util::CreateDirectory(dir_name); | 191 file_util::CreateDirectory(dir_name); |
| 191 } | 192 } |
| 192 out_ = file_util::OpenFile(path, "w"); | 193 out_ = file_util::OpenFile(path, "w"); |
| 193 if (!out_) { | 194 if (!out_) { |
| 194 LOG(ERROR) << "Cannot open output file: " | 195 LOG(ERROR) << "Cannot open output file: " |
| 195 << path.value() << "."; | 196 << path.value() << "."; |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 cycles--; | 744 cycles--; |
| 744 } | 745 } |
| 745 return exit_code; | 746 return exit_code; |
| 746 } | 747 } |
| 747 | 748 |
| 748 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { | 749 TestLauncherDelegate* GetCurrentTestLauncherDelegate() { |
| 749 return g_launcher_delegate; | 750 return g_launcher_delegate; |
| 750 } | 751 } |
| 751 | 752 |
| 752 } // namespace content | 753 } // namespace content |
| OLD | NEW |