Skip to content

Commit

Permalink
Fix madvise tests to not assume 4k pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreichold committed Dec 9, 2023
1 parent 3c71286 commit e5faf13
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,9 @@ mod test {
#[test]
#[cfg(target_os = "linux")]
fn advise_writes_unsafely() {
let mut mmap = MmapMut::map_anon(4096).unwrap();
let page_size = unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize };

let mut mmap = MmapMut::map_anon(page_size).unwrap();
mmap.as_mut().fill(255);
let mmap = mmap.make_read_only().unwrap();

Expand All @@ -1986,18 +1988,20 @@ mod test {
#[test]
#[cfg(target_os = "linux")]
fn advise_writes_unsafely_to_part_of_map() {
let mut mmap = MmapMut::map_anon(8192).unwrap();
let page_size = unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize };

let mut mmap = MmapMut::map_anon(2 * page_size).unwrap();
mmap.as_mut().fill(255);
let mmap = mmap.make_read_only().unwrap();

let a = mmap.as_ref()[0];
let b = mmap.as_ref()[4096];
let b = mmap.as_ref()[page_size];
unsafe {
mmap.unchecked_advise_range(UncheckedAdvice::DontNeed, 4096, 4096)
mmap.unchecked_advise_range(UncheckedAdvice::DontNeed, page_size, page_size)
.unwrap();
}
let c = mmap.as_ref()[0];
let d = mmap.as_ref()[4096];
let d = mmap.as_ref()[page_size];

assert_eq!(a, 255);
assert_eq!(b, 255);
Expand Down

0 comments on commit e5faf13

Please sign in to comment.