@@ -5,6 +5,7 @@ extern crate alloc;
55#[ macro_use] extern crate log;
66// #[macro_use] extern crate terminal_print;
77extern crate task;
8+ extern crate catch_unwind;
89
910
1011use alloc:: vec:: Vec ;
@@ -15,7 +16,7 @@ use alloc::string::String;
1516struct MyStruct ( pub usize ) ;
1617impl Drop for MyStruct {
1718 fn drop ( & mut self ) {
18- warn ! ( "DROPPING MYSTRUCT({})" , self . 0 ) ;
19+ warn ! ( "\n DROPPING MYSTRUCT({})\n " , self . 0 ) ;
1920 }
2021}
2122
@@ -36,7 +37,7 @@ fn foo(cause_page_fault: bool) {
3637}
3738
3839
39- pub fn main ( _args : Vec < String > ) -> isize {
40+ pub fn main ( args : Vec < String > ) -> isize {
4041
4142 // // dump some info about the this loaded app crate
4243 // {
@@ -52,11 +53,37 @@ pub fn main(_args: Vec<String>) -> isize {
5253
5354 let _my_struct = MyStruct ( 5 ) ;
5455
55- let cause_page_fault = match _args. get ( 0 ) . map ( |s| & * * s) {
56- Some ( "-e" ) => true ,
57- _ => false ,
56+ match args. get ( 0 ) . map ( |s| & * * s) {
57+ // cause a page fault to test unwinding through a machine exception
58+ Some ( "-e" ) => foo ( true ) ,
59+ // test catch_unwind and then resume_unwind
60+ Some ( "-c" ) => catch_resume_unwind ( ) ,
61+ _ => foo ( false ) ,
5862 } ;
5963
60- foo ( cause_page_fault) ;
64+ error ! ( "Test failure: unwind_test::main should not return!" ) ;
65+
6166 0
6267}
68+
69+ #[ inline( never) ]
70+ fn catch_resume_unwind ( ) {
71+ let _my_struct6 = MyStruct ( 6 ) ;
72+
73+ let res = catch_unwind:: catch_unwind_with_arg ( fn_to_catch, MyStruct ( 22 ) ) ;
74+ warn ! ( "CAUGHT UNWINDING ACTION, as expected." ) ;
75+ let _my_struct7 = MyStruct ( 7 ) ;
76+ if let Err ( e) = res {
77+ let _my_struct8 = MyStruct ( 8 ) ;
78+ catch_unwind:: resume_unwind ( e) ;
79+ }
80+
81+ error ! ( "Test failure: catch_resume_unwind should not return!" ) ;
82+ }
83+
84+ #[ inline( never) ]
85+ fn fn_to_catch ( _s : MyStruct ) {
86+ let _my_struct9 = MyStruct ( 9 ) ;
87+
88+ panic ! ( "intentional panic in unwind_test::fn_to_catch()" )
89+ }
0 commit comments