11use std:: any:: Any ;
22use std:: process:: ExitStatus ;
33
4+ #[ cfg( target_os = "fuchsia" ) ]
5+ use std:: os:: fuchsia:: process:: ExitStatusExt as _;
46#[ cfg( unix) ]
5- use std:: os:: unix:: process:: ExitStatusExt ;
7+ use std:: os:: unix:: process:: ExitStatusExt as _ ;
68
79use super :: bench:: BenchSamples ;
810use super :: options:: ShouldPanic ;
@@ -21,14 +23,6 @@ pub const TR_OK: i32 = 50;
2123#[ cfg( windows) ]
2224const STATUS_FAIL_FAST_EXCEPTION : i32 = 0xC0000409u32 as i32 ;
2325
24- // On Zircon (the Fuchsia kernel), an abort from userspace calls the
25- // LLVM implementation of __builtin_trap(), e.g., ud2 on x86, which
26- // raises a kernel exception. If a userspace process does not
27- // otherwise arrange exception handling, the kernel kills the process
28- // with this return code.
29- #[ cfg( target_os = "fuchsia" ) ]
30- const ZX_TASK_RETCODE_EXCEPTION_KILL : i32 = -1028 ;
31-
3226#[ derive( Debug , Clone , PartialEq ) ]
3327pub enum TestResult {
3428 TrOk ,
@@ -101,10 +95,19 @@ pub fn get_result_from_exit_code(
10195 time_opts : & Option < time:: TestTimeOptions > ,
10296 exec_time : & Option < time:: TestExecTime > ,
10397) -> TestResult {
104- let result = match status. code ( ) {
98+ #[ cfg( target_os = "fuchsia" ) ]
99+ let result = status. aborted_code ( ) . map ( |_| TestResult :: TrFailed ) ;
100+ #[ cfg( not( target_os = "fuchsia" ) ) ]
101+ let result: Option < TestResult > = None ;
102+
103+ let result = result. unwrap_or_else ( || match status. code ( ) {
105104 Some ( TR_OK ) => TestResult :: TrOk ,
106105 #[ cfg( windows) ]
107106 Some ( STATUS_FAIL_FAST_EXCEPTION ) => TestResult :: TrFailed ,
107+ #[ cfg( any( windows, unix) ) ]
108+ Some ( code) => TestResult :: TrFailedMsg ( format ! ( "got unexpected return code {code}" ) ) ,
109+ #[ cfg( not( any( windows, unix) ) ) ]
110+ Some ( _) => TestResult :: TrFailed ,
108111 #[ cfg( unix) ]
109112 None => match status. signal ( ) {
110113 Some ( libc:: SIGABRT ) => TestResult :: TrFailed ,
@@ -113,16 +116,9 @@ pub fn get_result_from_exit_code(
113116 }
114117 None => unreachable ! ( "status.code() returned None but status.signal() was None" ) ,
115118 } ,
116- // Upon an abort, Fuchsia returns the status code ZX_TASK_RETCODE_EXCEPTION_KILL.
117- #[ cfg( target_os = "fuchsia" ) ]
118- Some ( ZX_TASK_RETCODE_EXCEPTION_KILL ) => TestResult :: TrFailed ,
119119 #[ cfg( not( unix) ) ]
120120 None => TestResult :: TrFailedMsg ( format ! ( "unknown return code" ) ) ,
121- #[ cfg( any( windows, unix) ) ]
122- Some ( code) => TestResult :: TrFailedMsg ( format ! ( "got unexpected return code {code}" ) ) ,
123- #[ cfg( not( any( windows, unix) ) ) ]
124- Some ( _) => TestResult :: TrFailed ,
125- } ;
121+ } ) ;
126122
127123 // If test is already failed (or allowed to fail), do not change the result.
128124 if result != TestResult :: TrOk {
0 commit comments