use std::path::PathBuf;
use hyperlight_host::{MultiUseSandbox, SandboxBuilder};
use hyperlight_testing::{c_simple_guest_as_pathbuf, simple_guest_as_pathbuf};
fn rust_guest_path() -> PathBuf {
simple_guest_as_pathbuf()
}
fn c_guest_path() -> PathBuf {
c_simple_guest_as_pathbuf()
}
pub fn build_rust_sandbox<C>(configure: C) -> MultiUseSandbox
where
C: FnOnce(SandboxBuilder) -> SandboxBuilder,
{
configure(SandboxBuilder::from_file(rust_guest_path()))
.build()
.unwrap()
}
pub fn new_rust_sandbox() -> MultiUseSandbox {
build_rust_sandbox(|builder| builder)
}
pub fn with_rust_sandbox<F>(f: F)
where
F: FnOnce(MultiUseSandbox),
{
f(new_rust_sandbox());
}
pub fn with_rust_sandbox_from<C, F>(configure: C, f: F)
where
C: FnOnce(SandboxBuilder) -> SandboxBuilder,
F: FnOnce(MultiUseSandbox),
{
f(build_rust_sandbox(configure));
}
pub fn build_c_sandbox<C>(configure: C) -> MultiUseSandbox
where
C: FnOnce(SandboxBuilder) -> SandboxBuilder,
{
configure(SandboxBuilder::from_file(c_guest_path()))
.build()
.unwrap()
}
pub fn with_c_sandbox<F>(f: F)
where
F: FnOnce(MultiUseSandbox),
{
f(build_c_sandbox(|builder| builder));
}
pub fn with_c_sandbox_from<C, F>(configure: C, f: F)
where
C: FnOnce(SandboxBuilder) -> SandboxBuilder,
F: FnOnce(MultiUseSandbox),
{
f(build_c_sandbox(configure));
}
pub fn with_all_guests<F>(f: F)
where
F: Fn(PathBuf),
{
for path in [rust_guest_path(), c_guest_path()] {
f(path);
}
}
pub fn with_all_sandboxes<F>(f: F)
where
F: Fn(MultiUseSandbox),
{
with_all_guests(|path| {
f(SandboxBuilder::from_file(path).build().unwrap());
});
}