Skip to content

Commit

Permalink
Solaris: fixes build and tests, adds CI
Browse files Browse the repository at this point in the history
Disables some tests for Solaris.

test/test_sendfile.rs:

Solaris, sendfilev() doesn't support AF_UNIX sockets.
Instead, it expects an AF_INET or AF_INET6 sockets.

test/sys/test_timer.rs:

Note that sys::test_timer::alarm_fires can fail as timer_create(3C) function
requires the PRIV_PROC_CLOCK_HIGHRES. But since tests are supposed to run
with sudo it should be ok.
  • Loading branch information
psumbera committed Nov 20, 2024
1 parent 4b6a5e3 commit 0aaaff7
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 19 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,27 @@ jobs:
- name: before_cache_script
run: rm -rf $CARGO_HOME/registry/index

solaris:
name: solaris (x86_64-pc-solaris)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: build and test
uses: vmactions/solaris-vm@v1
with:
release: "11.4-gcc"
usesh: true
mem: 4096
copyback: false
prepare: |
source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install)
echo "~~~~ rustc --version ~~~~"
rustc --version
echo "~~~~ Solaris-version ~~~~"
uname -a
run: |
export PATH=$HOME/.rust_solaris/bin:$PATH
cargo build --target x86_64-pc-solaris --all-targets --all-features && sudo cargo test
# Test that we can build with the lowest version of all dependencies.
# "cargo test" doesn't work because some of our dev-dependencies, like
Expand Down
2 changes: 1 addition & 1 deletion src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use libc::{dirent, readdir_r};
/// let mut cwd = Dir::open(".", OFlag::O_RDONLY | OFlag::O_CLOEXEC, Mode::empty()).unwrap();
/// for res_entry in cwd.iter() {
/// let entry = res_entry.unwrap();
/// println!("File name: {}", entry.file_name().to_str().unwrap());
/// println!("File name: {}", entry.file_name().to_string_lossy());
/// }
/// ```
#[derive(Debug, Eq, Hash, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::ffi::OsString;
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
use std::ops::{Deref, DerefMut};
use std::os::unix::ffi::OsStringExt;
#[cfg(not(any(target_os = "redox", target_os = "solaris")))]
#[cfg(not(target_os = "redox"))]
use std::os::unix::io::OwnedFd;
use std::os::unix::io::RawFd;
#[cfg(any(
Expand Down Expand Up @@ -141,7 +141,7 @@ libc_bitflags!(
#[cfg(any(
freebsdlike,
linux_android,
solarish,
target_os = "illumos",
target_os = "netbsd"
))]
O_DIRECT;
Expand Down
1 change: 1 addition & 0 deletions src/sys/mman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ libc_bitflags! {
/// Additional parameters for [`mmap`].
pub struct MapFlags: c_int {
/// Compatibility flag. Ignored.
#[cfg(not(target_os = "solaris"))]
MAP_FILE;
/// Share this mapping. Mutually exclusive with `MAP_PRIVATE`.
MAP_SHARED;
Expand Down
20 changes: 16 additions & 4 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ libc_enum! {
SIGEMT,
#[cfg(not(any(linux_android, target_os = "emscripten",
target_os = "fuchsia", target_os = "redox",
target_os = "haiku", target_os = "aix")))]
target_os = "haiku", target_os = "aix",
target_os = "solaris")))]
/// Information request
SIGINFO,
}
Expand Down Expand Up @@ -188,7 +189,8 @@ impl FromStr for Signal {
target_os = "fuchsia",
target_os = "redox",
target_os = "aix",
target_os = "haiku"
target_os = "haiku",
target_os = "solaris"
)))]
"SIGINFO" => Signal::SIGINFO,
_ => return Err(Errno::EINVAL),
Expand Down Expand Up @@ -272,7 +274,8 @@ impl Signal {
target_os = "fuchsia",
target_os = "redox",
target_os = "aix",
target_os = "haiku"
target_os = "haiku",
target_os = "solaris"
)))]
Signal::SIGINFO => "SIGINFO",
}
Expand Down Expand Up @@ -356,13 +359,22 @@ const SIGNALS: [Signal; 30] = [
SIGURG, SIGPOLL, SIGIO, SIGSTOP, SIGTSTP, SIGCONT, SIGTTIN, SIGTTOU,
SIGVTALRM, SIGPROF, SIGXCPU, SIGXFSZ, SIGTRAP,
];
#[cfg(target_os = "solaris")]
#[cfg(feature = "signal")]
const SIGNALS: [Signal; 30] = [
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGKILL,
SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGCONT,
SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM,
SIGPROF, SIGWINCH, SIGIO, SIGSYS, SIGEMT,
];
#[cfg(not(any(
linux_android,
target_os = "fuchsia",
target_os = "emscripten",
target_os = "aix",
target_os = "redox",
target_os = "haiku"
target_os = "haiku",
target_os = "solaris"
)))]
#[cfg(feature = "signal")]
const SIGNALS: [Signal; 31] = [
Expand Down
5 changes: 1 addition & 4 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,12 +1679,9 @@ impl ControlMessage<'_> {
/// let localhost = SockaddrIn::from_str("1.2.3.4:8080").unwrap();
/// let fd = socket(AddressFamily::Inet, SockType::Datagram, SockFlag::empty(),
/// None).unwrap();
/// let (r, w) = pipe().unwrap();
///
/// let iov = [IoSlice::new(b"hello")];
/// let fds = [r.as_raw_fd()];
/// let cmsg = ControlMessage::ScmRights(&fds);
/// sendmsg(fd.as_raw_fd(), &iov, &[cmsg], MsgFlags::empty(), Some(&localhost)).unwrap();
/// sendmsg(fd.as_raw_fd(), &iov, &[], MsgFlags::empty(), Some(&localhost)).unwrap();
/// ```
pub fn sendmsg<S>(fd: RawFd, iov: &[IoSlice<'_>], cmsgs: &[ControlMessage],
flags: MsgFlags, addr: Option<&S>) -> Result<usize>
Expand Down
8 changes: 6 additions & 2 deletions src/sys/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ libc_enum! {
VEOL,
VEOL2,
VERASE,
#[cfg(any(freebsdlike, solarish))]
#[cfg(any(freebsdlike, target_os = "illumos"))]
VERASE2,
VINTR,
VKILL,
Expand All @@ -431,7 +431,7 @@ libc_enum! {
#[cfg(not(target_os = "haiku"))]
VREPRINT,
VSTART,
#[cfg(any(bsd, solarish))]
#[cfg(any(bsd, target_os = "illumos"))]
VSTATUS,
VSTOP,
VSUSP,
Expand Down Expand Up @@ -463,6 +463,10 @@ impl SpecialCharacterIndices {
pub use libc::NCCS;
#[cfg(any(linux_android, target_os = "aix", bsd))]
pub use libc::_POSIX_VDISABLE;
// Solaris can use libc::_POSIX_VDISABLE once following is pulled in:
// https://github.com/rust-lang/libc/pull/4103
#[cfg(target_os = "solaris")]
pub const _POSIX_VDISABLE: u8 = 0;

libc_bitflags! {
/// Flags for configuring the input mode of a terminal
Expand Down
2 changes: 1 addition & 1 deletion src/syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ libc_bitflags! {
/// which file descriptors are allocated.
LOG_NDELAY;
/// Write the message to standard error output as well to the system log.
#[cfg(not(any(target_os = "redox", target_os = "illumos")))]
#[cfg(not(any(solarish, target_os = "redox")))]
LOG_PERROR;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2157,7 +2157,9 @@ pub mod alarm {
//! sigset.add(Signal::SIGALRM);
//! sigset.wait();
//!
//! assert!(start.elapsed() >= Duration::from_secs(1));
//! // On Solaris, the signal can arrive before the full second.
//! const TOLERANCE: Duration = Duration::from_millis(10);
//! assert!(start.elapsed() + TOLERANCE >= Duration::from_secs(1));
//! ```
//!
//! # References
Expand Down
3 changes: 2 additions & 1 deletion test/sys/test_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ fn test_mkdirat_fail() {
freebsdlike,
apple_targets,
target_os = "haiku",
target_os = "redox"
target_os = "redox",
target_os = "solaris"
)))]
fn test_mknod() {
use stat::{lstat, mknod, SFlag};
Expand Down
1 change: 1 addition & 0 deletions test/sys/test_termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fn test_output_flags() {

// Test modifying local flags
#[test]
#[cfg(not(target_os = "solaris"))]
fn test_local_flags() {
// openpty uses ptname(3) internally
let _m = crate::PTSNAME_MTX.lock();
Expand Down
1 change: 1 addition & 0 deletions test/test_pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ fn make_raw<Fd: AsFd>(fd: Fd) {

/// Test `io::Read` on the PTTY master
#[test]
#[cfg(not(target_os = "solaris"))]
fn test_read_ptty_pair() {
let (mut master, mut slave) = open_ptty_pair();
make_raw(&slave);
Expand Down
13 changes: 10 additions & 3 deletions test/test_sendfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ use tempfile::tempfile;
cfg_if! {
if #[cfg(linux_android)] {
use nix::unistd::{pipe, read};
} else if #[cfg(any(freebsdlike, apple_targets, solarish))] {
} else if #[cfg(any(freebsdlike, apple_targets))] {
use std::net::Shutdown;
use std::os::unix::net::UnixStream;
} else if #[cfg(solarish)] {
use std::net::Shutdown;
use std::net::{TcpListener, TcpStream};
}
}

Expand Down Expand Up @@ -222,7 +225,11 @@ fn test_sendfilev() {
trailer_data
.write_all(trailer_strings.concat().as_bytes())
.unwrap();
let (mut rd, wr) = UnixStream::pair().unwrap();
// Create a TCP socket pair (listener and client)
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = listener.local_addr().unwrap();
let mut rd = TcpStream::connect(addr).unwrap();
let (wr, _) = listener.accept().unwrap();
let vec: &[SendfileVec] = &[
SendfileVec::new(
header_data.as_fd(),
Expand All @@ -243,7 +250,7 @@ fn test_sendfilev() {

let (res, bytes_written) = sendfilev(&wr, vec);
assert!(res.is_ok());
wr.shutdown(Shutdown::Both).unwrap();
wr.shutdown(Shutdown::Write).unwrap();

// Prepare the expected result
let expected_string = header_strings.concat()
Expand Down

0 comments on commit 0aaaff7

Please sign in to comment.