Skip to content

Commit

Permalink
Add helper script to output count of filtered tests (for PlzNav bot)
Browse files Browse the repository at this point in the history
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
sgraham authored and Commit bot committed Sep 24, 2016
1 parent d69e8cb commit a382acb
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
18 changes: 18 additions & 0 deletions testing/buildbot/chromium.fyi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,24 @@
},
"test": "unit_tests"
}
],
"scripts": [
{
"args": [
"browser_tests",
"../../testing/buildbot/filters/browser-side-navigation.linux.browser_tests.filter"
],
"name": "count_filtered_tests_browser_tests",
"script": "count_filtered_tests.py"
},
{
"args": [
"content_browsertests",
"../../testing/buildbot/filters/browser-side-navigation.linux.content_browsertests.filter"
],
"name": "count_filtered_tests_content_browsertests",
"script": "count_filtered_tests.py"
}
]
},
"CFI Linux": {
Expand Down
89 changes: 89 additions & 0 deletions testing/scripts/count_filtered_tests.py
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))

0 comments on commit a382acb

Please sign in to comment.