Skip to content

Commit 8b04b73

Browse files
committed
[*] bring back tests
- added convenience justfile rule to test like CI (w/ different feature combinations), - removed executable_heap feature (heap is always executable now). - fixed check_stack_guard functionality w/ stack cookie (currently broken in main). - fixed logging to get proper output_data_region address (host vs. guest address space when in process vs. in hypervisor). - modified print_output to return the message length. Signed-off-by: danbugs <[email protected]>
1 parent ae1637b commit 8b04b73

File tree

37 files changed

+2798
-4500
lines changed

37 files changed

+2798
-4500
lines changed

Justfile

+16-5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ clean-rust:
6262

6363
# Note: most testing recipes take an optional "features" comma separated list argument. If provided, these will be passed to cargo as **THE ONLY FEATURES**, i.e. default features will be disabled.
6464

65+
# run full CI test matrix
66+
test-like-ci config=default-target hypervisor="kvm":
67+
@# with default features
68+
just test {{config}} {{ if hypervisor == "mshv3" {"mshv3"} else {""} }}
69+
70+
@# with only one driver enabled + seccomp + inprocess
71+
just test {{config}} inprocess,seccomp,{{ if hypervisor == "mshv" {"mshv2"} else if hypervisor == "mshv3" {"mshv3"} else {"kvm"} }}
72+
73+
@# make sure certain cargo features compile
74+
cargo check -p hyperlight-host --features crashdump
75+
cargo check -p hyperlight-host --features print_debug
76+
cargo check -p hyperlight-host --features gdb
77+
78+
@# without any driver (should fail to compile)
79+
just test-compilation-fail {{config}}
80+
6581
# runs all tests
6682
test target=default-target features="": (test-unit target features) (test-isolated target features) (test-integration "rust" target features) (test-integration "c" target features) (test-seccomp target features)
6783

@@ -83,11 +99,6 @@ test-isolated target=default-target features="":
8399

84100
# runs integration tests. Guest can either be "rust" or "c"
85101
test-integration guest target=default-target features="":
86-
@# run execute_on_heap test with feature "executable_heap" on and off
87-
{{if os() == "windows" { "$env:" } else { "" } }}GUEST="{{guest}}"{{if os() == "windows" { ";" } else { "" } }} cargo test --profile={{ if target == "debug" { "dev" } else { target } }} --test integration_test execute_on_heap {{ if features =="" {" --features executable_heap"} else {"--features executable_heap," + features} }} -- --ignored
88-
{{if os() == "windows" { "$env:" } else { "" } }}GUEST="{{guest}}"{{if os() == "windows" { ";" } else { "" } }} cargo test --profile={{ if target == "debug" { "dev" } else { target } }} --test integration_test execute_on_heap {{ if features =="" {""} else {"--features " + features} }} -- --ignored
89-
90-
@# run the rest of the integration tests
91102
{{if os() == "windows" { "$env:" } else { "" } }}GUEST="{{guest}}"{{if os() == "windows" { ";" } else { "" } }} cargo test -p hyperlight-host {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} --test '*'
92103

93104
# runs seccomp tests

