Skip to content

Commit f2be3c3

Browse files
committed
Actually connect the mman tests to the build
This was an oversight from nix-rust#1306. Reported-by: @ocadaruma
1 parent 8cb9dc5 commit f2be3c3

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
4848
(#[1522](https://github.com/nix-rust/nix/pull/1522))
4949
- Added `MAP_CONCEAL` mmap flag for openbsd.
5050
(#[1531](https://github.com/nix-rust/nix/pull/1531))
51+
- Added `MAP_ANONYMOUS` for all operating systems.
52+
(#[1534](https://github.com/nix-rust/nix/pull/1534))
5153

5254
### Changed
5355

src/sys/mman.rs

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ libc_bitflags!{
4747
/// Synonym for `MAP_ANONYMOUS`.
4848
MAP_ANON;
4949
/// The mapping is not backed by any file.
50-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "freebsd"))]
5150
MAP_ANONYMOUS;
5251
/// Put the mapping into the first 2GB of the process address space.
5352
#[cfg(any(all(any(target_os = "android", target_os = "linux"),

test/sys/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ mod test_signal;
1111
target_os = "macos",
1212
target_os = "netbsd"))]
1313
mod test_aio;
14+
#[cfg(not(target_os = "redox"))]
15+
mod test_mman;
1416
#[cfg(target_os = "linux")]
1517
mod test_signalfd;
1618
#[cfg(not(target_os = "redox"))]

test/sys/test_mman.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
use nix::Error;
2-
use nix::libc::{c_void, size_t};
31
use nix::sys::mman::{mmap, MapFlags, ProtFlags};
42

5-
#[cfg(target_os = "linux")]
6-
use nix::sys::mman::{mremap, MRemapFlags};
7-
83
#[test]
94
fn test_mmap_anonymous() {
10-
let ref mut byte = unsafe {
5+
unsafe {
116
let ptr = mmap(std::ptr::null_mut(), 1,
127
ProtFlags::PROT_READ | ProtFlags::PROT_WRITE,
138
MapFlags::MAP_PRIVATE | MapFlags::MAP_ANONYMOUS, -1, 0)
14-
.unwrap();
15-
*(ptr as * mut u8)
16-
};
17-
assert_eq !(*byte, 0x00u8);
18-
*byte = 0xffu8;
19-
assert_eq !(*byte, 0xffu8);
9+
.unwrap() as *mut u8;
10+
assert_eq !(*ptr, 0x00u8);
11+
*ptr = 0xffu8;
12+
assert_eq !(*ptr, 0xffu8);
13+
}
2014
}
2115

2216
#[test]
2317
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
2418
fn test_mremap_grow() {
19+
use nix::sys::mman::{mremap, MRemapFlags};
20+
use nix::libc::{c_void, size_t};
21+
2522
const ONE_K : size_t = 1024;
2623
let slice : &mut[u8] = unsafe {
2724
let mem = mmap(std::ptr::null_mut(), ONE_K,
@@ -57,7 +54,12 @@ fn test_mremap_grow() {
5754

5855
#[test]
5956
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
57+
// Segfaults for unknown reasons under QEMU for 32-bit targets
58+
#[cfg_attr(all(target_pointer_width = "32", qemu), ignore)]
6059
fn test_mremap_shrink() {
60+
use nix::sys::mman::{mremap, MRemapFlags};
61+
use nix::libc::{c_void, size_t};
62+
6163
const ONE_K : size_t = 1024;
6264
let slice : &mut[u8] = unsafe {
6365
let mem = mmap(std::ptr::null_mut(), 10 * ONE_K,
@@ -77,9 +79,9 @@ fn test_mremap_shrink() {
7779
.unwrap();
7880
// Since we didn't supply MREMAP_MAYMOVE, the address should be the
7981
// same.
80-
#[cfg(target_os = "linux")]
82+
#[cfg(target_os = "netbsd")]
8183
let mem = mremap(slice.as_mut_ptr() as * mut c_void, 10 * ONE_K, ONE_K,
82-
MRemapFlags::MAP_FIXED), None)
84+
MRemapFlags::MAP_FIXED, None)
8385
.unwrap();
8486
assert_eq !(mem, slice.as_mut_ptr() as * mut c_void);
8587
std::slice::from_raw_parts_mut(mem as * mut u8, ONE_K)

0 commit comments

Comments
 (0)