Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2120)

Unified Diff: build/android/pylib/remote/device/remote_device_instrumentation_run.py

Issue 832493005: Add Instrumentation test support to remote device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/remote/device/remote_device_instrumentation_run.py
diff --git a/build/android/pylib/remote/device/remote_device_instrumentation_run.py b/build/android/pylib/remote/device/remote_device_instrumentation_run.py
new file mode 100644
index 0000000000000000000000000000000000000000..1d27fe699cee891f830ee7f1d2b42a26289c780d
--- /dev/null
+++ b/build/android/pylib/remote/device/remote_device_instrumentation_run.py
@@ -0,0 +1,91 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Run specific test on specific environment."""
+
+import logging
+import os
+import tempfile
+
+from pylib.base import base_test_result
+
+from pylib.remote.device import remote_device_test_run
+from pylib.utils import apk_helper
+
+
+_EXTRA_COMMAND_LINE_FILE = (
jbudorick 2015/01/16 20:44:14 This should not be in here. Instrumentation tests
rnephew (Wrong account) 2015/01/16 21:39:27 Done.
+ 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile')
+_INSTR_STATUS_CODE_START = 1
+
+class RemoteDeviceInstrumentationRun(
+ remote_device_test_run.RemoteDeviceTestRun):
+ """Run instrumentation tests on a remote device."""
+
+ #override
+ def TestPackage(self):
+ return self._test_instance.test_package
+
+ #override
+ def _TriggerSetUp(self):
+ """Set up the triggering of a test run."""
+
+ logging.info('Triggering test run.')
+ runner_package = self._test_instance.test_runner
+
+ with tempfile.NamedTemporaryFile(suffix='.flags.txt') as flag_file:
+ env_vars = {}
+ if self._test_instance.flags:
jbudorick 2015/01/16 20:44:14 This entire block should be removed for now.
rnephew (Wrong account) 2015/01/16 21:39:27 Done.
+ logging.info("Setting flags: %s", self._test_instance.flags)
+ flag_file.write('_ %s' % self._test_instance.flags)
+ flag_file.flush()
+ env_vars[_EXTRA_COMMAND_LINE_FILE] = os.path.basename(flag_file.name)
+ self._test_instance._data_deps.append(
+ (os.path.abspath(flag_file.name), None))
+
+ self._AmInstrumentTestSetup(
+ self._test_instance._apk_under_test, self._test_instance.test_apk,
+ runner_package, environment_variables=env_vars)
+
+ #override
+ def _ParseTestResults(self):
+ skip_counter = 0
+ logging.info('Parsing results from stdout.')
+ r = base_test_result.TestRunResults()
+
+ if self._results['results']['exception']:
+ r.AddResult(base_test_result.BaseTestResult(
+ self._results['results']['exception'],
+ base_test_result.ResultType.FAIL))
+ return r
+
+ _, errors, parsed_output = self._test_instance.ParseAmInstrumentRawOutput(
+ self._results['results']['output'].splitlines())
+
+ for status_code, bundle in parsed_output:
jbudorick 2015/01/16 20:44:14 This logic (or something along these lines) should
rnephew (Wrong account) 2015/01/16 21:39:27 Moved it to its own function in instrumentation_te
+ if status_code != _INSTR_STATUS_CODE_START:
+ # TODO(rnephew): Make skipped tests still output test name. This is only
+ # there to give skipped tests a unique name so they are counted
+ if 'test_skipped' in bundle:
+ test_name = "%s" % skip_counter
+ skip_counter += 1
+ else:
+ test_name = '%s#%s' % (
+ ''.join(bundle.get('class', [''])),
+ ''.join(bundle.get('test', [''])))
+
+ result = self._test_instance.GenerateTestResult(
+ test_name, [(status_code, bundle)], 0, 0)
+
+ if isinstance(result, base_test_result.BaseTestResult):
+ r.AddResult(result)
+ elif isinstance(result, list):
+ r.AddResults(result)
+ else:
+ raise Exception('Unexpected result type: %s' % type(result).__name__)
+
+ if len(errors) and errors.pop(0) == 'shortMsg=Native crash':
+ r.AddResult(
+ base_test_result.BaseTestResult(
+ 'Crash detected', base_test_result.ResultType.CRASH))
+ return r

Powered by Google App Engine
This is Rietveld 408576698