1818import os
1919import time
2020
21- def check_external_logs_active (rcmd ):
22- files_to_check = []
23- if "QEMU_ACE_MTRACE_FILE" in os .environ :
24- files_to_check .append (os .environ ["QEMU_ACE_MTRACE_FILE" ])
25-
26- for fp in files_to_check :
27- if os .path .isfile (fp ):
28- if time .time () - os .path .getmtime (fp ) < 2.0 :
29- return True
30- return False
21+
3122
3223import re
3324
@@ -56,7 +47,8 @@ def check_for_crash(output):
5647 "Exception" ,
5748 "PC=" , # QEMU PC output format
5849 "EXCCAUSE=" ,
59- "Backtrace:"
50+ "Backtrace:" ,
51+ "halting system"
6052 ]
6153 for keyword in crash_keywords :
6254 if keyword in output :
@@ -229,12 +221,17 @@ def main():
229221 # Suffix distinct files appropriately if chained
230222 active_log = args .log_file + (f".{ idx } " if len (runs ) > 1 else "" )
231223
224+ mtrace_file = os .environ .get ("QEMU_ACE_MTRACE_FILE" )
225+ mtrace_fd = None
226+ last_active_time = time .time ()
227+
232228 with open (active_log , "w" ) as log_file :
233229 try :
234230 while True :
235231 try :
236- index = child .expect ([r'\r\n' , pexpect .TIMEOUT , pexpect .EOF ], timeout = 2 )
232+ index = child .expect ([r'\r\n' , pexpect .TIMEOUT , pexpect .EOF ], timeout = 0.5 )
237233 if index == 0 :
234+ last_active_time = time .time ()
238235 line = child .before + '\n '
239236 clean_line = re .sub (r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])' , '' , line )
240237 log_file .write (clean_line )
@@ -245,23 +242,35 @@ def main():
245242 sys .stdout .flush ()
246243
247244 full_output += line
248- elif index == 1 : # TIMEOUT
249- if check_external_logs_active (rcmd ):
250- continue
251- print ("\n \n [sof-qemu-run] 2 seconds passed since last log event. Checking status..." )
252- break
253245 elif index == 2 : # EOF
254246 print ("\n \n [sof-qemu-run] QEMU process terminated." )
255247 break
256248
257249 except pexpect .TIMEOUT :
258- if check_external_logs_active (rcmd ):
259- continue
260- print ("\n \n [sof-qemu-run] 2 seconds passed since last log event. Checking status..." )
261- break
250+ pass
262251 except pexpect .EOF :
263252 print ("\n \n [sof-qemu-run] QEMU process terminated." )
264253 break
254+
255+ if mtrace_file and os .path .isfile (mtrace_file ):
256+ if not mtrace_fd :
257+ try :
258+ mtrace_fd = open (mtrace_file , "r" , encoding = "utf-8" , errors = "ignore" )
259+ except Exception :
260+ pass
261+
262+ if mtrace_fd :
263+ new_data = mtrace_fd .read ()
264+ if new_data :
265+ last_active_time = time .time ()
266+ full_output += new_data
267+ if "halting system" in new_data :
268+ print ("\n \n [sof-qemu-run] Detected 'halting system' in mtrace log! Breaking..." )
269+ break
270+
271+ if time .time () - last_active_time >= 5.0 :
272+ print ("\n \n [sof-qemu-run] 5 seconds passed since last log event. Checking status..." )
273+ break
265274
266275 except KeyboardInterrupt :
267276 print ("\n [sof-qemu-run] Interrupted by user." )
0 commit comments