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

Unified Diff: build/android/pylib/gtest/local_device_gtest_run.py

Issue 788753002: [Android] Implement gtest and local in platform mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « build/android/pylib/gtest/gtest_test_instance_test.py ('k') | build/android/pylib/gtest/test_package.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/gtest/local_device_gtest_run.py
diff --git a/build/android/pylib/gtest/local_device_gtest_run.py b/build/android/pylib/gtest/local_device_gtest_run.py
new file mode 100644
index 0000000000000000000000000000000000000000..4c66b2cf02b3889bbf3b7d3ad97b26980829a246
--- /dev/null
+++ b/build/android/pylib/gtest/local_device_gtest_run.py
@@ -0,0 +1,148 @@
+# 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.
+
+
+import logging
+import re
+
+from pylib import ports
+from pylib.base import base_test_result
+from pylib.base import test_run
+from pylib.gtest import gtest_test_instance
+
+from pylib.local import local_test_server_spawner
+from pylib.local.device import local_device_environment
+from pylib.local.device import local_device_test_run
+from pylib.utils import device_temp_file
+
+_COMMAND_LINE_FLAGS_SUPPORTED = True
+
+_EXTRA_COMMAND_LINE_FILE = (
+ 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile')
+_EXTRA_COMMAND_LINE_FLAGS = (
+ 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags')
+
+# TODO(jbudorick): Remove these once we're no longer parsing stdout to generate
+# results.
+_RE_TEST_STATUS = re.compile(
+ r'\[ +((?:RUN)|(?:FAILED)|(?:OK)) +\] ?(.*)(?: \((\d+) ms\))?')
+_RE_TEST_RUN_STATUS = re.compile(
+ r'\[ +(PASSED|RUNNER_FAILED|CRASHED) \] ?(.*)')
+
+# TODO(jbudorick): Move this up to the test instance if the net test server is
+# handled outside of the APK for the remote_device environment.
+_SUITE_REQUIRES_TEST_SERVER_SPAWNER = [
+ 'content_unittests', 'content_browsertests', 'net_unittests', 'unit_tests'
+]
+
+class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun):
+
+ def __init__(self, env, test_instance):
+ assert isinstance(env, local_device_environment.LocalDeviceEnvironment)
+ assert isinstance(test_instance, gtest_test_instance.GtestTestInstance)
+ super(LocalDeviceGtestRun, self).__init__(env, test_instance)
+
+ # TODO(jbudorick): These will be different for content_browsertests.
+ self._package = 'org.chromium.native_test'
+ self._runner = '.ChromiumNativeTestInstrumentationTestRunner'
+ self._component = '%s/%s' % (self._package, self._runner)
+ self._server_factories = []
klundberg 2014/12/09 15:55:33 Should be removed now that you no longer use it an
jbudorick 2014/12/11 01:01:02 Done.
+ self._servers = {}
+
+ #override
+ def TestPackage(self):
+ return self._test_instance._suite
+
+ #override
+ def SetUp(self):
+
+ def individual_device_set_up(dev, host_device_tuples):
+ # Install test APK.
+ dev.Install(self._test_instance.apk)
+
+ # Push data dependencies.
+ external_storage = dev.GetExternalStoragePath()
+ host_device_tuples = [
+ (h, d if d is not None else external_storage)
+ for h, d in host_device_tuples]
+ dev.PushChangedFiles(host_device_tuples)
+
+ self._servers[str(dev)] = []
+ if self.TestPackage() in _SUITE_REQUIRES_TEST_SERVER_SPAWNER:
+ self._servers[str(dev)].append(
+ local_test_server_spawner.LocalTestServerSpawner(
+ ports.AllocateTestServerPort(), dev, None))
+
+ for s in self._servers[str(dev)]:
+ s.SetUp()
+
+ self._env.parallel_devices.pMap(individual_device_set_up,
+ self._test_instance.GetDataDependencies())
+
+ #override
+ def _ShouldShard(self):
+ return True
+
+ #override
+ def _CreateShards(self, tests):
+ device_count = len(self._env.devices)
+ return [':'.join(tests[i::device_count])
+ for i in xrange(0, device_count)]
+
+ #override
+ def _GetTests(self):
+ tests = self._env.devices[0].StartInstrumentation(
+ self._component,
+ extras={_EXTRA_COMMAND_LINE_FLAGS: '_ --gtest_list_tests'},
+ raw=False)
+ tests = gtest_test_instance.ParseGTestListTests(tests)
+ tests = self._test_instance.FilterTests(tests)
+ return tests
+
+ #override
+ def _RunTest(self, device, test):
+
+ # Run the test.
+ with device_temp_file.DeviceTempFile(device) as command_line_file:
+ device.WriteFile(
+ command_line_file.name,
+ '_ --gtest_filter=%s' % test)
+
+ output = device.StartInstrumentation(
+ self._component,
+ extras={_EXTRA_COMMAND_LINE_FILE: command_line_file.name},
+ timeout=900, retries=0)
+
+ for s in self._servers[str(device)]:
+ s.Reset()
+ device.ClearApplicationState(self._package)
+
+ # Parse the output.
+ # TODO(jbudorick): Transition test scripts away from parsing stdout.
+ results = []
+ for l in output:
+ matcher = _RE_TEST_STATUS.match(l)
+ if matcher:
+ result_type = None
+ if matcher.group(1) == 'OK':
+ result_type = base_test_result.ResultType.PASS
+ elif matcher.group(1) == 'FAILED':
+ result_type = base_test_result.ResultType.FAIL
+
+ if result_type:
+ test_name = matcher.group(2)
+ duration = matcher.group(3) if matcher.group(3) else 0
+ results.append(base_test_result.BaseTestResult(
+ test_name, result_type, duration))
+ logging.info(l)
+ return results
+
+ #override
+ def TearDown(self):
+ def individual_device_tear_down(dev):
+ for s in self._servers[str(dev)]:
+ s.TearDown()
+
+ self._env.parallel_devices.pMap(individual_device_tear_down)
+
« no previous file with comments | « build/android/pylib/gtest/gtest_test_instance_test.py ('k') | build/android/pylib/gtest/test_package.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698