Skip to content

Commit a80a756

Browse files
committed
[*] bring back tests + benchmarks + fuzzing + examples
- 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 ca42784 commit a80a756

File tree

45 files changed

+1943
-3709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1943
-3709
lines changed

Justfile

Lines changed: 16 additions & 5 deletions
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

fuzz/fuzz_targets/guest_call.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,28 @@ limitations under the License.
1919
use std::sync::{Mutex, OnceLock};
2020

2121
use hyperlight_host::func::{ParameterValue, ReturnType};
22-
use hyperlight_host::sandbox::uninitialized::GuestBinary;
22+
use hyperlight_host::sandbox::sandbox_builder::SandboxBuilder;
2323
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
2424
use hyperlight_host::sandbox_state::transition::Noop;
25-
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
25+
use hyperlight_host::{GuestBinary, MultiUseSandbox};
2626
use hyperlight_testing::simple_guest_for_fuzzing_as_string;
2727
use libfuzzer_sys::fuzz_target;
28+
2829
static SANDBOX: OnceLock<Mutex<MultiUseSandbox>> = OnceLock::new();
2930

3031
// This fuzz target tests all combinations of ReturnType and Parameters for `call_guest_function_by_name`.
3132
// For fuzzing efficiency, we create one Sandbox and reuse it for all fuzzing iterations.
3233
fuzz_target!(
3334
init: {
34-
35-
let u_sbox = UninitializedSandbox::new(
36-
GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing")),
37-
None,
38-
None,
39-
None,
35+
let u_sbox = SandboxBuilder::new(
36+
GuestBinary::FilePath(
37+
simple_guest_for_fuzzing_as_string()
38+
.expect("Guest Binary Missing")
39+
)
4040
)
41-
.unwrap();
41+
.expect("Failed to create sandbox")
42+
.build()
43+
.expect("Failed to build sandbox");
4244

4345
let mu_sbox: MultiUseSandbox = u_sbox.evolve(Noop::default()).unwrap();
4446
SANDBOX.set(Mutex::new(mu_sbox)).unwrap();

fuzz/fuzz_targets/host_call.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ limitations under the License.
1919
use std::sync::{Mutex, OnceLock};
2020

2121
use hyperlight_host::func::{ParameterValue, ReturnType};
22-
use hyperlight_host::sandbox::uninitialized::GuestBinary;
23-
use hyperlight_host::sandbox::SandboxConfiguration;
2422
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
2523
use hyperlight_host::sandbox_state::transition::Noop;
26-
use hyperlight_host::{HyperlightError, MultiUseSandbox, UninitializedSandbox};
24+
use hyperlight_host::{HyperlightError, MultiUseSandbox};
2725
use hyperlight_testing::simple_guest_for_fuzzing_as_string;
2826
use libfuzzer_sys::fuzz_target;
2927
static SANDBOX: OnceLock<Mutex<MultiUseSandbox>> = OnceLock::new();
@@ -32,13 +30,15 @@ static SANDBOX: OnceLock<Mutex<MultiUseSandbox>> = OnceLock::new();
3230
// For fuzzing efficiency, we create one Sandbox and reuse it for all fuzzing iterations.
3331
fuzz_target!(
3432
init: {
35-
let u_sbox = UninitializedSandbox::new(
36-
GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing")),
37-
None,
38-
None,
39-
None,
33+
let u_sbox = SandboxBuilder::new(
34+
GuestBinary::FilePath(
35+
simple_guest_for_fuzzing_as_string()
36+
.expect("Guest Binary Missing")
37+
)
4038
)
41-
.unwrap();
39+
.expect("Failed to create sandbox")
40+
.build()
41+
.expect("Failed to build sandbox");
4242

4343
let mu_sbox: MultiUseSandbox = u_sbox.evolve(Noop::default()).unwrap();
4444
SANDBOX.set(Mutex::new(mu_sbox)).unwrap();

fuzz/fuzz_targets/host_print.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
use std::sync::{Mutex, OnceLock};
44

55
use hyperlight_host::func::{ParameterValue, ReturnType, ReturnValue};
6-
use hyperlight_host::sandbox::uninitialized::GuestBinary;
6+
use hyperlight_host::sandbox::sandbox_builder::SandboxBuilder;
77
use hyperlight_host::sandbox_state::sandbox::EvolvableSandbox;
88
use hyperlight_host::sandbox_state::transition::Noop;
9-
use hyperlight_host::{MultiUseSandbox, UninitializedSandbox};
9+
use hyperlight_host::{GuestBinary, MultiUseSandbox};
1010
use hyperlight_testing::simple_guest_for_fuzzing_as_string;
1111
use libfuzzer_sys::{fuzz_target, Corpus};
1212

@@ -18,13 +18,15 @@ static SANDBOX: OnceLock<Mutex<MultiUseSandbox>> = OnceLock::new();
1818
// For fuzzing efficiency, we create one Sandbox and reuse it for all fuzzing iterations.
1919
fuzz_target!(
2020
init: {
21-
let u_sbox = UninitializedSandbox::new(
22-
GuestBinary::FilePath(simple_guest_for_fuzzing_as_string().expect("Guest Binary Missing")),
23-
None,
24-
None,
25-
None,
21+
let u_sbox = SandboxBuilder::new(
22+
GuestBinary::FilePath(
23+
simple_guest_for_fuzzing_as_string()
24+
.expect("Guest Binary Missing")
25+
)
2626
)
27-
.unwrap();
27+
.expect("Failed to create sandbox")
28+
.build()
29+
.expect("Failed to build sandbox");
2830

2931
let mu_sbox: MultiUseSandbox = u_sbox.evolve(Noop::default()).unwrap();
3032
SANDBOX.set(Mutex::new(mu_sbox)).unwrap();

src/hyperlight_common/src/peb.rs

Lines changed: 4 additions & 2 deletions
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
@@ -166,7 +168,7 @@ impl HyperlightPEB {
166168

167169
/// Sets the guest stack data region.
168170
/// - HyperlightPEB is always set with a default size for stack from the guest binary, there's an
169-
/// option to override this size with the `size_override` parameter.
171+
/// option to override this size with the `size_override` parameter.
170172
171173
pub fn set_guest_stack_data_region(&mut self, offset: u64, size_override: Option<u64>) {
172174
let size = size_override.unwrap_or_else(|| {
@@ -237,7 +239,7 @@ impl HyperlightPEB {
237239

238240
/// Sets the guest heap data region.
239241
/// - HyperlightPEB is always set with a default size for heap from the guest binary, there's an
240-
/// option to override this size with the `size_override` parameter.
242+
/// option to override this size with the `size_override` parameter.
241243
pub fn set_guest_heap_data_region(&mut self, offset: u64, size_override: Option<u64>) {
242244
let size = size_override.unwrap_or_else(|| {
243245
self.guest_heap_data

src/hyperlight_guest/src/entrypoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub extern "win64" fn entrypoint(peb_address: u64, seed: u64, max_log_level: u64
8686

8787
// The guest sets the address to a "guest function dispatch" function, which is a function
8888
// that is called by the host to dispatch calls to guest functions.
89-
(*PEB).set_guest_function_dispatch_ptr(dispatch_function as u64);
89+
(*PEB).set_guest_function_dispatch_ptr(dispatch_function as usize as u64);
9090

9191
// Set up the guest heap
9292
HEAP_ALLOCATOR

src/hyperlight_guest/src/guest_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn write_error(error_code: ErrorCode, message: Option<&str>) {
3030
let output_data: OutputDataSection = peb.get_output_data_region().into();
3131

3232
let guest_error = GuestError::new(
33-
error_code.clone(),
33+
error_code,
3434
message.map_or("".to_string(), |m| m.to_string()),
3535
);
3636

src/hyperlight_guest/src/guest_function_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn internal_dispatch_function() -> Result<()> {
9393
.expect("Function call deserialization failed");
9494

9595
let result_vec = call_guest_function(function_call).inspect_err(|e| {
96-
set_error(e.kind.clone(), e.message.as_str());
96+
set_error(e.kind, e.message.as_str());
9797
})?;
9898

9999
output_data_section

src/hyperlight_guest/src/logging.rs

Lines changed: 2 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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();

0 commit comments

Comments
 (0)