forked from baxter104/fatx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·609 lines (596 loc) · 11.1 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
#!/bin/bash
SIZE=300
WAIT=3
TIMEOUT=120
DSK=disk.fatx
CMDFUSE="./fusefatx -d $DSK mnt/"
prepare() {
echo Prepare context
[ -e fusefatx ] || ln -sf fatx fusefatx
[ -e mkfs.fatx ] || ln -sf fatx mkfs.fatx
[ -e unrm.fatx ] || ln -sf fatx unrm.fatx
[ -e fsck.fatx ] || ln -sf fatx fsck.fatx
[ -e label.fatx ] || ln -sf fatx label.fatx
[ -d mnt ] || mkdir mnt
[ -e $DSK ] || dd if=<(yes $'\xFF' | tr -d "\n") of=$DSK bs=$((1024*1024)) count=$SIZE iflag=fullblock
# [ -e $DSK ] || dd if=/dev/urandom of=$DSK bs=$((1024*1024)) count=600 iflag=fullblock
rm -rf mnt/* || (fusermount -u mnt && rm -rf mnt/*)
}
remove() {
rm -rf mnt
rm -f fusefatx
rm -f mkfs.fatx
rm -f unrm.fatx
rm -f fsck.fatx
rm -f label.fatx
}
prefuse() {
$CMDFUSE $1 2>&1 &
FUSE=$!
count=0
while ! `df mnt | tail -n1 | cut -f 1 -d\ | grep -q fatx`; do
sleep 1
let count++
if [ "$1" == "" -a $((count)) == $TIMEOUT ]; then
echo Failed to mount disk
kilfuse
exit 1
fi
done
}
remfuse() {
sleep $WAIT
fusermount -u mnt
count=0
while kill -0 $FUSE 2>/dev/null; do
sleep 1
let count++
if [ $((count)) == $TIMEOUT ]; then
echo Failed to unmount disk
kilfuse
exit 1
fi
done
FUSE=
}
kilfuse() {
kill -9 $FUSE 2>/dev/null
FUSE=
fusermount -u mnt
}
mkfs1() {
echo Mkfs: make disk:
./mkfs.fatx -y $DSK 2>&1
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO"
exit 1
fi
}
fuse1() {
echo Fuse: simple file creation:
prefuse
cp fatx mnt
cmp -b fatx mnt/fatx
if [ $? != 0 ]; then
echo "### Test KO"
kilfuse
exit 1
fi
cp Makefile mnt/fatx
cmp -b Makefile mnt/fatx
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO"
kilfuse
exit 1
fi
remfuse
}
fuse2() {
echo Fuse: moving file:
prefuse
mkdir mnt/fuse2
mkdir mnt/fuse2/dir1
mkdir mnt/fuse2/dir2
mv -f mnt/fatx mnt/fatx.bis
mv -f mnt/fatx.bis mnt/fuse2/fatx
mv -f mnt/fuse2/fatx mnt/fuse2/dir1/
mv -f mnt/fuse2/dir1 mnt/fuse2/dir3
mv -f mnt/fuse2/dir3 mnt/fuse2/dir2/
ls mnt/fuse2/dir2/dir3/fatx >/dev/null 2>&1
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO"
kilfuse
exit 1
fi
remfuse
}
fuse3() {
echo Fuse: removing file:
prefuse
mkdir mnt/fuse3
cp fatx mnt/fuse3
rm mnt/fuse3/fatx
rmdir mnt/fuse3
ls mnt/fuse3 >/dev/null 2>&1
if [ $? != 0 ]; then
echo "*** Test OK"
else
echo "### Test KO"
kilfuse
exit 1
fi
remfuse
}
fuse4() {
echo Fuse: multiple file access:
prefuse
mkdir mnt/fuse4
nmax=5
for ((n = 1; n <= $nmax; n++)); do
cp Makefile mnt/fuse4/m$n
done
exec 3<>mnt/fuse4/m1
exec 4<>mnt/fuse4/m2
exec 5<>mnt/fuse4/m3
exec 6<mnt/fuse4/m4
exec 7>mnt/fuse4/m5
exec 7>&-
exec 6>&-
exec 5>&-
exec 4>&-
exec 3>&-
echo "*** Test OK"
remfuse
}
fuse5() {
echo Fuse: concurrent access:
prefuse
./fsck.fatx $DSK 2>&1
if [ $? != 0 ]; then
echo "*** Test OK"
else
echo "### Test KO"
kilfuse
exit 1
fi
remfuse
}
fuse6() {
echo Fuse: directory copies:
prefuse
mkdir mnt/test
cp fatx mnt/test/
mkdir mnt/fuse6
cp -r mnt/test mnt/fuse6
echo "*** Test OK"
remfuse
}
fuse7() {
echo Fuse: simultaneous copies:
prefuse
mkdir mnt/fuse7
tasks=
nmax=50
for ((n = 1; n <= $nmax; n++)); do
dd if=/dev/urandom of=mnt/fuse7/r$n bs=$((2 * 1024 * 1024 + 256)) count=1 >/dev/null 2>&1
if [ `du -b mnt/fuse7/r$n | cut -f 1` != $((2 * 1024 * 1024 + 256)) ]; then
echo "### Test KO", invalid file size
kilfuse
exit 1
fi
done
sleep $WAIT
for ((n = 1; n <= $nmax; n++)); do
cp mnt/fuse7/r$n mnt/fuse7/w$n &
tasks+=$!" "
sleep 0.1
done
tasks+=$!
nbtasks=${#tasks[*]}
error=1
ended=
for ((n = 1; $TIMEOUT == 0 || n <= $TIMEOUT; n++)); do
sleep 1
for pid in ${tasks}; do
kill -0 $pid 2>/dev/null
if (! kill -0 $pid 2>/dev/null) || !(echo $ended | grep $pid); then
ended+=$pid" "
fi
done
if [ ${#ended[*]} == $nbtasks ]; then
error=0
break;
fi
done
for ((n = 1; n <= $nmax; n++)); do
sleep 1
cmp -b mnt/fuse7/r$n mnt/fuse7/w$n || {
echo "### Test KO", files are different
kilfuse
exit 1
}
done
if [ $error != 0 ]; then
echo "### Test KO", timeout reached
kilfuse
exit 1
fi
echo "*** Test OK"
remfuse
}
fuse8() {
echo Fuse: directory max entries:
prefuse
mkdir mnt/fuse8
maxent=512
for ((i = 0; i < $maxent; i++)); do
touch mnt/fuse8/ent$i
done
remfuse
prefuse
if [ `ls mnt/fuse8/ent* | wc -w` != $maxent ]; then
echo "### Test KO"
kilfuse
exit 1
else
echo "*** Test OK"
fi
remfuse
}
fuse9() {
echo Fuse: recover mode:
prefuse
mkdir mnt/fuse9
cp fatx mnt/fuse9/tbff0
rm mnt/fuse9/tbff0
remfuse
prefuse -r
test -e mnt/fuse9/tbff0 && cmp -b fatx mnt/fuse9/tbff0
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO", file not found or files are different
kilfuse
exit 1
fi
remfuse
}
fuse10() {
echo Fuse: FAT stress:
prefuse
mkdir mnt/fuse10
avail1=$(df -k mnt | tail -1 | tr -s ' ' | cut -f3 -d' ')
nmax=100
for ((n = 1; n <= $nmax; n++)); do
size=$[($RANDOM % 1000) + 1]
dd if=/dev/urandom of=mnt/fuse10/ent$n bs=$((size * 1024 + 256)) count=1 >/dev/null 2>&1
if [ `du -b mnt/fuse10/ent$n | cut -f 1` != $((size * 1024 + 256)) ]; then
echo "### Test KO", invalid file size
kilfuse
exit 1
fi
done
avail2=$(df -k mnt | tail -1 | tr -s ' ' | cut -f3 -d' ')
avail3=$(du -k mnt/fuse10 | tail -1 | cut -f1)
if [ $avail3 == $[$avail2 - $avail1] ]; then
echo "*** Test OK", Used = $avail3, Occupped = $[$avail2 - $avail1]
else
echo "### Test KO", Used = $avail3, Occupped = $[$avail2 - $avail1]
kilfuse
exit 1
fi
remfuse
}
fuse11() {
echo Fuse: directory entries stress:
prefuse
mkdir mnt/fuse11
maxent=1024
tasks=
for ((i = 0; i < $maxent; i++)); do
echo "TEST" >mnt/fuse11/ent$i &
tasks+=$!" "
done
for job in $tasks; do
wait $job
done
remfuse
prefuse
if [ `ls mnt/fuse11/ent* | wc -w` != $maxent ]; then
echo "### Test KO"
kilfuse
exit 1
else
echo "*** Test OK"
fi
remfuse
}
fuse12() {
echo Fuse: simultaneous creations:
prefuse
mkdir mnt/fuse12
maxent=100
tasks=
for ((i = 0; i < $maxent; i++)); do
echo "TEST" >mnt/fuse12/ent &
tasks+=$!" "
done
for job in $tasks; do
wait $job
done
remfuse
prefuse
if [ `ls mnt/fuse12/ent* | wc -w` != 1 ]; then
echo "### Test KO"
kilfuse
exit 1
else
echo "*** Test OK"
fi
remfuse
}
fuse13() {
echo Fuse: check statfs:
prefuse
rm -rf mnt/*
MIN=$(($(df -k mnt | tail -1 | tr -s ' ' | cut -f3 -d' ') / 2))
echo TEST >mnt/fuse13
[ $(($MIN * 4)) -ge $(df -k mnt | tail -1 | tr -s ' ' | cut -f3 -d' ') ]
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO, found "$(df -k mnt | tail -1 | tr -s ' ' | cut -f3 -d' ')" expected < "$(($MIN * 4))
kilfuse
exit 1
fi
remfuse
}
fsck1() {
echo Fsck: sanity check:
./fsck.fatx -nv $DSK 2>&1
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO"
exit 1
fi
}
labl1() {
echo Label: check default name:
./label.fatx $DSK 2>&1
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO"
exit 1
fi
}
labl2() {
echo Label: check noname:
prefuse
rm mnt/name.txt
remfuse
./label.fatx $DSK 2>&1
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO"
exit 1
fi
}
labl3() {
echo Label: set label
./label.fatx $DSK $DSK 2>&1
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO"
exit 1
fi
}
unrm1() {
echo Unrm: remote recovery:
prefuse
mkdir mnt/unrm1
cp fatx mnt/unrm1/tbff1
rm mnt/unrm1/tbff1
remfuse
./unrm.fatx -y $DSK 2>&1
if [ $? != 0 ]; then
echo "### Test KO", unrm failed
exit 1
fi
prefuse
test -e mnt/unrm1/tbff1 && cmp -b fatx mnt/unrm1/tbff1
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO", file not recovered or files are different
kilfuse
exit 1
fi
remfuse
}
unrm2() {
echo Unrm: remote dir. recovery:
prefuse
mkdir mnt/unrm2
cp fatx mnt/unrm2/tbff2
rm mnt/unrm2/tbff2
rmdir mnt/unrm2
remfuse
./unrm.fatx -y $DSK 2>&1
if [ $? != 0 ]; then
echo "### Test KO", unrm failed
exit 1
fi
prefuse
test -d mnt/unrm2 && test -e mnt/unrm2/tbff2 && cmp -b fatx mnt/unrm2/tbff2
if [ $? == 0 ]; then
echo "*** Test OK"
else
echo "### Test KO", file not recovered or files are different
kilfuse
exit 1
fi
remfuse
}
unrm3() {
echo Unrm: local recovery:
[ -e ./tbff3 ] && rm -f ./tbff3
prefuse
mkdir mnt/unrm3
cp fatx mnt/unrm3/tbff3
rm mnt/unrm3/tbff3
remfuse
./unrm.fatx -ly $DSK 2>&1
if [ $? != 0 ]; then
echo "### Test KO", unrm failed
exit 1
fi
test -e tbff3 && cmp -b fatx tbff3
if [ $? == 0 ]; then
echo "*** Test OK"
rm tbff3
else
echo "### Test KO", file not recovered or files are different
exit 1
fi
}
unrm4() {
echo Unrm: lost chain recovery:
./fatx --as mkfs disk.fatx -vy
dd if=/dev/urandom of=tbff4 bs=$((1024 * 1024 + 256)) count=1 >/dev/null 2>&1
./fatx --as label disk.fatx -l XBOX -v --do "\
mkdir, /unrm4; \
lsfat, /; \
lsfat, /name.txt; \
lsfat, /unrm4; \
rcp, tbff4, /unrm4/tbff4.bak; \
lsfat, /unrm4/tbff4.bak; \
rm, /unrm4/tbff4.bak; \
rmdir, /unrm4; \
mklost, 30:32; \
mklost, 40:42; \
mklost, 67:68; \
mklost, 100:110; \
rmfat, 31; \
"
./fatx --as fsck disk.fatx -vn
./fatx --as unrm disk.fatx -vy
./fatx --as fsck disk.fatx -vn
./fatx --as label disk.fatx -v --do "\
lsfat, /unrm4/tbff4.bak; \
lcp, /unrm4/tbff4.bak, tbff4.bak; \
"
cmp -b tbff4 tbff4.bak
if [ $? == 0 ]; then
echo "*** Test OK"
rm tbff4 tbff4.bak
else
echo "### Test KO", file not recovered or files are different
exit 1
fi
}
close() {
remove
rm $DSK
}
scenario() {
df -h mnt
cp -r debian mnt/
rm -rf mnt/debian
cp fatx mnt
mkdir mnt/fuse2
mkdir mnt/fuse2/dir1
mkdir mnt/fuse2/dir2
mv -f mnt/fatx mnt/fatx.bis
mv -f mnt/fatx.bis mnt/fuse2/fatx
mv -f mnt/fuse2/fatx mnt/fuse2/dir1/
mv -f mnt/fuse2/dir1 mnt/fuse2/dir3
mv -f mnt/fuse2/dir3 mnt/fuse2/dir2/
mkdir mnt/fuse7
nmax=10
for ((n = 1; n <= $nmax; n++)); do
dd if=/dev/urandom of=mnt/fuse7/r$n bs=$((1024*1024)) count=1 >/dev/null 2>&1
done
for ((n = 1; n < $nmax; n++)); do
cp mnt/fuse7/r$n mnt/fuse7/w$n &
done
wait
df -h mnt
sleep $WAIT
fusermount -u mnt
}
tests=(
close
mkfs1
fuse1
fuse2
fuse3
fuse4
fuse5
fuse6
fuse7
fuse8
fuse9
fuse10
fuse11
fuse12
fsck1
labl1
labl2
labl3
unrm1
unrm2
unrm3
fuse13
fsck1
unrm4
)
testn=`basename $0`
case $testn in
test.sh)
for ((i = 0; i < ${#tests[*]}; i++)); do
[ -e test$i ] || ln -s test.sh test$i
done
[ -e analyse.sh ] || ln -s test.sh analyse.sh
[ -e profile.sh ] || ln -s test.sh profile.sh
;;
analyse.sh)
rm [0-9A-F]*.log >/dev/null 2>&1
IFS=$'\n'
sed -e 's/\([^ ]\{2\} {[0-9A-F]\{8\}}\)/\n\1/g' >/tmp/$$$$
for pid in `cat /tmp/$$$$ | cut -f 2 -d\{ | cut -f 1 -d\} | grep ^[0-9A-F]*$ | sort | uniq`; do
grep $pid /tmp/$$$$ >$pid.log
done
rm /tmp/$$$$
;;
profile.sh)
#PRE=--gen-suppressions=all
./fatx --as mkfs -y $DSK
valgrind $PRE --tool=memcheck --log-file=./leaks1.log $CMDFUSE
scenario
./fatx --as mkfs -y $DSK
valgrind $PRE --tool=helgrind --log-file=./locks1.log $CMDFUSE
scenario
./fatx --as mkfs -y $DSK
valgrind $PRE --tool=drd --log-file=./locks2.log $CMDFUSE
scenario
;;
*)
testn=${testn/test/}
testr=${tests[$testn]}
if [ "$testr" != "unrm4" ]; then
trap kilfuse SIGINT
fi
prepare
$testr
;;
esac