Skip to content

Commit 2ba6999

Browse files
committed
Check all tests in CI
Travis didn't compile check tests on platforms that couldn't run tests in CI, so they bitrotted. Let's see how bad they are. Most annoyingly, 32-bit Android defines mode_t as 16 bits, but stat.st_mode as 32-bits.
1 parent 6af11c1 commit 2ba6999

File tree

6 files changed

+70
-61
lines changed

6 files changed

+70
-61
lines changed

.cirrus.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ task:
2222
- cargo test --target i686-unknown-freebsd
2323
before_cache_script: rm -rf $CARGO_HOME/registry/index
2424

25+
# Test OSX and iOS in a full VM
2526
task:
2627
matrix:
2728
- name: OSX x86_64
@@ -162,24 +163,20 @@ task:
162163
- name: Linux x32
163164
env:
164165
TARGET: x86_64-unknown-linux-gnux32
165-
CHECK_TESTS: true
166166
- name: NetBSD x86_64
167167
env:
168168
TARGET: x86_64-unknown-netbsd
169169
- name: Fuchsia x86_64
170170
env:
171171
TARGET: x86_64-fuchsia
172-
CHECK_TESTS: true
173172
container:
174173
image: rust:1.40
175174
setup_script:
176175
- rustup target add $TARGET
177176
script:
178177
- cargo +$TOOLCHAIN check --target $TARGET
179178
- cargo +$TOOLCHAIN check --target $TARGET --release
180-
- 'if [ "$CHECK_TESTS" == true ]; then cargo +$TOOLCHAIN check --all-targets --target $TARGET; fi'
181-
# TODO: check the tests, too. The old Travis CI setup didn't do that, so
182-
# they don't build on all platforms.
179+
- cargo +$TOOLCHAIN check --all-targets --target $TARGET
183180
before_cache_script: rm -rf $CARGO_HOME/registry/index
184181

185182
# illumos toolchain isn't available via rustup until 1.50

test/sys/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ mod test_pthread;
4141
target_os = "netbsd",
4242
target_os = "openbsd"))]
4343
mod test_ptrace;
44-
#[cfg(any(target_os = "android", target_os = "linux"))]
44+
#[cfg(target_os = "linux")]
4545
mod test_timerfd;

