1 # Copyright 2014 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
16 _EXTRA_COMMAND_LINE_FILE
= (
17 'org.chromium.native_test.NativeTestActivity.CommandLineFile')
20 class RemoteDeviceGtestTestRun(remote_device_test_run
.RemoteDeviceTestRun
):
21 """Run gtests and uirobot tests on a remote device."""
23 DEFAULT_RUNNER_PACKAGE
= (
24 'org.chromium.native_test.NativeTestInstrumentationTestRunner')
27 def TestPackage(self
):
28 return self
._test
_instance
.suite
31 def _TriggerSetUp(self
):
32 """Set up the triggering of a test run."""
33 logging
.info('Triggering test run.')
35 if self
._env
.runner_type
:
36 logging
.warning('Ignoring configured runner_type "%s"',
37 self
._env
.runner_type
)
39 if not self
._env
.runner_package
:
40 runner_package
= self
.DEFAULT_RUNNER_PACKAGE
41 logging
.info('Using default runner package: %s',
42 self
.DEFAULT_RUNNER_PACKAGE
)
44 runner_package
= self
._env
.runner_package
46 dummy_app_path
= os
.path
.join(
47 constants
.GetOutDirectory(), 'apks', 'remote_device_dummy.apk')
49 # pylint: disable=protected-access
50 with tempfile
.NamedTemporaryFile(suffix
='.flags.txt') as flag_file
:
52 filter_string
= self
._test
_instance
._GenerateDisabledFilterString
(None)
54 flag_file
.write('_ --gtest_filter=%s' % filter_string
)
56 env_vars
[_EXTRA_COMMAND_LINE_FILE
] = os
.path
.basename(flag_file
.name
)
57 self
._test
_instance
._data
_deps
.append(
58 (os
.path
.abspath(flag_file
.name
), None))
59 self
._AmInstrumentTestSetup
(
60 dummy_app_path
, self
._test
_instance
.apk
, runner_package
,
61 environment_variables
=env_vars
)
63 _INSTRUMENTATION_STREAM_LEADER
= 'INSTRUMENTATION_STATUS: stream='
66 def _ParseTestResults(self
):
67 logging
.info('Parsing results from stdout.')
68 results
= base_test_result
.TestRunResults()
69 output
= self
._results
['results']['output'].splitlines()
70 output
= (l
[len(self
._INSTRUMENTATION
_STREAM
_LEADER
):] for l
in output
71 if l
.startswith(self
._INSTRUMENTATION
_STREAM
_LEADER
))
72 results_list
= self
._test
_instance
.ParseGTestOutput(output
)
73 results
.AddResults(results_list
)
74 if self
._env
.only_output_failures
:
75 logging
.info('See logcat for more results information.')
77 self
._DetectPlatformErrors
(results
)