Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3691,6 +3691,7 @@ fn test_linux(target: &str) {
let ppc64 = target.contains("powerpc64");
let ppc32 = ppc && !ppc64;
let s390x = target.contains("s390x");
let sparc = target.contains("sparc");
let sparc64 = target.contains("sparc64");
let x32 = target.contains("x32");
let x86_32 = target.contains("i686");
Expand Down Expand Up @@ -4793,25 +4794,38 @@ fn test_linux(target: &str) {
if gnu {
// old constants, so tests fail if glibc is too new
cfg.skip_const(|s| {
// grep -E -h '^B([0-9])*$' libc-test/semver/*
[
"B50", "B75", "B110", "B134", "B150", "B200", "B300", "B600", "B1200", "B1800",
"B2400", "B4800", "B9600", "B19200", "B38400", "EXTA", "EXTB", "B57600", "B115200",
"B230400", "B460800", "B500000", "B576000", "B921600", "B1000000", "B1152000",
"B1500000", "B2000000", "B2500000", "B3000000", "B3500000", "B4000000",
"EXTA", "EXTB", "B0", "B1000000", "B110", "B115200", "B1152000", "B1200", "B134",
"B14400", "B150", "B1500000", "B153600", "B1800", "B19200", "B200", "B2000000",
"B230400", "B2400", "B2500000", "B28800", "B300", "B3000000", "B307200",
"B3500000", "B38400", "B4000000", "B460800", "B4800", "B50", "B500000", "B57600",
"B576000", "B600", "B614400", "B7200", "B75", "B76800", "B921600", "B9600",
]
.contains(&s.ident())
});
if mips || sparc {
cfg.skip_const(|s| s.ident() == "NCCS");
}
// old symbols, so tests fail if glibc is too new
cfg.skip_fn_ptrcheck(|s| {
[
"cfgetispeed",
"cfgetospeed",
"cfsetispeed",
"cfsetospeed",
"cfsetspeed",
]
.contains(&s)
// note: `skip_fn_ptrcheck` overrides the previous function
cfg.skip_fn_ptrcheck(move |s| {
let mut result = false;
result = result || s == "cfgetispeed";
result = result || s == "cfgetospeed";
result = result || s == "cfsetispeed";
result = result || s == "cfsetospeed";
result = result || s == "cfsetspeed";
if mips || sparc {
result = result || s == "tcgetattr";
result = result || s == "tcsetattr";
}
result
});
// old structs, so tests fail if glibc is too new
if mips || sparc {
cfg.skip_struct(|s| s.ident() == "termios");
}
}

ctest::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
Expand Down
29 changes: 16 additions & 13 deletions libc-test/tests/linux_gnu_baud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ fn baud() {
assert!(ret >= 0);
let terminal_fd = unsafe { open(buffer.as_ptr(), O_RDWR | O_NOCTTY) };
assert!(terminal_fd >= 0);
let mut tio: termios = unsafe { std::mem::zeroed() };
let ret = unsafe { tcgetattr(terminal_fd, &mut tio) };
#[repr(C)]
struct Protector(termios, [u8; 512]);
let mut tio: Protector = unsafe { Protector(std::mem::zeroed(), [0xcc; _]) };
let ret = unsafe { tcgetattr(terminal_fd, &raw mut tio.0) };
assert!(ret >= 0);
assert_eq!(unsafe { cfgetispeed(&tio) }, B38400);
assert_eq!(unsafe { cfgetospeed(&tio) }, B38400);
let ret = unsafe { cfsetspeed(&mut tio, B1000000) };
assert_eq!(tio.1, [0xcc; _]);
assert_eq!(unsafe { cfgetispeed(&tio.0) }, B38400);
assert_eq!(unsafe { cfgetospeed(&tio.0) }, B38400);
let ret = unsafe { cfsetspeed(&mut tio.0, B1000000) };
assert!(ret >= 0);
assert_eq!(unsafe { cfgetispeed(&tio) }, B1000000);
assert_eq!(unsafe { cfgetospeed(&tio) }, B1000000);
let ret = unsafe { cfsetispeed(&mut tio, B9600) };
assert_eq!(unsafe { cfgetispeed(&tio.0) }, B1000000);
assert_eq!(unsafe { cfgetospeed(&tio.0) }, B1000000);
let ret = unsafe { cfsetispeed(&mut tio.0, B9600) };
assert!(ret >= 0);
assert_eq!(unsafe { cfgetispeed(&tio) }, B9600);
assert!(matches!(unsafe { cfgetospeed(&tio) }, B9600 | B1000000));
let ret = unsafe { cfsetospeed(&mut tio, B19200) };
assert_eq!(unsafe { cfgetispeed(&tio.0) }, B9600);
assert!(matches!(unsafe { cfgetospeed(&tio.0) }, B9600 | B1000000));
let ret = unsafe { cfsetospeed(&mut tio.0, B19200) };
assert!(ret >= 0);
assert!(matches!(unsafe { cfgetispeed(&tio) }, B9600 | B19200));
assert_eq!(unsafe { cfgetospeed(&tio) }, B19200);
assert!(matches!(unsafe { cfgetispeed(&tio.0) }, B9600 | B19200));
assert_eq!(unsafe { cfgetospeed(&tio.0) }, B19200);
}
96 changes: 86 additions & 10 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,11 @@ extern "C" {
link_name = "cfgetispeed@GLIBC_2.0"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "mips"),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "mips", target_arch = "mips32r6")
),
link_name = "cfgetispeed@GLIBC_2.0"
)]
#[cfg_attr(
Expand Down Expand Up @@ -1655,7 +1659,11 @@ extern "C" {
link_name = "cfgetispeed@GLIBC_2.36"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "mips64"),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "mips64", target_arch = "mips64r6")
),
link_name = "cfgetispeed@GLIBC_2.0"
)]
#[cfg_attr(
Expand Down Expand Up @@ -1720,7 +1728,11 @@ extern "C" {
link_name = "cfgetospeed@GLIBC_2.0"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "mips"),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "mips", target_arch = "mips32r6")
),
link_name = "cfgetospeed@GLIBC_2.0"
)]
#[cfg_attr(
Expand Down Expand Up @@ -1748,7 +1760,11 @@ extern "C" {
link_name = "cfgetospeed@GLIBC_2.36"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "mips64"),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "mips64", target_arch = "mips64r6")
),
link_name = "cfgetospeed@GLIBC_2.0"
)]
#[cfg_attr(
Expand Down Expand Up @@ -1813,7 +1829,11 @@ extern "C" {
link_name = "cfsetispeed@GLIBC_2.0"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "mips"),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "mips", target_arch = "mips32r6")
),
link_name = "cfsetispeed@GLIBC_2.0"
)]
#[cfg_attr(
Expand Down Expand Up @@ -1841,7 +1861,11 @@ extern "C" {
link_name = "cfsetispeed@GLIBC_2.36"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "mips64"),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "mips64", target_arch = "mips64r6")
),
link_name = "cfsetispeed@GLIBC_2.0"
)]
#[cfg_attr(
Expand Down Expand Up @@ -1906,7 +1930,11 @@ extern "C" {
link_name = "cfsetospeed@GLIBC_2.0"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "mips"),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "mips", target_arch = "mips32r6")
),
link_name = "cfsetospeed@GLIBC_2.0"
)]
#[cfg_attr(
Expand Down Expand Up @@ -1934,7 +1962,11 @@ extern "C" {
link_name = "cfsetospeed@GLIBC_2.36"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "mips64"),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "mips64", target_arch = "mips64r6")
),
link_name = "cfsetospeed@GLIBC_2.0"
)]
#[cfg_attr(
Expand Down Expand Up @@ -1986,7 +2018,43 @@ extern "C" {
link_name = "cfsetospeed@GLIBC_2.16"
)]
pub fn cfsetospeed(termios: *mut crate::termios, speed: crate::speed_t) -> c_int;
#[cfg_attr(
all(
target_os = "linux",
target_env = "gnu",
any(
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "mips64",
target_arch = "mips64r6",
target_arch = "sparc"
),
),
link_name = "tcgetattr@GLIBC_2.0"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "sparc64"),
link_name = "tcgetattr@GLIBC_2.2"
)]
pub fn tcgetattr(fd: c_int, termios: *mut crate::termios) -> c_int;
#[cfg_attr(
all(
target_os = "linux",
target_env = "gnu",
any(
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "mips64",
target_arch = "mips64r6",
target_arch = "sparc"
),
),
link_name = "tcsetattr@GLIBC_2.0"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "sparc64"),
link_name = "tcsetattr@GLIBC_2.2"
)]
pub fn tcsetattr(fd: c_int, optional_actions: c_int, termios: *const crate::termios) -> c_int;
pub fn tcflow(fd: c_int, action: c_int) -> c_int;
pub fn tcflush(fd: c_int, action: c_int) -> c_int;
Expand Down Expand Up @@ -2288,7 +2356,11 @@ cfg_if! {
link_name = "cfsetspeed@GLIBC_2.0"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "mips"),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "mips", target_arch = "mips32r6")
),
link_name = "cfsetspeed@GLIBC_2.0"
)]
#[cfg_attr(
Expand Down Expand Up @@ -2316,7 +2388,11 @@ cfg_if! {
link_name = "cfsetspeed@GLIBC_2.36"
)]
#[cfg_attr(
all(target_os = "linux", target_env = "gnu", target_arch = "mips64"),
all(
target_os = "linux",
target_env = "gnu",
any(target_arch = "mips64", target_arch = "mips64r6")
),
link_name = "cfsetspeed@GLIBC_2.0"
)]
#[cfg_attr(
Expand Down
Loading