55
66import argparse
77from pathlib import Path
8+ import shutil
89import socket
910import struct
1011import tempfile
1112import threading
1213import time
14+ import traceback
1315
1416from dualrx_sitl_test import (
1517 BOX_BEEPER ,
@@ -57,7 +59,7 @@ def __init__(self, name: str, channels: list[int], period_s: float = 0.02) -> No
5759 self ._lock = threading .Lock ()
5860 self ._stop = threading .Event ()
5961 self ._thread : threading .Thread | None = None
60- self .error : BaseException | None = None
62+ self .error : Exception | None = None
6163
6264 def start (self ) -> None :
6365 self ._thread = threading .Thread (target = self ._run_guarded , name = self .name , daemon = True )
@@ -76,12 +78,12 @@ def set_mode(self, mode: str) -> None:
7678
7779 def check (self ) -> None :
7880 if self .error is not None :
79- raise TestFailure (f"{ self .name } background thread failed: { self .error } " )
81+ raise TestFailure (f"{ self .name } background thread failed: { type ( self .error ). __name__ } : { self . error } " ) from self . error
8082
8183 def _run_guarded (self ) -> None :
8284 try :
8385 self ._run ()
84- except BaseException as exc :
86+ except Exception as exc :
8587 if not self ._stop .is_set ():
8688 self .error = exc
8789 self ._stop .set ()
@@ -342,9 +344,11 @@ def configure_case(kind: str) -> list[str]:
342344
343345def run_case (kind : str , binary : Path , repo : Path , tcp_base : int , temp_dir : Path ) -> None :
344346 eeprom = temp_dir / f"{ kind } .bin"
345- sitl = SitlProcess (binary , repo , eeprom , tcp_base , temp_dir / f"{ kind } .log" )
347+ log_path = temp_dir / f"{ kind } .log"
348+ sitl = SitlProcess (binary , repo , eeprom , tcp_base , log_path )
346349 msp : MspClient | None = None
347350 ingresses : list = []
351+ print (f"\n [CASE] { kind } " )
348352 try :
349353 sitl .start ()
350354 msp_port = tcp_port (tcp_base , UART_MSP )
@@ -386,6 +390,17 @@ def run_case(kind: str, binary: Path, repo: Path, tcp_base: int, temp_dir: Path)
386390 if kind == "crsf-mavlink" :
387391 exercise_legacy_msp_override (msp , rx1 , rx2 )
388392 exercise_selector (msp , rx1 , rx2 , kind .replace ("-" , " + " ).upper ())
393+ except Exception as exc :
394+ process_code = sitl .process .poll () if sitl .process is not None else None
395+ sitl_state = "still running" if sitl .process is not None and process_code is None else f"exited with code { process_code } "
396+ log_tail = sitl .tail_log (lines = 120 )
397+ raise TestFailure (
398+ f"{ kind } failed: { type (exc ).__name__ } : { exc } \n "
399+ f"SITL state: { sitl_state } \n "
400+ f"SITL log: { log_path } \n "
401+ f"EEPROM: { eeprom } \n "
402+ f"--- SITL LOG TAIL ---\n { log_tail } \n --- END SITL LOG TAIL ---"
403+ ) from exc
389404 finally :
390405 for ingress in reversed (ingresses ):
391406 ingress .close ()
@@ -410,17 +425,20 @@ def main() -> int:
410425 print ("Dual RX mixed-ingress SITL test" )
411426 print (f" repo: { repo } " )
412427 print (f" SITL: { binary } \n " )
428+
429+ temp_dir = Path (tempfile .mkdtemp (prefix = "inav-dualrx-mixed-" ))
413430 try :
414- with tempfile .TemporaryDirectory (prefix = "inav-dualrx-mixed-" ) as temp_name :
415- temp_dir = Path (temp_name )
416- for kind in ("crsf-mavlink" , "crsf-msp" , "mavlink-mavlink" ):
417- run_case (kind , binary , repo , args .tcp_base , temp_dir )
418- except BaseException as exc :
419- print (f"\n [FAIL] { exc } " )
431+ for kind in ("crsf-mavlink" , "crsf-msp" , "mavlink-mavlink" ):
432+ run_case (kind , binary , repo , args .tcp_base , temp_dir )
433+ except Exception :
434+ print (f"\n [FAIL] Full diagnostics retained in: { temp_dir } " )
435+ traceback .print_exc ()
420436 return 1
437+
438+ shutil .rmtree (temp_dir , ignore_errors = True )
421439 print ("\n ALL DUAL RX MIXED-INGRESS SITL TESTS PASSED" )
422440 return 0
423441
424442
425443if __name__ == "__main__" :
426- raise SystemExit (main ())
444+ raise SystemExit (main ())
0 commit comments