summaryrefslogtreecommitdiff
path: root/test/test_fcntl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_fcntl.rs')
-rw-r--r--test/test_fcntl.rs70
1 files changed, 33 insertions, 37 deletions
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs
index 5d1bafeb..48d46626 100644
--- a/test/test_fcntl.rs
+++ b/test/test_fcntl.rs
@@ -81,19 +81,18 @@ fn test_readlink() {
#[cfg(any(target_os = "linux", target_os = "android"))]
mod linux_android {
- use std::fs::File;
use std::io::prelude::*;
- use std::io::{BufRead, BufReader, SeekFrom};
+ use std::io::SeekFrom;
use std::os::unix::prelude::*;
-
use libc::loff_t;
use nix::fcntl::*;
- use nix::sys::stat::fstat;
use nix::sys::uio::IoVec;
use nix::unistd::{close, pipe, read, write};
- use tempfile::{tempfile, NamedTempFile};
+ use tempfile::tempfile;
+ #[cfg(any(target_os = "linux"))]
+ use tempfile::NamedTempFile;
use crate::*;
@@ -206,6 +205,7 @@ mod linux_android {
close(wr).unwrap();
}
+ #[cfg(any(target_os = "linux"))]
#[test]
fn test_fallocate() {
let tmp = NamedTempFile::new().unwrap();
@@ -224,17 +224,11 @@ mod linux_android {
// they run under QEMU.
#[test]
- #[cfg(not(any(target_arch = "aarch64",
- target_arch = "arm",
- target_arch = "armv7",
- target_arch = "x86",
- target_arch = "mips",
- target_arch = "mips64",
- target_arch = "mips64el",
- target_arch = "powerpc64",
- target_arch = "powerpc64le",
- target_env = "musl")))]
+ #[cfg(all(target_os = "linux", not(target_env = "musl")))]
fn test_ofd_write_lock() {
+ use nix::sys::stat::fstat;
+ use std::mem;
+
let tmp = NamedTempFile::new().unwrap();
let fd = tmp.as_raw_fd();
@@ -247,13 +241,14 @@ mod linux_android {
}
let inode = fstat(fd).expect("fstat failed").st_ino as usize;
- let mut flock = libc::flock {
- l_type: libc::F_WRLCK as libc::c_short,
- l_whence: libc::SEEK_SET as libc::c_short,
- l_start: 0,
- l_len: 0,
- l_pid: 0,
+ let mut flock: libc::flock = unsafe {
+ mem::zeroed() // required for Linux/mips
};
+ flock.l_type = libc::F_WRLCK as libc::c_short;
+ flock.l_whence = libc::SEEK_SET as libc::c_short;
+ flock.l_start = 0;
+ flock.l_len = 0;
+ flock.l_pid = 0;
fcntl(fd, FcntlArg::F_OFD_SETLKW(&flock)).expect("write lock failed");
assert_eq!(
Some(("OFDLCK".to_string(), "WRITE".to_string())),
@@ -266,17 +261,11 @@ mod linux_android {
}
#[test]
- #[cfg(not(any(target_arch = "aarch64",
- target_arch = "arm",
- target_arch = "armv7",
- target_arch = "x86",
- target_arch = "mips",
- target_arch = "mips64",
- target_arch = "mips64el",
- target_arch = "powerpc64",
- target_arch = "powerpc64le",
- target_env = "musl")))]
+ #[cfg(all(target_os = "linux", not(target_env = "musl")))]
fn test_ofd_read_lock() {
+ use nix::sys::stat::fstat;
+ use std::mem;
+
let tmp = NamedTempFile::new().unwrap();
let fd = tmp.as_raw_fd();
@@ -289,13 +278,14 @@ mod linux_android {
}
let inode = fstat(fd).expect("fstat failed").st_ino as usize;
- let mut flock = libc::flock {
- l_type: libc::F_RDLCK as libc::c_short,
- l_whence: libc::SEEK_SET as libc::c_short,
- l_start: 0,
- l_len: 0,
- l_pid: 0,
+ let mut flock: libc::flock = unsafe {
+ mem::zeroed() // required for Linux/mips
};
+ flock.l_type = libc::F_RDLCK as libc::c_short;
+ flock.l_whence = libc::SEEK_SET as libc::c_short;
+ flock.l_start = 0;
+ flock.l_len = 0;
+ flock.l_pid = 0;
fcntl(fd, FcntlArg::F_OFD_SETLKW(&flock)).expect("read lock failed");
assert_eq!(
Some(("OFDLCK".to_string(), "READ".to_string())),
@@ -307,7 +297,13 @@ mod linux_android {
assert_eq!(None, lock_info(inode));
}
+ #[cfg(all(target_os = "linux", not(target_env = "musl")))]
fn lock_info(inode: usize) -> Option<(String, String)> {
+ use std::{
+ fs::File,
+ io::BufReader
+ };
+
let file = File::open("/proc/locks").expect("open /proc/locks failed");
let buf = BufReader::new(file);