Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Run specific test on specific environment.""" | |
| 6 | |
| 7 import logging | |
| 8 import os | |
| 9 import tempfile | |
| 10 | |
| 11 from pylib.base import base_test_result | |
| 12 | |
| 13 from pylib.remote.device import remote_device_test_run | |
| 14 from pylib.utils import apk_helper | |
| 15 | |
| 16 | |
| 17 _EXTRA_COMMAND_LINE_FILE = ( | |
|
jbudorick
2015/01/16 20:44:14
This should not be in here. Instrumentation tests
rnephew (Wrong account)
2015/01/16 21:39:27
Done.
| |
| 18 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile') | |
| 19 _INSTR_STATUS_CODE_START = 1 | |
| 20 | |
| 21 class RemoteDeviceInstrumentationRun( | |
| 22 remote_device_test_run.RemoteDeviceTestRun): | |
| 23 """Run instrumentation tests on a remote device.""" | |
| 24 | |
| 25 #override | |
| 26 def TestPackage(self): | |
| 27 return self._test_instance.test_package | |
| 28 | |
| 29 #override | |
| 30 def _TriggerSetUp(self): | |
| 31 """Set up the triggering of a test run.""" | |
| 32 | |
| 33 logging.info('Triggering test run.') | |
| 34 runner_package = self._test_instance.test_runner | |
| 35 | |
| 36 with tempfile.NamedTemporaryFile(suffix='.flags.txt') as flag_file: | |
| 37 env_vars = {} | |
| 38 if self._test_instance.flags: | |
|
jbudorick
2015/01/16 20:44:14
This entire block should be removed for now.
rnephew (Wrong account)
2015/01/16 21:39:27
Done.
| |
| 39 logging.info("Setting flags: %s", self._test_instance.flags) | |
| 40 flag_file.write('_ %s' % self._test_instance.flags) | |
| 41 flag_file.flush() | |
| 42 env_vars[_EXTRA_COMMAND_LINE_FILE] = os.path.basename(flag_file.name) | |
| 43 self._test_instance._data_deps.append( | |
| 44 (os.path.abspath(flag_file.name), None)) | |
| 45 | |
| 46 self._AmInstrumentTestSetup( | |
| 47 self._test_instance._apk_under_test, self._test_instance.test_apk, | |
| 48 runner_package, environment_variables=env_vars) | |
| 49 | |
| 50 #override | |
| 51 def _ParseTestResults(self): | |
| 52 skip_counter = 0 | |
| 53 logging.info('Parsing results from stdout.') | |
| 54 r = base_test_result.TestRunResults() | |
| 55 | |
| 56 if self._results['results']['exception']: | |
| 57 r.AddResult(base_test_result.BaseTestResult( | |
| 58 self._results['results']['exception'], | |
| 59 base_test_result.ResultType.FAIL)) | |
| 60 return r | |
| 61 | |
| 62 _, errors, parsed_output = self._test_instance.ParseAmInstrumentRawOutput( | |
| 63 self._results['results']['output'].splitlines()) | |
| 64 | |
| 65 for status_code, bundle in parsed_output: | |
|
jbudorick
2015/01/16 20:44:14
This logic (or something along these lines) should
rnephew (Wrong account)
2015/01/16 21:39:27
Moved it to its own function in instrumentation_te
| |
| 66 if status_code != _INSTR_STATUS_CODE_START: | |
| 67 # TODO(rnephew): Make skipped tests still output test name. This is only | |
| 68 # there to give skipped tests a unique name so they are counted | |
| 69 if 'test_skipped' in bundle: | |
| 70 test_name = "%s" % skip_counter | |
| 71 skip_counter += 1 | |
| 72 else: | |
| 73 test_name = '%s#%s' % ( | |
| 74 ''.join(bundle.get('class', [''])), | |
| 75 ''.join(bundle.get('test', ['']))) | |
| 76 | |
| 77 result = self._test_instance.GenerateTestResult( | |
| 78 test_name, [(status_code, bundle)], 0, 0) | |
| 79 | |
| 80 if isinstance(result, base_test_result.BaseTestResult): | |
| 81 r.AddResult(result) | |
| 82 elif isinstance(result, list): | |
| 83 r.AddResults(result) | |
| 84 else: | |
| 85 raise Exception('Unexpected result type: %s' % type(result).__name__) | |
| 86 | |
| 87 if len(errors) and errors.pop(0) == 'shortMsg=Native crash': | |
| 88 r.AddResult( | |
| 89 base_test_result.BaseTestResult( | |
| 90 'Crash detected', base_test_result.ResultType.CRASH)) | |
| 91 return r | |
| OLD | NEW |