From 01ce12702074a1c68f4088c02b3e291735a0dbd0 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sun, 8 Dec 2024 16:31:31 -0800 Subject: [PATCH] Fix tests on illumos. Fix the layout of `epoll::Event` on x86 and x86_64 on illumos to match libc's layout. Adjust tests in tests/net/sockopt.rs to avoid using a buffer larger than supported on illumos. And change tests/pty/openpty.rs to avoid expecting we can write an EOF to a pty on illumos, as that doesn't appear to work. --- src/event/epoll.rs | 5 ++++- tests/net/sockopt.rs | 4 ++-- tests/pty/openpty.rs | 24 +++++++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/event/epoll.rs b/src/event/epoll.rs index b9a9a1bd7..b6fb8264d 100644 --- a/src/event/epoll.rs +++ b/src/event/epoll.rs @@ -259,6 +259,10 @@ impl<'a> Iterator for Iter<'a> { repr(packed) )] #[derive(Copy, Clone, Eq, PartialEq, Hash)] +#[cfg_attr( + all(solarish, any(target_arch = "x86", target_arch = "x86_64")), + repr(packed(4)) +)] pub struct Event { /// Which specific event(s) occurred. pub flags: EventFlags, @@ -451,7 +455,6 @@ mod tests { #[test] fn test_epoll_layouts() { - check_renamed_type!(Event, epoll_event); check_renamed_type!(Event, epoll_event); check_renamed_struct_renamed_field!(Event, epoll_event, flags, events); #[cfg(libc)] diff --git a/tests/net/sockopt.rs b/tests/net/sockopt.rs index 5690634b5..051735863 100644 --- a/tests/net/sockopt.rs +++ b/tests/net/sockopt.rs @@ -128,10 +128,10 @@ fn test_sockopts_socket(s: &OwnedFd) { // Set the send buffer size. let size = sockopt::get_socket_send_buffer_size(s).unwrap(); - sockopt::set_socket_send_buffer_size(s, size * 4).unwrap(); + sockopt::set_socket_send_buffer_size(s, size * 2).unwrap(); // Check that the send buffer size is set. - assert!(sockopt::get_socket_send_buffer_size(s).unwrap() >= size * 4); + assert!(sockopt::get_socket_send_buffer_size(s).unwrap() >= size * 2); // Check that the oobinline flag is not initially set. assert!(!sockopt::get_socket_oobinline(s).unwrap()); diff --git a/tests/pty/openpty.rs b/tests/pty/openpty.rs index 3c1153a17..730b88d69 100644 --- a/tests/pty/openpty.rs +++ b/tests/pty/openpty.rs @@ -1,3 +1,5 @@ +#![allow(unused_mut, unused_imports)] + use rustix::fs::{openat, Mode, OFlags, CWD}; use rustix::pty::*; use std::fs::File; @@ -37,7 +39,24 @@ fn openpty_basic() { controller.write_all(b"Hello, world!\n\x04").unwrap(); let mut s = String::new(); - user.read_to_string(&mut s).unwrap(); + + // Read the string back. Our `\x04` above ended the stream, so we can + // read to the end of the stream. + #[cfg(not(target_os = "illumos"))] + { + user.read_to_string(&mut s).unwrap(); + } + + // Except on illumos, where the `\0x04` doesn't seem to translate into an + // EOF, so we didn't end the stream, so just the line. + #[cfg(target_os = "illumos")] + use std::io::{BufRead, BufReader}; + #[cfg(target_os = "illumos")] + let mut user = BufReader::new(user); + #[cfg(target_os = "illumos")] + { + user.read_line(&mut s).unwrap(); + } assert_eq!(s, "Hello, world!\n"); } @@ -70,6 +89,9 @@ fn openpty_get_peer() { controller.write_all(b"Hello, world!\n\x04").unwrap(); let mut s = String::new(); + + // Read the string back. Our `\x04` above ended the stream, so we can + // read to the end of the stream. user.read_to_string(&mut s).unwrap(); assert_eq!(s, "Hello, world!\n");