Skip to content

Commit 81dc6f2

Browse files
committed
Add failing test due to host call error leak
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 87af189 commit 81dc6f2

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,38 @@ mod tests {
504504
#[cfg(target_os = "linux")]
505505
use crate::mem::shared_mem::{ExclusiveSharedMemory, GuestSharedMemory, SharedMemory as _};
506506
use crate::sandbox::SandboxConfiguration;
507-
use crate::{GuestBinary, HyperlightError, MultiUseSandbox, Result, UninitializedSandbox};
507+
use crate::{
508+
GuestBinary, HyperlightError, MultiUseSandbox, Result, UninitializedSandbox, new_error,
509+
};
510+
511+
/// Make sure input/output buffers are properly reset after guest call (with host call)
512+
#[test]
513+
fn host_func_error() {
514+
let path = simple_guest_as_string().unwrap();
515+
let mut sandbox = UninitializedSandbox::new(GuestBinary::FilePath(path), None).unwrap();
516+
sandbox
517+
.register("HostError", || -> Result<()> {
518+
Err(HyperlightError::Error("hi".to_string()))
519+
})
520+
.unwrap();
521+
let mut sandbox = sandbox.evolve().unwrap();
522+
523+
// will exhaust io if leaky
524+
for _ in 0..1000 {
525+
let result = sandbox
526+
.call::<i64>(
527+
"CallGivenParamlessHostFuncThatReturnsI64",
528+
"HostError".to_string(),
529+
)
530+
.unwrap_err();
531+
532+
assert!(
533+
matches!(result, HyperlightError::Error(ref msg) if msg == "hi"),
534+
"Expected HyperlightError::Error('hi'), got {:?}",
535+
result
536+
);
537+
}
538+
}
508539

509540
/// Tests that call_guest_function_by_name restores the state correctly
510541
#[test]

0 commit comments

Comments
 (0)