summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorChuyan Zhang <me@zcy.moe>2023-11-27 00:11:55 -0800
committerChuyan Zhang <me@zcy.moe>2023-11-27 00:11:55 -0800
commitec2f349a648e4d87fba12d20e338b1cd6d8ef29a (patch)
tree867221cfc9d46b10fee508de5b63996f12704051 /src/tests
parent9d1368b0ea380a9446b4697af668d1685464b6c7 (diff)
downloadmyfs-ec2f349a648e4d87fba12d20e338b1cd6d8ef29a.tar.gz
myfs-ec2f349a648e4d87fba12d20e338b1cd6d8ef29a.zip
Fix directory stuff
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/bitmap.rs15
-rw-r--r--src/tests/block_cache.rs33
2 files changed, 33 insertions, 15 deletions
diff --git a/src/tests/bitmap.rs b/src/tests/bitmap.rs
index 9b21b6f..1a43f09 100644
--- a/src/tests/bitmap.rs
+++ b/src/tests/bitmap.rs
@@ -1,4 +1,5 @@
use crate::tests::common;
+use indexmap::IndexMap;
#[test]
fn test_allocate() {
@@ -21,3 +22,17 @@ fn test_query() {
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/src/tests/block_cache.rs b/src/tests/block_cache.rs
index 90875ae..52117b9 100644
--- a/src/tests/block_cache.rs
+++ b/src/tests/block_cache.rs
@@ -26,8 +26,8 @@ fn test_basic_lru() {
fn test_inode_allocation() {
let mut fs = common::setup();
- let inode_index = fs.create_inode(0o755, InodeMode::IFDIR, 0, 0, 0).unwrap();
- let mut inode = fs.get_inode(inode_index).unwrap().clone();
+ 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;
@@ -76,20 +76,20 @@ fn test_inode_allocation() {
fn test_inode_deallocation() {
let mut fs = common::setup();
- let inode_index = fs.create_inode(0o755, InodeMode::IFDIR, 0, 0, 0).unwrap();
- let mut inode = fs.get_inode(inode_index).unwrap().clone();
+ 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());
+ 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!("Allocated {:?}", fs.allocate_block_for(&mut inode).unwrap());
}
println!("single indirect is {}", inode.single_indirect);
@@ -118,30 +118,33 @@ fn test_inode_deallocation() {
fn test_multiple_inode_allocation() {
let mut fs = common::setup();
- let inode_index_1 = fs.create_inode(0o755, InodeMode::IFDIR, 0, 0, 0).unwrap();
- let inode_index_2 = fs.create_inode(0o755, InodeMode::IFREG, 0, 0, 0).unwrap();
+ let (inode_index_1, inode_1) = fs.create_directory(0o755, 0, 0, 0, None).unwrap();
+ let mut inode_1 = inode_1.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();
+ 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 {}",
+ "Allocated {:?} in inode {}",
fs.allocate_block_for(&mut inode_1).unwrap(),
inode_index_1
);
println!(
- "Allocated {} in inode {}",
+ "Allocated {:?} in inode {}",
fs.allocate_block_for(&mut inode_2).unwrap(),
inode_index_2
);
}
- let inode_index_3 = fs.create_inode(0o755, InodeMode::IFDIR, 0, 0, 0).unwrap();
- let mut inode_3 = fs.get_inode(inode_index_3).unwrap().clone();
+ 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!(
@@ -150,7 +153,7 @@ fn test_multiple_inode_allocation() {
inode_index_1
);
println!(
- "Allocated {} in inode {}",
+ "Allocated {:?} in inode {}",
fs.allocate_block_for(&mut inode_3).unwrap(),
inode_index_3
);