|
26 | 26 |
|
27 | 27 | import os
|
28 | 28 | import platform
|
| 29 | +import shlex |
29 | 30 | import subprocess
|
| 31 | +import time |
30 | 32 | import threading
|
31 | 33 |
|
32 | 34 | from absl import app
|
@@ -104,28 +106,40 @@ class Test(object):
|
104 | 106 | # them as fields so they can be accessed from the main thread.
|
105 | 107 | def run(self):
|
106 | 108 | """Executes this testapp."""
|
107 |
| - result = None # Ensures this var is defined if timeout occurs. |
108 | 109 | 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() |
109 | 114 | try:
|
110 | 115 | result = subprocess.run(
|
111 |
| - args=FLAGS.cmd_prefix.split() + [self.testapp_path], |
| 116 | + args=args, |
112 | 117 | cwd=os.path.dirname(self.testapp_path), # Testapp uses CWD for config
|
113 | 118 | stdout=subprocess.PIPE,
|
114 | 119 | stderr=subprocess.STDOUT,
|
115 | 120 | text=True,
|
| 121 | + errors="replace", |
116 | 122 | check=False,
|
117 | 123 | timeout=900)
|
118 | 124 | except subprocess.TimeoutExpired as e:
|
119 |
| - logging.error("Testapp timed out!") |
| 125 | + logging.error("Testapp timed out: %s", args_str) |
120 | 126 | # e.output will sometimes be bytes, sometimes string. Decode if needed.
|
121 | 127 | try:
|
122 | 128 | self.logs = e.output.decode()
|
123 | 129 | except AttributeError: # This will happen if it's already a string.
|
124 | 130 | self.logs = e.output
|
125 |
| - if result: |
| 131 | + else: |
126 | 132 | 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) |
129 | 143 |
|
130 | 144 |
|
131 | 145 | if __name__ == "__main__":
|
|
0 commit comments