@@ -70,6 +70,47 @@ fn coroutine_delay() -> std::io::Result<()> {
7070 Ok ( ( ) )
7171}
7272
73+ #[ test]
74+ fn sp_in_bounds ( ) -> std:: io:: Result < ( ) > {
75+ let mut coroutine = co ! ( |suspender, input| {
76+ let current = Coroutine :: <( ) , ( ) , ( ) >:: current( ) . unwrap( ) ;
77+ let stack_info = current. stack_infos( ) . back( ) . cloned( ) . unwrap( ) ;
78+ assert!( current. stack_ptr_in_bounds( psm:: stack_pointer( ) as u64 ) ) ;
79+ assert_eq!(
80+ current. stack_ptr_in_bounds( stack_info. stack_top as u64 + 1 ) ,
81+ false
82+ ) ;
83+ assert_eq!(
84+ current. stack_ptr_in_bounds( stack_info. stack_bottom as u64 - 1 ) ,
85+ false
86+ ) ;
87+ assert_eq!( 1 , input) ;
88+ assert_eq!( 3 , suspender. suspend_with( 2 ) ) ;
89+ 4
90+ } ) ?;
91+ assert_eq ! ( CoroutineState :: Suspend ( 2 , 0 ) , coroutine. resume_with( 1 ) ?) ;
92+ assert_eq ! ( CoroutineState :: Complete ( 4 ) , coroutine. resume_with( 3 ) ?) ;
93+ println ! ( "{:?}" , coroutine) ;
94+ println ! ( "{}" , coroutine) ;
95+ Ok ( ( ) )
96+ }
97+
98+ #[ test]
99+ fn thread_stack_growth ( ) {
100+ fn recurse ( i : u32 , p : & mut [ u8 ; 10240 ] ) {
101+ Coroutine :: < ( ) , ( ) , ( ) > :: maybe_grow ( || {
102+ // Ensure the stack allocation isn't optimized away.
103+ unsafe { std:: ptr:: read_volatile ( & p) } ;
104+ if i > 0 {
105+ recurse ( i - 1 , & mut [ 0 ; 10240 ] ) ;
106+ }
107+ } )
108+ . expect ( "allocate stack failed" )
109+ }
110+ // Use 10MB of stack.
111+ recurse ( 1000 , & mut [ 0 ; 10240 ] ) ;
112+ }
113+
73114#[ test]
74115fn coroutine_stack_growth ( ) -> std:: io:: Result < ( ) > {
75116 let mut coroutine = co ! ( |_: & Suspender <( ) , ( ) >, ( ) | {
0 commit comments