Skip to content

Commit

Permalink
test(memory): removed forking of the test process
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ShadowCurse committed Oct 10, 2023
1 parent ff75106 commit c75284a
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions src/vmm/src/vstate/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,40 +495,12 @@ mod tests {

use super::*;

fn fork_and_run(function: &dyn Fn(), expect_sigsegv: bool) {
let pid = unsafe { libc::fork() };
match pid {
0 => {
function();
}
child_pid => {
let mut child_status: i32 = -1;
let pid_done = unsafe { libc::waitpid(child_pid, &mut child_status, 0) };
assert_eq!(pid_done, child_pid);

if expect_sigsegv {
// Asserts that the child process terminated because
// it received a signal that was not handled.
assert!(libc::WIFSIGNALED(child_status));
// Signal code should be a SIGSEGV
assert_eq!(libc::WTERMSIG(child_status), libc::SIGSEGV);
} else {
assert!(libc::WIFEXITED(child_status));
// Signal code should be a SIGSEGV
assert_eq!(libc::WEXITSTATUS(child_status), 0);
}
}
};
}

fn validate_guard_region(region: &GuestMmapRegion) {
let read_mem = |addr| unsafe { std::ptr::read_volatile::<u8>(addr) };
let write_mem = |addr, val| unsafe {
std::ptr::write(addr, val);
};

let page_size = get_page_size().unwrap();

// Check that the created range allows us to write inside it
let region_first_byte = region.as_ptr();
let region_last_byte = unsafe { region_first_byte.add(region.size() - 1) };
Expand All @@ -540,16 +512,6 @@ mod tests {
// Write and read from the end of the region
write_mem(region_last_byte, 0x69);
assert_eq!(read_mem(region_last_byte), 0x69);

// Try a read/write operation against the left guard border of the range
let left_border_first_byte = unsafe { region_first_byte.sub(page_size) };
fork_and_run(&|| write_mem(left_border_first_byte, 0x69), true);
fork_and_run(&|| _ = read_mem(left_border_first_byte), true);

// Try a read/write operation against the right guard border of the range
let right_border_first_byte = unsafe { region_last_byte.add(1) };
fork_and_run(&|| write_mem(right_border_first_byte, 0x69), true);
fork_and_run(&|| _ = read_mem(right_border_first_byte), true);
}

#[test]
Expand Down

0 comments on commit c75284a

Please sign in to comment.