From 6cd42b6d1de1feaed37a14062f56952a91632317 Mon Sep 17 00:00:00 2001 From: "huanr@chromium.org" Date: Wed, 29 Jul 2009 21:15:55 +0000 Subject: Update smoketests.py so we can run ui_tests in parallel, with the number of shards equal to NUMBER_OF_PROCESSORS. Review URL: http://codereview.chromium.org/159568 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21996 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/tools/test/smoketests.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'chrome/tools') diff --git a/chrome/tools/test/smoketests.py b/chrome/tools/test/smoketests.py index 50ddd83..f0513df 100755 --- a/chrome/tools/test/smoketests.py +++ b/chrome/tools/test/smoketests.py @@ -109,6 +109,39 @@ def _MakeSubstitutions(list, options): return [word % substitutions for word in list] +def RunTestsInShards(test_command, verbose=True): + """Runs a test in shards. The number of shards is equal to + NUMBER_OF_PROCESSORS. + + Args: + test_command: the test command to run, which is a list of one or more + strings. + verbose: if True, combines stdout and stderr into stdout. + Otherwise, prints only the command's stderr to stdout. + + Returns: + The first shard process's exit status. + + Raises: + CommandNotFound if the command executable could not be found. + """ + processor_count = 2 + try: + processor_count = int(os.environ['NUMBER_OF_PROCESSORS']) + except KeyError: + print 'No NUMBER_OF_PROCESSORS defined. Use 2 instances.' + + commands = [] + for i in xrange(processor_count): + command = [test_command[j] for j in xrange(len(test_command))] + # To support sharding, the test executable needs to provide --batch-count + # --batch-index command line switches. + command.append('--batch-count=%s' % processor_count) + command.append('--batch-index=%d' % i) + commands.append(command) + return google.process_utils.RunCommandsInParallel(commands, verbose)[0][0] + + def main(options, args): """Runs all the selected tests for the given build type and target.""" options.build_type = options.build_type.lower() @@ -184,7 +217,10 @@ def main(options, args): print print 'Running %s:' % test, try: - result = google.process_utils.RunCommand(command, options.verbose) + if test == 'ui': + result = RunTestsInShards(command, options.verbose) + else: + result = google.process_utils.RunCommand(command, options.verbose) except google.process_utils.CommandNotFound, e: print '%s' % e raise -- cgit v1.1