Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ updates:
- dependency-name: "mshv-bindings"
versions: [ ">=0.2.1" ]
open-pull-requests-limit: 20
# Excluded workspace members - guests with custom linker flags
- package-ecosystem: "cargo"
directory: "/src/tests/rust_guests/callbackguest"
schedule:
interval: "daily"
time: "03:00"
labels:
- "kind/dependencies"
- "area/guest"
open-pull-requests-limit: 5
- package-ecosystem: "cargo"
directory: "/src/tests/rust_guests/dummyguest"
schedule:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/Benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ jobs:

- name: Copy Guest Binaries
run: |
cp ./downloaded-rust-guest-binaries-release/callbackguest ./src/tests/rust_guests/bin/release/callbackguest
cp ./downloaded-rust-guest-binaries-release/simpleguest ./src/tests/rust_guests/bin/release/simpleguest
cp ./downloaded-rust-guest-binaries-release/dummyguest ./src/tests/rust_guests/bin/release/dummyguest
cp ./downloaded-c-guest-binaries-release/callbackguest ./src/tests/c_guests/bin/release/callbackguest
cp ./downloaded-c-guest-binaries-release/simpleguest ./src/tests/c_guests/bin/release/simpleguest

### Benchmarks ###
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/dep_build_guest_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
with:
name: rust-guest-binaries-${{ matrix.config }}
path: |
src\tests\rust_guests\bin\${{ matrix.config }}\callbackguest
src\tests\rust_guests\bin\${{ matrix.config }}\dummyguest
src\tests\rust_guests\bin\${{ matrix.config }}\simpleguest
if-no-files-found: error
Expand All @@ -55,6 +54,5 @@ jobs:
with:
name: c-guest-binaries-${{ matrix.config }}
path: |
src\tests\c_guests\bin\${{ matrix.config }}\callbackguest
src\tests\c_guests\bin\${{ matrix.config }}\simpleguest
if-no-files-found: error
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"Cargo.toml",
// guest crates for testing, not part of the workspace
"src/tests/rust_guests/simpleguest/Cargo.toml",
"src/tests/rust_guests/callbackguest/Cargo.toml"
]
}
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ members = [
]
# Guests have custom linker flags, so we need to exclude them from the workspace
exclude = [
"src/tests/rust_guests/callbackguest",
"src/tests/rust_guests/dummyguest",
"src/tests/rust_guests/simpleguest",
"src/tests/rust_guests/witguest",
Expand Down
7 changes: 0 additions & 7 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ root := justfile_directory()
default-target := "debug"
simpleguest_source := "src/tests/rust_guests/simpleguest/target/x86_64-unknown-none"
dummyguest_source := "src/tests/rust_guests/dummyguest/target/x86_64-unknown-none"
callbackguest_source := "src/tests/rust_guests/callbackguest/target/x86_64-unknown-none"
witguest_source := "src/tests/rust_guests/witguest/target/x86_64-unknown-none"
rust_guests_bin_dir := "src/tests/rust_guests/bin"

Expand Down Expand Up @@ -39,13 +38,11 @@ witguest-wit:
cd src/tests/rust_guests/witguest && wasm-tools component wit guest.wit -w -o interface.wasm

build-rust-guests target=default-target features="": (witguest-wit)
cd src/tests/rust_guests/callbackguest && cargo build {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }}
cd src/tests/rust_guests/simpleguest && cargo build {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }}
cd src/tests/rust_guests/dummyguest && cargo build {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }}
cd src/tests/rust_guests/witguest && cargo build {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }}

@move-rust-guests target=default-target:
cp {{ callbackguest_source }}/{{ target }}/callbackguest* {{ rust_guests_bin_dir }}/{{ target }}/
cp {{ simpleguest_source }}/{{ target }}/simpleguest* {{ rust_guests_bin_dir }}/{{ target }}/
cp {{ dummyguest_source }}/{{ target }}/dummyguest* {{ rust_guests_bin_dir }}/{{ target }}/
cp {{ witguest_source }}/{{ target }}/witguest* {{ rust_guests_bin_dir }}/{{ target }}/
Expand All @@ -59,7 +56,6 @@ clean-rust:
cargo clean
cd src/tests/rust_guests/simpleguest && cargo clean
cd src/tests/rust_guests/dummyguest && cargo clean
cd src/tests/rust_guests/callbackguest && cargo clean
{{ if os() == "windows" { "cd src/tests/rust_guests/witguest -ErrorAction SilentlyContinue; cargo clean" } else { "[ -d src/tests/rust_guests/witguest ] && cd src/tests/rust_guests/witguest && cargo clean || true" } }}
{{ if os() == "windows" { "Remove-Item src/tests/rust_guests/witguest/interface.wasm -Force -ErrorAction SilentlyContinue" } else { "rm -f src/tests/rust_guests/witguest/interface.wasm" } }}
git clean -fdx src/tests/c_guests/bin src/tests/rust_guests/bin
Expand Down Expand Up @@ -229,7 +225,6 @@ check:

