Sha256: 60ca35d0b20e99b3af3777b89036b0479881d7a18f596df7c0991530dc61b72f

Contents?: true

Size: 1.59 KB

Versions: 38

Compression:

Stored size: 1.59 KB

Contents

extern crate memfd;
use std::fs;
use std::os::unix::io::AsRawFd;

#[test]
fn test_memfd_default() {
    let opts = memfd::MemfdOptions::default();
    let m0 = opts.create("default").unwrap();
    let meta0 = m0.as_file().metadata().unwrap();
    assert_eq!(meta0.len(), 0);
    assert_eq!(meta0.is_file(), true);
    assert_eq!(get_close_on_exec(&m0).unwrap(), true);
    drop(m0)
}

#[test]
fn test_memfd_no_cloexec() {
    let memfd = memfd::MemfdOptions::default()
        .close_on_exec(false)
        .create("no-cloexec")
        .unwrap();
    assert_eq!(get_close_on_exec(&memfd).unwrap(), false);
}

#[test]
fn test_memfd_multi() {
    let opts = memfd::MemfdOptions::default();
    let m0 = opts.create("default").unwrap();
    let f0 = m0.as_file().as_raw_fd();

    let m1 = opts.create("default").unwrap();
    let f1 = m1.as_file().as_raw_fd();
    assert!(f0 != f1);

    let m0_file = m0.into_file();
    assert_eq!(f0, m0_file.as_raw_fd());
}

#[test]
fn test_memfd_from_into() {
    let opts = memfd::MemfdOptions::default();
    let m0 = opts.create("default").unwrap();
    let f0 = m0.into_file();
    let _ = memfd::Memfd::try_from_file(f0).expect("failed to convert a legit memfd file");

    let rootdir = fs::File::open("/").unwrap();
    let _ = memfd::Memfd::try_from_file(rootdir)
        .expect_err("unexpected conversion from a non-memfd file");
}

/// Check if the close-on-exec flag is set for the memfd.
pub fn get_close_on_exec(memfd: &memfd::Memfd) -> std::io::Result<bool> {
    let flags = rustix::fs::fcntl_getfd(memfd.as_file())?;
    Ok(flags.contains(rustix::fs::FdFlags::CLOEXEC))
}

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
wasmtime-14.0.3 ./ext/cargo-vendor/memfd-0.6.4/tests/memfd.rs
wasmtime-14.0.1 ./ext/cargo-vendor/memfd-0.6.4/tests/memfd.rs
wasmtime-14.0.0 ./ext/cargo-vendor/memfd-0.6.4/tests/memfd.rs
wasmtime-13.0.0 ./ext/cargo-vendor/memfd-0.6.3/tests/memfd.rs
wasmtime-12.0.1 ./ext/cargo-vendor/memfd-0.6.3/tests/memfd.rs
wasmtime-12.0.0 ./ext/cargo-vendor/memfd-0.6.3/tests/memfd.rs
wasmtime-11.0.0 ./ext/cargo-vendor/memfd-0.6.3/tests/memfd.rs
wasmtime-10.0.1 ./ext/cargo-vendor/memfd-0.6.3/tests/memfd.rs
wasmtime-10.0.0 ./ext/cargo-vendor/memfd-0.6.3/tests/memfd.rs
wasmtime-9.0.4 ./ext/cargo-vendor/memfd-0.6.3/tests/memfd.rs
wasmtime-9.0.1 ./ext/cargo-vendor/memfd-0.6.3/tests/memfd.rs
wasmtime-8.0.0 ./ext/cargo-vendor/memfd-0.6.3/tests/memfd.rs
wasmtime-7.0.0 ./ext/cargo-vendor/memfd-0.6.3/tests/memfd.rs
wasmtime-6.0.1 ./ext/cargo-vendor/memfd-0.6.2/tests/memfd.rs
wasmtime-6.0.0 ./ext/cargo-vendor/memfd-0.6.2/tests/memfd.rs
wasmtime-5.0.0 ./ext/cargo-vendor/memfd-0.6.2/tests/memfd.rs
wasmtime-0.4.1 ./ext/cargo-vendor/memfd-0.6.2/tests/memfd.rs
wasmtime-0.4.0 ./ext/cargo-vendor/memfd-0.6.2/tests/memfd.rs