File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed 
src/hyperlight_host/tests Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -786,3 +786,32 @@ fn log_test_messages(levelfilter: Option<log::LevelFilter>) {
786786            . unwrap ( ) ; 
787787    } 
788788} 
789+ 
790+ #[ test]  
791+ // Test to ensure that the state of a sandbox is reset after each function call 
792+ // This uses the simpleguest and calls the "echo" function 1000 times with a 64-character string 
793+ // The fact that we can successfully call the function 1000 times and get consistent 
794+ // results indicates that the sandbox state is being properly reset between calls. 
795+ // If there were state leaks, we would expect to see failures or inconsistent behavior 
796+ // as the calls accumulate, specifically the input buffer would fill up and cause an error 
797+ // if the default size of the input buffer is changed this test should be updated accordingly 
798+ fn  sandbox_state_reset_between_calls ( )  { 
799+     let  mut  sbox = new_uninit ( ) . unwrap ( ) . evolve ( Noop :: default ( ) ) . unwrap ( ) ; 
800+ 
801+     // Create a 64-character test string 
802+     let  test_string = "A" . repeat ( 64 ) ; 
803+ 
804+     // Call the echo function 1000 times 
805+     for  i in  0 ..1000  { 
806+         let  result = sbox
807+             . call_guest_function_by_name :: < String > ( "Echo" ,  test_string. clone ( ) ) 
808+             . unwrap ( ) ; 
809+ 
810+         // Verify that the echo function returns the same string we sent 
811+         assert_eq ! ( 
812+             result,  test_string, 
813+             "Echo function returned unexpected result on iteration {}: expected '{}', got '{}'" , 
814+             i,  test_string,  result
815+         ) ; 
816+     } 
817+ } 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments