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,16 @@ 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+ #[ cfg( unix) ]
20+ const SIGABRT : i32 = 6 ;
21+
22+ #[ cfg( windows) ]
23+ const EXIT_ABORTED : i32 = 3 ;
1524
1625#[ derive( Debug , Clone , PartialEq ) ]
1726pub enum TestResult {
@@ -81,14 +90,25 @@ pub fn calc_result<'a>(
8190/// Creates a `TestResult` depending on the exit code of test subprocess.
8291pub fn get_result_from_exit_code (
8392 desc : & TestDesc ,
84- code : i32 ,
93+ status : ExitStatus ,
8594 time_opts : & Option < time:: TestTimeOptions > ,
8695 exec_time : & Option < time:: TestExecTime > ,
8796) -> 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}" ) ) ,
97+ let result = match status. code ( ) {
98+ Some ( TR_OK ) => TestResult :: TrOk ,
99+ #[ cfg( unix) ]
100+ None => match status. signal ( ) {
101+ Some ( SIGABRT ) => TestResult :: TrFailed ,
102+ Some ( signal) => {
103+ TestResult :: TrFailedMsg ( format ! ( "child process exited with signal {signal}" ) )
104+ }
105+ None => unreachable ! ( "status.code() returned None but status.signal() was None" ) ,
106+ } ,
107+ #[ cfg( not( unix) ) ]
108+ None => TestResult :: TrFailedMsg ( format ! ( "unknown return code" ) ) ,
109+ #[ cfg( windows) ]
110+ Some ( EXIT_ABORTED ) => TestResult :: TrFailed ,
111+ Some ( code) => TestResult :: TrFailedMsg ( format ! ( "got unexpected return code {code}" ) ) ,
92112 } ;
93113
94114 // If test is already failed (or allowed to fail), do not change the result.
0 commit comments