#[path = "../../../os-turkfs-allocation/src/lib.rs"] mod allocation; const RESERVED: u64 = 0x1f; #[test] fn os_turkfs_allocation_extent_growth_positive() { let all = (1u64 << 32) - 1; let mut bitmap = allocation::Bitmap::validate(32, RESERVED, all & !(1u64 << 20) & !(1u64 << 30)).unwrap(); let mut file = allocation::ExtentFile::one_block(10, &bitmap).unwrap(); let first = file.blocks()[0]; assert_eq!(file.count(), 1); assert_eq!(bitmap.counts().free, 2); assert_eq!(file.grow_to_three(&mut bitmap), Ok(())); assert_eq!(file.count(), 3); assert_eq!(file.blocks(), [first, 20, 30]); assert_eq!(bitmap.counts().free, 0); assert_eq!(bitmap.counts().reserved + bitmap.counts().user, 32); } #[test] fn os_turkfs_allocation_extent_growth_negative() { let all = (1u64 << 32) - 1; let mut bitmap = allocation::Bitmap::validate(32, RESERVED, all & !(1u64 << 20)).unwrap(); let mut file = allocation::ExtentFile::one_block(10, &bitmap).unwrap(); let file_before = file; let bitmap_before = bitmap; assert_eq!(file.grow_to_three(&mut bitmap), Err(allocation::Error::NoSpace)); assert_eq!(file, file_before); assert_eq!(bitmap, bitmap_before); assert_eq!(allocation::ExtentFile::one_block(2, &bitmap), Err(allocation::Error::UnownedFirstBlock)); assert_eq!(allocation::ExtentFile::one_block(32, &bitmap), Err(allocation::Error::OutOfBounds)); }