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 | |
12 from pylib.base import base_test_result | 11 from pylib.base import base_test_result |
13 from pylib.remote.device import remote_device_test_run | 12 from pylib.remote.device import remote_device_test_run |
14 from pylib.utils import apk_helper | 13 from pylib.utils import apk_helper |
15 | 14 |
16 | 15 |
17 class RemoteDeviceInstrumentationTestRun( | 16 class RemoteDeviceInstrumentationTestRun( |
18 remote_device_test_run.RemoteDeviceTestRun): | 17 remote_device_test_run.RemoteDeviceTestRun): |
19 """Run instrumentation tests on a remote device.""" | 18 """Run instrumentation tests on a remote device.""" |
20 | 19 |
21 #override | 20 #override |
22 def TestPackage(self): | 21 def TestPackage(self): |
23 return self._test_instance.test_package | 22 return self._test_instance.test_package |
24 | 23 |
25 #override | 24 #override |
26 def _TriggerSetUp(self): | 25 def _TriggerSetUp(self): |
27 """Set up the triggering of a test run.""" | 26 """Set up the triggering of a test run.""" |
28 logging.info('Triggering test run.') | 27 logging.info('Triggering test run.') |
29 | 28 self._AmInstrumentTestSetup( |
30 with tempfile.NamedTemporaryFile(suffix='.txt') as test_list_file: | 29 self._test_instance._apk_under_test, self._test_instance.test_apk, |
31 tests = self._test_instance.GetTests() | 30 self._test_instance.test_runner, environment_variables={}) |
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)) | |
41 | |
42 env_vars = self._test_instance.GetDriverEnvironmentVars( | |
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 self._AmInstrumentTestSetup( | |
51 self._test_instance.apk_under_test, | |
52 self._test_instance.driver_apk, | |
53 self._test_instance.driver_name, | |
54 environment_variables=env_vars, | |
55 extra_apks=[self._test_instance.test_apk]) | |
56 | 31 |
57 #override | 32 #override |
58 def _ParseTestResults(self): | 33 def _ParseTestResults(self): |
59 logging.info('Parsing results from stdout.') | 34 logging.info('Parsing results from stdout.') |
60 r = base_test_result.TestRunResults() | 35 r = base_test_result.TestRunResults() |
61 result_code, result_bundle, statuses = ( | 36 result_code, result_bundle, statuses = ( |
62 self._test_instance.ParseAmInstrumentRawOutput( | 37 self._test_instance.ParseAmInstrumentRawOutput( |
63 self._results['results']['output'].splitlines())) | 38 self._results['results']['output'].splitlines())) |
64 result = self._test_instance.GenerateTestResults( | 39 result = self._test_instance.GenerateTestResults( |
65 result_code, result_bundle, statuses, 0, 0) | 40 result_code, result_bundle, statuses, 0, 0) |
66 | 41 |
67 if isinstance(result, base_test_result.BaseTestResult): | 42 if isinstance(result, base_test_result.BaseTestResult): |
68 r.AddResult(result) | 43 r.AddResult(result) |
69 elif isinstance(result, list): | 44 elif isinstance(result, list): |
70 r.AddResults(result) | 45 r.AddResults(result) |
71 else: | 46 else: |
72 raise Exception('Unexpected result type: %s' % type(result).__name__) | 47 raise Exception('Unexpected result type: %s' % type(result).__name__) |
73 | 48 |
74 return r | 49 return r |
OLD | NEW |