test/sys/test_socket.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ pub fn test_af_alg_aead() {
757757
target_os = "netbsd"))]
758758
#[test]
759759
pub fn test_sendmsg_ipv4packetinfo() {
760+
use cfg_if::cfg_if;
760761
use nix::sys::uio::IoVec;
761762
use nix::sys::socket::{socket, sendmsg, bind,
762763
AddressFamily, SockType, SockFlag, SockAddr,
@@ -778,11 +779,21 @@ pub fn test_sendmsg_ipv4packetinfo() {
778779
let iov = [IoVec::from_slice(&slice)];
779780

780781
if let InetAddr::V4(sin) = inet_addr {
781-
let pi = libc::in_pktinfo {
782-
ipi_ifindex: 0, /* Unspecified interface */
783-
ipi_addr: libc::in_addr { s_addr: 0 },
784-
ipi_spec_dst: sin.sin_addr,
785-
};
782+
cfg_if! {
783+
if #[cfg(target_os = "netbsd")] {
784+
drop(sin);
785+
let pi = libc::in_pktinfo {
786+
ipi_ifindex: 0, /* Unspecified interface */
787+
ipi_addr: libc::in_addr { s_addr: 0 },
788+
};
789+
} else {
790+
let pi = libc::in_pktinfo {
791+
ipi_ifindex: 0, /* Unspecified interface */
792+
ipi_addr: libc::in_addr { s_addr: 0 },
793+
ipi_spec_dst: sin.sin_addr,
794+
};
795+
}
796+
}
786797

787798
let cmsg = [ControlMessage::Ipv4PacketInfo(&pi)];
788799

@@ -1472,13 +1483,13 @@ pub fn test_recv_ipv6pktinfo() {
14721483
Some(ControlMessageOwned::Ipv6PacketInfo(pktinfo)) => {
14731484
let i = if_nametoindex(lo_name.as_bytes()).expect("if_nametoindex");
14741485
assert_eq!(
1475-
pktinfo.ipi6_ifindex,
1486+
pktinfo.ipi6_ifindex as libc::c_uint,
14761487
i,
14771488
"unexpected ifindex (expected {}, got {})",
14781489
i,
14791490
pktinfo.ipi6_ifindex
14801491
);
1481-
}
1492+
},
14821493
_ => (),
14831494
}
14841495
assert!(cmsgs.next().is_none(), "unexpected additional control msg");

test/test_fcntl.rs

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,18 @@ fn test_readlink() {
8181

8282
#[cfg(any(target_os = "linux", target_os = "android"))]
8383
mod linux_android {
84-
use std::fs::File;
8584
use std::io::prelude::*;
86-
use std::io::{BufRead, BufReader, SeekFrom};
85+
use std::io::SeekFrom;
8786
use std::os::unix::prelude::*;
88-
8987
use libc::loff_t;
9088

9189
use nix::fcntl::*;
92-
use nix::sys::stat::fstat;
9390
use nix::sys::uio::IoVec;
9491
use nix::unistd::{close, pipe, read, write};
9592

96-
use tempfile::{tempfile, NamedTempFile};
93+
use tempfile::tempfile;
94+
#[cfg(any(target_os = "linux"))]
95+
use tempfile::NamedTempFile;
9796

9897
use crate::*;
9998

@@ -206,6 +205,7 @@ mod linux_android {
206205
close(wr).unwrap();
207206
}
208207

208+
#[cfg(any(target_os = "linux"))]
209209
#[test]
210210
fn test_fallocate() {
211211
let tmp = NamedTempFile::new().unwrap();
@@ -224,17 +224,11 @@ mod linux_android {
224224
// they run under QEMU.
225225

226226
#[test]
227-
#[cfg(not(any(target_arch = "aarch64",
228-
target_arch = "arm",
229-
target_arch = "armv7",
230-
target_arch = "x86",
231-
target_arch = "mips",
232-
target_arch = "mips64",
233-
target_arch = "mips64el",
234-
target_arch = "powerpc64",
235-
target_arch = "powerpc64le",
236-
target_env = "musl")))]
227+
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
237228
fn test_ofd_write_lock() {
229+
use nix::sys::stat::fstat;
230+
use std::mem;
231+
238232
let tmp = NamedTempFile::new().unwrap();
239233

240234
let fd = tmp.as_raw_fd();
@@ -247,13 +241,14 @@ mod linux_android {
247241
}
248242
let inode = fstat(fd).expect("fstat failed").st_ino as usize;
249243

250-
let mut flock = libc::flock {
251-
l_type: libc::F_WRLCK as libc::c_short,
252-
l_whence: libc::SEEK_SET as libc::c_short,
253-
l_start: 0,
254-
l_len: 0,
255-
l_pid: 0,
244+
let mut flock: libc::flock = unsafe {
245+
mem::zeroed() // required for Linux/mips
256246
};
247+
flock.l_type = libc::F_WRLCK as libc::c_short;
248+
flock.l_whence = libc::SEEK_SET as libc::c_short;
249+
flock.l_start = 0;
250+
flock.l_len = 0;
251+
flock.l_pid = 0;
257252
fcntl(fd, FcntlArg::F_OFD_SETLKW(&flock)).expect("write lock failed");
258253
assert_eq!(
259254
Some(("OFDLCK".to_string(), "WRITE".to_string())),
@@ -266,17 +261,11 @@ mod linux_android {
266261
}
267262

268263
#[test]
269-
#[cfg(not(any(target_arch = "aarch64",
270-
target_arch = "arm",
271-
target_arch = "armv7",
272-
target_arch = "x86",
273-
target_arch = "mips",
274-
target_arch = "mips64",
275-
target_arch = "mips64el",
276-
target_arch = "powerpc64",
277-
target_arch = "powerpc64le",
278-
target_env = "musl")))]
264+
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
279265
fn test_ofd_read_lock() {
266+
use nix::sys::stat::fstat;
267+
use std::mem;
268+
280269
let tmp = NamedTempFile::new().unwrap();
281270

282271
let fd = tmp.as_raw_fd();
@@ -289,13 +278,14 @@ mod linux_android {
289278
}
290279
let inode = fstat(fd).expect("fstat failed").st_ino as usize;
291280

292-
let mut flock = libc::flock {
293-
l_type: libc::F_RDLCK as libc::c_short,
294-
l_whence: libc::SEEK_SET as libc::c_short,
295-
l_start: 0,
296-
l_len: 0,
297-
l_pid: 0,
281+
let mut flock: libc::flock = unsafe {
282+
mem::zeroed() // required for Linux/mips
298283
};
284+
flock.l_type = libc::F_RDLCK as libc::c_short;
285+
flock.l_whence = libc::SEEK_SET as libc::c_short;
286+
flock.l_start = 0;
287+
flock.l_len = 0;
288+
flock.l_pid = 0;
299289
fcntl(fd, FcntlArg::F_OFD_SETLKW(&flock)).expect("read lock failed");
300290
assert_eq!(
301291
Some(("OFDLCK".to_string(), "READ".to_string())),
@@ -307,7 +297,13 @@ mod linux_android {
307297
assert_eq!(None, lock_info(inode));
308298
}
309299

300+
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
310301
fn lock_info(inode: usize) -> Option<(String, String)> {
302+
use std::{
303+
fs::File,
304+
io::BufReader
305+
};
306+
311307
let file = File::open("/proc/locks").expect("open /proc/locks failed");
312308
let buf = BufReader::new(file);
313309

test/test_stat.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use std::time::{Duration, UNIX_EPOCH};
1010
use std::path::Path;
1111

1212
#[cfg(not(any(target_os = "netbsd", target_os = "redox")))]
13-
use libc::{S_IFMT, S_IFLNK, mode_t};
13+
use libc::{S_IFMT, S_IFLNK};
14+
#[cfg(not(target_os = "redox"))]
15+
use libc::mode_t;
1416

1517
#[cfg(not(target_os = "redox"))]
1618
use nix::{fcntl, Error};
@@ -69,6 +71,8 @@ fn assert_stat_results(stat_result: Result<FileStat>) {
6971
}
7072

7173
#[cfg(not(any(target_os = "netbsd", target_os = "redox")))]
74+
// (Android's st_blocks is ulonglong which is always non-negative.)
75+
#[cfg_attr(target_os = "android", allow(unused_comparisons))]
7276
fn assert_lstat_results(stat_result: Result<FileStat>) {
7377
let stats = stat_result.expect("stat call failed");
7478
assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent
@@ -86,7 +90,6 @@ fn assert_lstat_results(stat_result: Result<FileStat>) {
8690

8791
// st_blocks depends on whether the machine's file system uses fast
8892
// or slow symlinks, so just make sure it's not negative
89-
// (Android's st_blocks is ulonglong which is always non-negative.)
9093
assert!(stats.st_blocks >= 0);
9194
}
9295

@@ -159,14 +162,14 @@ fn test_fchmod() {
159162
fchmod(file.as_raw_fd(), mode1).unwrap();
160163

161164
let file_stat1 = stat(&filename).unwrap();
162-
assert_eq!(file_stat1.st_mode & 0o7777, mode1.bits());
165+
assert_eq!(file_stat1.st_mode as mode_t & 0o7777, mode1.bits());
163166

164167
let mut mode2 = Mode::empty();
165168
mode2.insert(Mode::S_IROTH);
166169
fchmod(file.as_raw_fd(), mode2).unwrap();
167170

168171
let file_stat2 = stat(&filename).unwrap();
169-
assert_eq!(file_stat2.st_mode & 0o7777, mode2.bits());
172+
assert_eq!(file_stat2.st_mode as mode_t & 0o7777, mode2.bits());
170173
}
171174

172175
#[test]
@@ -186,7 +189,7 @@ fn test_fchmodat() {
186189
fchmodat(Some(dirfd), filename, mode1, FchmodatFlags::FollowSymlink).unwrap();
187190

188191
let file_stat1 = stat(&fullpath).unwrap();
189-
assert_eq!(file_stat1.st_mode & 0o7777, mode1.bits());
192+
assert_eq!(file_stat1.st_mode as mode_t & 0o7777, mode1.bits());
190193

191194
chdir(tempdir.path()).unwrap();
192195

@@ -195,7 +198,7 @@ fn test_fchmodat() {
195198
fchmodat(None, filename, mode2, FchmodatFlags::FollowSymlink).unwrap();
196199

197200
let file_stat2 = stat(&fullpath).unwrap();
198-
assert_eq!(file_stat2.st_mode & 0o7777, mode2.bits());
201+
assert_eq!(file_stat2.st_mode as mode_t & 0o7777, mode2.bits());
199202
}
200203

201204
/// Asserts that the atime and mtime in a file's metadata match expected values.

test/test_unistd.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::os::unix::prelude::*;
2323
#[cfg(not(target_os = "redox"))]
2424
use std::path::Path;
2525
use tempfile::{tempdir, tempfile};
26-
use libc::{_exit, off_t};
26+
use libc::{_exit, mode_t, off_t};
2727

2828
use crate::*;
2929

@@ -102,7 +102,7 @@ fn test_mkfifo() {
102102
mkfifo(&mkfifo_fifo, Mode::S_IRUSR).unwrap();
103103

104104
let stats = stat::stat(&mkfifo_fifo).unwrap();
105-
let typ = stat::SFlag::from_bits_truncate(stats.st_mode);
105+
let typ = stat::SFlag::from_bits_truncate(stats.st_mode as mode_t);
106106
assert!(typ == SFlag::S_IFIFO);
107107
}
108108

@@ -629,10 +629,10 @@ fn test_sysconf_unsupported() {
629629
#[test]
630630
fn test_pipe() {
631631
let (fd0, fd1) = pipe().unwrap();
632-
let m0 = stat::SFlag::from_bits_truncate(stat::fstat(fd0).unwrap().st_mode);
632+
let m0 = stat::SFlag::from_bits_truncate(stat::fstat(fd0).unwrap().st_mode as mode_t);
633633
// S_IFIFO means it's a pipe
634634
assert_eq!(m0, SFlag::S_IFIFO);
635-
let m1 = stat::SFlag::from_bits_truncate(stat::fstat(fd1).unwrap().st_mode);
635+
let m1 = stat::SFlag::from_bits_truncate(stat::fstat(fd1).unwrap().st_mode as mode_t);
636636
assert_eq!(m1, SFlag::S_IFIFO);
637637
}
638638

@@ -926,7 +926,9 @@ fn test_linkat_follow_symlink() {
926926
let newfilestat = stat::stat(&newfilepath).unwrap();
927927

928928
// Check the file type of the new link
929-
assert!((stat::SFlag::from_bits_truncate(newfilestat.st_mode) & SFlag::S_IFMT) == SFlag::S_IFREG);
929+
assert_eq!((stat::SFlag::from_bits_truncate(newfilestat.st_mode as mode_t) & SFlag::S_IFMT),
930+
SFlag::S_IFREG
931+
);
930932

931933
// Check the number of hard links to the original file
932934
assert_eq!(newfilestat.st_nlink, 2);

0 commit comments

Comments
 (0)