Skip to content

Commit fcb0bd7

Browse files
committed
Make create_1000_sandboxes be able to run concurrently
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent bea1fc7 commit fcb0bd7

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

Justfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ test-unit target=default-target features="":
165165
test-isolated target=default-target features="" :
166166
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::uninitialized::tests::test_trace_trace --exact --ignored
167167
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::uninitialized::tests::test_log_trace --exact --ignored
168-
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::create_1000_sandboxes --exact --ignored
169168
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::outb::tests::test_log_outb_log --exact --ignored
170169
{{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F init-paging," + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --test integration_test -- log_message --exact --ignored
171170
@# metrics tests

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,41 +1071,38 @@ mod tests {
10711071
}
10721072

10731073
#[test]
1074-
#[ignore] // this test runs by itself because it uses a lot of system resources
1075-
fn create_1000_sandboxes() {
1076-
let barrier = Arc::new(Barrier::new(21));
1074+
fn create_200_sandboxes() {
1075+
const NUM_THREADS: usize = 10;
1076+
const SANDBOXES_PER_THREAD: usize = 20;
10771077

1078-
let mut handles = vec![];
1078+
// barrier to make sure all threads start their work simultaneously
1079+
let start_barrier = Arc::new(Barrier::new(NUM_THREADS + 1));
1080+
let mut thread_handles = vec![];
10791081

1080-
for _ in 0..20 {
1081-
let c = barrier.clone();
1082+
for _ in 0..NUM_THREADS {
1083+
let barrier = start_barrier.clone();
10821084

10831085
let handle = thread::spawn(move || {
1084-
c.wait();
1085-
1086-
for _ in 0..50 {
1087-
let usbox = UninitializedSandbox::new(
1088-
GuestBinary::FilePath(
1089-
simple_guest_as_string().expect("Guest Binary Missing"),
1090-
),
1091-
None,
1092-
)
1093-
.unwrap();
1086+
barrier.wait();
10941087

1095-
let mut multi_use_sandbox: MultiUseSandbox = usbox.evolve().unwrap();
1088+
for _ in 0..SANDBOXES_PER_THREAD {
1089+
let guest_path = simple_guest_as_string().expect("Guest Binary Missing");
1090+
let uninit =
1091+
UninitializedSandbox::new(GuestBinary::FilePath(guest_path), None).unwrap();
10961092

1097-
let res: i32 = multi_use_sandbox.call("GetStatic", ()).unwrap();
1093+
let mut sandbox: MultiUseSandbox = uninit.evolve().unwrap();
10981094

1099-
assert_eq!(res, 0);
1095+
let result: i32 = sandbox.call("GetStatic", ()).unwrap();
1096+
assert_eq!(result, 0);
11001097
}
11011098
});
11021099

1103-
handles.push(handle);
1100+
thread_handles.push(handle);
11041101
}
11051102

1106-
barrier.wait();
1103+
start_barrier.wait();
11071104

1108-
for handle in handles {
1105+
for handle in thread_handles {
11091106
handle.join().unwrap();
11101107
}
11111108
}

0 commit comments

Comments
 (0)