OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 """Run specific test on specific environment.""" |
| 6 |
| 7 import logging |
| 8 import os |
| 9 import sys |
| 10 import tempfile |
| 11 |
| 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 |
| 17 |
| 18 |
| 19 _EXTRA_COMMAND_LINE_FILE = ( |
| 20 'org.chromium.native_test.NativeTestActivity.CommandLineFile') |
| 21 |
| 22 |
| 23 class RemoteDeviceGtestTestRun(remote_device_test_run.RemoteDeviceTestRun): |
| 24 """Run gtests and uirobot tests on a remote device.""" |
| 25 |
| 26 DEFAULT_RUNNER_PACKAGE = ( |
| 27 'org.chromium.native_test.NativeTestInstrumentationTestRunner') |
| 28 |
| 29 #override |
| 30 def TestPackage(self): |
| 31 return self._test_instance.suite |
| 32 |
| 33 #override |
| 34 def _TriggerSetUp(self): |
| 35 """Set up the triggering of a test run.""" |
| 36 logging.info('Triggering test run.') |
| 37 |
| 38 if self._env.runner_type: |
| 39 logging.warning('Ignoring configured runner_type "%s"', |
| 40 self._env.runner_type) |
| 41 |
| 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) |
| 46 else: |
| 47 runner_package = self._env.runner_package |
| 48 |
| 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: |
| 52 env_vars = {} |
| 53 filter_string = self._test_instance._GenerateDisabledFilterString(None) |
| 54 if filter_string: |
| 55 flag_file.write('_ --gtest_filter=%s' % filter_string) |
| 56 flag_file.flush() |
| 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) |
| 63 |
| 64 _INSTRUMENTATION_STREAM_LEADER = 'INSTRUMENTATION_STATUS: stream=' |
| 65 |
| 66 #override |
| 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)) |
| 81 return results |
OLD | NEW |