| OLD | NEW |
| 1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium OS 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 """Module that contains the interface for au_test_harness workers. | 5 """Module that contains the interface for au_test_harness workers. |
| 6 | 6 |
| 7 An au test harnss worker is a class that contains the logic for performing | 7 An au test harnss worker is a class that contains the logic for performing |
| 8 and validating updates on a target. This should be subclassed to handle | 8 and validating updates on a target. This should be subclassed to handle |
| 9 various types of target. Types of targets include VM's, real devices, etc. | 9 various types of target. Types of targets include VM's, real devices, etc. |
| 10 """ | 10 """ |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 private_key_path) | 185 private_key_path) |
| 186 cache_path = self.update_cache[update_id] | 186 cache_path = self.update_cache[update_id] |
| 187 if cache_path: | 187 if cache_path: |
| 188 update_url = dev_server_wrapper.DevServerWrapper.GetDevServerURL( | 188 update_url = dev_server_wrapper.DevServerWrapper.GetDevServerURL( |
| 189 proxy_port, cache_path) | 189 proxy_port, cache_path) |
| 190 cmd.append('--update_url=%s' % update_url) | 190 cmd.append('--update_url=%s' % update_url) |
| 191 else: | 191 else: |
| 192 cmd.append('--image=%s' % image_path) | 192 cmd.append('--image=%s' % image_path) |
| 193 if src_image_path: cmd.append('--src_image=%s' % src_image_path) | 193 if src_image_path: cmd.append('--src_image=%s' % src_image_path) |
| 194 | 194 |
| 195 def RunUpdateCmd(self, cmd): | 195 def RunUpdateCmd(self, cmd, log_directory=None): |
| 196 """Runs the given update cmd given verbose options. | 196 """Runs the given update cmd given verbose options. |
| 197 | 197 |
| 198 Raises an update_exception.UpdateException if the update fails. | 198 Raises an update_exception.UpdateException if the update fails. |
| 199 """ | 199 """ |
| 200 if self.verbose: | 200 if self.verbose: |
| 201 try: | 201 try: |
| 202 cros_lib.RunCommand(cmd) | 202 if log_directory: |
| 203 cros_lib.RunCommand(cmd, log_to_file=os.path.join(log_directory, |
| 204 'update.log')) |
| 205 else: |
| 206 cros_lib.RunCommand(cmd) |
| 203 except Exception as e: | 207 except Exception as e: |
| 204 Warning(str(e)) | 208 Warning(str(e)) |
| 205 raise update_exception.UpdateException(1, str(e)) | 209 raise update_exception.UpdateException(1, str(e)) |
| 206 else: | 210 else: |
| 207 (code, stdout, stderr) = cros_lib.RunCommandCaptureOutput(cmd) | 211 (code, stdout, stderr) = cros_lib.RunCommandCaptureOutput(cmd) |
| 208 if code != 0: | 212 if code != 0: |
| 209 Warning(stdout) | 213 Warning(stdout) |
| 210 raise update_exception.UpdateException(code, stdout) | 214 raise update_exception.UpdateException(code, stdout) |
| 211 | 215 |
| 212 def AssertEnoughTestsPassed(self, unittest, output, percent_required_to_pass): | 216 def AssertEnoughTestsPassed(self, unittest, output, percent_required_to_pass): |
| (...skipping 16 matching lines...) Expand all Loading... |
| 229 return percent_passed | 233 return percent_passed |
| 230 | 234 |
| 231 def InitializeResultsDirectory(self): | 235 def InitializeResultsDirectory(self): |
| 232 """Called by a test to initialize a results directory for this worker.""" | 236 """Called by a test to initialize a results directory for this worker.""" |
| 233 # Use the name of the test. | 237 # Use the name of the test. |
| 234 test_name = inspect.stack()[1][3] | 238 test_name = inspect.stack()[1][3] |
| 235 self.results_directory = os.path.join(self.test_results_root, test_name) | 239 self.results_directory = os.path.join(self.test_results_root, test_name) |
| 236 self.results_count = 0 | 240 self.results_count = 0 |
| 237 | 241 |
| 238 def GetNextResultsPath(self, label): | 242 def GetNextResultsPath(self, label): |
| 239 """Returns a new results path based for this label. | 243 """Returns a path for the results directory for this label. |
| 240 | 244 |
| 241 Prefixes directory returned for worker with time called i.e. 1_label, | 245 Prefixes directory returned for worker with time called i.e. 1_label, |
| 242 2_label, etc. | 246 2_label, etc. The directory returned is outside the chroot so if passing |
| 247 to an script that is called with enther_chroot, make sure to use |
| 248 ReinterpretPathForChroot. |
| 243 """ | 249 """ |
| 244 self.results_count += 1 | 250 self.results_count += 1 |
| 245 return os.path.join(self.results_directory, '%s_%s' % (self.results_count, | 251 dir = os.path.join(self.results_directory, '%s_%s' % (self.results_count, |
| 246 label)) | 252 label)) |
| 253 if not os.path.exists(dir): |
| 254 os.makedirs(dir) |
| 255 |
| 256 return dir |
| 247 | 257 |
| 248 # --- PRIVATE HELPER FUNCTIONS --- | 258 # --- PRIVATE HELPER FUNCTIONS --- |
| 249 | 259 |
| 250 def _ParseGenerateTestReportOutput(self, output): | 260 def _ParseGenerateTestReportOutput(self, output): |
| 251 """Returns the percentage of tests that passed based on output.""" | 261 """Returns the percentage of tests that passed based on output.""" |
| 252 percent_passed = 0 | 262 percent_passed = 0 |
| 253 lines = output.split('\n') | 263 lines = output.split('\n') |
| 254 | 264 |
| 255 for line in lines: | 265 for line in lines: |
| 256 if line.startswith("Total PASS:"): | 266 if line.startswith("Total PASS:"): |
| 257 # FORMAT: ^TOTAL PASS: num_passed/num_total (percent%)$ | 267 # FORMAT: ^TOTAL PASS: num_passed/num_total (percent%)$ |
| 258 percent_passed = line.split()[3].strip('()%') | 268 percent_passed = line.split()[3].strip('()%') |
| 259 cros_lib.Info('Percent of tests passed %s' % percent_passed) | 269 cros_lib.Info('Percent of tests passed %s' % percent_passed) |
| 260 break | 270 break |
| 261 | 271 |
| 262 return int(percent_passed) | 272 return int(percent_passed) |
| OLD | NEW |