11#! /usr/bin/env bash
22
3+ . script/test_func.sh
34. script/test_large_file.sh
5+ . script/test_remount.sh
6+ . script/config
47
58SIMPLEFS_MOD=simplefs.ko
69IMAGE=$1
710IMAGESIZE=$2
811MKFS=$3
912
10- D_MOD=" drwxr-xr-x"
11- F_MOD=" -rw-r--r--"
12- S_MOD=" lrwxrwxrwx"
13- MAXFILESIZE=11173888 # SIMPLEFS_MAX_EXTENTS * SIMPLEFS_MAX_BLOCKS_PER_EXTENT * SIMPLEFS_BLOCK_SIZE
14- MAXFILES=40920 # max files per dir
15- MOUNT_TEST=100
16-
17- test_op () {
18- local op=$1
19- echo
20- echo -n " Testing cmd: $op ..."
21- sudo sh -c " $op " > /dev/null && echo " Success"
22- }
23-
24- check_exist () {
25- local mode=$1
26- local nlink=$2
27- local name=$3
28- echo
29- echo -n " Check if exist: $mode $nlink $name ..."
30- sudo ls -lR | grep -e " $mode $nlink " .* $name > /dev/null && echo " Success" || \
31- echo " Failed"
32- }
33-
3413if [ " $EUID " -eq 0 ]
3514 then echo " Don't run this script as root"
3615 exit
@@ -46,62 +25,32 @@ echo && \
4625sudo insmod $SIMPLEFS_MOD && \
4726dd if=/dev/zero of=$IMAGE bs=1M count=$IMAGESIZE status=none && \
4827./$MKFS $IMAGE && \
28+
4929sudo mount -t simplefs -o loop $IMAGE test && \
5030pushd test > /dev/null
5131
52- # create 40920 files
53- for (( i= 0 ; i<= $MAXFILES ; i++ ))
54- do
55- test_op " touch $i .txt" # expected to fail with more than 40920 files
56- done
57- filecnts=$( ls | wc -w)
58- test $filecnts -eq $MAXFILES || echo " Failed, it should be $MAXFILES files"
59- find . -name ' [0-9]*.txt' | xargs -n 2000 sudo rm
60- sync
61-
62- # create 100 files with filenames inside
63- for (( i= 1 ; i<= $MOUNT_TEST ; i++ ))
64- do
65- echo file_$i | sudo tee file_$i .txt > /dev/null && echo " file_$i .txt created."
66- done
67- sync
32+ # test serial to write
33+ test_create_max_nr_files
34+ # test remount file exist or not
35+ test_remount_file_exist
6836
69- # unmount and remount the filesystem
70- echo " Unmounting filesystem..."
7137popd > /dev/null || { echo " popd failed" ; exit 1; }
72- sudo umount test || { echo " umount failed" ; exit 1; }
73- sleep 1
74- echo " Remounting filesystem..."
75- sudo mount -t simplefs -o loop $IMAGE test || { echo " mount failed" ; exit 1; }
76- echo " Remount succeeds."
77- pushd test > /dev/null || { echo " pushd failed" ; exit 1; }
7838
79- # check if files exist and content is correct after remounting
80- for (( i= 1 ; i<= $MOUNT_TEST ; i++ ))
81- do
82- if [[ -f " file_$i .txt" ]]; then
83- content=$( cat " file_$i .txt" | tr -d ' \000' )
84- if [[ " $content " == " file_$i " ]]; then
85- echo " Success: file_$i .txt content is correct."
86- else
87- echo " Failed: file_$i .txt content is incorrect."
88- exit 1
89- fi
90- else
91- echo " Failed: file_$i .txt does not exist."
92- exit 1
93- fi
94- done
95- find . -name ' file_[0-9]*.txt' | xargs sudo rm || { echo " Failed to delete files" ; exit 1; }
39+ # Get ready to count free block
40+ sudo touch test/test.txt
41+ sudo rm test/* -rf
9642sync
9743
98- popd > /dev/null || { echo " popd failed" ; exit 1; }
99- ls test -laR
100- rm test/* -rf
10144nr_free_blk=$(( $(dd if= $IMAGE bs= 1 skip= 28 count= 4 2 >/ dev/ null | hexdump - v - e '1 / 4 "0 x% 08 x\n"')) )
10245echo " $nr_free_blk "
10346pushd test > /dev/null || { echo " pushd failed" ; exit 1; }
10447
48+ # write a file larger than max size
49+ test_too_large_file
50+
51+ # Write the a file larger than BLOCK_SIZE
52+ test_file_size_larger_than_block_size
53+
10554# mkdir
10655test_op ' mkdir dir'
10756test_op ' mkdir dir' # expected to fail
@@ -128,13 +77,6 @@ test_op 'ln -s dir len_of_name_of_the_link_is_29'
12877test_op ' echo abc > file'
12978test $( cat file) = " abc" || echo " Failed to write"
13079
131- # file too large
132- test_too_large_file
133-
134- # Write the file size larger than BLOCK_SIZE
135- # test serial to write
136- test_file_size_larger_than_block_size
137-
13880# test remove symbolic link
13981test_op ' ln -s file symlink_fake'
14082test_op ' rm -f symlink_fake'
0 commit comments