Skip to content

Commit 7116e5a

Browse files
committed
fixup! update uses of call_guest_function_by_name with run
Signed-off-by: Jorge Prendes <[email protected]>
1 parent d99d24b commit 7116e5a

File tree

10 files changed

+36
-102
lines changed

10 files changed

+36
-102
lines changed

src/hyperlight_host/benches/benchmarks.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ limitations under the License.
1616

1717
use criterion::{Criterion, criterion_group, criterion_main};
1818
use hyperlight_host::GuestBinary;
19-
use hyperlight_host::sandbox::{
20-
MultiUseSandbox, SandboxConfiguration, UninitializedSandbox,
21-
};
19+
use hyperlight_host::sandbox::{MultiUseSandbox, SandboxConfiguration, UninitializedSandbox};
2220
use hyperlight_testing::simple_guest_as_string;
2321

2422
fn create_uninit_sandbox() -> UninitializedSandbox {
@@ -65,11 +63,7 @@ fn guest_call_benchmark(c: &mut Criterion) {
6563

6664
let mut multiuse_sandbox: MultiUseSandbox = uninitialized_sandbox.evolve().unwrap();
6765

68-
b.iter(|| {
69-
multiuse_sandbox
70-
.run::<i32>("Add", (1_i32, 41_i32))
71-
.unwrap()
72-
});
66+
b.iter(|| multiuse_sandbox.run::<i32>("Add", (1_i32, 41_i32)).unwrap());
7367
});
7468

7569
group.finish();
@@ -99,10 +93,7 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {
9993

10094
b.iter(|| {
10195
sandbox
102-
.run::<()>(
103-
"LargeParameters",
104-
(large_vec.clone(), large_string.clone()),
105-
)
96+
.run::<()>("LargeParameters", (large_vec.clone(), large_string.clone()))
10697
.unwrap()
10798
});
10899
});

src/hyperlight_host/examples/func_ctx/main.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ fn main() {
2929

3030
// Do several calls against a sandbox running the `simpleguest.exe` binary,
3131
// and print their results
32-
let res: String = sbox
33-
.run("Echo", "hello".to_string())
34-
.unwrap();
32+
let res: String = sbox.run("Echo", "hello".to_string()).unwrap();
3533
println!("got Echo res: {res}");
3634

37-
let res: i32 = sbox
38-
.run("CallMalloc", 200_i32)
39-
.unwrap();
35+
let res: i32 = sbox.run("CallMalloc", 200_i32).unwrap();
4036
println!("got CallMalloc res: {res}");
4137
}

src/hyperlight_host/examples/logging/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ fn main() -> Result<()> {
9494

9595
for _ in 0..NUM_CALLS {
9696
barrier.wait();
97-
multiuse_sandbox
98-
.run::<()>("Spin", ())
99-
.unwrap_err();
97+
multiuse_sandbox.run::<()>("Spin", ()).unwrap_err();
10098
}
10199
thread.join().unwrap();
102100

src/hyperlight_host/examples/metrics/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ fn do_hyperlight_stuff() {
108108

109109
for _ in 0..NUM_CALLS {
110110
barrier.wait();
111-
multiuse_sandbox
112-
.run::<()>("Spin", ())
113-
.unwrap_err();
111+
multiuse_sandbox.run::<()>("Spin", ()).unwrap_err();
114112
}
115113

116114
for join_handle in join_handles {

src/hyperlight_host/examples/tracing-otlp/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ fn run_example(wait_input: bool) -> HyperlightResult<()> {
179179
);
180180
let _entered = span.enter();
181181
barrier.wait();
182-
multiuse_sandbox
183-
.run::<()>("Spin", ())
184-
.unwrap_err();
182+
multiuse_sandbox.run::<()>("Spin", ()).unwrap_err();
185183
}
186184
thread.join().expect("Thread panicked");
187185
}

src/hyperlight_host/examples/tracing/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ fn run_example() -> Result<()> {
131131
);
132132
let _entered = span.enter();
133133
barrier.wait();
134-
multiuse_sandbox
135-
.run::<()>("Spin", ())
136-
.unwrap_err();
134+
multiuse_sandbox.run::<()>("Spin", ()).unwrap_err();
137135
}
138136

