From aee0b5d31737f476e5c3ea2eb34e00a6f101caea Mon Sep 17 00:00:00 2001 From: ehmaldonado Date: Wed, 16 Nov 2016 16:48:09 -0800 Subject: [PATCH] Fixed a bug where only the tests in the first shard were run. This is because: 1) The environment variables were still around when the test was executed. 2) gtest-parallel executes only one test at a time. So when the test was invoked from a shard different than the 0th one, for example as: ./something_unittests --gtest_filter=Test.Name It read the environment variables, and the environment variables together with the gtest_filter flag, told it that there were several shards, but only one test to be run, so if it wasn't the 0th shard, it wouldn't run the test at all. This is fixed by erasing the environment variables once read. Also change swarming-related flag names to fit the rest of the flags and validate their values. NOTRY=True BUG=chromium:497757, chromium:664425 TBR=pbos@webrtc.org, kjellander@webrtc.org Review-Url: https://codereview.webrtc.org/2505093003 Cr-Commit-Position: refs/heads/master@{#15110} --- third_party/gtest-parallel/gtest-parallel | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/third_party/gtest-parallel/gtest-parallel b/third_party/gtest-parallel/gtest-parallel index 22517cc1bd..5c4d44e63b 100755 --- a/third_party/gtest-parallel/gtest-parallel +++ b/third_party/gtest-parallel/gtest-parallel @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # Copyright 2013 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -266,12 +266,12 @@ parser.add_option('--format', type='string', default='filter', help='output format (raw,filter)') parser.add_option('--print_test_times', action='store_true', default=False, help='When done, list the run time of each test') -parser.add_option('--shard-count', type='int', - default=int(os.environ.get('GTEST_TOTAL_SHARDS', 1)), +parser.add_option('--shard_count', type='int', + default=int(os.environ.pop('GTEST_TOTAL_SHARDS', 1)), help=('Total number of shards (for sharding test execution ' 'between multiple machines). Default: %default')) -parser.add_option('--shard-index', type='int', - default=int(os.environ.get('GTEST_SHARD_INDEX', 0)), +parser.add_option('--shard_index', type='int', + default=int(os.environ.pop('GTEST_SHARD_INDEX', 0)), help=('Zero-indexed number identifying this shard (for ' 'sharding test execution between multiple machines). ' 'Default: %default')) @@ -290,6 +290,14 @@ elif options.format == 'filter': else: sys.exit("Unknown output format: " + options.format) +if options.shard_count < 1: + sys.exit("Invalid number of shards: %d. Must be at least 1." % + options.shard_count) +if options.shard_index < 0 or options.shard_count <= options.shard_index: + sys.exit("Invalid shard index: %d. Must be between 0 and %d." % + (options.shard_index, options.shard_count - 1)) + + # Find tests. save_file = os.path.join(os.path.expanduser("~"), ".gtest-parallel-times") times = TestTimes(save_file)