Skip to content

Commit 801d264

Browse files
committed
Improve printing of cts_exe.py
It now shows the error code and a sampler of the output on CI.
1 parent cf78d84 commit 801d264

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

test/conformance/cts_exe.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import sys
1515
import argparse
16+
import signal
1617
import subprocess # nosec B404
1718

1819

@@ -59,6 +60,22 @@ def _print_environ(env):
5960
_print_end_header()
6061

6162

63+
def _print_failure(code, stdout):
64+
signalname = "???"
65+
try:
66+
signalname = signal.strsignal(abs(code))
67+
except ValueError:
68+
pass
69+
_print_format("Got error code {} ({})", code, signalname)
70+
71+
# Display some context in the CI log so the user doesn't have to click down the lines
72+
if _ci():
73+
lines = stdout.split("\n")
74+
_print_format("Last 20 lines of output (expand section above for more):")
75+
for l in lines[-20:]:
76+
print(l)
77+
78+
6279
def _check_filter(cmd, filter):
6380
"""
6481
Checks that the filter matches at least one test for the given cmd
@@ -83,17 +100,20 @@ def _run_cmd(cmd, comment, filter):
83100
if not _check_filter(cmd, filter):
84101
_print_end_header()
85102
_print_error("Could not find any tests with this filter")
86-
return 2
103+
return (2, "")
87104

88105
sys.stdout.flush()
89-
result = subprocess.call( # nosec B603
106+
proc = subprocess.Popen( # nosec B603
90107
cmd,
91-
stdout=sys.stdout,
92-
stderr=sys.stdout,
108+
stdout=subprocess.PIPE,
109+
stderr=subprocess.STDOUT,
93110
env=(os.environ | {"GTEST_FILTER": filter}),
94111
)
112+
stdout = proc.communicate()[0].decode("utf-8")
113+
returncode = proc.wait()
114+
print(stdout)
95115
_print_end_header()
96-
return result
116+
return (returncode, stdout)
97117

98118

99119
if __name__ == "__main__":
@@ -155,23 +175,25 @@ def _run_cmd(cmd, comment, filter):
155175
# First, run all the known good tests
156176
gtest_filter = "-" + (":".join(map(lambda x: x["pattern"], fail_patterns)))
157177
if _check_filter(base_invocation, gtest_filter):
158-
result = _run_cmd(base_invocation, "known good tests", gtest_filter)
178+
(result, stdout) = _run_cmd(base_invocation, "known good tests", gtest_filter)
159179
if result != 0:
160180
_print_error("Tests we expected to pass have failed")
181+
_print_failure(result, stdout)
161182
final_result = result
162183
else:
163184
_print_format("Note: No tests in this suite are expected to pass")
164185

165186
# Then run each known failing tests
166187
for fail in fail_patterns:
167-
result = _run_cmd(
188+
(result, stdout) = _run_cmd(
168189
base_invocation, "failing test {}".format(fail["pattern"]), fail["pattern"]
169190
)
170191

171192
if result == 0 and not fail["optional"]:
172193
_print_error(
173194
"Test {} is passing when we expect it to fail!", fail["pattern"]
174195
)
196+
_print_failure(result, stdout)
175197
final_result = 1
176198

177199
sys.exit(final_result)

0 commit comments

Comments
 (0)