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 mac ci #285

Closed
wants to merge 13 commits into from
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,26 @@ jobs:

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

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

- name: Install macfuse
run: brew install --cask macfuse

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

- name: Run mount test
run: ./osx_mount_tests.sh
env:
RUST_LOG: DEBUG
timeout-minutes: 5

- name: Run tests
run: cargo test --features=libfuse
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
8 changes: 7 additions & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ use std::time::Duration;
use tempfile::TempDir;

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

impl Filesystem for NoSendFS {}

let tmpdir: TempDir = tempfile::tempdir().unwrap();
let mut session = Session::new(NoSendFS(Rc::new(())), tmpdir.path(), &[]).unwrap();
log::debug!("Session created");
let mut unmounter = session.unmount_callable();
thread::spawn(move || {
thread::sleep(Duration::from_secs(1));
log::debug!("unmounting");
unmounter.unmount().unwrap();
log::debug!("unmounted");
});
log::debug!("running session");
session.run().unwrap();
log::debug!("session finished")
}
Loading