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

Side by Side Diff: build/android/pylib/local/device/local_device_instrumentation_test_run.py

Issue 794923003: [Android] Implement instrumentation tests in platform mode. (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 unified diff | Download patch
OLDNEW
(Empty)
1
klundberg 2015/01/07 22:56:30 Copyright?
jbudorick 2015/01/12 16:32:16 Done.
2 import logging
3 import time
4
5 from pylib import flag_changer
6 from pylib.base import base_test_result
7 from pylib.base import test_run
8 from pylib.local.device import local_device_test_run
9
10
11 TIMEOUT_ANNOTATIONS = [
12 ('Manual', 10 * 60 * 60),
13 ('IntegrationTest', 30 * 60),
14 ('External', 10 * 60),
15 ('EnormousTest', 10 * 60),
16 ('LargeTest', 5 * 60),
17 ('MediumTest', 3 * 60),
18 ('SmallTest', 1 * 60),
19 ]
20
21
22 # TODO(jbudorick): Make this private once the instrumentation test_runner is
23 # deprecated.
24 def DidPackageCrashOnDevice(package_name, device):
25 # Dismiss any error dialogs. Limit the number in case we have an error
26 # loop or we are failing to dismiss.
27 for _ in xrange(10):
28 package = device.old_interface.DismissCrashDialogIfNeeded()
29 if not package:
30 return False
31 # Assume test package convention of ".test" suffix
32 if package in package_name:
33 return True
34 return False
35
36
37 class LocalDeviceInstrumentationTestRun(
38 local_device_test_run.LocalDeviceTestRun):
39 def __init__(self, env, test_instance):
40 super(LocalDeviceInstrumentationTestRun, self).__init__(env, test_instance)
41 self._flag_changers = {}
42
43 def TestPackage(self):
44 return None
45
46 def SetUp(self):
47 def substitute_external_storage(d, external_storage):
48 if not d:
49 return external_storage
50 elif isinstance(d, list):
51 return '/'.join(p if p else external_storage for p in d)
52 else:
53 return d
54
55 def individual_device_set_up(dev, host_device_tuples):
klundberg 2015/01/07 22:56:30 Does this mean that the test runner will always in
jbudorick 2015/01/12 16:32:16 Yes. It's ok if they're already installed, though.
56 dev.Install(self._test_instance.apk_under_test)
57 dev.Install(self._test_instance.test_apk)
58
59 external_storage = dev.GetExternalStoragePath()
60 host_device_tuples = [
61 (h, substitute_external_storage(d, external_storage))
62 for h, d in host_device_tuples]
63 logging.info('instrumentation data deps:')
64 for h, d in host_device_tuples:
65 logging.info('%r -> %r', h, d)
66 dev.PushChangedFiles(host_device_tuples)
67 if self._test_instance.flags:
68 if not self._test_instance.package_info:
69 logging.error("Couldn't set flags: no package info")
70 elif not self._test_instance.package_info.cmdline_file:
71 logging.error("Couldn't set flags: no cmdline_file")
72 else:
73 self._flag_changers[str(dev)] = flag_changer.FlagChanger(
74 dev, self._test_instance.package_info.cmdline_file)
75 logging.debug('Attempting to set flags: %r',
76 self._test_instance.flags)
77 self._flag_changers[str(dev)].AddFlags(self._test_instance.flags)
78
79 self._env.parallel_devices.pMap(
80 individual_device_set_up,
81 self._test_instance.GetDataDependencies())
82
83 def TearDown(self):
84 def individual_device_tear_down(dev):
85 if str(dev) in self._flag_changers:
86 self._flag_changers[str(dev)].Restore()
87
88 self._env.parallel_devices.pMap(individual_device_tear_down)
89
90 #override
91 def _CreateShards(self, tests):
92 return tests
93
94 #override
95 def _GetTests(self):
96 return self._test_instance.GetTests()
97
98 #override
99 def _GetTestName(self, test):
100 return '%s#%s' % (test['class'], test['method'])
101
102 #override
103 def _RunTest(self, device, test):
104 test_name = self._GetTestName(test)
105 logging.info('preparing to run %s: %s' % (test_name, test))
106
107 extras = {
108 'class': test_name,
109 'org.chromium.chrome.test.ChromeInstrumentationTestRunner'
110 '.EnableTestHttpServer': '',
111 }
112 timeout = self._GetTimeoutFromAnnotations(test['annotations'], test_name)
113
114 time_ms = lambda: int(time.time() * 1e3)
115 start_ms = time_ms()
116 output = device.StartInstrumentation(
117 '%s/%s' % (self._test_instance.test_package,
118 self._test_instance.test_runner),
119 raw=True, extras=extras, timeout=timeout, retries=0)
120 duration_ms = time_ms() - start_ms
121
122 # TODO(jbudorick): Make instrumentation tests output a JSON so this
123 # doesn't have to parse the output.
124 logging.info('output from %s:' % test_name)
125 for l in output:
126 logging.info(' %s' % l)
127
128 _, _, statuses = self._test_instance.ParseAmInstrumentRawOutput(output)
129 result = self._test_instance.GenerateTestResult(
130 test_name, statuses, start_ms, duration_ms)
131 if DidPackageCrashOnDevice(self._test_instance.test_package, device):
132 result.SetType(base_test_result.ResultType.CRASH)
133 return result
134
135 #override
136 def _ShouldShard(self):
137 return True
138
139 @staticmethod
140 def _GetTimeoutFromAnnotations(annotations, test_name):
141 for k, v in TIMEOUT_ANNOTATIONS:
142 if k in annotations:
143 timeout = v
144 else:
145 logging.warning('Using default 1 minute timeout for %s' % test_name)
146 timeout = 60
147
148 try:
149 scale = int(annotations.get('TimeoutScale', 1))
150 except ValueError as e:
151 logging.warning("Non-integer value of TimeoutScale ignored. (%s)", str(e))
152 scale = 1
153 timeout *= scale
154
155 return timeout
156
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698