forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper script to output count of filtered tests (for PlzNav bot)
After (an embarassing amount of time spent doing) trial-and-error, it doesn't seem possible for this type of script to boost the output to STEP_TEXT so that it shows up on the top-level bot run page unfortunately. But this at least makes the data available with a click through to see progress. Example output here: https://build.chromium.org/p/tryserver.chromium.linux/builders/linux_chromium_browser_side_navigation_rel/builds/146/steps/count_filtered_tests_browser_tests%20%28with%20patch%29/logs/json.output BUG=504374 Review-Url: https://codereview.chromium.org/2353583003 Cr-Commit-Position: refs/heads/master@{#420795}
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Copyright 2016 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import fnmatch | ||
import json | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
|
||
import common | ||
|
||
|
||
def ParseTestList(test_list_contents): | ||
lines = test_list_contents.splitlines() | ||
|
||
all_tests = [] | ||
fixture = None | ||
for line in lines: | ||
if '#' in line: | ||
line = line[:line.index('#')] | ||
line = line.rstrip() | ||
if line[0] == ' ': | ||
assert fixture | ||
all_tests.append(fixture + line.lstrip()) | ||
else: | ||
fixture = line | ||
|
||
return all_tests | ||
|
||
|
||
def LoadFilterList(filter_file): | ||
with open(filter_file, 'r') as f: | ||
lines = f.readlines() | ||
|
||
all_filters = [] | ||
for line in lines: | ||
if '#' in line: | ||
line = line[:line.index('#')] | ||
line = line.strip() | ||
if not line: | ||
continue | ||
assert line.startswith('-') # TODO(scottmg): Handle +s. | ||
all_filters.append(line[1:]) | ||
|
||
return all_filters | ||
|
||
|
||
def FilterMatchesTest(filter_string, test_string): | ||
"""Does something close enough to base/strings/pattern.h's MatchPattern() for | ||
our purposes here.""" | ||
return fnmatch.fnmatch(test_string, filter_string) | ||
|
||
|
||
def main_run(args): | ||
binary_name = args.args[0] | ||
test_filter_file = args.args[1] | ||
base_path = os.path.join(args.paths['checkout'], 'out', args.build_config_fs) | ||
list_tests_output = subprocess.check_output( | ||
[os.path.join(base_path, binary_name), '--gtest_list_tests']) | ||
tests = ParseTestList(list_tests_output) | ||
negative_filter_list = LoadFilterList( | ||
os.path.join(base_path, test_filter_file)) | ||
|
||
result = {'valid': True} | ||
result['total_tests'] = len(tests) | ||
result['disabled_tests'] = len([t for t in tests if '.DISABLED_' in t]) | ||
|
||
# Filter out all the tests that aren't being run. | ||
for f in negative_filter_list: | ||
tests = [t for t in tests if not FilterMatchesTest(f, t)] | ||
result['filtered_tests'] = result['total_tests'] - len(tests) | ||
|
||
json.dump(result, args.output) | ||
return 0 | ||
|
||
|
||
def main_compile_targets(args): | ||
# TODO(scottmg): Get the binary name passed here instead of hardcoding. | ||
json.dump(['browser_tests', 'content_browsertests'], args.output) | ||
|
||
|
||
if __name__ == '__main__': | ||
funcs = { | ||
'run': main_run, | ||
'compile_targets': main_compile_targets, | ||
} | ||
sys.exit(common.run_script(sys.argv[1:], funcs)) |