src/hyperlight_common/src/peb.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ pub struct MemoryRegion {
2727
#[repr(C)]
2828
#[derive(Clone, Default)]
2929
pub struct HyperlightPEB {
30+
/// The minimum stack address is the lowest address of the stack.
3031
pub min_stack_address: u64,
32+
3133
// - Host configured fields
3234
/// Hyperlight supports two primary modes:
3335
/// 1. Hypervisor mode

src/hyperlight_guest/src/logging.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ fn write_log_data(
4444
.try_into()
4545
.expect("Failed to convert GuestLogData to bytes");
4646

47-
let output_data_section: OutputDataSection = unsafe { (*PEB).clone() }
48-
.get_output_data_guest_region()
49-
.into();
47+
let output_data_section: OutputDataSection =
48+
unsafe { (*PEB).clone() }.get_output_data_region().into();
5049

5150
output_data_section
5251
.push_shared_output_data(bytes)

src/hyperlight_guest_capi/src/dispatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use core::mem;
77
use hyperlight_common::flatbuffer_wrappers::function_call::FunctionCall;
88
use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterType, ReturnType};
99
use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode;
10+
use hyperlight_common::host_calling::call_host_function;
1011
use hyperlight_guest::error::{HyperlightGuestError, Result};
1112
use hyperlight_guest::guest_function_definition::GuestFunctionDefinition;
1213
use hyperlight_guest::guest_function_register::GuestFunctionRegister;
13-
use hyperlight_guest::host_function_call::call_host_function;
1414

1515
use crate::types::{FfiFunctionCall, FfiVec};
1616
static mut REGISTERED_C_GUEST_FUNCTIONS: GuestFunctionRegister = GuestFunctionRegister::new();

src/hyperlight_guest_capi/src/flatbuffer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alloc::boxed::Box;
22
use core::ffi::{c_char, CStr};
33

44
use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result;
5-
use hyperlight_guest::host_function_call::get_host_return_value;
5+
use hyperlight_common::host_calling::get_host_return_value;
66

77
use crate::types::FfiVec;
88

src/hyperlight_host/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ built = { version = "0.7.7", features = ["chrono", "git2"] }
121121
default = ["kvm", "mshv2", "seccomp"]
122122
seccomp = ["dep:seccompiler"]
123123
function_call_metrics = []
124-
executable_heap = []
125124
# This feature enables printing of debug information to stdout in debug builds
126125
print_debug = []
127126
crashdump = ["dep:tempfile"] # Dumps the VM state to a file on unexpected errors or crashes. The path of the file will be printed on stdout and logged. This feature can only be used in debug builds.
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
1-
/*
2-
Copyright 2024 The Hyperlight Authors.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
16-
17-
use hyperlight_host::func::{ParameterValue, ReturnType, ReturnValue};
18-
use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
19-
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
20-
use hyperlight_host::sandbox_state::transition::Noop;
21-
use hyperlight_host::{GuestBinary, MultiUseSandbox, Result};
22-
use hyperlight_testing::simple_guest_as_string;
23-
use tracing_chrome::ChromeLayerBuilder;
24-
use tracing_subscriber::prelude::*;
25-
26-
// This example can be run with `cargo run --package hyperlight_host --example chrome-tracing --release`
27-
fn main() -> Result<()> {
28-
// set up tracer
29-
let (chrome_layer, _guard) = ChromeLayerBuilder::new().build();
30-
tracing_subscriber::registry().with(chrome_layer).init();
31-
32-
let simple_guest_path =
33-
simple_guest_as_string().expect("Cannot find the guest binary at the expected location.");
34-
35-
// Create a new sandbox.
36-
let usandbox =
37-
UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None, None, None)?;
38-
39-
let mut sbox = usandbox
40-
.evolve(Noop::<UninitializedSandbox, MultiUseSandbox>::default())
41-
.unwrap();
42-
43-
// do the function call
44-
let current_time = std::time::Instant::now();
45-
let res = sbox.call_guest_function_by_name(
46-
"Echo",
47-
ReturnType::String,
48-
Some(vec![ParameterValue::String("Hello, World!".to_string())]),
49-
)?;
50-
let elapsed = current_time.elapsed();
51-
println!("Function call finished in {:?}.", elapsed);
52-
assert!(matches!(res, ReturnValue::String(s) if s == "Hello, World!"));
1+
// TODO(danbugs:297): bring back
2+
// /*
3+
// Copyright 2024 The Hyperlight Authors.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
// */
17+
//
18+
// use hyperlight_host::func::{ParameterValue, ReturnType, ReturnValue};
19+
// use hyperlight_host::sandbox::uninitialized::UninitializedSandbox;
20+
// use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
21+
// use hyperlight_host::sandbox_state::transition::Noop;
22+
// use hyperlight_host::{GuestBinary, MultiUseSandbox, Result};
23+
// use hyperlight_testing::simple_guest_as_string;
24+
// use tracing_chrome::ChromeLayerBuilder;
25+
// use tracing_subscriber::prelude::*;
26+
//
27+
// // This example can be run with `cargo run --package hyperlight_host --example chrome-tracing --release`
28+
fn main() -> hyperlight_host::Result<()> {
29+
// // set up tracer
30+
// let (chrome_layer, _guard) = ChromeLayerBuilder::new().build();
31+
// tracing_subscriber::registry().with(chrome_layer).init();
32+
//
33+
// let simple_guest_path =
34+
// simple_guest_as_string().expect("Cannot find the guest binary at the expected location.");
35+
//
36+
// // Create a new sandbox.
37+
// let usandbox =
38+
// UninitializedSandbox::new(GuestBinary::FilePath(simple_guest_path), None, None, None)?;
39+
//
40+
// let mut sbox = usandbox
41+
// .evolve(Noop::<UninitializedSandbox, MultiUseSandbox>::default())
42+
// .unwrap();
43+
//
44+
// // do the function call
45+
// let current_time = std::time::Instant::now();
46+
// let res = sbox.call_guest_function_by_name(
47+
// "Echo",
48+
// ReturnType::String,
49+
// Some(vec![ParameterValue::String("Hello, World!".to_string())]),
50+
// )?;
51+
// let elapsed = current_time.elapsed();
52+
// println!("Function call finished in {:?}.", elapsed);
53+
// assert!(matches!(res, ReturnValue::String(s) if s == "Hello, World!"));
5354
Ok(())
5455
}
+75-74
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,77 @@
1-
/*
2-
Copyright 2024 The Hyperlight Authors.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
16-
17-
use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, ReturnType};
18-
use hyperlight_host::func::call_ctx::MultiUseGuestCallContext;
19-
use hyperlight_host::sandbox::{MultiUseSandbox, UninitializedSandbox};
20-
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
21-
use hyperlight_host::sandbox_state::transition::Noop;
22-
use hyperlight_host::{new_error, GuestBinary, Result};
23-
use hyperlight_testing::simple_guest_as_string;
24-
1+
// TODO(danbugs:297): bring back
2+
// /*
3+
// Copyright 2024 The Hyperlight Authors.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
// */
17+
//
18+
// use hyperlight_common::flatbuffer_wrappers::function_types::{ParameterValue, ReturnType};
19+
// use hyperlight_host::func::call_ctx::MultiUseGuestCallContext;
20+
// use hyperlight_host::sandbox::{MultiUseSandbox, UninitializedSandbox};
21+
// use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
22+
// use hyperlight_host::sandbox_state::transition::Noop;
23+
// use hyperlight_host::{new_error, GuestBinary, Result};
24+
// use hyperlight_testing::simple_guest_as_string;
25+
//
2526
fn main() {
26-
// create a new `MultiUseSandbox` configured to run the `simpleguest.exe`
27-
// test guest binary
28-
let sbox1: MultiUseSandbox = {
29-
let path = simple_guest_as_string().unwrap();
30-
let u_sbox =
31-
UninitializedSandbox::new(GuestBinary::FilePath(path), None, None, None).unwrap();
32-
u_sbox.evolve(Noop::default())
33-
}
34-
.unwrap();
35-
36-
// create a new call context from the sandbox, then do some calls with it.
37-
let ctx1 = sbox1.new_call_context();
38-
let sbox2 = do_calls(ctx1).unwrap();
39-
// create a new call context from the returned sandbox, then do some calls
40-
// with that one
41-
let ctx2 = sbox2.new_call_context();
42-
do_calls(ctx2).unwrap();
43-
}
44-
45-
/// Given a `MultiUseGuestCallContext` derived from an existing
46-
/// `MultiUseSandbox` configured to run the `simpleguest.exe` test guest
47-
/// binary, do several calls against that binary, print their results, then
48-
/// call `ctx.finish()` and return the resulting `MultiUseSandbox`. Return an `Err`
49-
/// if anything failed.
50-
fn do_calls(mut ctx: MultiUseGuestCallContext) -> Result<MultiUseSandbox> {
51-
{
52-
let res1: String = {
53-
let rv = ctx.call(
54-
"Echo",
55-
ReturnType::Int,
56-
Some(vec![ParameterValue::String("hello".to_string())]),
57-
)?;
58-
rv.try_into()
59-
}
60-
.map_err(|e| new_error!("failed to get Echo result: {}", e))?;
61-
println!("got Echo res: {res1}");
62-
}
63-
{
64-
let res2: i32 = {
65-
let rv = ctx.call(
66-
"CallMalloc",
67-
ReturnType::Int,
68-
Some(vec![ParameterValue::Int(200)]),
69-
)?;
70-
rv.try_into()
71-
}
72-
.map_err(|e| new_error!("failed to get CallMalloc result: {}", e))?;
73-
println!("got CallMalloc res: {res2}");
74-
}
75-
ctx.finish()
27+
// // create a new `MultiUseSandbox` configured to run the `simpleguest.exe`
28+
// // test guest binary
29+
// let sbox1: MultiUseSandbox = {
30+
// let path = simple_guest_as_string().unwrap();
31+
// let u_sbox =
32+
// UninitializedSandbox::new(GuestBinary::FilePath(path), None, None, None).unwrap();
33+
// u_sbox.evolve(Noop::default())
34+
// }
35+
// .unwrap();
36+
//
37+
// // create a new call context from the sandbox, then do some calls with it.
38+
// let ctx1 = sbox1.new_call_context();
39+
// let sbox2 = do_calls(ctx1).unwrap();
40+
// // create a new call context from the returned sandbox, then do some calls
41+
// // with that one
42+
// let ctx2 = sbox2.new_call_context();
43+
// do_calls(ctx2).unwrap();
7644
}
45+
//
46+
// /// Given a `MultiUseGuestCallContext` derived from an existing
47+
// /// `MultiUseSandbox` configured to run the `simpleguest.exe` test guest
48+
// /// binary, do several calls against that binary, print their results, then
49+
// /// call `ctx.finish()` and return the resulting `MultiUseSandbox`. Return an `Err`
50+
// /// if anything failed.
51+
// fn do_calls(mut ctx: MultiUseGuestCallContext) -> Result<MultiUseSandbox> {
52+
// {
53+
// let res1: String = {
54+
// let rv = ctx.call(
55+
// "Echo",
56+
// ReturnType::Int,
57+
// Some(vec![ParameterValue::String("hello".to_string())]),
58+
// )?;
59+
// rv.try_into()
60+
// }
61+
// .map_err(|e| new_error!("failed to get Echo result: {}", e))?;
62+
// println!("got Echo res: {res1}");
63+
// }
64+
// {
65+
// let res2: i32 = {
66+
// let rv = ctx.call(
67+
// "CallMalloc",
68+
// ReturnType::Int,
69+
// Some(vec![ParameterValue::Int(200)]),
70+
// )?;
71+
// rv.try_into()
72+
// }
73+
// .map_err(|e| new_error!("failed to get CallMalloc result: {}", e))?;
74+
// println!("got CallMalloc res: {res2}");
75+
// }
76+
// ctx.finish()
77+
// }

0 commit comments

Comments
 (0)