summaryrefslogtreecommitdiff
path: root/ayafs/src/tests
diff options
context:
space:
mode:
authorChuyan Zhang <me@zcy.moe>2023-11-30 12:01:11 -0800
committerChuyan Zhang <me@zcy.moe>2023-11-30 12:01:11 -0800
commitfd125947c9db0b33761414e65e919f73d9bf1815 (patch)
treec4c66d95ba85601427928aa7f23659590055d464 /ayafs/src/tests
parent1eac97eea4ec0bcef0be061a2cba93a584355283 (diff)
downloadmyfs-fd125947c9db0b33761414e65e919f73d9bf1815.tar.gz
myfs-fd125947c9db0b33761414e65e919f73d9bf1815.zip
Refactor workspace
Diffstat (limited to 'ayafs/src/tests')
-rw-r--r--ayafs/src/tests/bitmap.rs38
-rw-r--r--ayafs/src/tests/block_cache.rs245
-rw-r--r--ayafs/src/tests/common/mod.rs9
-rw-r--r--ayafs/src/tests/mod.rs6
4 files changed, 0 insertions, 298 deletions
diff --git a/ayafs/src/tests/bitmap.rs b/ayafs/src/tests/bitmap.rs
deleted file mode 100644
index 1a43f09..0000000
--- a/ayafs/src/tests/bitmap.rs
+++ /dev/null
@@ -1,38 +0,0 @@
-use crate::tests::common;
-use indexmap::IndexMap;
-
-#[test]
-fn test_allocate() {
- let mut fs = common::setup();
- for _ in 0..10 {
- fs.data_bitmap.allocate().unwrap();
- }
- assert!(fs.data_bitmap.deallocate(5));
- assert_eq!(fs.data_bitmap.allocate().unwrap(), 5);
- assert_eq!(fs.data_bitmap.allocate().unwrap(), 11);
-}
-
-#[test]
-fn test_query() {
- let mut fs = common::setup();
- for _ in 0..10 {
- fs.data_bitmap.allocate().unwrap();
- }
- assert_eq!(fs.data_bitmap.query(0), false);
- assert_eq!(fs.data_bitmap.query(5), true);
- assert_eq!(fs.data_bitmap.query(11), false);
-}
-
-#[test]
-fn test_index_map() {
- let mut map: IndexMap<i32, i32> = IndexMap::new();
- map.insert(1, 2);
- map.insert(2, 3);
- map.insert(3, 4);
- map.insert(4, 5);
- map.remove(&3);
-
- for (entry_index, (key, value)) in map.iter().enumerate() {
- println!("index {}, key {}, value {}", entry_index, key, value);
- }
-}
diff --git a/ayafs/src/tests/block_cache.rs b/ayafs/src/tests/block_cache.rs
deleted file mode 100644
index 52117b9..0000000
--- a/ayafs/src/tests/block_cache.rs
+++ /dev/null
@@ -1,245 +0,0 @@
-use crate::disk::block::{DataBlock, DoubleIndirectBlock, IndirectBlock};
-use crate::disk::inode::InodeMode;
-use crate::tests::common;
-
-#[test]
-fn test_basic_lru() {
- let mut fs = common::setup();
-
- let v: Vec<usize> = (1..=256)
- .map(|_| {
- let index = fs.data_bitmap.allocate().unwrap();
- fs.get_block::<DataBlock>(index).unwrap();
- index
- })
- .collect();
- assert!(fs.peek_block::<DataBlock>(v[0]).is_some());
-
- for i in 0..256 {
- let index = fs.data_bitmap.allocate().unwrap();
- fs.get_block::<DataBlock>(index).unwrap();
- assert!(fs.peek_block::<DataBlock>(v[i]).is_none());
- }
-}
-
-#[test]
-fn test_inode_allocation() {
- let mut fs = common::setup();
-
- let (inode_index, inode) = fs.create_directory(0o755, 0, 0, 0, None).unwrap();
- let mut inode = inode.clone();
-
- const DIRECT_NUMBER: u32 = 15;
- const INDIRECT_NUMBER: u32 = 1024;
- // const DOUBLE_INDIRECT_NUMBER: u32 = 1024 * 1024;
-
- for i in 0..DIRECT_NUMBER {
- fs.allocate_block_for(&mut inode).unwrap();
- assert!(fs.data_bitmap.query(inode.direct[i as usize] as usize))
- }
-
- for _i in 0..INDIRECT_NUMBER {
- fs.allocate_block_for(&mut inode).unwrap();
- }
-
- println!("single indirect is {}", inode.single_indirect);
- println!("double indirect is {}", inode.double_indirect);
- println!("triple indirect is {}", inode.triple_indirect);
-
- let indirect_block = fs
- .peek_block::<IndirectBlock>(inode.single_indirect as usize)
- .unwrap();
- for entry in indirect_block.block.entries {
- assert_ne!(entry, 0);
- assert!(fs.data_bitmap.query(entry as usize));
- }
-
- assert_eq!(fs.data_bitmap.query(inode.double_indirect as usize), false);
- assert_eq!(fs.data_bitmap.query(inode.triple_indirect as usize), false);
-
- for _i in 0..INDIRECT_NUMBER {
- fs.allocate_block_for(&mut inode).unwrap();
- }
-
- let double_indirect = inode.double_indirect;
- println!(
- "double indirect is {} after allocation",
- inode.double_indirect
- );
-
- fs.update_inode(inode_index, inode);
-
- assert!(fs.data_bitmap.query(double_indirect as usize));
-}
-
-#[test]
-fn test_inode_deallocation() {
- let mut fs = common::setup();
-
- let (inode_index, inode) = fs.create_directory(0o755, 0, 0, 0, None).unwrap();
- let mut inode = inode.clone();
-
- const DIRECT_NUMBER: u32 = 15;
- const INDIRECT_NUMBER: u32 = 1024;
- // const DOUBLE_INDIRECT_NUMBER: u32 = 1024 * 1024;
-
- for i in 0..DIRECT_NUMBER {
- println!("Allocated {:?}", fs.allocate_block_for(&mut inode).unwrap());
- assert!(fs.data_bitmap.query(inode.direct[i as usize] as usize))
- }
-
- for _i in 0..2 * INDIRECT_NUMBER {
- println!("Allocated {:?}", fs.allocate_block_for(&mut inode).unwrap());
- }
-
- println!("single indirect is {}", inode.single_indirect);
- println!("double indirect is {}", inode.double_indirect);
- println!("triple indirect is {}", inode.triple_indirect);
-
- assert!(fs.data_bitmap.query(inode.double_indirect as usize));
-
- for i in 0..INDIRECT_NUMBER + 5 {
- println!(
- "Deallocated {}",
- fs.deallocate_block_for(&mut inode).unwrap()
- );
- }
-
- println!("single indirect is {}", inode.single_indirect);
- println!("double indirect is {}", inode.double_indirect);
- println!("triple indirect is {}", inode.triple_indirect);
-
- assert_eq!(fs.data_bitmap.query(inode.double_indirect as usize), false);
-
- fs.update_inode(inode_index, inode);
-}
-
-#[test]
-fn test_multiple_inode_allocation() {
- let mut fs = common::setup();
-
- let (inode_index_1, inode_1) = fs.create_directory(0o755, 0, 0, 0, None).unwrap();
- let mut inode_1 = inode_1.clone();
-
- let (inode_index_2, inode_2) = fs.create_file(0o755, 0, 0, 0).unwrap();
- let mut inode_2 = inode_2.clone();
- // let mut inode_1 = fs.get_inode(inode_index_1).unwrap().clone();
- // let mut inode_2 = fs.get_inode(inode_index_2).unwrap().clone();
-
- const DIRECT_NUMBER: u32 = 15;
- const INDIRECT_NUMBER: u32 = 1024;
-
- for i in 0..DIRECT_NUMBER + INDIRECT_NUMBER {
- println!(
- "Allocated {:?} in inode {}",
- fs.allocate_block_for(&mut inode_1).unwrap(),
- inode_index_1
- );
- println!(
- "Allocated {:?} in inode {}",
- fs.allocate_block_for(&mut inode_2).unwrap(),
- inode_index_2
- );
- }
-
- let (inode_index_3, inode_3) = fs.create_directory(0o755, 0, 0, 0, None).unwrap();
- let mut inode_3 = inode_3.clone();
- // let mut inode_3 = fs.get_inode(inode_index_3).unwrap().clone();
-
- for _i in 0..INDIRECT_NUMBER {
- println!(
- "Deallocated {} in inode {}",
- fs.deallocate_block_for(&mut inode_1).unwrap(),
- inode_index_1
- );
- println!(
- "Allocated {:?} in inode {}",
- fs.allocate_block_for(&mut inode_3).unwrap(),
- inode_index_3
- );
- }
-
- for _i in 0..DIRECT_NUMBER {
- println!(
- "Deallocated {} in inode {}",
- fs.deallocate_block_for(&mut inode_1).unwrap(),
- inode_index_1
- );
- }
-
- assert!(fs.deallocate_block_for(&mut inode_1).is_none());
-
- println!(
- "single indirect is {} for {}",
- inode_1.single_indirect, inode_index_1
- );
- println!(
- "double indirect is {} for {}",
- inode_1.double_indirect, inode_index_1
- );
- println!(
- "single indirect is {} for {}",
- inode_2.single_indirect, inode_index_2
- );
- println!(
- "double indirect is {} for {}",
- inode_2.double_indirect, inode_index_2
- );
- println!(
- "single indirect is {} for {}",
- inode_3.single_indirect, inode_index_3
- );
- println!(
- "double indirect is {} for {}",
- inode_3.double_indirect, inode_index_3
- );
-
- assert_eq!(
- fs.data_bitmap.query(inode_1.single_indirect as usize),
- false
- );
- assert!(fs.data_bitmap.query(inode_2.single_indirect as usize));
- assert_eq!(
- fs.data_bitmap.query(inode_2.double_indirect as usize),
- false
- );
- assert!(fs.data_bitmap.query(inode_3.single_indirect as usize));
- assert_eq!(
- fs.data_bitmap.query(inode_3.double_indirect as usize),
- false
- );
-
- fs.allocate_block_for(&mut inode_2).unwrap();
- println!("-----------------");
- println!(
- "double indirect is {} for {}",
- inode_2.double_indirect, inode_index_2
- );
-
- assert!(fs.data_bitmap.query(inode_2.double_indirect as usize));
-
- for _i in 0..DIRECT_NUMBER {
- fs.allocate_block_for(&mut inode_3).unwrap();
- }
- println!("-----------------");
- println!(
- "double indirect is {} for {}",
- inode_3.double_indirect, inode_index_3
- );
- assert_eq!(
- fs.data_bitmap.query(inode_3.double_indirect as usize),
- false
- );
-
- fs.allocate_block_for(&mut inode_3).unwrap();
- println!("-----------------");
- println!(
- "double indirect is {} for {}",
- inode_3.double_indirect, inode_index_3
- );
- assert!(fs.data_bitmap.query(inode_3.double_indirect as usize));
-
- fs.update_inode(inode_index_1, inode_1);
- fs.update_inode(inode_index_2, inode_2);
- fs.update_inode(inode_index_3, inode_3);
-}
diff --git a/ayafs/src/tests/common/mod.rs b/ayafs/src/tests/common/mod.rs
deleted file mode 100644
index 3abfcb4..0000000
--- a/ayafs/src/tests/common/mod.rs
+++ /dev/null
@@ -1,9 +0,0 @@
-use crate::block_device::memory_disk::MemoryDisk;
-use crate::AyaFS;
-use std::sync::Arc;
-
-#[allow(unused)]
-pub(crate) fn setup() -> AyaFS {
- let mem_disk = Arc::new(MemoryDisk::new(1059715));
- AyaFS::new(mem_disk, 1059715)
-}
diff --git a/ayafs/src/tests/mod.rs b/ayafs/src/tests/mod.rs
deleted file mode 100644
index df442c1..0000000
--- a/ayafs/src/tests/mod.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-#[cfg(test)]
-mod bitmap;
-mod common;
-
-#[cfg(test)]
-mod block_cache;