[Android] Add an out-of-app instrumentation driver APK. (RELAND)
[chromium-blink-merge.git] / build / android / pylib / remote / device / remote_device_instrumentation_test_run.py
blobbcdb90c82f3402f1e54ce5b6a9026e1c0b6dd1d2
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
3 # found in the LICENSE file.
5 """Run specific test on specific environment."""
7 import logging
8 import os
9 import tempfile
11 from pylib import constants
12 from pylib.base import base_test_result
13 from pylib.remote.device import remote_device_test_run
14 from pylib.utils import apk_helper
17 class RemoteDeviceInstrumentationTestRun(
18 remote_device_test_run.RemoteDeviceTestRun):
19 """Run instrumentation tests on a remote device."""
21 #override
22 def TestPackage(self):
23 return self._test_instance.test_package
25 #override
26 def _TriggerSetUp(self):
27 """Set up the triggering of a test run."""
28 logging.info('Triggering test run.')
30 with tempfile.NamedTemporaryFile(suffix='.txt') as test_list_file:
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))
42 env_vars = self._test_instance.GetDriverEnvironmentVars(
43 test_list_file_path=test_list_file.name)
44 env_vars.update(self._test_instance.GetHttpServerEnvironmentVars())
46 logging.debug('extras:')
47 for k, v in env_vars.iteritems():
48 logging.debug(' %s: %s', k, v)
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])
57 #override
58 def _ParseTestResults(self):
59 logging.info('Parsing results from stdout.')
60 r = base_test_result.TestRunResults()
61 result_code, result_bundle, statuses = (
62 self._test_instance.ParseAmInstrumentRawOutput(
63 self._results['results']['output'].splitlines()))
64 result = self._test_instance.GenerateTestResults(
65 result_code, result_bundle, statuses, 0, 0)
67 if isinstance(result, base_test_result.BaseTestResult):
68 r.AddResult(result)
69 elif isinstance(result, list):
70 r.AddResults(result)
71 else:
72 raise Exception('Unexpected result type: %s' % type(result).__name__)
74 return r