Skip to content

Commit ad7471d

Browse files
committed
test(memory): removed forking of the test process
After moving all memory tests from `utils` into `vmm` forking a test process to verify guard pages became unusable. Because `vmm` crate has a lot more tests than `utils` has, when test process from `vmm` is run, forking this process causes test to hang. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent 465b79d commit ad7471d

File tree

1 file changed

+0
-38
lines changed

1 file changed

+0
-38
lines changed

src/vmm/src/vstate/memory.rs

-38
Original file line numberDiff line numberDiff line change
@@ -495,40 +495,12 @@ mod tests {
495495

496496
use super::*;
497497

498-
fn fork_and_run(function: &dyn Fn(), expect_sigsegv: bool) {
499-
let pid = unsafe { libc::fork() };
500-
match pid {
501-
0 => {
502-
function();
503-
}
504-
child_pid => {
505-
let mut child_status: i32 = -1;
506-
let pid_done = unsafe { libc::waitpid(child_pid, &mut child_status, 0) };
507-
assert_eq!(pid_done, child_pid);
508-
509-
if expect_sigsegv {
510-
// Asserts that the child process terminated because
511-
// it received a signal that was not handled.
512-
assert!(libc::WIFSIGNALED(child_status));
513-
// Signal code should be a SIGSEGV
514-
assert_eq!(libc::WTERMSIG(child_status), libc::SIGSEGV);
515-
} else {
516-
assert!(libc::WIFEXITED(child_status));
517-
// Signal code should be a SIGSEGV
518-
assert_eq!(libc::WEXITSTATUS(child_status), 0);
519-
}
520-
}
521-
};
522-
}
523-
524498
fn validate_guard_region(region: &GuestMmapRegion) {
525499
let read_mem = |addr| unsafe { std::ptr::read_volatile::<u8>(addr) };
526500
let write_mem = |addr, val| unsafe {
527501
std::ptr::write(addr, val);
528502
};
529503

530-
let page_size = get_page_size().unwrap();
531-
532504
// Check that the created range allows us to write inside it
533505
let region_first_byte = region.as_ptr();
534506
let region_last_byte = unsafe { region_first_byte.add(region.size() - 1) };
@@ -540,16 +512,6 @@ mod tests {
540512
// Write and read from the end of the region
541513
write_mem(region_last_byte, 0x69);
542514
assert_eq!(read_mem(region_last_byte), 0x69);
543-
544-
// Try a read/write operation against the left guard border of the range
545-
let left_border_first_byte = unsafe { region_first_byte.sub(page_size) };
546-
fork_and_run(&|| write_mem(left_border_first_byte, 0x69), true);
547-
fork_and_run(&|| _ = read_mem(left_border_first_byte), true);
548-
549-
// Try a read/write operation against the right guard border of the range
550-
let right_border_first_byte = unsafe { region_last_byte.add(1) };
551-
fork_and_run(&|| write_mem(right_border_first_byte, 0x69), true);
552-
fork_and_run(&|| _ = read_mem(right_border_first_byte), true);
553515
}
554516

555517
#[test]

0 commit comments

Comments
 (0)