| 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 #include <memory> | 
|  | 8 | 
| 7 #include "base/at_exit.h" | 9 #include "base/at_exit.h" | 
| 8 #include "base/bind.h" | 10 #include "base/bind.h" | 
| 9 #include "base/command_line.h" | 11 #include "base/command_line.h" | 
| 10 #include "base/environment.h" | 12 #include "base/environment.h" | 
| 11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" | 
| 12 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" | 
| 13 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" | 
| 14 #include "base/format_macros.h" | 16 #include "base/format_macros.h" | 
| 15 #include "base/hash.h" | 17 #include "base/hash.h" | 
| 16 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" | 
| 17 #include "base/location.h" | 19 #include "base/location.h" | 
| 18 #include "base/logging.h" | 20 #include "base/logging.h" | 
| 19 #include "base/macros.h" | 21 #include "base/macros.h" | 
| 20 #include "base/memory/scoped_ptr.h" |  | 
| 21 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" | 
| 22 #include "base/process/kill.h" | 23 #include "base/process/kill.h" | 
| 23 #include "base/process/launch.h" | 24 #include "base/process/launch.h" | 
| 24 #include "base/single_thread_task_runner.h" | 25 #include "base/single_thread_task_runner.h" | 
| 25 #include "base/strings/pattern.h" | 26 #include "base/strings/pattern.h" | 
| 26 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" | 
| 27 #include "base/strings/string_split.h" | 28 #include "base/strings/string_split.h" | 
| 28 #include "base/strings/string_util.h" | 29 #include "base/strings/string_util.h" | 
| 29 #include "base/strings/stringize_macros.h" | 30 #include "base/strings/stringize_macros.h" | 
| 30 #include "base/strings/stringprintf.h" | 31 #include "base/strings/stringprintf.h" | 
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 163 | 164 | 
| 164  private: | 165  private: | 
| 165   DISALLOW_COPY_AND_ASSIGN(SignalFDWatcher); | 166   DISALLOW_COPY_AND_ASSIGN(SignalFDWatcher); | 
| 166 }; | 167 }; | 
| 167 #endif  // defined(OS_POSIX) | 168 #endif  // defined(OS_POSIX) | 
| 168 | 169 | 
| 169 // Parses the environment variable var as an Int32.  If it is unset, returns | 170 // Parses the environment variable var as an Int32.  If it is unset, returns | 
| 170 // true.  If it is set, unsets it then converts it to Int32 before | 171 // true.  If it is set, unsets it then converts it to Int32 before | 
| 171 // returning it in |result|.  Returns true on success. | 172 // returning it in |result|.  Returns true on success. | 
| 172 bool TakeInt32FromEnvironment(const char* const var, int32_t* result) { | 173 bool TakeInt32FromEnvironment(const char* const var, int32_t* result) { | 
| 173   scoped_ptr<Environment> env(Environment::Create()); | 174   std::unique_ptr<Environment> env(Environment::Create()); | 
| 174   std::string str_val; | 175   std::string str_val; | 
| 175 | 176 | 
| 176   if (!env->GetVar(var, &str_val)) | 177   if (!env->GetVar(var, &str_val)) | 
| 177     return true; | 178     return true; | 
| 178 | 179 | 
| 179   if (!env->UnSetVar(var)) { | 180   if (!env->UnSetVar(var)) { | 
| 180     LOG(ERROR) << "Invalid environment: we could not unset " << var << ".\n"; | 181     LOG(ERROR) << "Invalid environment: we could not unset " << var << ".\n"; | 
| 181     return false; | 182     return false; | 
| 182   } | 183   } | 
| 183 | 184 | 
| 184   if (!StringToInt(str_val, result)) { | 185   if (!StringToInt(str_val, result)) { | 
| 185     LOG(ERROR) << "Invalid environment: " << var << " is not an integer.\n"; | 186     LOG(ERROR) << "Invalid environment: " << var << " is not an integer.\n"; | 
| 186     return false; | 187     return false; | 
| 187   } | 188   } | 
| 188 | 189 | 
| 189   return true; | 190   return true; | 
| 190 } | 191 } | 
| 191 | 192 | 
| 192 // Unsets the environment variable |name| and returns true on success. | 193 // Unsets the environment variable |name| and returns true on success. | 
| 193 // Also returns true if the variable just doesn't exist. | 194 // Also returns true if the variable just doesn't exist. | 
| 194 bool UnsetEnvironmentVariableIfExists(const std::string& name) { | 195 bool UnsetEnvironmentVariableIfExists(const std::string& name) { | 
| 195   scoped_ptr<Environment> env(Environment::Create()); | 196   std::unique_ptr<Environment> env(Environment::Create()); | 
| 196   std::string str_val; | 197   std::string str_val; | 
| 197 | 198 | 
| 198   if (!env->GetVar(name.c_str(), &str_val)) | 199   if (!env->GetVar(name.c_str(), &str_val)) | 
| 199     return true; | 200     return true; | 
| 200 | 201 | 
| 201   return env->UnSetVar(name.c_str()); | 202   return env->UnSetVar(name.c_str()); | 
| 202 } | 203 } | 
| 203 | 204 | 
| 204 // Returns true if bot mode has been requested, i.e. defaults optimized | 205 // Returns true if bot mode has been requested, i.e. defaults optimized | 
| 205 // for continuous integration bots. This way developers don't have to remember | 206 // for continuous integration bots. This way developers don't have to remember | 
| 206 // special command-line flags. | 207 // special command-line flags. | 
| 207 bool BotModeEnabled() { | 208 bool BotModeEnabled() { | 
| 208   scoped_ptr<Environment> env(Environment::Create()); | 209   std::unique_ptr<Environment> env(Environment::Create()); | 
| 209   return CommandLine::ForCurrentProcess()->HasSwitch( | 210   return CommandLine::ForCurrentProcess()->HasSwitch( | 
| 210       switches::kTestLauncherBotMode) || | 211       switches::kTestLauncherBotMode) || | 
| 211       env->HasVar("CHROMIUM_TEST_LAUNCHER_BOT_MODE"); | 212       env->HasVar("CHROMIUM_TEST_LAUNCHER_BOT_MODE"); | 
| 212 } | 213 } | 
| 213 | 214 | 
| 214 // Returns command line command line after gtest-specific processing | 215 // Returns command line command line after gtest-specific processing | 
| 215 // and applying |wrapper|. | 216 // and applying |wrapper|. | 
| 216 CommandLine PrepareCommandLineForGTest(const CommandLine& command_line, | 217 CommandLine PrepareCommandLineForGTest(const CommandLine& command_line, | 
| 217                                        const std::string& wrapper) { | 218                                        const std::string& wrapper) { | 
| 218   CommandLine new_command_line(command_line.GetProgram()); | 219   CommandLine new_command_line(command_line.GetProgram()); | 
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1120   } | 1121   } | 
| 1121 | 1122 | 
| 1122   std::string snippet(full_output.substr(run_pos)); | 1123   std::string snippet(full_output.substr(run_pos)); | 
| 1123   if (end_pos != std::string::npos) | 1124   if (end_pos != std::string::npos) | 
| 1124     snippet = full_output.substr(run_pos, end_pos - run_pos); | 1125     snippet = full_output.substr(run_pos, end_pos - run_pos); | 
| 1125 | 1126 | 
| 1126   return snippet; | 1127   return snippet; | 
| 1127 } | 1128 } | 
| 1128 | 1129 | 
| 1129 }  // namespace base | 1130 }  // namespace base | 
| OLD | NEW | 
|---|