11use std:: any:: Any ;
2+ use std:: process:: ExitStatus ;
3+
4+ #[ cfg( unix) ]
5+ use std:: os:: unix:: process:: ExitStatusExt ;
26
37use super :: bench:: BenchSamples ;
48use super :: options:: ShouldPanic ;
@@ -7,11 +11,15 @@ use super::types::TestDesc;
711
812pub use self :: TestResult :: * ;
913
10- // Return codes for secondary process.
14+ // Return code for secondary process.
1115// Start somewhere other than 0 so we know the return code means what we think
1216// it means.
1317pub const TR_OK : i32 = 50 ;
14- pub const TR_FAILED : i32 = 51 ;
18+
19+ // On Windows we use __fastfail to abort, which is documented to use this
20+ // exception code.
21+ #[ cfg( windows) ]
22+ const STATUS_ABORTED : i32 = 0xC0000409u32 as i32 ;
1523
1624#[ derive( Debug , Clone , PartialEq ) ]
1725pub enum TestResult {
@@ -81,14 +89,28 @@ pub fn calc_result<'a>(
8189/// Creates a `TestResult` depending on the exit code of test subprocess.
8290pub fn get_result_from_exit_code (
8391 desc : & TestDesc ,
84- code : i32 ,
92+ status : ExitStatus ,
8593 time_opts : & Option < time:: TestTimeOptions > ,
8694 exec_time : & Option < time:: TestExecTime > ,
8795) -> TestResult {
88- let result = match code {
89- TR_OK => TestResult :: TrOk ,
90- TR_FAILED => TestResult :: TrFailed ,
91- _ => TestResult :: TrFailedMsg ( format ! ( "got unexpected return code {code}" ) ) ,
96+ let result = match status. code ( ) {
97+ Some ( TR_OK ) => TestResult :: TrOk ,
98+ #[ cfg( windows) ]
99+ Some ( STATUS_ABORTED ) => TestResult :: TrFailed ,
100+ #[ cfg( unix) ]
101+ None => match status. signal ( ) {
102+ Some ( libc:: SIGABRT ) => TestResult :: TrFailed ,
103+ Some ( signal) => {
104+ TestResult :: TrFailedMsg ( format ! ( "child process exited with signal {signal}" ) )
105+ }
106+ None => unreachable ! ( "status.code() returned None but status.signal() was None" ) ,
107+ } ,
108+ #[ cfg( not( unix) ) ]
109+ None => TestResult :: TrFailedMsg ( format ! ( "unknown return code" ) ) ,
110+ #[ cfg( any( windows, unix) ) ]
111+ Some ( code) => TestResult :: TrFailedMsg ( format ! ( "got unexpected return code {code}" ) ) ,
112+ #[ cfg( not( any( windows, unix) ) ) ]
113+ Some ( _) => TestResult :: TrFailed ,
92114 } ;
93115
94116 // If test is already failed (or allowed to fail), do not change the result.
0 commit comments