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."""
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."""
22 def TestPackage(self
):
23 return self
._test
_instance
.test_package
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:',
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
])
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
):
69 elif isinstance(result
, list):
72 raise Exception('Unexpected result type: %s' % type(result
).__name
__)