@@ -180,7 +180,7 @@ fn interrupt_same_thread() {
180180 }
181181 } ) ;
182182
183- for _ in 0 ..NUM_ITERS {
183+ for i in 0 ..NUM_ITERS {
184184 barrier. wait ( ) ;
185185 sbox1
186186 . call_guest_function_by_name :: < String > ( "Echo" , "hello" . to_string ( ) )
@@ -190,7 +190,7 @@ fn interrupt_same_thread() {
190190 // Only allow successful calls or interrupted.
191191 // The call can be successful in case the call is finished before kill() is called.
192192 }
193- _ => panic ! ( "Unexpected return" ) ,
193+ Err ( e ) => panic ! ( "Unexpected return from sandbox 2: {:?} iteration {}" , e , i ) ,
194194 } ;
195195 sbox3
196196 . call_guest_function_by_name :: < String > ( "Echo" , "hello" . to_string ( ) )
@@ -234,7 +234,7 @@ fn interrupt_same_thread_no_barrier() {
234234 // Only allow successful calls or interrupted.
235235 // The call can be successful in case the call is finished before kill() is called.
236236 }
237- _ => panic ! ( "Unexpected return" ) ,
237+ Err ( e ) => panic ! ( "Unexpected return from sandbox 2: {:?}" , e ) ,
238238 } ;
239239 sbox3
240240 . call_guest_function_by_name :: < String > ( "Echo" , "hello" . to_string ( ) )
@@ -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+ }
0 commit comments