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..ba30a7b1dcd90ace6d97fea5d608e54ad8f67b48 |
--- /dev/null |
+++ b/build/android/pylib/gtest/local_device_gtest_run.py |
@@ -0,0 +1,145 @@ |
+# 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') |
+ |
+_RE_TEST_STATUS = re.compile( |
klundberg
2014/12/09 02:30:47
Might be worth having a note that these are needed
jbudorick
2014/12/09 15:46:51
Done.
|
+ r'\[ +((?:RUN)|(?:FAILED)|(?:OK)) +\] ?(.*)(?: \((\d+) ms\))?') |
+_RE_TEST_RUN_STATUS = re.compile( |
+ r'\[ +(PASSED|RUNNER_FAILED|CRASHED) \] ?(.*)') |
+ |
+# Maybe this should move to the test instance? |
klundberg
2014/12/09 02:30:47
If this a question for the reviewers?
If this is o
jbudorick
2014/12/09 15:46:51
No, this was a question for me. Whether or not thi
|
+_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 = [] |
+ self._servers = {} |
+ |
+ if self.TestPackage() in _SUITE_REQUIRES_TEST_SERVER_SPAWNER: |
+ def test_server_spawner_factory(dev): |
+ port = ports.AllocateTestServerPort() |
+ return local_test_server_spawner.LocalTestServerSpawner(port, dev, None) |
+ self._server_factories.append(test_server_spawner_factory) |
klundberg
2014/12/09 02:30:47
I think I remember that different tests have diffe
jbudorick
2014/12/09 15:46:51
At the time, I wasn't sure if the gtests would nee
|
+ |
+ #override |
+ def TestPackage(self): |
+ return self._test_instance._suite |
+ |
+ #override |
+ def SetUp(self): |
+ |
+ def individual_device_set_up(dev, hdt): |
klundberg
2014/12/09 02:30:47
I'm not sure what hdt is supposed to stand for?
Wo
jbudorick
2014/12/09 15:46:51
shorthand for host_device_tuples
|
+ # install test apk |
klundberg
2014/12/09 02:30:47
Install test APK.
jbudorick
2014/12/09 15:46:51
Done.
|
+ dev.Install(self._test_instance.apk) |
+ |
+ # push data deps |
klundberg
2014/12/09 02:30:47
Push data dependencies.
jbudorick
2014/12/09 15:46:51
Done.
|
+ external_storage = dev.GetExternalStoragePath() |
+ hdt = [(h, d if d is not None else external_storage) |
+ for h, d in hdt] |
+ dev.PushChangedFiles(hdt) |
+ |
+ self._servers[str(dev)] = [s(dev) for s in self._server_factories] |
+ 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.adb) 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) |
+ |