| 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 """Class for running instrumentation tests on a single device.""" | 5 """Class for running instrumentation tests on a single device.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import sys | 10 import sys |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 def _RunTest(self, test, timeout): | 362 def _RunTest(self, test, timeout): |
| 363 """Runs a single instrumentation test. | 363 """Runs a single instrumentation test. |
| 364 | 364 |
| 365 Args: | 365 Args: |
| 366 test: Test class/method. | 366 test: Test class/method. |
| 367 timeout: Timeout time in seconds. | 367 timeout: Timeout time in seconds. |
| 368 | 368 |
| 369 Returns: | 369 Returns: |
| 370 The raw output of am instrument as a list of lines. | 370 The raw output of am instrument as a list of lines. |
| 371 """ | 371 """ |
| 372 # Build the 'am instrument' command | 372 extras = self._GetInstrumentationArgs() |
| 373 instrumentation_path = ( | 373 extras['class'] = test |
| 374 '%s/%s' % (self.test_pkg.GetPackageName(), self.options.test_runner)) | 374 return self.device.StartInstrumentation( |
| 375 | 375 '%s/%s' % (self.test_pkg.GetPackageName(), self.options.test_runner), |
| 376 cmd = ['am', 'instrument', '-r'] | 376 raw=True, extras=extras, timeout=timeout, retries=0) |
| 377 for k, v in self._GetInstrumentationArgs().iteritems(): | |
| 378 cmd.extend(['-e', k, v]) | |
| 379 cmd.extend(['-e', 'class', test]) | |
| 380 cmd.extend(['-w', instrumentation_path]) | |
| 381 return self.device.RunShellCommand(cmd, timeout=timeout, retries=0) | |
| 382 | 377 |
| 383 @staticmethod | 378 @staticmethod |
| 384 def _ParseAmInstrumentRawOutput(raw_output): | 379 def _ParseAmInstrumentRawOutput(raw_output): |
| 385 """Parses the output of an |am instrument -r| call. | 380 """Parses the output of an |am instrument -r| call. |
| 386 | 381 |
| 387 Args: | 382 Args: |
| 388 raw_output: the output of an |am instrument -r| call as a list of lines | 383 raw_output: the output of an |am instrument -r| call as a list of lines |
| 389 Returns: | 384 Returns: |
| 390 A 3-tuple containing: | 385 A 3-tuple containing: |
| 391 - the instrumentation code as an integer | 386 - the instrumentation code as an integer |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 test, result_type, start_ms, duration_ms, log=log) | 494 test, result_type, start_ms, duration_ms, log=log) |
| 500 | 495 |
| 501 #override | 496 #override |
| 502 def RunTest(self, test): | 497 def RunTest(self, test): |
| 503 results = base_test_result.TestRunResults() | 498 results = base_test_result.TestRunResults() |
| 504 timeout = (self._GetIndividualTestTimeoutSecs(test) * | 499 timeout = (self._GetIndividualTestTimeoutSecs(test) * |
| 505 self._GetIndividualTestTimeoutScale(test) * | 500 self._GetIndividualTestTimeoutScale(test) * |
| 506 self.tool.GetTimeoutScale()) | 501 self.tool.GetTimeoutScale()) |
| 507 if (self.device.GetProp('ro.build.version.sdk') | 502 if (self.device.GetProp('ro.build.version.sdk') |
| 508 < constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN): | 503 < constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN): |
| 509 timeout *= 4 | 504 timeout *= 10 |
| 510 | 505 |
| 511 start_ms = 0 | 506 start_ms = 0 |
| 512 duration_ms = 0 | 507 duration_ms = 0 |
| 513 try: | 508 try: |
| 514 self.TestSetup(test) | 509 self.TestSetup(test) |
| 515 | 510 |
| 516 time_ms = lambda: int(time.time() * 1000) | 511 time_ms = lambda: int(time.time() * 1000) |
| 517 start_ms = time_ms() | 512 start_ms = time_ms() |
| 518 raw_output = self._RunTest(test, timeout) | 513 raw_output = self._RunTest(test, timeout) |
| 519 duration_ms = time_ms() - start_ms | 514 duration_ms = time_ms() - start_ms |
| 520 | 515 |
| 521 # Parse the test output | 516 # Parse the test output |
| 522 _, _, statuses = self._ParseAmInstrumentRawOutput(raw_output) | 517 _, _, statuses = self._ParseAmInstrumentRawOutput(raw_output) |
| 523 result = self._GenerateTestResult(test, statuses, start_ms, duration_ms) | 518 result = self._GenerateTestResult(test, statuses, start_ms, duration_ms) |
| 524 results.AddResult(result) | 519 results.AddResult(result) |
| 525 except device_errors.CommandTimeoutError as e: | 520 except device_errors.CommandTimeoutError as e: |
| 526 results.AddResult(test_result.InstrumentationTestResult( | 521 results.AddResult(test_result.InstrumentationTestResult( |
| 527 test, base_test_result.ResultType.TIMEOUT, start_ms, duration_ms, | 522 test, base_test_result.ResultType.TIMEOUT, start_ms, duration_ms, |
| 528 log=str(e) or 'No information')) | 523 log=str(e) or 'No information')) |
| 529 except device_errors.DeviceUnreachableError as e: | 524 except device_errors.DeviceUnreachableError as e: |
| 530 results.AddResult(test_result.InstrumentationTestResult( | 525 results.AddResult(test_result.InstrumentationTestResult( |
| 531 test, base_test_result.ResultType.CRASH, start_ms, duration_ms, | 526 test, base_test_result.ResultType.CRASH, start_ms, duration_ms, |
| 532 log=str(e) or 'No information')) | 527 log=str(e) or 'No information')) |
| 533 self.TestTeardown(test, results) | 528 self.TestTeardown(test, results) |
| 534 return (results, None if results.DidRunPass() else test) | 529 return (results, None if results.DidRunPass() else test) |
| OLD | NEW |