Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI to run tests on macOS #286

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,23 @@ jobs:

- name: Run tests
run: INTERACTIVE="" make ${{ matrix.test_group }}

test-mac:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

# Note that this is a partial install of macFUSE, for a complete installation that would require to install the kernel extension
# But that currently not possible without restarting the machine
- name: Install macFUSE
run: brew install --cask macfuse

- uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Run tests
# The macFuse kernel extension is not installed so we need to skip the unmount_no_send test
run: cargo test --features=libfuse -- --skip unmount_no_send
env:
RUST_LOG: DEBUG
timeout-minutes: 5

6 changes: 6 additions & 0 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,9 @@ impl Filesystem for SimpleFS {
flags: u32,
reply: ReplyEmpty,
) {
#[cfg(target_os = "macos")]
let _ = flags;

let mut inode_attrs = match self.lookup_name(parent, name) {
Ok(attrs) => attrs,
Err(error_code) => {
Expand Down Expand Up @@ -1922,6 +1925,9 @@ fn as_file_kind(mut mode: u32) -> FileKind {
}

fn get_groups(pid: u32) -> Vec<u32> {
#[cfg(target_os = "macos")]
let _ = pid;

#[cfg(not(target_os = "macos"))]
{
let path = format!("/proc/{pid}/task/{pid}/status");
Expand Down
12 changes: 9 additions & 3 deletions src/mnt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod mount_options;

#[cfg(any(feature = "libfuse", test))]
use fuse2_sys::fuse_args;
#[cfg(any(test, not(feature = "libfuse")))]
#[cfg(any(all(test, not(target_os = "macos")), not(feature = "libfuse")))]
use std::fs::File;
#[cfg(any(test, not(feature = "libfuse"), not(feature = "libfuse3")))]
use std::io;
Expand Down Expand Up @@ -87,7 +87,7 @@ fn libc_umount(mnt: &CStr) -> io::Result<()> {

/// Warning: This will return true if the filesystem has been detached (lazy unmounted), but not
/// yet destroyed by the kernel.
#[cfg(any(test, not(feature = "libfuse")))]
#[cfg(any(all(test, not(target_os = "macos")), not(feature = "libfuse")))]
fn is_mounted(fuse_device: &File) -> bool {
use libc::{poll, pollfd};
use std::os::unix::prelude::AsRawFd;
Expand Down Expand Up @@ -121,7 +121,7 @@ fn is_mounted(fuse_device: &File) -> bool {
#[cfg(test)]
mod test {
use super::*;
use std::{ffi::CStr, mem::ManuallyDrop};
use std::ffi::CStr;

#[test]
fn fuse_args() {
Expand All @@ -142,6 +142,8 @@ mod test {
},
);
}

#[cfg(not(target_os = "macos"))]
fn cmd_mount() -> String {
std::str::from_utf8(
std::process::Command::new("sh")
Expand All @@ -156,8 +158,12 @@ mod test {
.to_owned()
}

// Mountpoint are not directly available on MacOS.
#[cfg(not(target_os = "macos"))]
#[test]
fn mount_unmount() {
use std::mem::ManuallyDrop;

// We use ManuallyDrop here to leak the directory on test failure. We don't
// want to try and clean up the directory if it's a mountpoint otherwise we'll
// deadlock.
Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use std::time::Duration;
use tempfile::TempDir;

#[test]
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "macos"))]
fn unmount_no_send() {
env_logger::init();
// Rc to make this !Send
struct NoSendFS(Rc<()>);

Expand Down
Loading