Skip to content

Commit 78917c3

Browse files
authored
desktop_tester.py: some random improvements to help with debugging failed runs (#1027)
1 parent 8b7b067 commit 78917c3

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

scripts/gha/desktop_tester.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
import os
2828
import platform
29+
import shlex
2930
import subprocess
31+
import time
3032
import threading
3133

3234
from absl import app
@@ -104,28 +106,40 @@ class Test(object):
104106
# them as fields so they can be accessed from the main thread.
105107
def run(self):
106108
"""Executes this testapp."""
107-
result = None # Ensures this var is defined if timeout occurs.
108109
os.chmod(self.testapp_path, 0o777)
110+
args = list(shlex.split(FLAGS.cmd_prefix)) + [self.testapp_path]
111+
args_str = subprocess.list2cmdline(args)
112+
logging.info("Test starting: %s", args_str)
113+
start_time_secs = time.monotonic()
109114
try:
110115
result = subprocess.run(
111-
args=FLAGS.cmd_prefix.split() + [self.testapp_path],
116+
args=args,
112117
cwd=os.path.dirname(self.testapp_path), # Testapp uses CWD for config
113118
stdout=subprocess.PIPE,
114119
stderr=subprocess.STDOUT,
115120
text=True,
121+
errors="replace",
116122
check=False,
117123
timeout=900)
118124
except subprocess.TimeoutExpired as e:
119-
logging.error("Testapp timed out!")
125+
logging.error("Testapp timed out: %s", args_str)
120126
# e.output will sometimes be bytes, sometimes string. Decode if needed.
121127
try:
122128
self.logs = e.output.decode()
123129
except AttributeError: # This will happen if it's already a string.
124130
self.logs = e.output
125-
if result:
131+
else:
126132
self.logs = result.stdout
127-
logging.info("Test result: %s", self.logs)
128-
logging.info("Finished running %s", self.testapp_path)
133+
logging.info(
134+
"Test result of %s (exit code: %s): %s",
135+
args_str, result.returncode, self.logs)
136+
137+
end_time_secs = time.monotonic()
138+
elapsed_time_secs = end_time_secs - start_time_secs
139+
elapsed_time_str = f"{elapsed_time_secs/60:.2f} minutes"
140+
logging.info(
141+
"Test completed (elapsed time: %s): %s",
142+
elapsed_time_str, args_str)
129143

130144

131145
if __name__ == "__main__":

0 commit comments

Comments
 (0)