@@ -1406,15 +1406,12 @@ mod tests {
14061406 assert_eq ! ( res, 0 ) ;
14071407 }
14081408
1409- // Tests to ensure that many (1000) function calls can be made in a call context with a small stack (24K) and heap(32K) .
1410- // This test effectively ensures that the stack is being properly reset after each call and we are not leaking memory in the Guest .
1409+ // Checks that 1,000 calls work with constrained guest memory .
1410+ // This catches guest stack reset and heap leaks .
14111411 #[ test]
14121412 fn test_with_small_stack_and_heap ( ) {
1413- const HEAP_SIZE : u64 = 32 * 1024 ;
1414- // min_scratch_size already includes 1 page (4k on most
1415- // platforms) of guest stack, so add 20k more to get 24k
1416- // total, and then add some more for the eagerly-copied page
1417- // tables on amd64
1413+ const HEAP_SIZE : u64 = 128 * 1024 ;
1414+ // Leave headroom for legacy transport and eagerly copied page tables.
14181415 let scratch_size = {
14191416 let defaults = SandboxConfiguration :: default ( ) ;
14201417 hyperlight_common:: layout:: min_scratch_size (
@@ -1425,8 +1422,7 @@ mod tests {
14251422 defaults. get_g2h_pool_pages ( ) ,
14261423 defaults. get_h2g_pool_pages ( ) ,
14271424 )
1428- } + 0x10000
1429- + 0x10000 ;
1425+ } + 0x40000 ;
14301426
14311427 let mut sbox1 = SandboxBuilder :: from_file ( simple_guest_as_pathbuf ( ) )
14321428 . heap_size ( HEAP_SIZE )
@@ -2147,7 +2143,7 @@ mod tests {
21472143 #[ test]
21482144 fn snapshot_restore_recovers_oom_with_larger_heap ( ) {
21492145 let mut source_cfg = SandboxConfiguration :: default ( ) ;
2150- source_cfg. set_heap_size ( 0x20_000 ) ;
2146+ source_cfg. set_heap_size ( 0x40_000 ) ;
21512147 let path = simple_guest_as_pathbuf ( ) ;
21522148 let mut source = UninitializedSandbox :: new ( GuestBinary :: FilePath ( path) , Some ( source_cfg) )
21532149 . unwrap ( )
@@ -2156,7 +2152,7 @@ mod tests {
21562152 let snapshot = source. snapshot ( ) . unwrap ( ) ;
21572153
21582154 let mut target_cfg = SandboxConfiguration :: default ( ) ;
2159- target_cfg. set_heap_size ( 0x8000 ) ;
2155+ target_cfg. set_heap_size ( 0x20_000 ) ;
21602156 let path = simple_guest_as_pathbuf ( ) ;
21612157 let mut target = UninitializedSandbox :: new ( GuestBinary :: FilePath ( path) , Some ( target_cfg) )
21622158 . unwrap ( )
@@ -2177,7 +2173,7 @@ mod tests {
21772173 #[ test]
21782174 fn snapshot_restore_applies_smaller_heap_limit ( ) {
21792175 let mut source_cfg = SandboxConfiguration :: default ( ) ;
2180- source_cfg. set_heap_size ( 0x8000 ) ;
2176+ source_cfg. set_heap_size ( 0x20_000 ) ;
21812177 let path = simple_guest_as_pathbuf ( ) ;
21822178 let mut source = UninitializedSandbox :: new ( GuestBinary :: FilePath ( path) , Some ( source_cfg) )
21832179 . unwrap ( )
@@ -2186,26 +2182,28 @@ mod tests {
21862182 let snapshot = source. snapshot ( ) . unwrap ( ) ;
21872183
21882184 let mut target_cfg = SandboxConfiguration :: default ( ) ;
2189- target_cfg. set_heap_size ( 0x20_000 ) ;
2185+ target_cfg. set_heap_size ( 0x80_000 ) ;
21902186 let path = simple_guest_as_pathbuf ( ) ;
21912187 let mut target = UninitializedSandbox :: new ( GuestBinary :: FilePath ( path) , Some ( target_cfg) )
21922188 . unwrap ( )
21932189 . evolve ( )
21942190 . unwrap ( ) ;
21952191
21962192 assert_eq ! (
2197- target. call:: <i32 >( "CallMalloc" , 0x10_000i32 ) . unwrap( ) ,
2198- 0x10_000
2193+ target. call:: <i32 >( "CallMalloc" , 0x30_000i32 ) . unwrap( ) ,
2194+ 0x30_000
21992195 ) ;
22002196 target. restore ( snapshot) . unwrap ( ) ;
2201- assert_eq ! ( target. mem_mgr. layout. heap_size( ) , 0x8000 ) ;
2202- assert ! ( target. call:: <i32 >( "CallMalloc" , 0x10_000i32 ) . is_err( ) ) ;
2197+ assert_eq ! ( target. mem_mgr. layout. heap_size( ) , 0x20_000 ) ;
2198+ assert ! ( target. call:: <i32 >( "CallMalloc" , 0x30_000i32 ) . is_err( ) ) ;
22032199 assert ! ( target. status( ) . is_poisoned( ) ) ;
22042200 }
22052201
22062202 #[ test]
22072203 fn snapshot_restore_applies_smaller_io_limits ( ) {
22082204 let mut source_cfg = SandboxConfiguration :: default ( ) ;
2205+ source_cfg. set_heap_size ( 0x40_000 ) ;
2206+ source_cfg. set_scratch_size ( SandboxConfiguration :: DEFAULT_SCRATCH_SIZE + 256 * 1024 ) ;
22092207 source_cfg. set_input_data_size ( 0x2000 ) ;
22102208 source_cfg. set_output_data_size ( 0x2000 ) ;
22112209 let path = simple_guest_as_pathbuf ( ) ;
@@ -2216,6 +2214,8 @@ mod tests {
22162214 let snapshot = source. snapshot ( ) . unwrap ( ) ;
22172215
22182216 let mut target_cfg = SandboxConfiguration :: default ( ) ;
2217+ target_cfg. set_heap_size ( 0x40_000 ) ;
2218+ target_cfg. set_scratch_size ( SandboxConfiguration :: DEFAULT_SCRATCH_SIZE + 256 * 1024 ) ;
22192219 target_cfg. set_input_data_size ( 0x8000 ) ;
22202220 target_cfg. set_output_data_size ( 0x8000 ) ;
22212221 let path = simple_guest_as_pathbuf ( ) ;
@@ -2242,7 +2242,7 @@ mod tests {
22422242 let mut small_cfg = SandboxConfiguration :: default ( ) ;
22432243 small_cfg. set_input_data_size ( 0x2000 ) ;
22442244 small_cfg. set_output_data_size ( 0x2000 ) ;
2245- small_cfg. set_heap_size ( 0x8000 ) ;
2245+ small_cfg. set_heap_size ( 0x20_000 ) ;
22462246 let path = simple_guest_as_pathbuf ( ) ;
22472247 let mut small = UninitializedSandbox :: new ( GuestBinary :: FilePath ( path) , Some ( small_cfg) )
22482248 . unwrap ( )
@@ -2272,15 +2272,15 @@ mod tests {
22722272
22732273 target. restore ( small_snapshot. clone ( ) ) . unwrap ( ) ;
22742274 assert_eq ! ( target. call:: <i32 >( "GetStatic" , ( ) ) . unwrap( ) , 11 ) ;
2275- assert_eq ! ( target. mem_mgr. layout. heap_size( ) , 0x8000 ) ;
2275+ assert_eq ! ( target. mem_mgr. layout. heap_size( ) , 0x20_000 ) ;
22762276
22772277 target. restore ( large_snapshot) . unwrap ( ) ;
22782278 assert_eq ! ( target. call:: <i32 >( "GetStatic" , ( ) ) . unwrap( ) , 22 ) ;
22792279 assert_eq ! ( target. mem_mgr. layout. heap_size( ) , 0x40_000 ) ;
22802280
22812281 target. restore ( small_snapshot) . unwrap ( ) ;
22822282 assert_eq ! ( target. call:: <i32 >( "GetStatic" , ( ) ) . unwrap( ) , 11 ) ;
2283- assert_eq ! ( target. mem_mgr. layout. heap_size( ) , 0x8000 ) ;
2283+ assert_eq ! ( target. mem_mgr. layout. heap_size( ) , 0x20_000 ) ;
22842284 }
22852285
22862286 #[ test]
0 commit comments