1
1
#! /usr/bin/env bash
2
2
3
+ . script/test_func.sh
3
4
. script/test_large_file.sh
5
+ . script/test_remount.sh
6
+ . script/config
4
7
5
8
SIMPLEFS_MOD=simplefs.ko
6
9
IMAGE=$1
7
10
IMAGESIZE=$2
8
11
MKFS=$3
9
12
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
-
34
13
if [ " $EUID " -eq 0 ]
35
14
then echo " Don't run this script as root"
36
15
exit
@@ -46,62 +25,32 @@ echo && \
46
25
sudo insmod $SIMPLEFS_MOD && \
47
26
dd if=/dev/zero of=$IMAGE bs=1M count=$IMAGESIZE status=none && \
48
27
./$MKFS $IMAGE && \
28
+
49
29
sudo mount -t simplefs -o loop $IMAGE test && \
50
30
pushd test > /dev/null
51
31
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
68
36
69
- # unmount and remount the filesystem
70
- echo " Unmounting filesystem..."
71
37
popd > /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; }
78
38
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
96
42
sync
97
43
98
- popd > /dev/null || { echo " popd failed" ; exit 1; }
99
- ls test -laR
100
- rm test/* -rf
101
44
nr_free_blk=$(( $(dd if= $IMAGE bs= 1 skip= 28 count= 4 2 >/ dev/ null | hexdump - v - e '1 / 4 "0 x% 08 x\n"')) )
102
45
echo " $nr_free_blk "
103
46
pushd test > /dev/null || { echo " pushd failed" ; exit 1; }
104
47
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
+
105
54
# mkdir
106
55
test_op ' mkdir dir'
107
56
test_op ' mkdir dir' # expected to fail
@@ -128,13 +77,6 @@ test_op 'ln -s dir len_of_name_of_the_link_is_29'
128
77
test_op ' echo abc > file'
129
78
test $( cat file) = " abc" || echo " Failed to write"
130
79
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
-
138
80
# test remove symbolic link
139
81
test_op ' ln -s file symlink_fake'
140
82
test_op ' rm -f symlink_fake'
0 commit comments