139137
for join_handle in join_handles {

src/hyperlight_host/src/metrics/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ mod tests {
119119
.run::<i32>("PrintOutput", "Hello".to_string())
120120
.unwrap();
121121

122-
multi
123-
.run::<i32>("Spin", ())
124-
.unwrap_err();
122+
multi.run::<i32>("Spin", ()).unwrap_err();
125123
thread.join().unwrap();
126124

127125
snapshotter.snapshot()

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,12 @@ mod tests {
373373
let _ = sbox.run::<i32>("AddToStatic", 5i32).unwrap();
374374
let res: i32 = sbox.run("GetStatic", ()).unwrap();
375375
assert_eq!(res, 5);
376-
376+
377377
sbox.restore(&snapshot).unwrap();
378378
#[allow(deprecated)]
379-
let _ = sbox.call_guest_function_by_name::<i32>("AddToStatic", 5i32).unwrap();
379+
let _ = sbox
380+
.call_guest_function_by_name::<i32>("AddToStatic", 5i32)
381+
.unwrap();
380382
#[allow(deprecated)]
381383
let res: i32 = sbox.call_guest_function_by_name("GetStatic", ()).unwrap();
382384
assert_eq!(res, 0);
@@ -646,9 +648,7 @@ mod tests {
646648

647649
let mut multi_use_sandbox: MultiUseSandbox = usbox.evolve().unwrap();
648650

649-
let res: i32 = multi_use_sandbox
650-
.run("GetStatic", ())
651-
.unwrap();
651+
let res: i32 = multi_use_sandbox.run("GetStatic", ()).unwrap();
652652

653653
assert_eq!(res, 0);
654654
}

src/hyperlight_host/tests/integration_test.rs

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ fn interrupt_host_call() {
7070
}
7171
});
7272

73-
let result = sandbox
74-
.run::<i32>("CallHostSpin", ())
75-
.unwrap_err();
73+
let result = sandbox.run::<i32>("CallHostSpin", ()).unwrap_err();
7674
assert!(matches!(result, HyperlightError::ExecutionCanceledByHost()));
7775

7876
thread.join().unwrap();
@@ -96,16 +94,12 @@ fn interrupt_in_progress_guest_call() {
9694
assert!(interrupt_handle.dropped());
9795
});
9896

99-
let res = sbox1
100-
.run::<i32>("Spin", ())
101-
.unwrap_err();
97+
let res = sbox1.run::<i32>("Spin", ()).unwrap_err();
10298
assert!(matches!(res, HyperlightError::ExecutionCanceledByHost()));
10399

104100
barrier.wait();
105101
// Make sure we can still call guest functions after the VM was interrupted
106-
sbox1
107-
.run::<String>("Echo", "hello".to_string())
108-
.unwrap();
102+
sbox1.run::<String>("Echo", "hello".to_string()).unwrap();
109103

110104
// drop vm to make sure other thread can detect it
111105
drop(sbox1);
@@ -131,15 +125,11 @@ fn interrupt_guest_call_in_advance() {
131125
});
132126

133127
barrier.wait(); // wait until `kill()` is called before starting the guest call
134-
let res = sbox1
135-
.run::<i32>("Spin", ())
136-
.unwrap_err();
128+
let res = sbox1.run::<i32>("Spin", ()).unwrap_err();
137129
assert!(matches!(res, HyperlightError::ExecutionCanceledByHost()));
138130

139131
// Make sure we can still call guest functions after the VM was interrupted
140-
sbox1
141-
.run::<String>("Echo", "hello".to_string())
142-
.unwrap();
132+
sbox1.run::<String>("Echo", "hello".to_string()).unwrap();
143133

