From e1baab9dc132f18e13f446df0271a5e46723848d Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Tue, 21 Nov 2017 22:27:15 -0800 Subject: Upgrade to Bitflags 1.0 The libc_bitflags! macro was replaced with a non-recursive one supporting only public structs. I could not figure out how to make the old macro work with the upgrade, so I reworked part of the bitflags! macro directly to suit our needs, much as the original recursive macro was made. There are no uses of this macro for non-public structs, so this is not a problem for internal code. --- test/sys/test_aio.rs | 6 +++--- test/sys/test_epoll.rs | 5 ++--- test/sys/test_ptrace.rs | 4 ++-- test/sys/test_socket.rs | 10 ++++------ test/sys/test_termios.rs | 12 ++++++------ test/sys/test_uio.rs | 1 - test/sys/test_wait.rs | 5 ++--- test/test_fcntl.rs | 4 ++-- test/test_mount.rs | 22 +++++++++++----------- test/test_mq.rs | 30 ++++++++++++++---------------- test/test_poll.rs | 15 ++++++++------- test/test_pty.rs | 20 ++++++++++---------- test/test_ptymaster_drop.rs | 4 ++-- test/test_unistd.rs | 25 +++++++++++++------------ 14 files changed, 79 insertions(+), 84 deletions(-) (limited to 'test') diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index 630dff9a..79a6b6c4 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -2,7 +2,7 @@ use libc::c_int; use nix::{Error, Result}; use nix::errno::*; use nix::sys::aio::*; -use nix::sys::signal::*; +use nix::sys::signal::{SaFlags, SigAction, sigaction, SigevNotify, SigHandler, Signal, SigSet}; use nix::sys::time::{TimeSpec, TimeValLike}; use std::io::{Write, Read, Seek, SeekFrom}; use std::ops::Deref; @@ -325,7 +325,7 @@ fn test_write_sigev_signal() { #[allow(unused_variables)] let m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test"); let sa = SigAction::new(SigHandler::Handler(sigfunc), - SA_RESETHAND, + SaFlags::SA_RESETHAND, SigSet::empty()); SIGNALED.store(false, Ordering::Relaxed); unsafe { sigaction(Signal::SIGUSR2, &sa) }.unwrap(); @@ -462,7 +462,7 @@ fn test_lio_listio_signal() { const EXPECT: &'static [u8] = b"abCDEF123456"; let mut f = tempfile().unwrap(); let sa = SigAction::new(SigHandler::Handler(sigfunc), - SA_RESETHAND, + SaFlags::SA_RESETHAND, SigSet::empty()); let sigev_notify = SigevNotify::SigevSignal { signal: Signal::SIGUSR2, si_value: 0 }; diff --git a/test/sys/test_epoll.rs b/test/sys/test_epoll.rs index a73fea6d..e32a4e23 100644 --- a/test/sys/test_epoll.rs +++ b/test/sys/test_epoll.rs @@ -1,5 +1,4 @@ -use nix::sys::epoll::{EpollCreateFlags, EpollOp, EpollEvent}; -use nix::sys::epoll::{EPOLLIN, EPOLLERR}; +use nix::sys::epoll::{EpollCreateFlags, EpollFlags, EpollOp, EpollEvent}; use nix::sys::epoll::{epoll_create1, epoll_ctl}; use nix::{Error, Errno}; @@ -18,7 +17,7 @@ pub fn test_epoll_errno() { #[test] pub fn test_epoll_ctl() { let efd = epoll_create1(EpollCreateFlags::empty()).unwrap(); - let mut event = EpollEvent::new(EPOLLIN | EPOLLERR, 1); + let mut event = EpollEvent::new(EpollFlags::EPOLLIN | EpollFlags::EPOLLERR, 1); epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, &mut event).unwrap(); epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None).unwrap(); } diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index 20cde1aa..d3e579f3 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -1,7 +1,7 @@ use nix::Error; use nix::errno::Errno; use nix::unistd::getpid; -use nix::sys::ptrace; +use nix::sys::ptrace::{self, Options}; use std::mem; @@ -16,7 +16,7 @@ fn test_ptrace() { // Just make sure ptrace_setoptions can be called at all, for now. #[test] fn test_ptrace_setoptions() { - let err = ptrace::setoptions(getpid(), ptrace::PTRACE_O_TRACESYSGOOD).unwrap_err(); + let err = ptrace::setoptions(getpid(), Options::PTRACE_O_TRACESYSGOOD).unwrap_err(); assert!(err != Error::UnsupportedOperation); } diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index b3d983d3..8ec7f1fd 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -122,8 +122,7 @@ pub fn test_scm_rights() { use nix::unistd::{pipe, read, write, close}; use nix::sys::socket::{socketpair, sendmsg, recvmsg, AddressFamily, SockType, SockFlag, - ControlMessage, CmsgSpace, MsgFlags, - MSG_TRUNC, MSG_CTRUNC}; + ControlMessage, CmsgSpace, MsgFlags}; let (fd1, fd2) = socketpair(AddressFamily::Unix, SockType::Stream, None, SockFlag::empty()) .unwrap(); @@ -154,7 +153,7 @@ pub fn test_scm_rights() { panic!("unexpected cmsg"); } } - assert!(!msg.flags.intersects(MSG_TRUNC | MSG_CTRUNC)); + assert!(!msg.flags.intersects(MsgFlags::MSG_TRUNC | MsgFlags::MSG_CTRUNC)); close(fd2).unwrap(); } @@ -178,8 +177,7 @@ pub fn test_sendmsg_empty_cmsgs() { use nix::unistd::close; use nix::sys::socket::{socketpair, sendmsg, recvmsg, AddressFamily, SockType, SockFlag, - CmsgSpace, MsgFlags, - MSG_TRUNC, MSG_CTRUNC}; + CmsgSpace, MsgFlags}; let (fd1, fd2) = socketpair(AddressFamily::Unix, SockType::Stream, None, SockFlag::empty()) .unwrap(); @@ -199,7 +197,7 @@ pub fn test_sendmsg_empty_cmsgs() { for _ in msg.cmsgs() { panic!("unexpected cmsg"); } - assert!(!msg.flags.intersects(MSG_TRUNC | MSG_CTRUNC)); + assert!(!msg.flags.intersects(MsgFlags::MSG_TRUNC | MsgFlags::MSG_CTRUNC)); close(fd2).unwrap(); } } diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs index 6640c3af..a3a948b3 100644 --- a/test/sys/test_termios.rs +++ b/test/sys/test_termios.rs @@ -4,7 +4,7 @@ use tempfile::tempfile; use nix::{Error, fcntl}; use nix::errno::Errno; use nix::pty::openpty; -use nix::sys::termios::{self, ECHO, OPOST, OCRNL, Termios, tcgetattr}; +use nix::sys::termios::{self, LocalFlags, OutputFlags, Termios, tcgetattr}; use nix::unistd::{read, write, close}; /// Helper function analogous to std::io::Write::write_all, but for `RawFd`s @@ -61,11 +61,11 @@ fn test_output_flags() { }; // Make sure postprocessing '\r' isn't specified by default or this test is useless. - assert!(!termios.output_flags.contains(OPOST | OCRNL)); + assert!(!termios.output_flags.contains(OutputFlags::OPOST | OutputFlags::OCRNL)); // Specify that '\r' characters should be transformed to '\n' // OPOST is specified to enable post-processing - termios.output_flags.insert(OPOST | OCRNL); + termios.output_flags.insert(OutputFlags::OPOST | OutputFlags::OCRNL); // Open a pty let pty = openpty(None, &termios).unwrap(); @@ -104,10 +104,10 @@ fn test_local_flags() { }; // Make sure echo is specified by default or this test is useless. - assert!(termios.local_flags.contains(ECHO)); + assert!(termios.local_flags.contains(LocalFlags::ECHO)); // Disable local echo - termios.local_flags.remove(ECHO); + termios.local_flags.remove(LocalFlags::ECHO); // Open a new pty with our modified termios settings let pty = openpty(None, &termios).unwrap(); @@ -116,7 +116,7 @@ fn test_local_flags() { // Set the master is in nonblocking mode or reading will never return. let flags = fcntl::fcntl(pty.master, fcntl::F_GETFL).unwrap(); - let new_flags = fcntl::OFlag::from_bits_truncate(flags) | fcntl::O_NONBLOCK; + let new_flags = fcntl::OFlag::from_bits_truncate(flags) | fcntl::OFlag::O_NONBLOCK; fcntl::fcntl(pty.master, fcntl::F_SETFL(new_flags)).unwrap(); // Write into the master diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs index 57296938..a2b68d07 100644 --- a/test/sys/test_uio.rs +++ b/test/sys/test_uio.rs @@ -199,7 +199,6 @@ fn test_process_vm_readv() { use nix::unistd::ForkResult::*; use nix::sys::signal::*; use nix::sys::wait::*; - use std::str; #[allow(unused_variables)] let m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs index 0fcaa19c..44a111a3 100644 --- a/test/sys/test_wait.rs +++ b/test/sys/test_wait.rs @@ -54,8 +54,7 @@ fn test_waitstatus_pid() { // FIXME: qemu-user doesn't implement ptrace on most arches #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] mod ptrace { - use nix::sys::ptrace; - use nix::sys::ptrace::*; + use nix::sys::ptrace::{self, Options, Event}; use nix::sys::signal::*; use nix::sys::wait::*; use nix::unistd::*; @@ -74,7 +73,7 @@ mod ptrace { // Wait for the raised SIGTRAP assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, SIGTRAP))); // We want to test a syscall stop and a PTRACE_EVENT stop - assert!(ptrace::setoptions(child, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT).is_ok()); + assert!(ptrace::setoptions(child, Options::PTRACE_O_TRACESYSGOOD | Options::PTRACE_O_TRACEEXIT).is_ok()); // First, stop on the next system call, which will be exit() assert!(ptrace::syscall(child).is_ok()); diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index d171b91d..795b6c85 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -1,4 +1,4 @@ -use nix::fcntl::{openat, open, OFlag, O_RDONLY, readlink, readlinkat}; +use nix::fcntl::{openat, open, OFlag, readlink, readlinkat}; use nix::sys::stat::Mode; use nix::unistd::{close, read}; use tempdir::TempDir; @@ -17,7 +17,7 @@ fn test_openat() { Mode::empty()).unwrap(); let fd = openat(dirfd, tmp.path().file_name().unwrap(), - O_RDONLY, + OFlag::O_RDONLY, Mode::empty()).unwrap(); let mut buf = [0u8; 1024]; diff --git a/test/test_mount.rs b/test/test_mount.rs index 57ff2106..e4cd6ba7 100644 --- a/test/test_mount.rs +++ b/test/test_mount.rs @@ -18,9 +18,9 @@ mod test_mount { use libc::{EACCES, EROFS}; use nix::errno::Errno; - use nix::mount::{mount, umount, MsFlags, MS_BIND, MS_RDONLY, MS_NOEXEC}; - use nix::sched::{unshare, CLONE_NEWNS, CLONE_NEWUSER}; - use nix::sys::stat::{self, S_IRWXU, S_IRWXG, S_IRWXO, S_IXUSR, S_IXGRP, S_IXOTH}; + use nix::mount::{mount, umount, MsFlags}; + use nix::sched::{unshare, CloneFlags}; + use nix::sys::stat::{self, Mode}; use nix::unistd::getuid; use tempdir::TempDir; @@ -48,7 +48,7 @@ exit 23"; fs::OpenOptions::new() .create(true) .write(true) - .mode((S_IRWXU | S_IRWXG | S_IRWXO).bits()) + .mode((Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO).bits()) .open(&test_path) .or_else(|e| if Errno::from_i32(e.raw_os_error().unwrap()) == Errno::EOVERFLOW { @@ -95,7 +95,7 @@ exit 23"; mount(NONE, tempdir.path(), Some(b"tmpfs".as_ref()), - MS_RDONLY, + MsFlags::MS_RDONLY, NONE) .unwrap_or_else(|e| panic!("mount failed: {}", e)); @@ -113,7 +113,7 @@ exit 23"; mount(NONE, tempdir.path(), Some(b"tmpfs".as_ref()), - MS_NOEXEC, + MsFlags::MS_NOEXEC, NONE) .unwrap_or_else(|e| panic!("mount failed: {}", e)); @@ -122,7 +122,7 @@ exit 23"; fs::OpenOptions::new() .create(true) .write(true) - .mode((S_IRWXU | S_IRWXG | S_IRWXO).bits()) + .mode((Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO).bits()) .open(&test_path) .and_then(|mut f| f.write(SCRIPT_CONTENTS)) .unwrap_or_else(|e| panic!("write failed: {}", e)); @@ -134,7 +134,7 @@ exit 23"; panic!("metadata failed: {}", e) })); - assert!(mode.contains(S_IXUSR | S_IXGRP | S_IXOTH), + assert!(mode.contains(Mode::S_IXUSR | Mode::S_IXGRP | Mode::S_IXOTH), "{:?} did not have execute permissions", &test_path); @@ -157,14 +157,14 @@ exit 23"; mount(Some(tempdir.path()), mount_point.path(), NONE, - MS_BIND, + MsFlags::MS_BIND, NONE) .unwrap_or_else(|e| panic!("mount failed: {}", e)); fs::OpenOptions::new() .create(true) .write(true) - .mode((S_IRWXU | S_IRWXG | S_IRWXO).bits()) + .mode((Mode::S_IRWXU | Mode::S_IRWXG | Mode::S_IRWXO).bits()) .open(mount_point.path().join(file_name)) .and_then(|mut f| f.write(SCRIPT_CONTENTS)) .unwrap_or_else(|e| panic!("write failed: {}", e)); @@ -186,7 +186,7 @@ exit 23"; // Hold on to the uid in the parent namespace. let uid = getuid(); - unshare(CLONE_NEWNS | CLONE_NEWUSER).unwrap_or_else(|e| { + unshare(CloneFlags::CLONE_NEWNS | CloneFlags::CLONE_NEWUSER).unwrap_or_else(|e| { let stderr = io::stderr(); let mut handle = stderr.lock(); writeln!(handle, diff --git a/test/test_mq.rs b/test/test_mq.rs index 39e6b62a..bf32696c 100644 --- a/test/test_mq.rs +++ b/test/test_mq.rs @@ -1,15 +1,13 @@ -use nix::mqueue::{mq_open, mq_close, mq_send, mq_receive, mq_getattr, mq_setattr, mq_unlink, mq_set_nonblock, mq_remove_nonblock}; -use nix::mqueue::{O_CREAT, O_WRONLY, O_RDONLY, O_NONBLOCK}; - +use libc::c_long; -use nix::mqueue::MqAttr; -use nix::sys::stat::{S_IWUSR, S_IRUSR, S_IRGRP, S_IROTH}; use std::ffi::CString; use std::str; -use libc::c_long; use nix::errno::Errno::*; use nix::Error::Sys; +use nix::mqueue::{mq_open, mq_close, mq_send, mq_receive, mq_getattr, mq_setattr, mq_unlink, mq_set_nonblock, mq_remove_nonblock}; +use nix::mqueue::{MqAttr, MQ_OFlag}; +use nix::sys::stat::Mode; #[test] fn test_mq_send_and_receive() { @@ -17,14 +15,14 @@ fn test_mq_send_and_receive() { let attr = MqAttr::new(0, 10, MSG_SIZE, 0); let mq_name= &CString::new(b"/a_nix_test_queue".as_ref()).unwrap(); - let mqd0 = mq_open(mq_name, O_CREAT | O_WRONLY, - S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, + let mqd0 = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, + Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&attr)).unwrap(); let msg_to_send = "msg_1"; mq_send(mqd0, msg_to_send.as_bytes(), 1).unwrap(); - let mqd1 = mq_open(mq_name, O_CREAT | O_RDONLY, - S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, + let mqd1 = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_RDONLY, + Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&attr)).unwrap(); let mut buf = [0u8; 32]; let mut prio = 0u32; @@ -42,7 +40,7 @@ fn test_mq_getattr() { const MSG_SIZE: c_long = 32; let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0); let mq_name = &CString::new("/attr_test_get_attr".as_bytes().as_ref()).unwrap(); - let mqd = mq_open(mq_name, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, Some(&initial_attr)).unwrap(); + let mqd = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap(); let read_attr = mq_getattr(mqd); assert!(read_attr.unwrap() == initial_attr); mq_close(mqd).unwrap(); @@ -55,7 +53,7 @@ fn test_mq_setattr() { const MSG_SIZE: c_long = 32; let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0); let mq_name = &CString::new("/attr_test_get_attr".as_bytes().as_ref()).unwrap(); - let mqd = mq_open(mq_name, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, Some(&initial_attr)).unwrap(); + let mqd = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap(); let new_attr = MqAttr::new(0, 20, MSG_SIZE * 2, 100); let old_attr = mq_setattr(mqd, &new_attr); @@ -66,7 +64,7 @@ fn test_mq_setattr() { // O_NONBLOCK can be set (see tests below) assert!(new_attr_get.unwrap() != new_attr); - let new_attr_non_blocking = MqAttr::new(O_NONBLOCK.bits() as c_long, 10, MSG_SIZE, 0); + let new_attr_non_blocking = MqAttr::new(MQ_OFlag::O_NONBLOCK.bits() as c_long, 10, MSG_SIZE, 0); mq_setattr(mqd, &new_attr_non_blocking).unwrap(); let new_attr_get = mq_getattr(mqd); @@ -83,10 +81,10 @@ fn test_mq_set_nonblocking() { const MSG_SIZE: c_long = 32; let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0); let mq_name = &CString::new("/attr_test_get_attr".as_bytes().as_ref()).unwrap(); - let mqd = mq_open(mq_name, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, Some(&initial_attr)).unwrap(); + let mqd = mq_open(mq_name, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap(); mq_set_nonblock(mqd).unwrap(); let new_attr = mq_getattr(mqd); - assert!(new_attr.unwrap().flags() == O_NONBLOCK.bits() as c_long); + assert!(new_attr.unwrap().flags() == MQ_OFlag::O_NONBLOCK.bits() as c_long); mq_remove_nonblock(mqd).unwrap(); let new_attr = mq_getattr(mqd); assert!(new_attr.unwrap().flags() == 0); @@ -99,7 +97,7 @@ fn test_mq_unlink() { let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0); let mq_name_opened = &CString::new("/mq_unlink_test".as_bytes().as_ref()).unwrap(); let mq_name_not_opened = &CString::new("/mq_unlink_test".as_bytes().as_ref()).unwrap(); - let mqd = mq_open(mq_name_opened, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH, Some(&initial_attr)).unwrap(); + let mqd = mq_open(mq_name_opened, MQ_OFlag::O_CREAT | MQ_OFlag::O_WRONLY, Mode::S_IWUSR | Mode::S_IRUSR | Mode::S_IRGRP | Mode::S_IROTH, Some(&initial_attr)).unwrap(); let res_unlink = mq_unlink(mq_name_opened); assert!(res_unlink == Ok(()) ); diff --git a/test/test_poll.rs b/test/test_poll.rs index a48604f9..c28c8fd8 100644 --- a/test/test_poll.rs +++ b/test/test_poll.rs @@ -1,4 +1,4 @@ -use nix::poll::*; +use nix::poll::{EventFlags, poll, PollFd}; use nix::sys::signal::SigSet; use nix::sys::time::{TimeSpec, TimeValLike}; use nix::unistd::{write, pipe}; @@ -6,19 +6,19 @@ use nix::unistd::{write, pipe}; #[test] fn test_poll() { let (r, w) = pipe().unwrap(); - let mut fds = [PollFd::new(r, POLLIN)]; + let mut fds = [PollFd::new(r, EventFlags::POLLIN)]; // Poll an idle pipe. Should timeout let nfds = poll(&mut fds, 100).unwrap(); assert_eq!(nfds, 0); - assert!(!fds[0].revents().unwrap().contains(POLLIN)); + assert!(!fds[0].revents().unwrap().contains(EventFlags::POLLIN)); write(w, b".").unwrap(); // Poll a readable pipe. Should return an event. let nfds = poll(&mut fds, 100).unwrap(); assert_eq!(nfds, 1); - assert!(fds[0].revents().unwrap().contains(POLLIN)); + assert!(fds[0].revents().unwrap().contains(EventFlags::POLLIN)); } // ppoll(2) is the same as poll except for how it handles timeouts and signals. @@ -30,19 +30,20 @@ fn test_poll() { target_os = "linux"))] #[test] fn test_ppoll() { + use nix::poll::ppoll; let timeout = TimeSpec::milliseconds(1); let (r, w) = pipe().unwrap(); - let mut fds = [PollFd::new(r, POLLIN)]; + let mut fds = [PollFd::new(r, EventFlags::POLLIN)]; // Poll an idle pipe. Should timeout let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap(); assert_eq!(nfds, 0); - assert!(!fds[0].revents().unwrap().contains(POLLIN)); + assert!(!fds[0].revents().unwrap().contains(EventFlags::POLLIN)); write(w, b".").unwrap(); // Poll a readable pipe. Should return an event. let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap(); assert_eq!(nfds, 1); - assert!(fds[0].revents().unwrap().contains(POLLIN)); + assert!(fds[0].revents().unwrap().contains(EventFlags::POLLIN)); } diff --git a/test/test_pty.rs b/test/test_pty.rs index 89706f0c..7104a9a5 100644 --- a/test/test_pty.rs +++ b/test/test_pty.rs @@ -3,7 +3,7 @@ use std::path::Path; use std::os::unix::prelude::*; use tempfile::tempfile; -use nix::fcntl::{O_RDWR, open}; +use nix::fcntl::{OFlag, open}; use nix::pty::*; use nix::sys::stat; use nix::sys::termios::*; @@ -14,7 +14,7 @@ use nix::unistd::{write, close}; #[test] fn test_explicit_close() { let mut f = { - let m = posix_openpt(O_RDWR).unwrap(); + let m = posix_openpt(OFlag::O_RDWR).unwrap(); close(m.into_raw_fd()).unwrap(); tempfile().unwrap() }; @@ -31,7 +31,7 @@ fn test_ptsname_equivalence() { let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open a new PTTY master - let master_fd = posix_openpt(O_RDWR).unwrap(); + let master_fd = posix_openpt(OFlag::O_RDWR).unwrap(); assert!(master_fd.as_raw_fd() > 0); // Get the name of the slave @@ -49,7 +49,7 @@ fn test_ptsname_copy() { let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open a new PTTY master - let master_fd = posix_openpt(O_RDWR).unwrap(); + let master_fd = posix_openpt(OFlag::O_RDWR).unwrap(); assert!(master_fd.as_raw_fd() > 0); // Get the name of the slave @@ -66,7 +66,7 @@ fn test_ptsname_copy() { #[cfg(any(target_os = "android", target_os = "linux"))] fn test_ptsname_r_copy() { // Open a new PTTY master - let master_fd = posix_openpt(O_RDWR).unwrap(); + let master_fd = posix_openpt(OFlag::O_RDWR).unwrap(); assert!(master_fd.as_raw_fd() > 0); // Get the name of the slave @@ -84,11 +84,11 @@ fn test_ptsname_unique() { let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open a new PTTY master - let master1_fd = posix_openpt(O_RDWR).unwrap(); + let master1_fd = posix_openpt(OFlag::O_RDWR).unwrap(); assert!(master1_fd.as_raw_fd() > 0); // Open a second PTTY master - let master2_fd = posix_openpt(O_RDWR).unwrap(); + let master2_fd = posix_openpt(OFlag::O_RDWR).unwrap(); assert!(master2_fd.as_raw_fd() > 0); // Get the name of the slave @@ -108,7 +108,7 @@ fn test_open_ptty_pair() { let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); // Open a new PTTY master - let master_fd = posix_openpt(O_RDWR).expect("posix_openpt failed"); + let master_fd = posix_openpt(OFlag::O_RDWR).expect("posix_openpt failed"); assert!(master_fd.as_raw_fd() > 0); // Allow a slave to be generated for it @@ -119,7 +119,7 @@ fn test_open_ptty_pair() { let slave_name = unsafe { ptsname(&master_fd) }.expect("ptsname failed"); // Open the slave device - let slave_fd = open(Path::new(&slave_name), O_RDWR, stat::Mode::empty()).unwrap(); + let slave_fd = open(Path::new(&slave_name), OFlag::O_RDWR, stat::Mode::empty()).unwrap(); assert!(slave_fd > 0); } @@ -176,7 +176,7 @@ fn test_openpty_with_termios() { termios }; // Make sure newlines are not transformed so the data is preserved when sent. - termios.output_flags.remove(ONLCR); + termios.output_flags.remove(OutputFlags::ONLCR); let pty = openpty(None, &termios).unwrap(); // Must be valid file descriptors diff --git a/test/test_ptymaster_drop.rs b/test/test_ptymaster_drop.rs index 664a4dd6..bde8510c 100644 --- a/test/test_ptymaster_drop.rs +++ b/test/test_ptymaster_drop.rs @@ -1,6 +1,6 @@ extern crate nix; -use nix::fcntl::O_RDWR; +use nix::fcntl::OFlag; use nix::pty::*; use nix::unistd::close; use std::os::unix::io::AsRawFd; @@ -15,7 +15,7 @@ use std::os::unix::io::AsRawFd; // why. It doesn't happen on any other target, and it doesn't happen on my PC. #[cfg_attr(all(target_env = "musl", target_arch = "x86"), ignore)] fn test_double_close() { - let m = posix_openpt(O_RDWR).unwrap(); + let m = posix_openpt(OFlag::O_RDWR).unwrap(); close(m.as_raw_fd()).unwrap(); drop(m); // should panic here } diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 442c5921..b29ece3e 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -1,10 +1,9 @@ extern crate tempdir; -use nix::fcntl; use nix::unistd::*; use nix::unistd::ForkResult::*; use nix::sys::wait::*; -use nix::sys::stat; +use nix::sys::stat::{self, Mode, SFlag}; use std::{self, env, iter}; use std::ffi::CString; use std::fs::File; @@ -91,17 +90,17 @@ fn test_mkfifo() { let tempdir = TempDir::new("nix-test_mkfifo").unwrap(); let mkfifo_fifo = tempdir.path().join("mkfifo_fifo"); - mkfifo(&mkfifo_fifo, stat::S_IRUSR).unwrap(); + mkfifo(&mkfifo_fifo, Mode::S_IRUSR).unwrap(); let stats = stat::stat(&mkfifo_fifo).unwrap(); let typ = stat::SFlag::from_bits_truncate(stats.st_mode); - assert!(typ == stat::S_IFIFO); + assert!(typ == SFlag::S_IFIFO); } #[test] fn test_mkfifo_directory() { // mkfifo should fail if a directory is given - assert!(mkfifo(&env::temp_dir(), stat::S_IRUSR).is_err()); + assert!(mkfifo(&env::temp_dir(), Mode::S_IRUSR).is_err()); } #[test] @@ -257,19 +256,21 @@ cfg_if!{ cfg_if!{ if #[cfg(target_os = "android")] { + use nix::fcntl::AtFlags; execve_test_factory!(test_execveat_empty, execveat, File::open("/system/bin/sh").unwrap().into_raw_fd(), - "", fcntl::AT_EMPTY_PATH); + "", AtFlags::AT_EMPTY_PATH); execve_test_factory!(test_execveat_relative, execveat, File::open("/system/bin/").unwrap().into_raw_fd(), - "./sh", fcntl::AtFlags::empty()); + "./sh", AtFlags::empty()); execve_test_factory!(test_execveat_absolute, execveat, File::open("/").unwrap().into_raw_fd(), - "/system/bin/sh", fcntl::AtFlags::empty()); + "/system/bin/sh", AtFlags::empty()); } else if #[cfg(all(target_os = "linux"), any(target_arch ="x86_64", target_arch ="x86"))] { + use nix::fcntl::AtFlags; execve_test_factory!(test_execveat_empty, execveat, File::open("/bin/sh").unwrap().into_raw_fd(), - "", fcntl::AT_EMPTY_PATH); + "", AtFlags::AT_EMPTY_PATH); execve_test_factory!(test_execveat_relative, execveat, File::open("/bin/").unwrap().into_raw_fd(), - "./sh", fcntl::AtFlags::empty()); + "./sh", AtFlags::empty()); execve_test_factory!(test_execveat_absolute, execveat, File::open("/").unwrap().into_raw_fd(), - "/bin/sh", fcntl::AtFlags::empty()); + "/bin/sh", AtFlags::empty()); } } @@ -308,7 +309,7 @@ fn test_getcwd() { for _ in 0..5 { let newdir = iter::repeat("a").take(100).collect::(); inner_tmp_dir.push(newdir); - assert!(mkdir(inner_tmp_dir.as_path(), stat::S_IRWXU).is_ok()); + assert!(mkdir(inner_tmp_dir.as_path(), Mode::S_IRWXU).is_ok()); } assert!(chdir(inner_tmp_dir.as_path()).is_ok()); assert_eq!(getcwd().unwrap(), inner_tmp_dir.as_path()); -- cgit v1.2.3