fmt-check:
cargo +nightly fmt --all -- --check
cargo +nightly fmt --manifest-path src/tests/rust_guests/callbackguest/Cargo.toml -- --check
cargo +nightly fmt --manifest-path src/tests/rust_guests/simpleguest/Cargo.toml -- --check
cargo +nightly fmt --manifest-path src/tests/rust_guests/dummyguest/Cargo.toml -- --check
cargo +nightly fmt --manifest-path src/tests/rust_guests/witguest/Cargo.toml -- --check
Expand All @@ -240,7 +235,6 @@ check-license-headers:

fmt-apply:
cargo +nightly fmt --all
cargo +nightly fmt --manifest-path src/tests/rust_guests/callbackguest/Cargo.toml
cargo +nightly fmt --manifest-path src/tests/rust_guests/simpleguest/Cargo.toml
cargo +nightly fmt --manifest-path src/tests/rust_guests/dummyguest/Cargo.toml
cargo +nightly fmt --manifest-path src/tests/rust_guests/witguest/Cargo.toml
Expand All @@ -251,7 +245,6 @@ clippy target=default-target: (witguest-wit)

clippy-guests target=default-target: (witguest-wit)
cd src/tests/rust_guests/simpleguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
cd src/tests/rust_guests/callbackguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
cd src/tests/rust_guests/witguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings

clippy-apply-fix-unix:
Expand Down
3 changes: 0 additions & 3 deletions c.just
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ build-rust-capi target=default-target:
compile-c-guest target=default-target:
# elf
cd src/tests/c_guests/c_simpleguest && {{ mkdir }} "./out/{{target}}" && clang -c {{ c-compile-options-elf }} {{ if target == "debug" { c-flags-debug-elf } else { c-flags-release-elf } }} main.c {{c-include-flags-elf}} -o "out/{{ target }}/main.o"
cd src/tests/c_guests/c_callbackguest && {{ mkdir }} "./out/{{target}}" && clang -c {{ c-compile-options-elf }} {{ if target == "debug" { c-flags-debug-elf } else { c-flags-release-elf } }} main.c {{c-include-flags-elf}} -o "out/{{ target }}/main.o"

link-c-guest target=default-target:
# elf
cd src/tests/c_guests/c_simpleguest && ld.lld -o out/{{target}}/simpleguest {{c-linker-options-elf}} out/{{target}}/main.o -l hyperlight_guest_capi -L "{{justfile_directory()}}/target/x86_64-unknown-none/{{target}}"
cd src/tests/c_guests/c_callbackguest && ld.lld -o out/{{target}}/callbackguest {{c-linker-options-elf}} out/{{target}}/main.o -l hyperlight_guest_capi -L "{{justfile_directory()}}/target/x86_64-unknown-none/{{target}}"

move-c-guests target=default-target:
# elf
cp src/tests/c_guests/c_simpleguest/out/{{target}}/simpleguest src/tests/c_guests/bin/{{target}}/
cp src/tests/c_guests/c_callbackguest/out/{{target}}/callbackguest src/tests/c_guests/bin/{{target}}/
3 changes: 1 addition & 2 deletions src/hyperlight_host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ pub(crate) mod seccomp;
/// Signal handling for Linux
#[cfg(target_os = "linux")]
pub(crate) mod signal_handlers;
/// Utilities for testing including interacting with `simpleguest.exe`
/// and `callbackguest.exe`, our two most basic guest binaries for testing
/// Utilities for testing including interacting with `simpleguest` testing guest binary
#[cfg(test)]
pub(crate) mod testing;

