Skip to content

Commit 6a6f7a8

Browse files
authored
Fix tests on illumos. (#1238)
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.
1 parent 734b8fe commit 6a6f7a8

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

src/event/epoll.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ impl<'a> Iterator for Iter<'a> {
259259
repr(packed)
260260
)]
261261
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
262+
#[cfg_attr(
263+
all(solarish, any(target_arch = "x86", target_arch = "x86_64")),
264+
repr(packed(4))
265+
)]
262266
pub struct Event {
263267
/// Which specific event(s) occurred.
264268
pub flags: EventFlags,
@@ -451,7 +455,6 @@ mod tests {
451455

452456
#[test]
453457
fn test_epoll_layouts() {
454-
check_renamed_type!(Event, epoll_event);
455458
check_renamed_type!(Event, epoll_event);
456459
check_renamed_struct_renamed_field!(Event, epoll_event, flags, events);
457460
#[cfg(libc)]

tests/net/sockopt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ fn test_sockopts_socket(s: &OwnedFd) {
128128

129129
// Set the send buffer size.
130130
let size = sockopt::get_socket_send_buffer_size(s).unwrap();
131-
sockopt::set_socket_send_buffer_size(s, size * 4).unwrap();
131+
sockopt::set_socket_send_buffer_size(s, size * 2).unwrap();
132132

133133
// Check that the send buffer size is set.
134-
assert!(sockopt::get_socket_send_buffer_size(s).unwrap() >= size * 4);
134+
assert!(sockopt::get_socket_send_buffer_size(s).unwrap() >= size * 2);
135135

136136
// Check that the oobinline flag is not initially set.
137137
assert!(!sockopt::get_socket_oobinline(s).unwrap());

tests/pty/openpty.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused_mut, unused_imports)]
2+
13
use rustix::fs::{openat, Mode, OFlags, CWD};
24
use rustix::pty::*;
35
use std::fs::File;
@@ -37,7 +39,24 @@ fn openpty_basic() {
3739
controller.write_all(b"Hello, world!\n\x04").unwrap();
3840

3941
let mut s = String::new();
40-
user.read_to_string(&mut s).unwrap();
42+
43+
// Read the string back. Our `\x04` above ended the stream, so we can
44+
// read to the end of the stream.
45+
#[cfg(not(target_os = "illumos"))]
46+
{
47+
user.read_to_string(&mut s).unwrap();
48+
}
49+
50+
// Except on illumos, where the `\0x04` doesn't seem to translate into an
51+
// EOF, so we didn't end the stream, so just the line.
52+
#[cfg(target_os = "illumos")]
53+
use std::io::{BufRead, BufReader};
54+
#[cfg(target_os = "illumos")]
55+
let mut user = BufReader::new(user);
56+
#[cfg(target_os = "illumos")]
57+
{
58+
user.read_line(&mut s).unwrap();
59+
}
4160

4261
assert_eq!(s, "Hello, world!\n");
4362
}
@@ -70,6 +89,9 @@ fn openpty_get_peer() {
7089
controller.write_all(b"Hello, world!\n\x04").unwrap();
7190

7291
let mut s = String::new();
92+
93+
// Read the string back. Our `\x04` above ended the stream, so we can
94+
// read to the end of the stream.
7395
user.read_to_string(&mut s).unwrap();
7496

7597
assert_eq!(s, "Hello, world!\n");

0 commit comments

Comments
 (0)