Skip to content

Commit 625411c

Browse files
committed
twister: if qemu binary doesn't exist, failed
When the qemu binary file doesn't exist or it is unexecutable, the twister can't detect this error then the twister will hang forever. Signed-off-by: Jingru Wang <[email protected]>
1 parent 825170e commit 625411c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

scripts/pylib/twister/twisterlib.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,15 @@ def __init__(self, instance, type_str):
920920
self.ignore_qemu_crash = False
921921
self.ignore_unexpected_eof = False
922922

923+
@staticmethod
924+
def _is_qemu_executable(qemu_binary):
925+
cmd = [qemu_binary, "-h"]
926+
try:
927+
_ = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
928+
except subprocess.CalledProcessError as _:
929+
return False
930+
return True
931+
923932
@staticmethod
924933
def _get_cpu_time(pid):
925934
"""get process CPU time.
@@ -1075,6 +1084,12 @@ def _thread(handler, timeout, outdir, logfile, fifo_fn, pid_fn, results, harness
10751084

10761085
def handle(self):
10771086
self.results = {}
1087+
qemu_executable = self.instance.platform.filter_data.get("QEMU")
1088+
if not (qemu_executable and QEMUHandler._is_qemu_executable(qemu_executable)):
1089+
logger.debug(f"Test failed, QEMU binary {qemu_executable} is unexecutable")
1090+
self.set_state("failed", 0)
1091+
self.instance.reason = f"QEMU is unexecutable"
1092+
return
10781093
self.run = True
10791094

10801095
# We pass this to QEMU which looks for fifos with .in and .out
@@ -2160,6 +2175,8 @@ def parse_generated(self):
21602175
filter_data.update(self.defconfig)
21612176
filter_data.update(self.cmake_cache)
21622177

2178+
self.platform.filter_data = filter_data
2179+
21632180
edt_pickle = os.path.join(self.build_dir, "zephyr", "edt.pickle")
21642181
if self.testcase and self.testcase.tc_filter:
21652182
try:
@@ -2180,7 +2197,6 @@ def parse_generated(self):
21802197
else:
21812198
return {os.path.join(self.platform.name, self.testcase.name): False}
21822199
else:
2183-
self.platform.filter_data = filter_data
21842200
return filter_data
21852201

21862202

0 commit comments

Comments
 (0)