Expand Down
7 changes: 2 additions & 5 deletions src/hyperlight_host/src/sandbox/uninitialized_evolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,15 @@ pub(crate) fn set_up_hypervisor_partition(

#[cfg(test)]
mod tests {
use hyperlight_testing::{callback_guest_as_string, simple_guest_as_string};
use hyperlight_testing::simple_guest_as_string;

use super::evolve_impl_multi_use;
use crate::UninitializedSandbox;
use crate::sandbox::uninitialized::GuestBinary;

#[test]
fn test_evolve() {
let guest_bin_paths = vec![
simple_guest_as_string().unwrap(),
callback_guest_as_string().unwrap(),
];
let guest_bin_paths = vec![simple_guest_as_string().unwrap()];
for guest_bin_path in guest_bin_paths {
let u_sbox =
UninitializedSandbox::new(GuestBinary::FilePath(guest_bin_path.clone()), None)
Expand Down
19 changes: 3 additions & 16 deletions src/hyperlight_host/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ limitations under the License.
*/
use hyperlight_host::func::HostFunction;
use hyperlight_host::{GuestBinary, MultiUseSandbox, Result, UninitializedSandbox};
use hyperlight_testing::{
c_callback_guest_as_string, c_simple_guest_as_string, callback_guest_as_string,
simple_guest_as_string,
};
use hyperlight_testing::{c_simple_guest_as_string, simple_guest_as_string};

/// Returns a rust/c simpleguest depending on environment variable GUEST.
/// Uses rust guest by default. Run test with environment variable GUEST="c" to use the c version
Expand Down Expand Up @@ -59,10 +56,10 @@ pub fn get_simpleguest_sandboxes(
.collect()
}

pub fn get_callbackguest_uninit_sandboxes(
pub fn get_uninit_simpleguest_sandboxes(
writer: Option<HostFunction<i32, (String,)>>, // An optional writer to make sure correct info is passed to the host printer
) -> Vec<UninitializedSandbox> {
let elf_path = get_c_or_rust_callbackguest_path();
let elf_path = get_c_or_rust_simpleguest_path();

let sandboxes = [
// in hypervisor elf
Expand All @@ -89,13 +86,3 @@ pub(crate) fn get_c_or_rust_simpleguest_path() -> String {
_ => panic!("Unknown guest type '{guest_type}', use either 'rust' or 'c'"),
}
}

// returns the the path of callbackguest binary. Picks rust/ version depending on environment variable GUEST (or rust by default if unset)
fn get_c_or_rust_callbackguest_path() -> String {
let guest_type = std::env::var("GUEST").unwrap_or("rust".to_string());
match guest_type.as_str() {
"rust" => callback_guest_as_string().unwrap(),
"c" => c_callback_guest_as_string().unwrap(),
_ => panic!("Unknown guest type '{guest_type}', use either 'rust' or 'c'"),
}
}
8 changes: 3 additions & 5 deletions src/hyperlight_host/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ use hyperlight_common::mem::PAGE_SIZE;
use hyperlight_host::sandbox::SandboxConfiguration;
use hyperlight_host::{GuestBinary, HyperlightError, MultiUseSandbox, UninitializedSandbox};
use hyperlight_testing::simplelogger::{LOGGER, SimpleLogger};
use hyperlight_testing::{
c_simple_guest_as_string, callback_guest_as_string, simple_guest_as_string,
};
use hyperlight_testing::{c_simple_guest_as_string, simple_guest_as_string};
use log::LevelFilter;

pub mod common; // pub to disable dead_code warning
Expand All @@ -40,7 +38,7 @@ fn interrupt_host_call() {
let barrier2 = barrier.clone();

let mut usbox = UninitializedSandbox::new(
GuestBinary::FilePath(callback_guest_as_string().expect("Guest Binary Missing")),
GuestBinary::FilePath(simple_guest_as_string().expect("Guest Binary Missing")),
None,
)
.unwrap();
Expand Down Expand Up @@ -312,7 +310,7 @@ fn interrupt_custom_signal_no_and_retry_delay() {
#[test]
fn interrupt_spamming_host_call() {
let mut uninit = UninitializedSandbox::new(
GuestBinary::FilePath(callback_guest_as_string().unwrap()),
GuestBinary::FilePath(simple_guest_as_string().unwrap()),
None,
)
.unwrap();
Expand Down
8 changes: 4 additions & 4 deletions src/hyperlight_host/tests/sandbox_host_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use core::f64;
use std::sync::mpsc::channel;
use std::sync::{Arc, Mutex};

use common::new_uninit;
use common::{get_uninit_simpleguest_sandboxes, new_uninit};
use hyperlight_host::sandbox::SandboxConfiguration;
use hyperlight_host::{
GuestBinary, HyperlightError, MultiUseSandbox, Result, UninitializedSandbox, new_error,
Expand All @@ -28,7 +28,7 @@ use hyperlight_testing::simple_guest_as_string;
use serial_test::serial; // using LoadLibrary requires serial tests

pub mod common; // pub to disable dead_code warning
use crate::common::{get_callbackguest_uninit_sandboxes, get_simpleguest_sandboxes};
use crate::common::get_simpleguest_sandboxes;

#[test]
#[cfg_attr(target_os = "windows", serial)] // using LoadLibrary requires serial tests
Expand Down Expand Up @@ -312,7 +312,7 @@ fn simple_test_parallel() {
}

fn callback_test_helper() -> Result<()> {
for mut sandbox in get_callbackguest_uninit_sandboxes(None).into_iter() {
for mut sandbox in get_uninit_simpleguest_sandboxes(None).into_iter() {
// create host function
let (tx, rx) = channel();
sandbox.register("HostMethod1", move |msg: String| {
Expand Down Expand Up @@ -357,7 +357,7 @@ fn callback_test_parallel() {
#[test]
#[cfg_attr(target_os = "windows", serial)] // using LoadLibrary requires serial tests
fn host_function_error() -> Result<()> {
for mut sandbox in get_callbackguest_uninit_sandboxes(None).into_iter() {
for mut sandbox in get_uninit_simpleguest_sandboxes(None).into_iter() {
// create host function
sandbox.register("HostMethod1", |_: String| -> Result<String> {
Err(new_error!("Host function error!"))
Expand Down
17 changes: 1 addition & 16 deletions src/hyperlight_testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,12 @@ pub fn simple_guest_as_string() -> Result<String> {
.ok_or_else(|| anyhow!("couldn't convert simple guest PathBuf to string"))
}

/// Get a fully qualified OS-specific path to the callbackguest elf binary
pub fn callback_guest_as_string() -> Result<String> {
let buf = rust_guest_as_pathbuf("callbackguest");
buf.to_str()
.map(|s| s.to_string())
.ok_or_else(|| anyhow!("couldn't convert callback guest PathBuf to string"))
}

/// Get a fully-qualified OS-specific path to the witguest elf binary
pub fn wit_guest_as_string() -> Result<String> {
let buf = rust_guest_as_pathbuf("witguest");
buf.to_str()
.map(|s| s.to_string())
.ok_or_else(|| anyhow!("couldn't convert callback guest PathBuf to string"))
.ok_or_else(|| anyhow!("couldn't convert wit guest PathBuf to string"))
}

/// Get a fully qualified OS-specific path to the dummyguest elf binary
Expand Down Expand Up @@ -116,13 +108,6 @@ pub fn c_simple_guest_as_string() -> Result<String> {
.ok_or_else(|| anyhow!("couldn't convert simple guest PathBuf to string"))
}

pub fn c_callback_guest_as_string() -> Result<String> {
let buf = c_guest_as_pathbuf("callbackguest");
buf.to_str()
.map(|s| s.to_string())
.ok_or_else(|| anyhow!("couldn't convert callback guest PathBuf to string"))
}

/// Get a fully qualified path to a simple guest binary preferring a binary
/// in the same directory as the parent executable. This will be used in
/// fuzzing scenarios where pre-built binaries will be built and submitted to
Expand Down
51 changes: 0 additions & 51 deletions src/tests/c_guests/c_callbackguest/main.c

This file was deleted.

19 changes: 19 additions & 0 deletions src/tests/c_guests/c_simpleguest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,26 @@ hl_Vec *twenty_four_k_in_eight_k_out(const hl_FunctionCall* params) {
return hl_flatbuffer_result_from_Bytes(input.data, 8 * 1024);
}

int guest_function(const char *from_host) {
char guest_message[256] = "Hello from GuestFunction1, ";
int len = strlen(from_host);
strncat(guest_message, from_host, len);

hl_Parameter params = {.tag = hl_ParameterType_String,
.value = {.String = guest_message}};
const hl_FunctionCall host_call = {.function_name = "HostMethod1",
.parameters = &params,
.parameters_len = 1,
.return_type = hl_ReturnType_Int};
hl_call_host_function(&host_call);
hl_get_host_return_value_as_Int();

return 0;
}

HYPERLIGHT_WRAP_FUNCTION(echo, String, 1, String)
// HYPERLIGHT_WRAP_FUNCTION(set_byte_array_to_zero, 1, VecBytes) is not valid for functions that return VecBytes
HYPERLIGHT_WRAP_FUNCTION(guest_function, Int, 1, String)
HYPERLIGHT_WRAP_FUNCTION(print_output, Int, 1, String)
HYPERLIGHT_WRAP_FUNCTION(stack_allocate, Int, 1, Int)
HYPERLIGHT_WRAP_FUNCTION(stack_overflow, Int, 1, Int)
Expand Down Expand Up @@ -275,6 +293,7 @@ void hyperlight_main(void)
// HYPERLIGHT_REGISTER_FUNCTION macro does not work for functions that return VecBytes,
// so we use hl_register_function_definition directly
hl_register_function_definition("SetByteArrayToZero", set_byte_array_to_zero, 1, (hl_ParameterType[]){hl_ParameterType_VecBytes}, hl_ReturnType_VecBytes);
HYPERLIGHT_REGISTER_FUNCTION("GuestMethod1", guest_function);
HYPERLIGHT_REGISTER_FUNCTION("PrintOutput", print_output);
HYPERLIGHT_REGISTER_FUNCTION("StackAllocate", stack_allocate);
HYPERLIGHT_REGISTER_FUNCTION("StackOverflow", stack_overflow);
Expand Down
Loading
Loading