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

Side by Side Diff: build/android/pylib/instrumentation/test_runner.py

Issue 132463007: Enable presubmit pylint in build/android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Class for running instrumentation tests on a single device.""" 5 """Class for running instrumentation tests on a single device."""
6 6
7 import logging 7 import logging
8 import os 8 import os
9 import re 9 import re
10 import sys 10 import sys
11 import time 11 import time
12 12
13 13
14 sys.path.append(os.path.join(sys.path[0], 14 sys.path.append(os.path.join(sys.path[0],
15 os.pardir, os.pardir, 'build', 'util', 'lib', 15 os.pardir, os.pardir, 'build', 'util', 'lib',
16 'common')) 16 'common'))
17 import perf_tests_results_helper 17 import perf_tests_results_helper
18 18
19 from pylib import android_commands 19 from pylib import android_commands
20 from pylib import constants 20 from pylib import constants
21 from pylib import flag_changer 21 from pylib import flag_changer
22 from pylib import valgrind_tools 22 from pylib import valgrind_tools
23 from pylib.base import base_test_result 23 from pylib.base import base_test_result
24 from pylib.base import base_test_runner 24 from pylib.base import base_test_runner
25 from pylib.instrumentation import json_perf_parser 25 from pylib.instrumentation import json_perf_parser
26 26
27 import test_result 27 from . import test_result
28 28
29 29
30 _PERF_TEST_ANNOTATION = 'PerfTest' 30 _PERF_TEST_ANNOTATION = 'PerfTest'
31 31
32 32
33 def _GetDataFilesForTestSuite(suite_basename): 33 def _GetDataFilesForTestSuite(suite_basename):
34 """Returns a list of data files/dirs needed by the test suite. 34 """Returns a list of data files/dirs needed by the test suite.
35 35
36 Args: 36 Args:
37 suite_basename: The test suite basename for which to return file paths. 37 suite_basename: The test suite basename for which to return file paths.
(...skipping 28 matching lines...) Expand all
66 device: Attached android device. 66 device: Attached android device.
67 shard_index: Shard index. 67 shard_index: Shard index.
68 test_pkg: A TestPackage object. 68 test_pkg: A TestPackage object.
69 additional_flags: A list of additional flags to add to the command line. 69 additional_flags: A list of additional flags to add to the command line.
70 """ 70 """
71 super(TestRunner, self).__init__(device, test_options.tool, 71 super(TestRunner, self).__init__(device, test_options.tool,
72 test_options.push_deps, 72 test_options.push_deps,
73 test_options.cleanup_test_files) 73 test_options.cleanup_test_files)
74 self._lighttp_port = constants.LIGHTTPD_RANDOM_PORT_FIRST + shard_index 74 self._lighttp_port = constants.LIGHTTPD_RANDOM_PORT_FIRST + shard_index
75 75
76 self.coverage_device_file = ''
frankf 2014/02/03 18:58:51 why not None?
jbudorick 2014/02/03 19:33:57 because I'm still getting used to dynamic typing :
77 self.coverage_dir = test_options.coverage_dir
78 self.coverage_host_file = ''
76 self.options = test_options 79 self.options = test_options
77 self.test_pkg = test_pkg 80 self.test_pkg = test_pkg
78 self.coverage_dir = test_options.coverage_dir
79 # Use the correct command line file for the package under test. 81 # Use the correct command line file for the package under test.
80 cmdline_file = [a.cmdline_file for a in constants.PACKAGE_INFO.itervalues() 82 cmdline_file = [a.cmdline_file for a in constants.PACKAGE_INFO.itervalues()
81 if a.test_package == self.test_pkg.GetPackageName()] 83 if a.test_package == self.test_pkg.GetPackageName()]
82 assert len(cmdline_file) < 2, 'Multiple packages have the same test package' 84 assert len(cmdline_file) < 2, 'Multiple packages have the same test package'
83 if len(cmdline_file) and cmdline_file[0]: 85 if len(cmdline_file) and cmdline_file[0]:
84 self.flags = flag_changer.FlagChanger(self.adb, cmdline_file[0]) 86 self.flags = flag_changer.FlagChanger(self.adb, cmdline_file[0])
85 if additional_flags: 87 if additional_flags:
86 self.flags.AddFlags(additional_flags) 88 self.flags.AddFlags(additional_flags)
87 else: 89 else:
88 self.flags = None 90 self.flags = None
(...skipping 16 matching lines...) Expand all
105 # Make sure SD card is ready. 107 # Make sure SD card is ready.
106 self.adb.WaitForSdCardReady(20) 108 self.adb.WaitForSdCardReady(20)
107 for p in test_data: 109 for p in test_data:
108 self.adb.PushIfNeeded( 110 self.adb.PushIfNeeded(
109 os.path.join(constants.DIR_SOURCE_ROOT, p), 111 os.path.join(constants.DIR_SOURCE_ROOT, p),
110 os.path.join(self.adb.GetExternalStorage(), p)) 112 os.path.join(self.adb.GetExternalStorage(), p))
111 113
112 # TODO(frankf): Specify test data in this file as opposed to passing 114 # TODO(frankf): Specify test data in this file as opposed to passing
113 # as command-line. 115 # as command-line.
114 for dest_host_pair in self.options.test_data: 116 for dest_host_pair in self.options.test_data:
115 dst_src = dest_host_pair.split(':',1) 117 dst_src = dest_host_pair.split(':', 1)
116 dst_layer = dst_src[0] 118 dst_layer = dst_src[0]
117 host_src = dst_src[1] 119 host_src = dst_src[1]
118 host_test_files_path = '%s/%s' % (constants.DIR_SOURCE_ROOT, host_src) 120 host_test_files_path = '%s/%s' % (constants.DIR_SOURCE_ROOT, host_src)
119 if os.path.exists(host_test_files_path): 121 if os.path.exists(host_test_files_path):
120 self.adb.PushIfNeeded(host_test_files_path, '%s/%s/%s' % ( 122 self.adb.PushIfNeeded(host_test_files_path, '%s/%s/%s' % (
121 self.adb.GetExternalStorage(), TestRunner._DEVICE_DATA_DIR, 123 self.adb.GetExternalStorage(), TestRunner._DEVICE_DATA_DIR,
122 dst_layer)) 124 dst_layer))
123 self.tool.CopyFiles() 125 self.tool.CopyFiles()
124 TestRunner._DEVICE_HAS_TEST_FILES[self.device] = True 126 TestRunner._DEVICE_HAS_TEST_FILES[self.device] = True
125 127
(...skipping 19 matching lines...) Expand all
145 if not self.adb.IsRootEnabled(): 147 if not self.adb.IsRootEnabled():
146 logging.warning('Unable to enable java asserts for %s, non rooted device', 148 logging.warning('Unable to enable java asserts for %s, non rooted device',
147 self.device) 149 self.device)
148 else: 150 else:
149 if self.adb.SetJavaAssertsEnabled(True): 151 if self.adb.SetJavaAssertsEnabled(True):
150 self.adb.Reboot(full_reboot=False) 152 self.adb.Reboot(full_reboot=False)
151 153
152 # We give different default value to launch HTTP server based on shard index 154 # We give different default value to launch HTTP server based on shard index
153 # because it may have race condition when multiple processes are trying to 155 # because it may have race condition when multiple processes are trying to
154 # launch lighttpd with same port at same time. 156 # launch lighttpd with same port at same time.
155 http_server_ports = self.LaunchTestHttpServer( 157 self.LaunchTestHttpServer(
156 os.path.join(constants.DIR_SOURCE_ROOT), self._lighttp_port) 158 os.path.join(constants.DIR_SOURCE_ROOT), self._lighttp_port)
157 if self.flags: 159 if self.flags:
158 self.flags.AddFlags(['--disable-fre', '--enable-test-intents']) 160 self.flags.AddFlags(['--disable-fre', '--enable-test-intents'])
159 161
160 def TearDown(self): 162 def TearDown(self):
161 """Cleans up the test harness and saves outstanding data from test run.""" 163 """Cleans up the test harness and saves outstanding data from test run."""
162 if self.flags: 164 if self.flags:
163 self.flags.Restore() 165 self.flags.Restore()
164 super(TestRunner, self).TearDown() 166 super(TestRunner, self).TearDown()
165 167
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 self._GetInstrumentationArgs(), timeout) 327 self._GetInstrumentationArgs(), timeout)
326 except android_commands.errors.WaitForResponseTimedOutError: 328 except android_commands.errors.WaitForResponseTimedOutError:
327 logging.info('Ran the test with timeout of %ds.' % timeout) 329 logging.info('Ran the test with timeout of %ds.' % timeout)
328 raise 330 raise
329 331
330 #override 332 #override
331 def RunTest(self, test): 333 def RunTest(self, test):
332 raw_result = None 334 raw_result = None
333 start_date_ms = None 335 start_date_ms = None
334 results = base_test_result.TestRunResults() 336 results = base_test_result.TestRunResults()
335 timeout=(self._GetIndividualTestTimeoutSecs(test) * 337 timeout = (self._GetIndividualTestTimeoutSecs(test) *
336 self._GetIndividualTestTimeoutScale(test) * 338 self._GetIndividualTestTimeoutScale(test) *
337 self.tool.GetTimeoutScale()) 339 self.tool.GetTimeoutScale())
338 try: 340 try:
339 self.TestSetup(test) 341 self.TestSetup(test)
340 start_date_ms = int(time.time()) * 1000 342 start_date_ms = int(time.time()) * 1000
341 raw_result = self._RunTest(test, timeout) 343 raw_result = self._RunTest(test, timeout)
342 duration_ms = int(time.time()) * 1000 - start_date_ms 344 duration_ms = int(time.time()) * 1000 - start_date_ms
343 status_code = raw_result.GetStatusCode() 345 status_code = raw_result.GetStatusCode()
344 if status_code: 346 if status_code:
345 if self.options.screenshot_failures: 347 if self.options.screenshot_failures:
346 self._TakeScreenshot(test) 348 self._TakeScreenshot(test)
347 log = raw_result.GetFailureReason() 349 log = raw_result.GetFailureReason()
(...skipping 22 matching lines...) Expand all
370 duration_ms = 0 372 duration_ms = 0
371 message = str(e) 373 message = str(e)
372 if not message: 374 if not message:
373 message = 'No information.' 375 message = 'No information.'
374 results.AddResult(test_result.InstrumentationTestResult( 376 results.AddResult(test_result.InstrumentationTestResult(
375 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms, 377 test, base_test_result.ResultType.CRASH, start_date_ms, duration_ms,
376 log=message)) 378 log=message))
377 raw_result = None 379 raw_result = None
378 self.TestTeardown(test, raw_result) 380 self.TestTeardown(test, raw_result)
379 return (results, None if results.DidRunPass() else test) 381 return (results, None if results.DidRunPass() else test)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698