144134
// drop vm to make sure other thread can detect it
145135
drop(sbox1);
@@ -257,9 +247,7 @@ fn interrupt_moved_sandbox() {
257247

258248
let thread = thread::spawn(move || {
259249
barrier2.wait();
260-
let res = sbox1
261-
.run::<i32>("Spin", ())
262-
.unwrap_err();
250+
let res = sbox1.run::<i32>("Spin", ()).unwrap_err();
263251
assert!(matches!(res, HyperlightError::ExecutionCanceledByHost()));
264252
});
265253

@@ -272,9 +260,7 @@ fn interrupt_moved_sandbox() {
272260
assert!(interrupt_handle2.kill());
273261
});
274262

275-
let res = sbox2
276-
.run::<i32>("Spin", ())
277-
.unwrap_err();
263+
let res = sbox2.run::<i32>("Spin", ()).unwrap_err();
278264
assert!(matches!(res, HyperlightError::ExecutionCanceledByHost()));
279265

280266
thread.join().expect("Thread should finish");
@@ -315,9 +301,7 @@ fn interrupt_custom_signal_no_and_retry_delay() {
315301
});
316302

317303
for _ in 0..NUM_ITERS {
318-
let res = sbox1
319-
.run::<i32>("Spin", ())
320-
.unwrap_err();
304+
let res = sbox1.run::<i32>("Spin", ()).unwrap_err();
321305
assert!(matches!(res, HyperlightError::ExecutionCanceledByHost()));
322306
// immediately reenter another guest function call after having being cancelled,
323307
// so that the vcpu is running again before the interruptor-thread has a chance to see that the vcpu is not running
@@ -441,10 +425,7 @@ fn guest_abort_with_context2() {
441425
Proin sagittis nisl rhoncus mattis rhoncus urna. Magna eget est lorem ipsum.";
442426

443427
let res = sbox1
444-
.run::<()>(
445-
"GuestAbortWithMessage",
446-
(60_i32, abort_message.to_string()),
447-
)
428+
.run::<()>("GuestAbortWithMessage", (60_i32, abort_message.to_string()))
448429
.unwrap_err();
449430
println!("{:?}", res);
450431
assert!(
@@ -494,9 +475,7 @@ fn guest_malloc() {
494475
let mut sbox1 = new_uninit_rust().unwrap().evolve().unwrap();
495476

496477
let size_to_allocate = 2000_i32;
497-
sbox1
498-
.run::<i32>("TestMalloc", size_to_allocate)
499-
.unwrap();
478+
sbox1.run::<i32>("TestMalloc", size_to_allocate).unwrap();
500479
}
501480

502481
#[test]
@@ -522,9 +501,7 @@ fn guest_malloc_abort() {
522501

523502
let size = 20000000_i32; // some big number that should fail when allocated
524503

525-
let res = sbox1
526-
.run::<i32>("TestMalloc", size)
527-
.unwrap_err();
504+
let res = sbox1.run::<i32>("TestMalloc", size).unwrap_err();
528505
println!("{:?}", res);
529506
assert!(
530507
matches!(res, HyperlightError::GuestAborted(code, _) if code == ErrorCode::MallocFailed as u8)
@@ -564,9 +541,7 @@ fn dynamic_stack_allocate_c_guest() {
564541
let uninit = UninitializedSandbox::new(guest_path, None);
565542
let mut sbox1: MultiUseSandbox = uninit.unwrap().evolve().unwrap();
566543

567-
let res: i32 = sbox1
568-
.run("StackAllocate", 100_i32)
569-
.unwrap();
544+
let res: i32 = sbox1.run("StackAllocate", 100_i32).unwrap();
570545
assert_eq!(res, 100);
571546

572547
let res = sbox1
@@ -588,9 +563,7 @@ fn static_stack_allocate() {
588563
#[test]
589564
fn static_stack_allocate_overflow() {
590565
let mut sbox1 = new_uninit().unwrap().evolve().unwrap();
591-
let res = sbox1
592-
.run::<i32>("LargeVar", ())
593-
.unwrap_err();
566+
let res = sbox1.run::<i32>("LargeVar", ()).unwrap_err();
594567
assert!(matches!(res, HyperlightError::StackOverflow()));
595568
}
596569

@@ -601,9 +574,7 @@ fn recursive_stack_allocate() {
601574

602575
let iterations = 1_i32;
603576

604-
sbox1
605-
.run::<i32>("StackOverflow", iterations)
606-
.unwrap();
577+
sbox1.run::<i32>("StackOverflow", iterations).unwrap();
607578
}
608579

609580
// checks stack guard page (between guest stack and heap)
@@ -646,19 +617,15 @@ fn guard_page_check_2() {
646617
// this test is rust-guest only
647618
let mut sbox1 = new_uninit_rust().unwrap().evolve().unwrap();
648619

649-
let result = sbox1
650-
.run::<()>("InfiniteRecursion", ())
651-
.unwrap_err();
620+
let result = sbox1.run::<()>("InfiniteRecursion", ()).unwrap_err();
652621
assert!(matches!(result, HyperlightError::StackOverflow()));
653622
}
654623

655624
#[test]
656625
fn execute_on_stack() {
657626
let mut sbox1 = new_uninit().unwrap().evolve().unwrap();
658627

659-
let result = sbox1
660-
.run::<String>("ExecuteOnStack", ())
661-
.unwrap_err();
628+
let result = sbox1.run::<String>("ExecuteOnStack", ()).unwrap_err();
662629

663630
let err = result.to_string();
664631
assert!(
@@ -693,9 +660,7 @@ fn recursive_stack_allocate_overflow() {
693660

694661
let iterations = 10_i32;
695662

696-
let res = sbox1
697-
.run::<()>("StackOverflow", iterations)
698-
.unwrap_err();
663+
let res = sbox1.run::<()>("StackOverflow", iterations).unwrap_err();
699664
println!("{:?}", res);
700665
assert!(matches!(res, HyperlightError::StackOverflow()));
701666
}

src/hyperlight_host/tests/sandbox_host_tests.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ fn float_roundtrip() {
8585
];
8686
let mut sandbox: MultiUseSandbox = new_uninit().unwrap().evolve().unwrap();
8787
for f in doubles.iter() {
88-
let res: f64 = sandbox
89-
.run("EchoDouble", *f)
90-
.unwrap();
88+
let res: f64 = sandbox.run("EchoDouble", *f).unwrap();
9189

9290
assert!(
9391
res.total_cmp(f).is_eq(),
@@ -97,9 +95,7 @@ fn float_roundtrip() {
9795
);
9896
}
9997
for f in floats.iter() {
100-
let res: f32 = sandbox
101-
.run("EchoFloat", *f)
102-
.unwrap();
98+
let res: f32 = sandbox.run("EchoFloat", *f).unwrap();
10399

104100
assert!(
105101
res.total_cmp(f).is_eq(),
@@ -260,14 +256,10 @@ fn simple_test_helper() -> Result<()> {
260256
let message2 = "world";
261257

262258
for mut sandbox in get_simpleguest_sandboxes(Some(writer.into())).into_iter() {
263-
let res: i32 = sandbox
264-
.run("PrintOutput", message.to_string())
265-
.unwrap();
259+
let res: i32 = sandbox.run("PrintOutput", message.to_string()).unwrap();
266260
assert_eq!(res, 5);
267261

268-
let res: String = sandbox
269-
.run("Echo", message2.to_string())
270-
.unwrap();
262+
let res: String = sandbox.run("Echo", message2.to_string()).unwrap();
271263
assert_eq!(res, "world");
272264

273265
let buffer = [1u8, 2, 3, 4, 5, 6];

0 commit comments

Comments
 (0)