Skip to content

Commit b28a62b

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

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
4646
(#[1525](https://github.com/nix-rust/nix/pull/1525))
4747
- Added `MAP_ALIGNED_SUPER` mmap flag for freebsd.
4848
(#[1522](https://github.com/nix-rust/nix/pull/1522))
49+
- Added `MAP_ANONYMOUS` for all operating systems.
50+
(#[1534](https://github.com/nix-rust/nix/pull/1534))
4951

5052
### Changed
5153

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

+14-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,
@@ -58,6 +55,9 @@ fn test_mremap_grow() {
5855
#[test]
5956
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
6057
fn test_mremap_shrink() {
58+
use nix::sys::mman::{mremap, MRemapFlags};
59+
use nix::libc::{c_void, size_t};
60+
6161
const ONE_K : size_t = 1024;
6262
let slice : &mut[u8] = unsafe {
6363
let mem = mmap(std::ptr::null_mut(), 10 * ONE_K,
@@ -77,9 +77,9 @@ fn test_mremap_shrink() {
7777
.unwrap();
7878
// Since we didn't supply MREMAP_MAYMOVE, the address should be the
7979
// same.
80-
#[cfg(target_os = "linux")]
80+
#[cfg(target_os = "netbsd")]
8181
let mem = mremap(slice.as_mut_ptr() as * mut c_void, 10 * ONE_K, ONE_K,
82-
MRemapFlags::MAP_FIXED), None)
82+
MRemapFlags::MAP_FIXED, None)
8383
.unwrap();
8484
assert_eq !(mem, slice.as_mut_ptr() as * mut c_void);
8585
std::slice::from_raw_parts_mut(mem as * mut u8, ONE_K)

0 commit comments

Comments
 (0)