OLD | NEW |
---|---|
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 """Run specific test on specific environment.""" | 5 """Run specific test on specific environment.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import tempfile | 9 import tempfile |
10 | 10 |
11 from pylib import constants | |
11 from pylib.base import base_test_result | 12 from pylib.base import base_test_result |
12 from pylib.remote.device import remote_device_test_run | 13 from pylib.remote.device import remote_device_test_run |
13 from pylib.utils import apk_helper | 14 from pylib.utils import apk_helper |
14 | 15 |
15 | 16 |
16 class RemoteDeviceInstrumentationTestRun( | 17 class RemoteDeviceInstrumentationTestRun( |
17 remote_device_test_run.RemoteDeviceTestRun): | 18 remote_device_test_run.RemoteDeviceTestRun): |
18 """Run instrumentation tests on a remote device.""" | 19 """Run instrumentation tests on a remote device.""" |
19 | 20 |
20 #override | 21 #override |
21 def TestPackage(self): | 22 def TestPackage(self): |
22 return self._test_instance.test_package | 23 return self._test_instance.test_package |
23 | 24 |
24 #override | 25 #override |
25 def _TriggerSetUp(self): | 26 def _TriggerSetUp(self): |
26 """Set up the triggering of a test run.""" | 27 """Set up the triggering of a test run.""" |
27 logging.info('Triggering test run.') | 28 logging.info('Triggering test run.') |
28 self._AmInstrumentTestSetup( | 29 |
29 self._test_instance._apk_under_test, self._test_instance.test_apk, | 30 with tempfile.NamedTemporaryFile(suffix='.txt') as test_list_file: |
30 self._test_instance.test_runner, environment_variables={}) | 31 tests = self._test_instance.GetTests() |
32 logging.debug('preparing to run %d instrumentation tests remotely:', | |
33 len(tests)) | |
34 for t in tests: | |
35 test_name = '%s#%s' % (t['class'], t['method']) | |
36 logging.debug(' %s', test_name) | |
37 test_list_file.write('%s\n' % test_name) | |
38 test_list_file.flush() | |
39 self._test_instance._data_deps.append( | |
40 (os.path.abspath(test_list_file.name), None)) | |
klundberg
2015/03/27 16:13:30
Do you really need the extra parentheses in "(os.p
jbudorick
2015/04/07 00:54:38
Yep. _data_deps is a list of (host path, device pa
| |
41 | |
42 env_vars = self._test_instance.GetOutstrumentationEnvironmentVars( | |
43 test_list_file_path=test_list_file.name) | |
44 env_vars.update(self._test_instance.GetHttpServerEnvironmentVars()) | |
45 | |
46 logging.debug('extras:') | |
47 for k, v in env_vars.iteritems(): | |
48 logging.debug(' %s: %s', k, v) | |
49 | |
50 outstrumentation_apk = os.path.join( | |
51 constants.GetOutDirectory(), 'apks', 'Outstrumentation.apk') | |
52 outstrumentation = apk_helper.GetInstrumentationName(outstrumentation_apk) | |
53 | |
54 self._AmInstrumentTestSetup( | |
55 self._test_instance._apk_under_test, | |
56 outstrumentation_apk, | |
57 outstrumentation, | |
58 environment_variables=env_vars, | |
59 extra_apks=[self._test_instance.test_apk]) | |
31 | 60 |
32 #override | 61 #override |
33 def _ParseTestResults(self): | 62 def _ParseTestResults(self): |
34 logging.info('Parsing results from stdout.') | 63 logging.info('Parsing results from stdout.') |
35 r = base_test_result.TestRunResults() | 64 r = base_test_result.TestRunResults() |
36 result_code, result_bundle, statuses = ( | 65 result_code, result_bundle, statuses = ( |
37 self._test_instance.ParseAmInstrumentRawOutput( | 66 self._test_instance.ParseAmInstrumentRawOutput( |
38 self._results['results']['output'].splitlines())) | 67 self._results['results']['output'].splitlines())) |
39 result = self._test_instance.GenerateTestResults( | 68 result = self._test_instance.GenerateTestResults( |
40 result_code, result_bundle, statuses, 0, 0) | 69 result_code, result_bundle, statuses, 0, 0) |
41 | 70 |
42 if isinstance(result, base_test_result.BaseTestResult): | 71 if isinstance(result, base_test_result.BaseTestResult): |
43 r.AddResult(result) | 72 r.AddResult(result) |
44 elif isinstance(result, list): | 73 elif isinstance(result, list): |
45 r.AddResults(result) | 74 r.AddResults(result) |
46 else: | 75 else: |
47 raise Exception('Unexpected result type: %s' % type(result).__name__) | 76 raise Exception('Unexpected result type: %s' % type(result).__name__) |
48 | 77 |
49 return r | 78 return r |
OLD | NEW |