Skip to content

Commit e60e35d

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 <[email protected]>
1 parent a01806a commit e60e35d

File tree

1 file changed

+0
-38
lines changed

1 file changed

+0
-38
lines changed

src/vmm/src/vstate/memory.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -494,40 +494,12 @@ mod tests {
494494

495495
use super::*;
496496

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

529-
let page_size = get_page_size().unwrap();
530-
531503
// Check that the created range allows us to write inside it
532504
let region_first_byte = region.as_ptr();
533505
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)