Skip to content

Commit

Permalink
Fix tests on illumos. (#1238)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sunfishcode committed Dec 9, 2024
1 parent bed5c48 commit 7b9bb5a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/event/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions tests/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
24 changes: 23 additions & 1 deletion tests/pty/openpty.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_mut, unused_imports)]

use rustix::fs::{openat, Mode, OFlags, CWD};
use rustix::pty::*;
use std::fs::File;
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 7b9bb5a

Please sign in to comment.