1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # This script compares the gtest test list for two different builds.
8 # compare_test_lists.py <build_dir_1> <build_dir_2> <binary_name>
10 # For example, from the "src" directory:
11 # python tools/gn/bin/compare_test_lists.py out/Debug out/gnbuild ipc_tests
13 # This will compile the given binary in both output directories, then extracts
14 # the test lists and prints missing or extra tests between the first and the
21 def BuildBinary(build_dir
, binary_name
):
22 """Builds the given binary in the given directory with Ninja.
24 Returns True on success."""
25 return subprocess
.call(["ninja", "-C", build_dir
, binary_name
]) == 0
28 def GetTestList(path_to_binary
):
29 """Returns a set of full test names.
31 Each test will be of the form "Case.Test". There will be a separate line
32 for each combination of Case/Test (there are often multiple tests in each
35 Throws an exception on failure."""
36 raw_output
= subprocess
.check_output([path_to_binary
, "--gtest_list_tests"])
37 input_lines
= raw_output
.split('\n')
39 # The format of the gtest_list_tests output is:
41 # " Test1 # <Optional extra stuff>"
45 case_name
= '' # Includes trailing dot.
47 for line
in input_lines
:
50 # Indented means a test in previous case.
51 test_set
.add(case_name
+ line
[:line
.find('#')].strip())
54 case_name
= line
.strip()
59 def PrintSetDiff(a_name
, a
, b_name
, b
, binary_name
):
60 """Prints the test list difference between the given sets a and b.
62 a_name and b_name will be used to refer to the directories of the two sets,
63 and the binary name will be shown as the source of the output."""
67 print "\n", binary_name
, "tests in", a_name
, "but not", b_name
74 print "\n", binary_name
, "tests in", b_name
, "but not", a_name
79 if len(a_not_b
) == 0 and len(b_not_a
) == 0:
80 print "\nTests match!"
83 def Run(a_dir
, b_dir
, binary_name
):
84 if not BuildBinary(a_dir
, binary_name
):
85 print "Building", binary_name
, "in", a_dir
, "failed"
87 if not BuildBinary(b_dir
, binary_name
):
88 print "Building", binary_name
, "in", b_dir
, "failed"
91 a_tests
= GetTestList(os
.path
.join(a_dir
, binary_name
))
92 b_tests
= GetTestList(os
.path
.join(b_dir
, binary_name
))
94 PrintSetDiff(a_dir
, a_tests
, b_dir
, b_tests
, binary_name
)
97 if len(sys
.argv
) != 4:
98 print "Usage: compare_test_lists.py <build_dir_1> <build_dir_2> " \
101 sys
.exit(Run(sys
.argv
[1], sys
.argv
[2], sys
.argv
[3]))