@@ -198,6 +198,88 @@ fn test_crash_tracking_errors_intake_uds_socket() {
198198 ) ;
199199}
200200
201+ #[ test]
202+ #[ cfg_attr( miri, ignore) ]
203+ fn test_crash_tracking_bin_panic ( ) {
204+ test_crash_tracking_app ( "panic" ) ;
205+ }
206+
207+ #[ test]
208+ #[ cfg_attr( miri, ignore) ]
209+ fn test_crash_tracking_bin_segfault ( ) {
210+ test_crash_tracking_app ( "segfault" ) ;
211+ }
212+
213+ fn test_crash_tracking_app ( crash_type : & str ) {
214+ let ( _, crashtracker_receiver) = setup_crashtracking_crates ( BuildProfile :: Release ) ;
215+
216+ let crashing_app = ArtifactsBuild {
217+ name : "crashing_test_app" . to_owned ( ) ,
218+ build_profile : BuildProfile :: Debug ,
219+ artifact_type : ArtifactType :: Bin ,
220+ triple_target : None ,
221+ panic_abort : Some ( true ) ,
222+ ..Default :: default ( )
223+ } ;
224+
225+ let fixtures = setup_test_fixtures ( & [ & crashtracker_receiver, & crashing_app] ) ;
226+
227+ let mut p = process:: Command :: new ( & fixtures. artifacts [ & crashing_app] )
228+ . arg ( format ! ( "file://{}" , fixtures. crash_profile_path. display( ) ) )
229+ . arg ( fixtures. artifacts [ & crashtracker_receiver] . as_os_str ( ) )
230+ . arg ( & fixtures. output_dir )
231+ . arg ( crash_type)
232+ . spawn ( )
233+ . unwrap ( ) ;
234+
235+ let exit_status = bin_tests:: timeit!( "exit after signal" , {
236+ eprintln!( "Waiting for exit" ) ;
237+ p. wait( ) . unwrap( )
238+ } ) ;
239+ assert ! ( !exit_status. success( ) ) ;
240+
241+ let stderr_path = format ! ( "{0}/out.stderr" , fixtures. output_dir. display( ) ) ;
242+ let stderr = fs:: read ( stderr_path)
243+ . context ( "reading crashtracker stderr" )
244+ . unwrap ( ) ;
245+ let stdout_path = format ! ( "{0}/out.stdout" , fixtures. output_dir. display( ) ) ;
246+ let stdout = fs:: read ( stdout_path)
247+ . context ( "reading crashtracker stdout" )
248+ . unwrap ( ) ;
249+ let s = String :: from_utf8 ( stderr) ;
250+ assert ! (
251+ matches!(
252+ s. as_deref( ) ,
253+ Ok ( "" ) | Ok ( "Failed to fully receive crash. Exit state was: StackTrace([])\n " )
254+ | Ok ( "Failed to fully receive crash. Exit state was: InternalError(\" {\\ \" ip\\ \" : \\ \" \" )\n " ) ,
255+ ) ,
256+ "got {s:?}"
257+ ) ;
258+ assert_eq ! ( Ok ( "" ) , String :: from_utf8( stdout) . as_deref( ) ) ;
259+
260+ let crash_profile = fs:: read ( fixtures. crash_profile_path )
261+ . context ( "reading crashtracker profiling payload" )
262+ . unwrap ( ) ;
263+ let crash_payload = serde_json:: from_slice :: < serde_json:: Value > ( & crash_profile)
264+ . context ( "deserializing crashtracker profiling payload to json" )
265+ . unwrap ( ) ;
266+
267+ let sig_info = & crash_payload[ "sig_info" ] ;
268+
269+ match crash_type {
270+ "panic" => {
271+ let error = & crash_payload[ "error" ] ;
272+ let expected_message = "program panicked" ;
273+ assert_eq ! ( error[ "message" ] . as_str( ) . unwrap( ) , expected_message) ;
274+ }
275+ "segfault" => {
276+ let error = & crash_payload[ "error" ] ;
277+ assert_error_message ( & error[ "message" ] , sig_info) ;
278+ }
279+ _ => unreachable ! ( "Invalid crash type: {crash_type}" ) ,
280+ }
281+ }
282+
201283// This test is disabled for now on x86_64 musl and macos
202284// It seems that on aarch64 musl, libc has CFI which allows
203285// unwinding passed the signal frame.
@@ -208,9 +290,6 @@ fn test_crasht_tracking_validate_callstack() {
208290 test_crash_tracking_callstack ( )
209291}
210292
211- #[ test]
212- #[ cfg( not( any( all( target_arch = "x86_64" , target_env = "musl" ) , target_os = "macos" ) ) ) ]
213- #[ cfg_attr( miri, ignore) ]
214293fn test_crash_tracking_callstack ( ) {
215294 let ( _, crashtracker_receiver) = setup_crashtracking_crates ( BuildProfile :: Release ) ;
216295
@@ -230,6 +309,7 @@ fn test_crash_tracking_callstack() {
230309 . arg ( format ! ( "file://{}" , fixtures. crash_profile_path. display( ) ) )
231310 . arg ( fixtures. artifacts [ & crashtracker_receiver] . as_os_str ( ) )
232311 . arg ( & fixtures. output_dir )
312+ . arg ( "segfault" )
233313 . spawn ( )
234314 . unwrap ( ) ;
235315
0 commit comments