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."""
12 from pylib
import constants
13 from pylib
.base
import base_test_result
14 from pylib
.remote
.device
import appurify_sanitized
15 from pylib
.remote
.device
import remote_device_test_run
16 from pylib
.remote
.device
import remote_device_helper
19 _EXTRA_COMMAND_LINE_FILE
= (
20 'org.chromium.native_test.NativeTestActivity.CommandLineFile')
23 class RemoteDeviceGtestTestRun(remote_device_test_run
.RemoteDeviceTestRun
):
24 """Run gtests and uirobot tests on a remote device."""
26 DEFAULT_RUNNER_PACKAGE
= (
27 'org.chromium.native_test.NativeTestInstrumentationTestRunner')
30 def TestPackage(self
):
31 return self
._test
_instance
.suite
34 def _TriggerSetUp(self
):
35 """Set up the triggering of a test run."""
36 logging
.info('Triggering test run.')
38 if self
._env
.runner_type
:
39 logging
.warning('Ignoring configured runner_type "%s"',
40 self
._env
.runner_type
)
42 if not self
._env
.runner_package
:
43 runner_package
= self
.DEFAULT_RUNNER_PACKAGE
44 logging
.info('Using default runner package: %s',
45 self
.DEFAULT_RUNNER_PACKAGE
)
47 runner_package
= self
._env
.runner_package
49 dummy_app_path
= os
.path
.join(
50 constants
.GetOutDirectory(), 'apks', 'remote_device_dummy.apk')
51 with tempfile
.NamedTemporaryFile(suffix
='.flags.txt') as flag_file
:
53 filter_string
= self
._test
_instance
._GenerateDisabledFilterString
(None)
55 flag_file
.write('_ --gtest_filter=%s' % filter_string
)
57 env_vars
[_EXTRA_COMMAND_LINE_FILE
] = os
.path
.basename(flag_file
.name
)
58 self
._test
_instance
._data
_deps
.append(
59 (os
.path
.abspath(flag_file
.name
), None))
60 self
._AmInstrumentTestSetup
(
61 dummy_app_path
, self
._test
_instance
.apk
, runner_package
,
62 environment_variables
=env_vars
)
64 _INSTRUMENTATION_STREAM_LEADER
= 'INSTRUMENTATION_STATUS: stream='
67 def _ParseTestResults(self
):
68 logging
.info('Parsing results from stdout.')
69 results
= base_test_result
.TestRunResults()
70 output
= self
._results
['results']['output'].splitlines()
71 output
= (l
[len(self
._INSTRUMENTATION
_STREAM
_LEADER
):] for l
in output
72 if l
.startswith(self
._INSTRUMENTATION
_STREAM
_LEADER
))
73 results_list
= self
._test
_instance
.ParseGTestOutput(output
)
74 results
.AddResults(results_list
)
75 if self
._env
.only_output_failures
:
76 logging
.info('See logcat for more results information.')
77 if not self
._results
['results']['pass']:
78 results
.AddResult(base_test_result
.BaseTestResult(
79 'Remote Service detected error.',
80 base_test_result
.ResultType
.FAIL
))