#[path = "../../../os-vfs-unmount/src/lib.rs"] mod unmount; #[test] fn os_vfs_unmount_positive() { let mut mount = unmount::Mount::new(2, 7).unwrap(); let old = mount.token(); let open = mount.acquire(unmount::Kind::Open).unwrap(); let lookup = mount.acquire(unmount::Kind::Lookup).unwrap(); let pin = mount.acquire(unmount::Kind::CachePin).unwrap(); assert_eq!(mount.counts(), unmount::Counts { open: 1, lookup: 1, cache_pins: 1 }); assert_eq!(mount.unmount(), Err(unmount::Error::Busy)); assert_eq!(mount.release(open), Ok(())); assert_eq!(mount.release(lookup), Ok(())); assert_eq!(mount.unmount(), Err(unmount::Error::Busy)); assert_eq!(mount.release(pin), Ok(())); assert_eq!(mount.unmount(), Ok(8)); assert!(!mount.mounted()); assert_eq!(mount.validate(old), Err(unmount::Error::Stale)); let fresh = mount.remount().unwrap(); assert_eq!((fresh.volume(), fresh.generation()), (2, 8)); assert_eq!(mount.validate(fresh), Ok(())); assert_eq!(mount.validate(old), Err(unmount::Error::Stale)); } #[test] fn os_vfs_unmount_negative() { assert_eq!(unmount::Mount::new(0, 1), Err(unmount::Error::InvalidMount)); let mut mount = unmount::Mount::new(1, 1).unwrap(); let pin = mount.acquire(unmount::Kind::CachePin).unwrap(); let before = mount; assert_eq!(mount.unmount(), Err(unmount::Error::Busy)); assert_eq!(mount, before); assert_eq!(mount.release(pin), Ok(())); let after_release = mount; assert_eq!(mount.release(pin), Err(unmount::Error::Stale)); assert_eq!(mount, after_release); let one = mount.acquire(unmount::Kind::Open).unwrap(); let two = mount.acquire(unmount::Kind::Open).unwrap(); let three = mount.acquire(unmount::Kind::Lookup).unwrap(); let full = mount; assert_eq!(mount.acquire(unmount::Kind::CachePin), Err(unmount::Error::NoSpace)); assert_eq!(mount, full); assert_eq!(mount.release(one), Ok(())); assert_eq!(mount.release(two), Ok(())); assert_eq!(mount.release(three), Ok(())); let mut terminal = unmount::Mount::new(1, u64::MAX).unwrap(); let before_overflow = terminal; assert_eq!(terminal.unmount(), Err(unmount::Error::Overflow)); assert_eq!(terminal, before_overflow); }