-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added selective environment passing for VM
- Loading branch information
1 parent
6d936b1
commit 795cb35
Showing
8 changed files
with
191 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
mod common; | ||
|
||
use std::collections::HashMap; | ||
|
||
use byte_unit::{Byte, Unit}; | ||
use common::{build_hermit_bin, check_result}; | ||
use uhyvelib::{ | ||
params::{EnvVars, Output, Params}, | ||
vm::UhyveVm, | ||
}; | ||
|
||
#[test] | ||
fn selective_env_test() { | ||
env_logger::try_init().ok(); | ||
let bin_path = build_hermit_bin("env"); | ||
|
||
let env_vars = [ | ||
("ASDF".to_string(), "ASDF".to_string()), | ||
("a0978gbsdf".to_string(), ";3254jgnsadfg".to_string()), | ||
("EMOJI".to_string(), "🙂".to_string()), | ||
]; | ||
|
||
println!("Launching kernel {}", bin_path.display()); | ||
let params = Params { | ||
cpu_count: 2.try_into().unwrap(), | ||
memory_size: Byte::from_u64_with_unit(64, Unit::MiB) | ||
.unwrap() | ||
.try_into() | ||
.unwrap(), | ||
output: Output::Buffer, | ||
env: EnvVars::Set(HashMap::from(env_vars.clone())), | ||
..Default::default() | ||
}; | ||
let vm = UhyveVm::new(bin_path, params).unwrap(); | ||
let res = vm.run(None); | ||
check_result(&res); | ||
println!("{:?}", res.output.as_ref().unwrap()); | ||
for (key, value) in env_vars.iter() { | ||
assert!(res | ||
.output | ||
.as_ref() | ||
.unwrap() | ||
.contains(&format!("ENVIRONMENT: {key}: {value}"))); | ||
} | ||
} | ||
|
||
#[test] | ||
fn host_env_test() { | ||
env_logger::try_init().ok(); | ||
let bin_path = build_hermit_bin("env"); | ||
|
||
println!("Launching kernel {}", bin_path.display()); | ||
let params = Params { | ||
cpu_count: 2.try_into().unwrap(), | ||
memory_size: Byte::from_u64_with_unit(64, Unit::MiB) | ||
.unwrap() | ||
.try_into() | ||
.unwrap(), | ||
output: Output::Buffer, | ||
env: EnvVars::Host, | ||
..Default::default() | ||
}; | ||
let vm = UhyveVm::new(bin_path, params).unwrap(); | ||
let res = vm.run(None); | ||
check_result(&res); | ||
println!("{:?}", res.output.as_ref().unwrap()); | ||
|
||
let common_env_vars = ["PWD", "CARGO_MANIFEST_DIR"]; | ||
for env in common_env_vars.iter() { | ||
assert!(res | ||
.output | ||
.as_ref() | ||
.unwrap() | ||
.contains(&format!("ENVIRONMENT: {env}:"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use std::env; | ||
|
||
#[cfg(target_os = "hermit")] | ||
use hermit as _; | ||
|
||
fn main() { | ||
println!("Environment Test"); | ||
for (key, value) in env::vars() { | ||
println!("ENVIRONMENT: {key}: {value}"); | ||
} | ||
} |