blob: ee0185794d143a3dade7bcb7d1f690d6aa2bd14a [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001# 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.
4
5"""Run specific test on specific environment."""
6
7import logging
8import os
9import tempfile
10
11from pylib.base import base_test_result
12from pylib.remote.device import remote_device_test_run
13
14
15class RemoteDeviceInstrumentationTestRun(
16 remote_device_test_run.RemoteDeviceTestRun):
17 """Run instrumentation tests on a remote device."""
18
19 #override
20 def TestPackage(self):
21 return self._test_instance.test_package
22
23 #override
24 def _TriggerSetUp(self):
25 """Set up the triggering of a test run."""
26 logging.info('Triggering test run.')
27
28 # pylint: disable=protected-access
29 with tempfile.NamedTemporaryFile(suffix='.txt') as test_list_file:
30 tests = self._test_instance.GetTests()
31 logging.debug('preparing to run %d instrumentation tests remotely:',
32 len(tests))
33 for t in tests:
34 test_name = '%s#%s' % (t['class'], t['method'])
35 logging.debug(' %s', test_name)
36 test_list_file.write('%s\n' % test_name)
37 test_list_file.flush()
38 self._test_instance._data_deps.append(
39 (os.path.abspath(test_list_file.name), None))
40
41 env_vars = self._test_instance.GetDriverEnvironmentVars(
42 test_list_file_path=test_list_file.name)
43
44 logging.debug('extras:')
45 for k, v in env_vars.iteritems():
46 logging.debug(' %s: %s', k, v)
47
48 self._AmInstrumentTestSetup(
49 self._test_instance.apk_under_test,
50 self._test_instance.driver_apk,
51 self._test_instance.driver_name,
52 environment_variables=env_vars,
53 extra_apks=([self._test_instance.test_apk] +
54 self._test_instance.additional_apks))
55
56 #override
57 def _ParseTestResults(self):
58 logging.info('Parsing results from stdout.')
59 r = base_test_result.TestRunResults()
60 result_code, result_bundle, statuses = (
61 self._test_instance.ParseAmInstrumentRawOutput(
62 self._results['results']['output'].splitlines()))
63 result = self._test_instance.GenerateTestResults(
64 result_code, result_bundle, statuses, 0, 0)
65
66 if isinstance(result, base_test_result.BaseTestResult):
67 r.AddResult(result)
68 elif isinstance(result, list):
69 r.AddResults(result)
70 else:
71 raise Exception('Unexpected result type: %s' % type(result).__name__)
72
73 self._DetectPlatformErrors(r)
74 return r