0
Files
android_webview
apps
ash
base
build
build_overrides
buildtools
cc
chrome
chromecast
chromeos
cloud_print
codelabs
components
content
courgette
crypto
dbus
device
docs
extensions
fuchsia
gin
google_apis
google_update
gpu
headless
infra
ios
ipc
jingle
media
mojo
native_client_sdk
net
pdf
ppapi
printing
remoting
rlz
sandbox
services
skia
sql
storage
styleguide
testing
third_party
tools
accessibility
android
binary_size
bisect_repackage
cfi
check_ecs_deps
checkbins
checklicenses
checkperms
checkteamtags
chrome_extensions
clang
code_coverage
compile_test
coverity
cr
cros
cygprofile
determinism
diagnosis
dromaeo_benchmark_runner
dump_process_memory
emacs
find_runtime_symbols
flags
flakiness
fuchsia
gdb
generate_library_loader
generate_shim_headers
generate_stubs
get_swarming_logs
git
gn
grit
gritsettings
idl_parser
imagediff
infra
ipc_fuzzer
json_comment_eater
json_schema_compiler
json_to_struct
linux
lldb
luci-go
mac
mb
md_browser
media_engagement_preload
memory
memory_inspector
metrics
msan
oopif
origin_trials
page_cycler
perf
polymer
privacy_budget
protoc_wrapper
python
real_world_impact
resources
resultdb
security
site_compare
stats_viewer
strict_enum_value_checker
style_variable_generator
sublime
symsrc
tcmalloc
tests
traceline
traffic_annotation
translation
ubsan
usb_gadget
v8_context_snapshot
valgrind
variations
vim
vscode
web_bluetooth
web_dev_style
win
.style.yapf
DEPS
DIR_METADATA
OWNERS
auto-nav.py
autotest.py
bash-completion
bisect-builds.py
bisect_test.py
boilerplate.py
buildstate.bat
buildstate.py
check_git_config.py
check_grd_for_unused_strings.py
clang-format-js
diagnose-me.py
download_optimization_profile.py
gypv8sh.py
include_tracer.py
ipc_messages_log.py
licenses.py
make-gtest-filter.py
multi_process_rss.py
nocompile_driver.py
omahaproxy.py
perry.py
remove_duplicate_includes.py
remove_stale_pyc_files.py
roll_webgl_conformance.py
run-swarmed.py
sort-headers.py
sort_sources.py
uberblame.py
unused-symbols-report.py
update_pgo_profiles.py
yes_no.py
ui
url
weblayer
.clang-format
.clang-tidy
.eslintrc.js
.git-blame-ignore-revs
.gitattributes
.gitignore
.gn
.vpython
.vpython3
.yapfignore
AUTHORS
BUILD.gn
CODE_OF_CONDUCT.md
DEPS
DIR_METADATA
ENG_REVIEW_OWNERS
LICENSE
LICENSE.chromium_os
OWNERS
PRESUBMIT.py
PRESUBMIT_test.py
PRESUBMIT_test_mocks.py
README.md
WATCHLISTS
codereview.settings
src/tools/perry.py
Raul Tambre 66e754dda9 tools: Use Python 3 style print statements [6/9]
Initial conversion performed using '2to3 -f print .'.
Imports added and duplicate parentheses removed manually.
Manually converted files, comments and inline code that 2to3 missed.
Afterwards ran "git cl format --python" and cherry-picked the formatting changes.

There are no intended behavioural changes.

Bug: 941669
Change-Id: I4a423a71375fd4d8cfc8283dd2703855781ece6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1818519
Commit-Queue: Nico Weber <thakis@chromium.org>
Reviewed-by: Brian White <bcwhite@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Auto-Submit: Raul Tambre <raul@tambre.ee>
Cr-Commit-Position: refs/heads/master@{#699709}
2019-09-25 12:03:44 +00:00

110 lines
2.9 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright 2017 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.
"""Runs all permutations of pairs of tests in a gtest binary to attempt to
detect state leakage between tests.
Example invocation:
gn gen out/asan --args='is_asan=true enable_nacl=false is_debug=false'
ninja -C out/asan base_unittests
tools/perry.py out/asan/base_unittests > perry.log &
tail -f perry.log
You might want to run it in `screen` as it'll take a while.
"""
from __future__ import print_function
import argparse
import os
import multiprocessing
import subprocess
import sys
def _GetTestList(path_to_binary):
"""Returns a set of full test names.
Each test will be of the form "Case.Test". There will be a separate line
for each combination of Case/Test (there are often multiple tests in each
case).
"""
raw_output = subprocess.check_output([path_to_binary, "--gtest_list_tests"])
input_lines = raw_output.splitlines()
# The format of the gtest_list_tests output is:
# "Case1."
# " Test1 # <Optional extra stuff>"
# " Test2"
# "Case2."
# " Test1"
case_name = '' # Includes trailing dot.
test_set = set()
for line in input_lines:
if len(line) > 1:
if '#' in line:
line = line[:line.find('#')]
if line[0] == ' ':
# Indented means a test in previous case.
test_set.add(case_name + line.strip())
else:
# New test case.
case_name = line.strip()
return test_set
def _CheckForFailure(data):
test_binary, pair0, pair1 = data
p = subprocess.Popen(
[test_binary, '--gtest_repeat=5', '--gtest_shuffle',
'--gtest_filter=' + pair0 + ':' + pair1],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = p.communicate()
if p.returncode != 0:
return (pair0, pair1, out)
return None
def _PrintStatus(i, total, failed):
status = '%d of %d tested (%d failures)' % (i+1, total, failed)
print('\r%s%s' % (status, '\x1B[K'), end=' ')
sys.stdout.flush()
def main():
parser = argparse.ArgumentParser(description="Find failing pairs of tests.")
parser.add_argument('binary', help='Path to gtest binary or wrapper script.')
args = parser.parse_args()
print('Getting test list...')
all_tests = _GetTestList(args.binary)
permuted = [(args.binary, x, y) for x in all_tests for y in all_tests]
failed = []
pool = multiprocessing.Pool()
total_count = len(permuted)
for i, result in enumerate(pool.imap_unordered(
_CheckForFailure, permuted, 1)):
if result:
print('\n--gtest_filter=%s:%s failed\n\n%s\n\n' % (result[0], result[1],
result[2]))
failed.append(result)
_PrintStatus(i, total_count, len(failed))
pool.terminate()
pool.join()
if failed:
print('Failed pairs:')
for f in failed:
print(f[0], f[1])
return 0
if __name__ == '__main__':
sys.exit(main())