use hyperlight_host::func::{ParameterValue, ReturnType, ReturnValue};
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
use hyperlight_host::sandbox_state::transition::Noop;
use hyperlight_host::{GuestBinary, MultiUseSandbox, Result};
use hyperlight_testing::simple_guest_as_string;
use tracing_chrome::ChromeLayerBuilder;
use tracing_subscriber::prelude::*;
fn main() -> Result<()> {
let (chrome_layer, _guard) = ChromeLayerBuilder::new().build();
tracing_subscriber::registry().with(chrome_layer).init();
let simple_guest_path =
simple_guest_as_string().expect("Cannot find the guest binary at the expected location.");
let usandbox =
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None, None, None)?;
let mut sbox = usandbox
.evolve(Noop::<UninitializedSandbox, MultiUseSandbox>::default())
.unwrap();
let current_time = std::time::Instant::now();
let res = sbox.call_guest_function_by_name(
"Echo",
ReturnType::String,
Some(vec![ParameterValue::String("Hello, World!".to_string())]),
)?;
let elapsed = current_time.elapsed();
println!("Function call finished in {:?}.", elapsed);
assert!(matches!(res, ReturnValue::String(s) if s == "Hello, World!"));
Ok(())
}