@@ -26,6 +26,7 @@ class IdfDut(IdfUnityDutMixin, SerialDut):
2626 Attributes:
2727 target (str): target chip type
2828 skip_check_coredump (bool): skip check core dumped or not while dut teardown if set to True
29+ skip_decode_panic (bool): skip decode panic output or not while dut teardown if set to True
2930 """
3031
3132 XTENSA_TARGETS = IdfApp .XTENSA_TARGETS
@@ -46,11 +47,12 @@ def __init__(
4647 self ,
4748 app : IdfApp ,
4849 skip_check_coredump : bool = False ,
50+ skip_decode_panic : bool = False ,
4951 ** kwargs ,
5052 ) -> None :
5153 self .target = app .target
5254 self .skip_check_coredump = skip_check_coredump
53-
55+ self . skip_decode_panic = skip_decode_panic
5456 super ().__init__ (app = app , ** kwargs )
5557
5658 self ._hard_reset_func = self .serial .hard_reset
@@ -76,7 +78,11 @@ def _get_prefix_map_path(self) -> str:
7678 return primary
7779 return fallback
7880
79- def _check_panic_decode_trigger (self ): # type: () -> None
81+ def _decode_panic (self ): # type: () -> None
82+ if self .target not in self .RISCV32_TARGETS :
83+ logging .debug ('panic decode only supported for riscv32 targets' )
84+ return
85+
8086 if not self .app .elf_file :
8187 logging .warning ('No elf file found. Skipping decode panic output...' )
8288 return
@@ -109,9 +115,11 @@ def _check_panic_decode_trigger(self): # type: () -> None
109115 'bt' ,
110116 ]
111117 try :
112- output = subprocess .check_output (cmd , stderr = subprocess .STDOUT )
113- logging .info ('\n \n Backtrace:\n ' )
114- logging .info (output .decode ())
118+ output = subprocess .check_output (cmd , stderr = subprocess .STDOUT ).decode ('utf-8' )
119+ logging .info (f'Backtrace:\n { output } ' )
120+ with open (self .logfile .replace ('dut' , 'panic_decoded' , 1 ), 'w' ) as fw :
121+ fw .write (output )
122+ logging .info (f'Please check decoded panic output file at: { fw .name } ' )
115123 except subprocess .CalledProcessError as e :
116124 logging .error (f'Failed to decode panic output: { e .output } . Command was: \n { " " .join (cmd )} ' )
117125 finally :
@@ -137,8 +145,6 @@ def _check_coredump(self) -> None:
137145 Returns:
138146 None
139147 """
140- if self .target in self .RISCV32_TARGETS :
141- self ._check_panic_decode_trigger () # need IDF_PATH
142148 if self .app .sdkconfig .get ('ESP_COREDUMP_ENABLE_TO_UART' , False ):
143149 self ._dump_b64_coredumps ()
144150 elif self .app .sdkconfig .get ('ESP_COREDUMP_ENABLE_TO_FLASH' , False ):
@@ -166,12 +172,12 @@ def _dump_b64_coredumps(self) -> None:
166172 coredump = CoreDump (
167173 chip = self .target ,
168174 core = coredump_file .name ,
169- core_format = 'b64' ,
170175 prog = self .app .elf_file ,
171176 )
172- with open (os . path . join ( self ._meta . logdir , f'coredump_output_ { i } ' ), 'w' ) as fw :
177+ with open (self .logfile . replace ( 'dut' , 'coredump' , 1 ), 'w' ) as fw :
173178 with redirect_stdout (fw ):
174179 coredump .info_corefile ()
180+ logging .info (f'Please check coredump output file at: { fw .name } ' )
175181 except Exception as e :
176182 logging .error (f'Error dumping b64 coredump { i } for target: { self .target } : { e } ' )
177183 finally :
@@ -185,25 +191,25 @@ def _dump_flash_coredump(self) -> None:
185191
186192 from esp_coredump import CoreDump # need IDF_PATH
187193
188- if self .app .sdkconfig ['ESP_COREDUMP_DATA_FORMAT_ELF' ]:
189- core_format = 'elf'
190- elif self .app .sdkconfig ['ESP_COREDUMP_DATA_FORMAT_BIN' ]:
191- core_format = 'raw'
192- else :
193- raise ValueError ('Invalid coredump format. Use _parse_b64_coredump for UART' )
194-
195- with self .serial .disable_redirect_thread ():
194+ self .serial .close ()
195+ with redirect_stdout (self ._q ):
196196 coredump = CoreDump (
197197 chip = self .target ,
198- core_format = core_format ,
199198 port = self .serial .port ,
200199 prog = self .app .elf_file ,
201200 )
202- with open (os . path . join ( self ._meta . logdir , 'coredump_output' ), 'w' ) as fw :
201+ with open (self .logfile . replace ( 'dut' , 'coredump' , 1 ), 'w' ) as fw :
203202 with redirect_stdout (fw ):
204203 coredump .info_corefile ()
204+ logging .info (f'Please check coredump output file at: { fw .name } ' )
205205
206206 def close (self ) -> None :
207+ if not self .skip_decode_panic :
208+ try :
209+ self ._decode_panic ()
210+ except Exception as e :
211+ logging .error (f'Error decoding panic output for target: { self .target } : { e } ' )
212+
207213 if not self .skip_check_coredump :
208214 try :
209215 self ._check_coredump ()
0 commit comments