diff options
author | Daniel Mueller <deso@posteo.net> | 2019-05-24 18:07:22 -0700 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2019-05-24 18:07:22 -0700 |
commit | 82cf43dd887801b8b22b8aae8c02854d921915d5 (patch) | |
tree | b1bf3710bd07fe83e396a5db8563f3e6c5e85689 /libc/libc-test/test | |
parent | 06722702ea35434189d7de2b13a00209b2ebbd6d (diff) | |
download | nitrocli-82cf43dd887801b8b22b8aae8c02854d921915d5.tar.gz nitrocli-82cf43dd887801b8b22b8aae8c02854d921915d5.tar.bz2 |
Update libc crate to 0.2.55
This change updates the libc crate to version 0.2.55.
Import subrepo libc/:libc at caf17a0641d29dc624621177f5756804dd180c13
Diffstat (limited to 'libc/libc-test/test')
-rw-r--r-- | libc/libc-test/test/cmsg.rs | 101 | ||||
-rw-r--r-- | libc/libc-test/test/linux_fcntl.rs | 7 | ||||
-rw-r--r-- | libc/libc-test/test/main.rs | 2 |
3 files changed, 107 insertions, 3 deletions
diff --git a/libc/libc-test/test/cmsg.rs b/libc/libc-test/test/cmsg.rs new file mode 100644 index 0000000..8304163 --- /dev/null +++ b/libc/libc-test/test/cmsg.rs @@ -0,0 +1,101 @@ +//! Compare libc's CMSG(3) family of functions against the actual C macros, for +//! various inputs. + +extern crate libc; + +#[cfg(unix)] +mod t { + + use libc::{self, c_uchar, c_uint, c_void, cmsghdr, msghdr}; + use std::mem; + + extern "C" { + pub fn cmsg_firsthdr(msgh: *const msghdr) -> *mut cmsghdr; + pub fn cmsg_nxthdr( + mhdr: *const msghdr, + cmsg: *const cmsghdr, + ) -> *mut cmsghdr; + pub fn cmsg_space(length: c_uint) -> usize; + pub fn cmsg_len(length: c_uint) -> usize; + pub fn cmsg_data(cmsg: *const cmsghdr) -> *mut c_uchar; + } + + #[test] + fn test_cmsg_data() { + for l in 0..128 { + let pcmsghdr = l as *const cmsghdr; + unsafe { + assert_eq!(libc::CMSG_DATA(pcmsghdr), cmsg_data(pcmsghdr)); + } + } + } + + #[test] + fn test_cmsg_firsthdr() { + let mut mhdr: msghdr = unsafe { mem::zeroed() }; + mhdr.msg_control = 0xdeadbeef as *mut c_void; + let pmhdr = &mhdr as *const msghdr; + for l in 0..128 { + mhdr.msg_controllen = l; + unsafe { + assert_eq!(libc::CMSG_FIRSTHDR(pmhdr), cmsg_firsthdr(pmhdr)); + } + } + } + + #[test] + fn test_cmsg_len() { + for l in 0..128 { + unsafe { + assert_eq!(libc::CMSG_LEN(l) as usize, cmsg_len(l)); + } + } + } + + // Skip on sparc64 + // https://github.com/rust-lang/libc/issues/1239 + #[cfg(not(target_arch = "sparc64"))] + #[test] + fn test_cmsg_nxthdr() { + use std::ptr; + + let mut buffer = [0u8; 256]; + let mut mhdr: msghdr = unsafe { mem::zeroed() }; + let pmhdr = &mhdr as *const msghdr; + for start_ofs in 0..64 { + let pcmsghdr = &mut buffer[start_ofs] as *mut u8 as *mut cmsghdr; + mhdr.msg_control = pcmsghdr as *mut c_void; + mhdr.msg_controllen = (160 - start_ofs) as _; + for cmsg_len in 0..64 { + for next_cmsg_len in 0..32 { + for i in buffer[start_ofs..].iter_mut() { + *i = 0; + } + unsafe { + (*pcmsghdr).cmsg_len = cmsg_len; + let libc_next = libc::CMSG_NXTHDR(pmhdr, pcmsghdr); + let next = cmsg_nxthdr(pmhdr, pcmsghdr); + assert_eq!(libc_next, next); + + if libc_next != ptr::null_mut() { + (*libc_next).cmsg_len = next_cmsg_len; + let libc_next = libc::CMSG_NXTHDR(pmhdr, pcmsghdr); + let next = cmsg_nxthdr(pmhdr, pcmsghdr); + assert_eq!(libc_next, next); + } + } + } + } + } + } + + #[test] + fn test_cmsg_space() { + unsafe { + for l in 0..128 { + assert_eq!(libc::CMSG_SPACE(l) as usize, cmsg_space(l)); + } + } + } + +} diff --git a/libc/libc-test/test/linux_fcntl.rs b/libc/libc-test/test/linux_fcntl.rs index 4c8ad52..a54636c 100644 --- a/libc/libc-test/test/linux_fcntl.rs +++ b/libc/libc-test/test/linux_fcntl.rs @@ -1,7 +1,10 @@ -#![allow(bad_style, improper_ctypes, unused)] +#![allow(bad_style, improper_ctypes, unused, deprecated)] extern crate libc; - use libc::*; +#[cfg(any(target_os = "linux", target_os = "android"))] include!(concat!(env!("OUT_DIR"), "/linux_fcntl.rs")); + +#[cfg(not(any(target_os = "linux", target_os = "android")))] +fn main() {} diff --git a/libc/libc-test/test/main.rs b/libc/libc-test/test/main.rs index 3d33610..62a587c 100644 --- a/libc/libc-test/test/main.rs +++ b/libc/libc-test/test/main.rs @@ -1,4 +1,4 @@ -#![allow(bad_style, improper_ctypes)] +#![allow(bad_style, improper_ctypes, deprecated)] extern crate libc; use libc::*; |