11#! /usr/bin/env bash
22
3+ . script/test_large_file.sh
4+
35SIMPLEFS_MOD=simplefs.ko
46IMAGE=$1
57IMAGESIZE=$2
@@ -47,13 +49,6 @@ dd if=/dev/zero of=$IMAGE bs=1M count=$IMAGESIZE status=none && \
4749sudo mount -t simplefs -o loop $IMAGE test && \
4850pushd test > /dev/null
4951
50- # mkdir
51- test_op ' mkdir dir'
52- test_op ' mkdir dir' # expected to fail
53-
54- # create file
55- test_op ' touch file'
56-
5752# create 40920 files
5853for (( i= 0 ; i<= $MAXFILES ; i++ ))
5954do
9893 fi
9994done
10095find . -name ' file_[0-9]*.txt' | xargs sudo rm || { echo " Failed to delete files" ; exit 1; }
96+ sync
97+
98+ popd > /dev/null || { echo " popd failed" ; exit 1; }
99+ ls test -laR
100+ rm test/* -rf
101+ 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+ echo " $nr_free_blk "
103+ pushd test > /dev/null || { echo " pushd failed" ; exit 1; }
104+
105+ # mkdir
106+ test_op ' mkdir dir'
107+ test_op ' mkdir dir' # expected to fail
108+
109+ # create file
110+ test_op ' touch file'
101111
102112# hard link
103113test_op ' ln file hdlink'
@@ -119,21 +129,11 @@ test_op 'echo abc > file'
119129test $( cat file) = " abc" || echo " Failed to write"
120130
121131# file too large
122- test_op ' dd if=/dev/zero of=file bs=1M count=12 status=none'
123- filesize=$( sudo ls -lR | grep -e " $F_MOD 2" .* file | awk ' {print $5}' )
124- test $filesize -le $MAXFILESIZE || echo " Failed, file size over the limit"
132+ test_too_large_file
125133
126134# Write the file size larger than BLOCK_SIZE
127135# test serial to write
128- test_op ' printf \"%.0s123456789\" {1..1600} > file.txt'
129- count=$( awk ' {count += gsub(/123456789/, "")} END {print count}' " file.txt" )
130- echo " test $count "
131- test " $count " -eq 1600 || echo " Failed, file size not matching"
132- # test block to write
133- test_op ' cat file.txt > checkfile.txt'
134- count=$( awk ' {count += gsub(/123456789/, "")} END {print count}' " checkfile.txt" )
135- echo " test $count "
136- test " $count " -eq 1600 || echo " Failed, file size not matching"
136+ test_file_size_larger_than_block_size
137137
138138# test remove symbolic link
139139test_op ' ln -s file symlink_fake'
@@ -152,7 +152,13 @@ check_exist $S_MOD 1 symlink
152152check_exist $F_MOD 1 symlink_fake
153153check_exist $F_MOD 1 symlink_hard_fake
154154
155+ # clean all files and directories
156+ test_op ' rm -rf ./*'
157+
155158sleep 1
156159popd > /dev/null
157160sudo umount test
158161sudo rmmod simplefs
162+
163+ af_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"')) )
164+ test $nr_free_blk -eq $af_nr_free_blk || echo " Failed, some blocks are not be reclaimed"
0 commit comments