Skip to content

Commit d0af98f

Browse files
authored
Merge pull request #2247 from RossBrunton/ross/formatbetter
Improve cts_exe.py formatting
2 parents b0a9e2b + db9638f commit d0af98f

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

test/conformance/cts_exe.py

Lines changed: 27 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,20 @@ def _print_environ(env):
5960
_print_end_header()
6061

6162

63+
def _print_failure(code, stdout):
64+
# Display some context in the CI log so the user doesn't have to click down the lines
65+
if _ci():
66+
_print_format("stdout/stderr of failure:")
67+
print(stdout)
68+
69+
signalname = "???"
70+
try:
71+
signalname = signal.strsignal(abs(code))
72+
except ValueError:
73+
pass
74+
_print_format("Got error code {} ({})", code, signalname)
75+
76+
6277
def _check_filter(cmd, filter):
6378
"""
6479
Checks that the filter matches at least one test for the given cmd
@@ -83,17 +98,20 @@ def _run_cmd(cmd, comment, filter):
8398
if not _check_filter(cmd, filter):
8499
_print_end_header()
85100
_print_error("Could not find any tests with this filter")
86-
return 2
101+
return (2, "")
87102

88103
sys.stdout.flush()
89-
result = subprocess.call( # nosec B603
104+
proc = subprocess.Popen( # nosec B603
90105
cmd,
91-
stdout=sys.stdout,
92-
stderr=sys.stdout,
106+
stdout=subprocess.PIPE,
107+
stderr=subprocess.STDOUT,
93108
env=(os.environ | {"GTEST_FILTER": filter}),
94109
)
110+
stdout = proc.communicate()[0].decode("utf-8")
111+
returncode = proc.wait()
112+
print(stdout)
95113
_print_end_header()
96-
return result
114+
return (returncode, stdout)
97115

98116

99117
if __name__ == "__main__":
@@ -155,23 +173,25 @@ def _run_cmd(cmd, comment, filter):
155173
# First, run all the known good tests
156174
gtest_filter = "-" + (":".join(map(lambda x: x["pattern"], fail_patterns)))
157175
if _check_filter(base_invocation, gtest_filter):
158-
result = _run_cmd(base_invocation, "known good tests", gtest_filter)
176+
(result, stdout) = _run_cmd(base_invocation, "known good tests", gtest_filter)
159177
if result != 0:
160178
_print_error("Tests we expected to pass have failed")
179+
_print_failure(result, stdout)
161180
final_result = result
162181
else:
163182
_print_format("Note: No tests in this suite are expected to pass")
164183

165184
# Then run each known failing tests
166185
for fail in fail_patterns:
167-
result = _run_cmd(
186+
(result, stdout) = _run_cmd(
168187
base_invocation, "failing test {}".format(fail["pattern"]), fail["pattern"]
169188
)
170189

171190
if result == 0 and not fail["optional"]:
172191
_print_error(
173192
"Test {} is passing when we expect it to fail!", fail["pattern"]
174193
)
194+
_print_failure(result, stdout)
175195
final_result = 1
176196

177197
sys.exit(final_result)

0 commit comments

Comments
 (0)