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

Side by Side Diff: build/android/pylib/remote/device/remote_device_instrumentation_test_run.py

Issue 1415533007: [Android] Add sharding for AMP instrumentation tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 """Run specific test on specific environment.""" 5 """Run specific test on specific environment."""
6 6
7 import logging 7 import logging
8 import os 8 import os
9 import tempfile 9 import tempfile
10 10
11 from pylib.base import base_test_result 11 from pylib.base import base_test_result
12 from pylib.remote.device import remote_device_test_run 12 from pylib.remote.device import remote_device_test_run
13 13
14 14
15 class RemoteDeviceInstrumentationTestRun( 15 class RemoteDeviceInstrumentationTestRun(
16 remote_device_test_run.RemoteDeviceTestRun): 16 remote_device_test_run.RemoteDeviceTestRun):
17 """Run instrumentation tests on a remote device.""" 17 """Run instrumentation tests on a remote device."""
18 18
19 #override 19 #override
20 def _GetAdditionalApks(self):
rnephew (Reviews Here) 2015/10/26 20:42:18 It looks like this is returning the test_apk as we
mikecase (-- gone --) 2015/10/27 01:27:43 Yeah, I don't like this either. So there is an --a
21 return [self._test_instance.test_apk] + self._test_instance.additional_apks
22
23 #override
24 def _GetAppPath(self):
25 return self._test_instance.apk_under_test
26
27 #override
28 def _GetTestFramework(self):
29 if self._env.test_framework:
30 logging.warning('Ignoring configured test_framework "%s"',
31 self._env.test_framework)
32 return 'robotium'
33
34 #override
35 def _GetTestPath(self):
36 return self._test_instance.driver_apk
37
38 #override
39 def _GetTestRunnerName(self):
rnephew (Reviews Here) 2015/10/26 20:42:18 Is this used anywhere else than _GetFrameworkConfi
mikecase (-- gone --) 2015/10/27 01:27:43 Merged!
40 return self._test_instance.driver_name
41
42 #override
43 def _GetFrameworkConfigs(self):
44 return {'runner': self._GetTestRunnerName()}
45
46 # pylint: disable=protected-access
rnephew (Reviews Here) 2015/10/26 20:42:18 Just an idea, feel free to ignore. Instead of dis
mikecase (-- gone --) 2015/10/27 01:27:43 We decided offline to keep as is.
47 #override
48 def _GetShardEnvironmentVars(self, num_shards):
49 """Returns a list of shard specfic environment configs."""
50 all_tests = self._test_instance.GetTests()
51 test_shards = [all_tests[i::num_shards] for i in range(num_shards)]
52
53 shard_env_vars = []
54 for i, tests in enumerate(test_shards):
55 test_list_file = tempfile.NamedTemporaryFile(
jbudorick 2015/10/26 22:23:30 Again, not a huge fan of this. Restructure the cod
mikecase (-- gone --) 2015/10/27 01:27:43 Using a context manager is super awkward when you
56 suffix='.txt', dir=self._base_tempfile_dir, delete=False)
57 self._test_instance._data_deps.append(
58 (os.path.abspath(test_list_file.name), None))
59 for t in tests:
60 test_name = '%s#%s' % (t['class'], t['method'])
61 logging.debug('shard %s: %s', i, test_name)
62 test_list_file.write('%s\n' % test_name)
63 test_list_file.flush()
64
65 env_vars = self._test_instance.GetDriverEnvironmentVars(
66 test_list_file_path=test_list_file.name)
67 env_vars.update(self._test_instance.GetHttpServerEnvironmentVars())
68 shard_env_vars.append(env_vars)
69
70 return shard_env_vars
71
72 #override
73 def _ShouldShard(self):
74 return True
75
76 #override
20 def TestPackage(self): 77 def TestPackage(self):
21 return self._test_instance.test_package 78 return self._test_instance.test_package
22 79
23 #override 80 #override
24 def _TriggerSetUp(self): 81 def _ParseTestResults(self, test_output, results_zip):
25 """Set up the triggering of a test run."""
26 logging.info('Triggering test run.')
27
28 # pylint: disable=protected-access
29 with tempfile.NamedTemporaryFile(suffix='.txt') as test_list_file:
30 tests = self._test_instance.GetTests()
31 logging.debug('preparing to run %d instrumentation tests remotely:',
32 len(tests))
33 for t in tests:
34 test_name = '%s#%s' % (t['class'], t['method'])
35 logging.debug(' %s', test_name)
36 test_list_file.write('%s\n' % test_name)
37 test_list_file.flush()
38 self._test_instance._data_deps.append(
39 (os.path.abspath(test_list_file.name), None))
40
41 env_vars = self._test_instance.GetDriverEnvironmentVars(
42 test_list_file_path=test_list_file.name)
43 env_vars.update(self._test_instance.GetHttpServerEnvironmentVars())
44
45 logging.debug('extras:')
46 for k, v in env_vars.iteritems():
47 logging.debug(' %s: %s', k, v)
48
49 self._AmInstrumentTestSetup(
50 self._test_instance.apk_under_test,
51 self._test_instance.driver_apk,
52 self._test_instance.driver_name,
53 environment_variables=env_vars,
54 extra_apks=([self._test_instance.test_apk] +
55 self._test_instance.additional_apks))
56
57 #override
58 def _ParseTestResults(self):
59 logging.info('Parsing results from stdout.') 82 logging.info('Parsing results from stdout.')
60 r = base_test_result.TestRunResults() 83 results = base_test_result.TestRunResults()
61 result_code, result_bundle, statuses = ( 84 result_code, result_bundle, statuses = (
62 self._test_instance.ParseAmInstrumentRawOutput( 85 self._test_instance.ParseAmInstrumentRawOutput(
63 self._results['results']['output'].splitlines())) 86 test_output['results']['output'].splitlines()))
64 result = self._test_instance.GenerateTestResults( 87 result = self._test_instance.GenerateTestResults(
65 result_code, result_bundle, statuses, 0, 0) 88 result_code, result_bundle, statuses, 0, 0)
66 89
67 if isinstance(result, base_test_result.BaseTestResult): 90 if isinstance(result, base_test_result.BaseTestResult):
68 r.AddResult(result) 91 results.AddResult(result)
69 elif isinstance(result, list): 92 elif isinstance(result, list):
70 r.AddResults(result) 93 results.AddResults(result)
71 else: 94 else:
72 raise Exception('Unexpected result type: %s' % type(result).__name__) 95 raise Exception('Unexpected result type: %s' % type(result).__name__)
73 96
74 self._DetectPlatformErrors(r) 97 self._DetectPlatformErrors(results, test_output, results_zip)
75 return r 98 return results
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698