diff options
author | Alan Somers <asomers@gmail.com> | 2021-09-19 09:10:07 -0600 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2021-09-19 10:11:37 -0600 |
commit | f2be3c3fe332576bfadeaeed9811a900516a8996 (patch) | |
tree | 5f91999127bcae89b1829be0ffa472b99d72d2d9 /test/sys | |
parent | 8cb9dc5b4ac58dc9f11c77fde5e1914b2d6c4c6c (diff) | |
download | nix-f2be3c3fe332576bfadeaeed9811a900516a8996.zip |
Actually connect the mman tests to the build
This was an oversight from #1306.
Reported-by: @ocadaruma
Diffstat (limited to 'test/sys')
-rw-r--r-- | test/sys/mod.rs | 2 | ||||
-rw-r--r-- | test/sys/test_mman.rs | 30 |
2 files changed, 18 insertions, 14 deletions
diff --git a/test/sys/mod.rs b/test/sys/mod.rs index 14b03784..e73d9b1d 100644 --- a/test/sys/mod.rs +++ b/test/sys/mod.rs @@ -11,6 +11,8 @@ mod test_signal; target_os = "macos", target_os = "netbsd"))] mod test_aio; +#[cfg(not(target_os = "redox"))] +mod test_mman; #[cfg(target_os = "linux")] mod test_signalfd; #[cfg(not(target_os = "redox"))] diff --git a/test/sys/test_mman.rs b/test/sys/test_mman.rs index 4d140948..a7ceedcb 100644 --- a/test/sys/test_mman.rs +++ b/test/sys/test_mman.rs @@ -1,27 +1,24 @@ -use nix::Error; -use nix::libc::{c_void, size_t}; use nix::sys::mman::{mmap, MapFlags, ProtFlags}; -#[cfg(target_os = "linux")] -use nix::sys::mman::{mremap, MRemapFlags}; - #[test] fn test_mmap_anonymous() { - let ref mut byte = unsafe { + unsafe { let ptr = mmap(std::ptr::null_mut(), 1, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE, MapFlags::MAP_PRIVATE | MapFlags::MAP_ANONYMOUS, -1, 0) - .unwrap(); - *(ptr as * mut u8) - }; - assert_eq !(*byte, 0x00u8); - *byte = 0xffu8; - assert_eq !(*byte, 0xffu8); + .unwrap() as *mut u8; + assert_eq !(*ptr, 0x00u8); + *ptr = 0xffu8; + assert_eq !(*ptr, 0xffu8); + } } #[test] #[cfg(any(target_os = "linux", target_os = "netbsd"))] fn test_mremap_grow() { + use nix::sys::mman::{mremap, MRemapFlags}; + use nix::libc::{c_void, size_t}; + const ONE_K : size_t = 1024; let slice : &mut[u8] = unsafe { let mem = mmap(std::ptr::null_mut(), ONE_K, @@ -57,7 +54,12 @@ fn test_mremap_grow() { #[test] #[cfg(any(target_os = "linux", target_os = "netbsd"))] +// Segfaults for unknown reasons under QEMU for 32-bit targets +#[cfg_attr(all(target_pointer_width = "32", qemu), ignore)] fn test_mremap_shrink() { + use nix::sys::mman::{mremap, MRemapFlags}; + use nix::libc::{c_void, size_t}; + const ONE_K : size_t = 1024; let slice : &mut[u8] = unsafe { let mem = mmap(std::ptr::null_mut(), 10 * ONE_K, @@ -77,9 +79,9 @@ fn test_mremap_shrink() { .unwrap(); // Since we didn't supply MREMAP_MAYMOVE, the address should be the // same. - #[cfg(target_os = "linux")] + #[cfg(target_os = "netbsd")] let mem = mremap(slice.as_mut_ptr() as * mut c_void, 10 * ONE_K, ONE_K, - MRemapFlags::MAP_FIXED), None) + MRemapFlags::MAP_FIXED, None) .unwrap(); assert_eq !(mem, slice.as_mut_ptr() as * mut c_void); std::slice::from_raw_parts_mut(mem as * mut u8, ONE_K) |