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

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

Issue 1703863003: Created separate shards for suspicious testcases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 4 years, 9 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 2014 The Chromium Authors. All rights reserved. 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 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 import collections 5 import collections
6 import itertools 6 import itertools
7 import os 7 import os
8 import posixpath 8 import posixpath
9 9
10 from devil.android import device_errors 10 from devil.android import device_errors
11 from devil.android import device_temp_file 11 from devil.android import device_temp_file
12 from devil.android import ports 12 from devil.android import ports
13 from devil.utils import reraiser_thread 13 from devil.utils import reraiser_thread
14 from pylib import constants 14 from pylib import constants
15 from pylib.gtest import gtest_test_instance 15 from pylib.gtest import gtest_test_instance
16 from pylib.local import local_test_server_spawner 16 from pylib.local import local_test_server_spawner
17 from pylib.local.device import local_device_environment 17 from pylib.local.device import local_device_environment
18 from pylib.local.device import local_device_test_run 18 from pylib.local.device import local_device_test_run
19 from pylib.base import base_test_result
jbudorick 2016/03/01 05:05:26 nit: alphabetize
19 20
20 _COMMAND_LINE_FLAGS_SUPPORTED = True 21 _COMMAND_LINE_FLAGS_SUPPORTED = True
21 22
22 _MAX_INLINE_FLAGS_LENGTH = 50 # Arbitrarily chosen. 23 _MAX_INLINE_FLAGS_LENGTH = 50 # Arbitrarily chosen.
23 _EXTRA_COMMAND_LINE_FILE = ( 24 _EXTRA_COMMAND_LINE_FILE = (
24 'org.chromium.native_test.NativeTestActivity.CommandLineFile') 25 'org.chromium.native_test.NativeTestActivity.CommandLineFile')
25 _EXTRA_COMMAND_LINE_FLAGS = ( 26 _EXTRA_COMMAND_LINE_FLAGS = (
26 'org.chromium.native_test.NativeTestActivity.CommandLineFlags') 27 'org.chromium.native_test.NativeTestActivity.CommandLineFlags')
27 _EXTRA_TEST_LIST = ( 28 _EXTRA_TEST_LIST = (
28 'org.chromium.native_test.NativeTestInstrumentationTestRunner' 29 'org.chromium.native_test.NativeTestInstrumentationTestRunner'
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 223
223 def __init__(self, env, test_instance): 224 def __init__(self, env, test_instance):
224 assert isinstance(env, local_device_environment.LocalDeviceEnvironment) 225 assert isinstance(env, local_device_environment.LocalDeviceEnvironment)
225 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance) 226 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance)
226 super(LocalDeviceGtestRun, self).__init__(env, test_instance) 227 super(LocalDeviceGtestRun, self).__init__(env, test_instance)
227 228
228 if self._test_instance.apk: 229 if self._test_instance.apk:
229 self._delegate = _ApkDelegate(self._test_instance) 230 self._delegate = _ApkDelegate(self._test_instance)
230 elif self._test_instance.exe: 231 elif self._test_instance.exe:
231 self._delegate = _ExeDelegate(self, self._test_instance.exe) 232 self._delegate = _ExeDelegate(self, self._test_instance.exe)
232 233 self._crashes = set()
233 self._servers = collections.defaultdict(list) 234 self._servers = collections.defaultdict(list)
234 235
235 #override 236 #override
236 def TestPackage(self): 237 def TestPackage(self):
237 return self._test_instance.suite 238 return self._test_instance.suite
238 239
239 #override 240 #override
240 def SetUp(self): 241 def SetUp(self):
241 @local_device_test_run.handle_shard_failures_with( 242 @local_device_test_run.handle_shard_failures_with(
242 on_failure=self._env.BlacklistDevice) 243 on_failure=self._env.BlacklistDevice)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 step() 277 step()
277 278
278 self._env.parallel_devices.pMap(individual_device_set_up) 279 self._env.parallel_devices.pMap(individual_device_set_up)
279 280
280 #override 281 #override
281 def _ShouldShard(self): 282 def _ShouldShard(self):
282 return True 283 return True
283 284
284 #override 285 #override
285 def _CreateShards(self, tests): 286 def _CreateShards(self, tests):
287 # _crashes are tests that might crash and make the tests in the same shard
288 # following the crashed testcase not run.
289 # Thus we need to create separate shards for each crashed testcase,
290 # so that other tests can be run.
286 device_count = len(self._env.devices) 291 device_count = len(self._env.devices)
287 shards = [] 292 shards = []
293
294 # Add shards with only one suspect testcase.
295 shards += [[crash] for crash in self._crashes if crash in tests]
296
297 # Delete suspect testcase from tests.
298 tests = [test for test in tests if not test in self._crashes]
299
288 for i in xrange(0, device_count): 300 for i in xrange(0, device_count):
289 unbounded_shard = tests[i::device_count] 301 unbounded_shard = tests[i::device_count]
290 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] 302 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE]
291 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] 303 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)]
292 return shards 304 return shards
293 305
294 #override 306 #override
295 def _GetTests(self): 307 def _GetTests(self):
296 if self._test_instance.extract_test_list_from_filter: 308 if self._test_instance.extract_test_list_from_filter:
297 # When the exact list of tests to run is given via command-line (e.g. when 309 # When the exact list of tests to run is given via command-line (e.g. when
(...skipping 30 matching lines...) Expand all
328 test, device, flags=self._test_instance.test_arguments, 340 test, device, flags=self._test_instance.test_arguments,
329 timeout=timeout, retries=0) 341 timeout=timeout, retries=0)
330 for s in self._servers[str(device)]: 342 for s in self._servers[str(device)]:
331 s.Reset() 343 s.Reset()
332 if self._test_instance.app_files: 344 if self._test_instance.app_files:
333 self._delegate.PullAppFiles(device, self._test_instance.app_files, 345 self._delegate.PullAppFiles(device, self._test_instance.app_files,
334 self._test_instance.app_file_dir) 346 self._test_instance.app_file_dir)
335 if not self._test_instance.skip_clear_data: 347 if not self._test_instance.skip_clear_data:
336 self._delegate.Clear(device) 348 self._delegate.Clear(device)
337 349
338 # Parse the output.
jbudorick 2016/03/01 05:05:26 ?
339 # TODO(jbudorick): Transition test scripts away from parsing stdout. 350 # TODO(jbudorick): Transition test scripts away from parsing stdout.
351
jbudorick 2016/03/01 05:05:26 nit: don't add this line
340 results = self._test_instance.ParseGTestOutput(output) 352 results = self._test_instance.ParseGTestOutput(output)
353
354 # Check whether there are any crashed testcases.
355 for result in results:
jbudorick 2016/03/01 05:05:26 These three lines can be: self._crashes.update(
356 if result.GetType() == base_test_result.ResultType.CRASH:
357 self._crashes.add(result.GetName())
341 return results 358 return results
342 359
343 #override 360 #override
344 def TearDown(self): 361 def TearDown(self):
345 @local_device_test_run.handle_shard_failures 362 @local_device_test_run.handle_shard_failures
346 def individual_device_tear_down(dev): 363 def individual_device_tear_down(dev):
347 for s in self._servers.get(str(dev), []): 364 for s in self._servers.get(str(dev), []):
348 s.TearDown() 365 s.TearDown()
349 366
350 tool = self.GetTool(dev) 367 tool = self.GetTool(dev)
351 tool.CleanUpEnvironment() 368 tool.CleanUpEnvironment()
352 369
353 self._env.parallel_devices.pMap(individual_device_tear_down) 370 self._env.parallel_devices.pMap(individual_device_tear_down)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698