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

Side by Side 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 unified diff | Download patch
OLDNEW
(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
6 import logging
7 import re
8
9 from pylib import ports
10 from pylib.base import base_test_result
11 from pylib.base import test_run
12 from pylib.gtest import gtest_test_instance
13
14 from pylib.local import local_test_server_spawner
15 from pylib.local.device import local_device_environment
16 from pylib.local.device import local_device_test_run
17 from pylib.utils import device_temp_file
18
19 _COMMAND_LINE_FLAGS_SUPPORTED = True
20
21 _EXTRA_COMMAND_LINE_FILE = (
22 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile')
23 _EXTRA_COMMAND_LINE_FLAGS = (
24 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags')
25
26 # TODO(jbudorick): Remove these once we're no longer parsing stdout to generate
27 # results.
28 _RE_TEST_STATUS = re.compile(
29 r'\[ +((?:RUN)|(?:FAILED)|(?:OK)) +\] ?(.*)(?: \((\d+) ms\))?')
30 _RE_TEST_RUN_STATUS = re.compile(
31 r'\[ +(PASSED|RUNNER_FAILED|CRASHED) \] ?(.*)')
32
33 # TODO(jbudorick): Move this up to the test instance if the net test server is
34 # handled outside of the APK for the remote_device environment.
35 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [
36 'content_unittests', 'content_browsertests', 'net_unittests', 'unit_tests'
37 ]
38
39 class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun):
40
41 def __init__(self, env, test_instance):
42 assert isinstance(env, local_device_environment.LocalDeviceEnvironment)
43 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance)
44 super(LocalDeviceGtestRun, self).__init__(env, test_instance)
45
46 # TODO(jbudorick): These will be different for content_browsertests.
47 self._package = 'org.chromium.native_test'
48 self._runner = '.ChromiumNativeTestInstrumentationTestRunner'
49 self._component = '%s/%s' % (self._package, self._runner)
50 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.
51 self._servers = {}
52
53 #override
54 def TestPackage(self):
55 return self._test_instance._suite
56
57 #override
58 def SetUp(self):
59
60 def individual_device_set_up(dev, host_device_tuples):
61 # Install test APK.
62 dev.Install(self._test_instance.apk)
63
64 # Push data dependencies.
65 external_storage = dev.GetExternalStoragePath()
66 host_device_tuples = [
67 (h, d if d is not None else external_storage)
68 for h, d in host_device_tuples]
69 dev.PushChangedFiles(host_device_tuples)
70
71 self._servers[str(dev)] = []
72 if self.TestPackage() in _SUITE_REQUIRES_TEST_SERVER_SPAWNER:
73 self._servers[str(dev)].append(
74 local_test_server_spawner.LocalTestServerSpawner(
75 ports.AllocateTestServerPort(), dev, None))
76
77 for s in self._servers[str(dev)]:
78 s.SetUp()
79
80 self._env.parallel_devices.pMap(individual_device_set_up,
81 self._test_instance.GetDataDependencies())
82
83 #override
84 def _ShouldShard(self):
85 return True
86
87 #override
88 def _CreateShards(self, tests):
89 device_count = len(self._env.devices)
90 return [':'.join(tests[i::device_count])
91 for i in xrange(0, device_count)]
92
93 #override
94 def _GetTests(self):
95 tests = self._env.devices[0].StartInstrumentation(
96 self._component,
97 extras={_EXTRA_COMMAND_LINE_FLAGS: '_ --gtest_list_tests'},
98 raw=False)
99 tests = gtest_test_instance.ParseGTestListTests(tests)
100 tests = self._test_instance.FilterTests(tests)
101 return tests
102
103 #override
104 def _RunTest(self, device, test):
105
106 # Run the test.
107 with device_temp_file.DeviceTempFile(device) as command_line_file:
108 device.WriteFile(
109 command_line_file.name,
110 '_ --gtest_filter=%s' % test)
111
112 output = device.StartInstrumentation(
113 self._component,
114 extras={_EXTRA_COMMAND_LINE_FILE: command_line_file.name},
115 timeout=900, retries=0)
116
117 for s in self._servers[str(device)]:
118 s.Reset()
119 device.ClearApplicationState(self._package)
120
121 # Parse the output.
122 # TODO(jbudorick): Transition test scripts away from parsing stdout.
123 results = []
124 for l in output:
125 matcher = _RE_TEST_STATUS.match(l)
126 if matcher:
127 result_type = None
128 if matcher.group(1) == 'OK':
129 result_type = base_test_result.ResultType.PASS
130 elif matcher.group(1) == 'FAILED':
131 result_type = base_test_result.ResultType.FAIL
132
133 if result_type:
134 test_name = matcher.group(2)
135 duration = matcher.group(3) if matcher.group(3) else 0
136 results.append(base_test_result.BaseTestResult(
137 test_name, result_type, duration))
138 logging.info(l)
139 return results
140
141 #override
142 def TearDown(self):
143 def individual_device_tear_down(dev):
144 for s in self._servers[str(dev)]:
145 s.TearDown()
146
147 self._env.parallel_devices.pMap(individual_device_tear_down)
148
OLDNEW
« 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