Blame view

test/fs/fs-test.sh 17.8 KB
6c016485a   Suriyan Ramasami   sandbox: script f...
1
2
3
4
5
6
7
8
9
10
11
  #!/bin/bash
  #
  # (C) Copyright 2014 Suriyan Ramasami
  #
  #  SPDX-License-Identifier:	GPL-2.0+
  #
  
  # Invoke this test script from U-Boot base directory as ./test/fs/fs-test.sh
  # It currently tests the fs/sb and native commands for ext4 and fat partitions
  # Expected results are as follows:
  # EXT4 tests:
7c890f149   Tuomas Tynkkynen   fs-test: Add test...
12
13
14
  # fs-test.sb.ext4.out: Summary: PASS: 24 FAIL: 0
  # fs-test.ext4.out: Summary: PASS: 24 FAIL: 0
  # fs-test.fs.ext4.out: Summary: PASS: 24 FAIL: 0
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
15
  # FAT16 tests:
7c890f149   Tuomas Tynkkynen   fs-test: Add test...
16
17
18
  # fs-test.sb.fat16.out: Summary: PASS: 24 FAIL: 0
  # fs-test.fat16.out: Summary: PASS: 21 FAIL: 3
  # fs-test.fs.fat16.out: Summary: PASS: 21 FAIL: 3
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
19
  # FAT32 tests:
7c890f149   Tuomas Tynkkynen   fs-test: Add test...
20
21
22
23
  # fs-test.sb.fat32.out: Summary: PASS: 24 FAIL: 0
  # fs-test.fat32.out: Summary: PASS: 21 FAIL: 3
  # fs-test.fs.fat32.out: Summary: PASS: 21 FAIL: 3
  # Total Summary: TOTAL PASS: 204 TOTAL FAIL: 12
6c016485a   Suriyan Ramasami   sandbox: script f...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  
  # pre-requisite binaries list.
  PREREQ_BINS="md5sum mkfs mount umount dd fallocate mkdir"
  
  # All generated output files from this test will be in $OUT_DIR
  # Hence everything is sandboxed.
  OUT_DIR="sandbox/test/fs"
  
  # Location of generated sandbox u-boot
  UBOOT="./sandbox/u-boot"
  
  # Our mount directory will be in the sandbox
  MOUNT_DIR="${OUT_DIR}/mnt"
  
  # The file system image we create will have the $IMG prefix.
  IMG="${OUT_DIR}/3GB"
  
  # $SMALL_FILE is the name of the 1MB file in the file system image
  SMALL_FILE="1MB.file"
  
  # $BIG_FILE is the name of the 2.5GB file in the file system image
  BIG_FILE="2.5GB.file"
  
  # $MD5_FILE will have the expected md5s when we do the test
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
48
  # They shall have a suffix which represents their file system (ext4/fat16/...)
6c016485a   Suriyan Ramasami   sandbox: script f...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  MD5_FILE="${OUT_DIR}/md5s.list"
  
  # $OUT shall be the prefix of the test output. Their suffix will be .out
  OUT="${OUT_DIR}/fs-test"
  
  # Full Path of the 1 MB file that shall be created in the fs image.
  MB1="${MOUNT_DIR}/${SMALL_FILE}"
  GB2p5="${MOUNT_DIR}/${BIG_FILE}"
  
  # ************************
  # * Functions start here *
  # ************************
  
  # Check if the prereq binaries exist, or exit
  function check_prereq() {
  	for prereq in $PREREQ_BINS; do
47b716445   Stephen Warren   fs-test.sh: fix p...
65
  		if [ ! -x "`which $prereq`" ]; then
6c016485a   Suriyan Ramasami   sandbox: script f...
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
  			echo "Missing $prereq binary. Exiting!"
  			exit
  		fi
  	done
  
  	# We use /dev/urandom to create files. Check if it exists.
  	if [ ! -c /dev/urandom ]; then
  		echo "Missing character special /dev/urandom. Exiting!"
  		exit
  	fi
  }
  
  # If 1st param is "clean", then clean out the generated files and exit
  function check_clean() {
  	if [ "$1" = "clean" ]; then
  		rm -rf "$OUT_DIR"
  		echo "Cleaned up generated files. Exiting"
  		exit
  	fi
  }
  
  # Generate sandbox U-Boot - gleaned from /test/dm/test-dm.sh
  function compile_sandbox() {
  	unset CROSS_COMPILE
  	NUM_CPUS=$(cat /proc/cpuinfo |grep -c processor)
  	make O=sandbox sandbox_config
  	make O=sandbox -s -j${NUM_CPUS}
  
  	# Check if U-Boot exists
  	if [ ! -x "$UBOOT" ]; then
  		echo "$UBOOT does not exist or is not executable"
  		echo "Build error?"
  		echo "Please run this script as ./test/fs/`basename $0`"
  		exit
  	fi
  }
  
  # Clean out all generated files other than the file system images
  # We save time by not deleting and recreating the file system images
  function prepare_env() {
  	rm -f ${MD5_FILE}.* ${OUT}.*
08eee2718   Stephen Warren   test/fs: error ca...
107
  	mkdir -p ${OUT_DIR}
6c016485a   Suriyan Ramasami   sandbox: script f...
108
109
110
  }
  
  # 1st parameter is the name of the image file to be created
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
111
  # 2nd parameter is the filesystem - fat16 ext4 etc
6c016485a   Suriyan Ramasami   sandbox: script f...
112
113
114
  # -F cant be used with fat as it means something else.
  function create_image() {
  	# Create image if not already present - saves time, while debugging
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
115
116
117
118
119
120
121
122
123
124
  	case "$2" in
  		fat16)
  		MKFS_OPTION="-F 16"
  		FS_TYPE="fat"
  		;;
  		fat32)
  		MKFS_OPTION="-F 32"
  		FS_TYPE="fat"
  		;;
  		ext4)
6c016485a   Suriyan Ramasami   sandbox: script f...
125
  		MKFS_OPTION="-F"
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
126
127
128
  		FS_TYPE="ext4"
  		;;
  	esac
6c016485a   Suriyan Ramasami   sandbox: script f...
129
130
  	if [ ! -f "$1" ]; then
  		fallocate -l 3G "$1" &> /dev/null
08eee2718   Stephen Warren   test/fs: error ca...
131
132
133
134
135
136
137
138
  		if [ $? -ne 0 ]; then
  			echo fallocate failed - using dd instead
  			dd if=/dev/zero of=$1 bs=1024 count=$((3 * 1024 * 1024))
  			if [ $? -ne 0 ]; then
  				echo Could not create empty disk image
  				exit $?
  			fi
  		fi
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
139
140
  		mkfs -t "$FS_TYPE" $MKFS_OPTION "$1" &> /dev/null
  		if [ $? -ne 0 -a "$FS_TYPE" = "fat" ]; then
6c016485a   Suriyan Ramasami   sandbox: script f...
141
142
143
  			# If we fail and we did fat, try vfat.
  			mkfs -t vfat $MKFS_OPTION "$1" &> /dev/null
  		fi
08eee2718   Stephen Warren   test/fs: error ca...
144
145
146
147
  		if [ $? -ne 0 ]; then
  			echo Could not create filesystem
  			exit $?
  		fi
6c016485a   Suriyan Ramasami   sandbox: script f...
148
149
  	fi
  }
6c016485a   Suriyan Ramasami   sandbox: script f...
150
  # 1st parameter is image file
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
151
  # 2nd parameter is file system type - fat16/ext4/...
6c016485a   Suriyan Ramasami   sandbox: script f...
152
153
154
155
156
157
158
159
160
161
162
163
  # 3rd parameter is name of small file
  # 4th parameter is name of big file
  # 5th parameter is fs/nonfs/sb - to dictate generic fs commands or
  # otherwise or sb hostfs
  # 6th parameter is the directory path for the files. Its "" for generic
  # fs and ext4/fat and full patch for sb hostfs
  # UBOOT is set in env
  function test_image() {
  	addr="0x01000008"
  	length="0x00100000"
  
  	case "$2" in
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
164
  		fat*)
86853568a   Stefan Brüns   test/fs: Restruct...
165
  		FPATH=""
6c016485a   Suriyan Ramasami   sandbox: script f...
166
167
168
169
170
  		PREFIX="fat"
  		WRITE="write"
  		;;
  
  		ext4)
86853568a   Stefan Brüns   test/fs: Restruct...
171
172
  		# ext4 needs absolute path
  		FPATH="/"
6c016485a   Suriyan Ramasami   sandbox: script f...
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
  		PREFIX="ext4"
  		WRITE="write"
  		;;
  
  		*)
  		echo "Unhandled filesystem $2. Exiting!"
  		exit
  		;;
  	esac
  
  	case "$5" in
  		fs)
  		PREFIX=""
  		WRITE="save"
  		SUFFIX=" 0:0"
  		;;
  
  		nonfs)
  		SUFFIX=" 0:0"
  		;;
  
  		sb)
  		PREFIX="sb "
  		WRITE="save"
  		SUFFIX="fs -"
  		;;
  
  		*)
  		echo "Unhandled mode $5. Exiting!"
  		exit
  		;;
  
  	esac
86853568a   Stefan Brüns   test/fs: Restruct...
206
207
208
  	# sb always uses full path to mointpoint, irrespective of filesystem
  	if [ "$5" = "sb" ]; then
  		FPATH=${6}/
6c016485a   Suriyan Ramasami   sandbox: script f...
209
  	fi
86853568a   Stefan Brüns   test/fs: Restruct...
210
211
212
  	FILE_WRITE=${3}.w
  	FILE_SMALL=$3
  	FILE_BIG=$4
6c016485a   Suriyan Ramasami   sandbox: script f...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  	# In u-boot commands, <interface> stands for host or hostfs
  	# hostfs maps to the host fs.
  	# host maps to the "sb bind" that we do
  
  	$UBOOT << EOF
  sb=$5
  setenv bind 'if test "\$sb" != sb; then sb bind 0 "$1"; fi'
  run bind
  # Test Case 1 - ls
  ${PREFIX}ls host${SUFFIX} $6
  #
  # We want ${PREFIX}size host 0:0 $3 for host commands and
  # sb size hostfs - $3 for hostfs commands.
  # 1MB is 0x0010 0000
7c890f149   Tuomas Tynkkynen   fs-test: Add test...
227
  # Test Case 2a - size of small file
86853568a   Stefan Brüns   test/fs: Restruct...
228
  ${PREFIX}size host${SUFFIX} ${FPATH}$FILE_SMALL
6c016485a   Suriyan Ramasami   sandbox: script f...
229
230
  printenv filesize
  setenv filesize
7c890f149   Tuomas Tynkkynen   fs-test: Add test...
231
232
233
234
  # Test Case 2b - size of small file via a path using '..'
  ${PREFIX}size host${SUFFIX} ${FPATH}SUBDIR/../$FILE_SMALL
  printenv filesize
  setenv filesize
6c016485a   Suriyan Ramasami   sandbox: script f...
235
236
237
  
  # 2.5GB (1024*1024*2500) is 0x9C40 0000
  # Test Case 3 - size of big file
86853568a   Stefan Brüns   test/fs: Restruct...
238
  ${PREFIX}size host${SUFFIX} ${FPATH}$FILE_BIG
6c016485a   Suriyan Ramasami   sandbox: script f...
239
240
241
242
243
244
245
246
  printenv filesize
  setenv filesize
  
  # Notes about load operation
  # If I use 0x01000000 I get DMA misaligned error message
  # Last two parameters are size and offset.
  
  # Test Case 4a - Read full 1MB of small file
86853568a   Stefan Brüns   test/fs: Restruct...
247
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
6c016485a   Suriyan Ramasami   sandbox: script f...
248
249
250
251
252
253
  printenv filesize
  # Test Case 4b - Read full 1MB of small file
  md5sum $addr \$filesize
  setenv filesize
  
  # Test Case 5a - First 1MB of big file
86853568a   Stefan Brüns   test/fs: Restruct...
254
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x0
6c016485a   Suriyan Ramasami   sandbox: script f...
255
256
257
258
259
260
261
  printenv filesize
  # Test Case 5b - First 1MB of big file
  md5sum $addr \$filesize
  setenv filesize
  
  # fails for ext as no offset support
  # Test Case 6a - Last 1MB of big file
86853568a   Stefan Brüns   test/fs: Restruct...
262
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x9C300000
6c016485a   Suriyan Ramasami   sandbox: script f...
263
264
265
266
267
268
269
  printenv filesize
  # Test Case 6b - Last 1MB of big file
  md5sum $addr \$filesize
  setenv filesize
  
  # fails for ext as no offset support
  # Test Case 7a - One from the last 1MB chunk of 2GB
86853568a   Stefan Brüns   test/fs: Restruct...
270
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x7FF00000
6c016485a   Suriyan Ramasami   sandbox: script f...
271
272
273
274
275
276
277
  printenv filesize
  # Test Case 7b - One from the last 1MB chunk of 2GB
  md5sum $addr \$filesize
  setenv filesize
  
  # fails for ext as no offset support
  # Test Case 8a - One from the start 1MB chunk from 2GB
86853568a   Stefan Brüns   test/fs: Restruct...
278
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x80000000
6c016485a   Suriyan Ramasami   sandbox: script f...
279
280
281
282
283
284
285
  printenv filesize
  # Test Case 8b - One from the start 1MB chunk from 2GB
  md5sum $addr \$filesize
  setenv filesize
  
  # fails for ext as no offset support
  # Test Case 9a - One 1MB chunk crossing the 2GB boundary
86853568a   Stefan Brüns   test/fs: Restruct...
286
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x7FF80000
6c016485a   Suriyan Ramasami   sandbox: script f...
287
288
289
290
291
292
293
  printenv filesize
  # Test Case 9b - One 1MB chunk crossing the 2GB boundary
  md5sum $addr \$filesize
  setenv filesize
  
  # Generic failure case
  # Test Case 10 - 2MB chunk from the last 1MB of big file
86853568a   Stefan Brüns   test/fs: Restruct...
294
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG 0x00200000 0x9C300000
6c016485a   Suriyan Ramasami   sandbox: script f...
295
296
297
298
  printenv filesize
  #
  
  # Read 1MB from small file
86853568a   Stefan Brüns   test/fs: Restruct...
299
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
6c016485a   Suriyan Ramasami   sandbox: script f...
300
301
  # Write it back to test the writes
  # Test Case 11a - Check that the write succeeded
86853568a   Stefan Brüns   test/fs: Restruct...
302
  ${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}$FILE_WRITE \$filesize
6c016485a   Suriyan Ramasami   sandbox: script f...
303
  mw.b $addr 00 100
86853568a   Stefan Brüns   test/fs: Restruct...
304
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_WRITE
6c016485a   Suriyan Ramasami   sandbox: script f...
305
306
307
308
  # Test Case 11b - Check md5 of written to is same as the one read from
  md5sum $addr \$filesize
  setenv filesize
  #
14678b3c6   Stefan Brüns   test/fs: Check ex...
309
310
311
312
313
314
  
  # Next test case checks writing a file whose dirent
  # is the first in the block, which is always true for "."
  # The write should fail, but the lookup should work
  # Test Case 12 - Check directory traversal
  ${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}. 0x10
2365a4b8e   Stefan Brüns   test/fs: Check wr...
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
  
  # Read 1MB from small file
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
  # Write it via "same directory", i.e. "." dirent
  # Test Case 13a - Check directory traversal
  ${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}./${FILE_WRITE}2 \$filesize
  mw.b $addr 00 100
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}./${FILE_WRITE}2
  # Test Case 13b - Check md5 of written to is same as the one read from
  md5sum $addr \$filesize
  setenv filesize
  mw.b $addr 00 100
  ${PREFIX}load host${SUFFIX} $addr ${FPATH}${FILE_WRITE}2
  # Test Case 13c - Check md5 of written to is same as the one read from
  md5sum $addr \$filesize
  setenv filesize
  #
6c016485a   Suriyan Ramasami   sandbox: script f...
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
  reset
  
  EOF
  }
  
  # 1st argument is the name of the image file.
  # 2nd argument is the file where we generate the md5s of the files
  # generated with the appropriate start and length that we use to test.
  # It creates the necessary files in the image to test.
  # $GB2p5 is the path of the big file (2.5 GB)
  # $MB1 is the path of the small file (1 MB)
  # $MOUNT_DIR is the path we can use to mount the image file.
  function create_files() {
  	# Mount the image so we can populate it.
  	mkdir -p "$MOUNT_DIR"
  	sudo mount -o loop,rw "$1" "$MOUNT_DIR"
7c890f149   Tuomas Tynkkynen   fs-test: Add test...
348
349
  	# Create a subdirectory.
  	sudo mkdir -p "$MOUNT_DIR/SUBDIR"
6c016485a   Suriyan Ramasami   sandbox: script f...
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
  	# Create big file in this image.
  	# Note that we work only on the start 1MB, couple MBs in the 2GB range
  	# and the last 1 MB of the huge 2.5GB file.
  	# So, just put random values only in those areas.
  	if [ ! -f "${GB2p5}" ]; then
  		sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 \
  			&> /dev/null
  		sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=2 seek=2047 \
  			&> /dev/null
  		sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 seek=2499 \
  			&> /dev/null
  	fi
  
  	# Create a small file in this image.
  	if [ ! -f "${MB1}" ]; then
  		sudo dd if=/dev/urandom of="${MB1}" bs=1M count=1 \
  			&> /dev/null
  	fi
2365a4b8e   Stefan Brüns   test/fs: Check wr...
368
  	# Delete the small file copies which possibly are written as part of a
6c016485a   Suriyan Ramasami   sandbox: script f...
369
370
  	# previous test.
  	sudo rm -f "${MB1}.w"
2365a4b8e   Stefan Brüns   test/fs: Check wr...
371
  	sudo rm -f "${MB1}.w2"
6c016485a   Suriyan Ramasami   sandbox: script f...
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
  
  	# Generate the md5sums of reads that we will test against small file
  	dd if="${MB1}" bs=1M skip=0 count=1 2> /dev/null | md5sum > "$2"
  
  	# Generate the md5sums of reads that we will test against big file
  	# One from beginning of file.
  	dd if="${GB2p5}" bs=1M skip=0 count=1 \
  		2> /dev/null | md5sum >> "$2"
  
  	# One from end of file.
  	dd if="${GB2p5}" bs=1M skip=2499 count=1 \
  		2> /dev/null | md5sum >> "$2"
  
  	# One from the last 1MB chunk of 2GB
  	dd if="${GB2p5}" bs=1M skip=2047 count=1 \
  		2> /dev/null | md5sum >> "$2"
  
  	# One from the start 1MB chunk from 2GB
  	dd if="${GB2p5}" bs=1M skip=2048 count=1 \
  		2> /dev/null | md5sum >> "$2"
  
  	# One 1MB chunk crossing the 2GB boundary
  	dd if="${GB2p5}" bs=512K skip=4095 count=2 \
  		2> /dev/null | md5sum >> "$2"
  
  	sync
  	sudo umount "$MOUNT_DIR"
  	rmdir "$MOUNT_DIR"
  }
  
  # 1st parameter is the text to print
  # if $? is 0 its a pass, else a fail
  # As a side effect it shall update env variable PASS and FAIL
  function pass_fail() {
  	if [ $? -eq 0 ]; then
  		echo pass - "$1"
  		PASS=$((PASS + 1))
  	else
  		echo FAIL - "$1"
  		FAIL=$((FAIL + 1))
  	fi
  }
  
  # 1st parameter is the string which leads to an md5 generation
  # 2nd parameter is the file we grep, for that string
  # 3rd parameter is the name of the file which has md5s in it
  # 4th parameter is the line # in the md5 file that we match it against
  # This function checks if the md5 of the file in the sandbox matches
  # that calculated while generating the file
  # 5th parameter is the string to print with the result
  check_md5() {
  	# md5sum in u-boot has output of form:
  	# md5 for 01000008 ... 01100007 ==> <md5>
  	# the 7th field is the actual md5
d9554b7f4   Stefan Brüns   test/fs: strip no...
426
  	md5_src=`grep -A2 "$1" "$2" | grep "md5 for" | tr -d '\r'`
6c016485a   Suriyan Ramasami   sandbox: script f...
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
  	md5_src=($md5_src)
  	md5_src=${md5_src[6]}
  
  	# The md5 list, each line is of the form:
  	# - <md5>
  	# the 2nd field is the actual md5
  	md5_dst=`sed -n $4p $3`
  	md5_dst=($md5_dst)
  	md5_dst=${md5_dst[0]}
  
  	# For a pass they should match.
  	[ "$md5_src" = "$md5_dst" ]
  	pass_fail "$5"
  }
  
  # 1st parameter is the name of the output file to check
  # 2nd parameter is the name of the file containing the md5 expected
  # 3rd parameter is the name of the small file
  # 4th parameter is the name of the big file
  # 5th paramter is the name of the written file
  # This function checks the output file for correct results.
  function check_results() {
  	echo "** Start $1"
  
  	PASS=0
  	FAIL=0
  
  	# Check if the ls is showing correct results for 2.5 gb file
7c890f149   Tuomas Tynkkynen   fs-test: Add test...
455
  	grep -A7 "Test Case 1 " "$1" | egrep -iq "2621440000 *$4"
6c016485a   Suriyan Ramasami   sandbox: script f...
456
457
458
  	pass_fail "TC1: ls of $4"
  
  	# Check if the ls is showing correct results for 1 mb file
7c890f149   Tuomas Tynkkynen   fs-test: Add test...
459
  	grep -A7 "Test Case 1 " "$1" | egrep -iq "1048576 *$3"
6c016485a   Suriyan Ramasami   sandbox: script f...
460
461
462
  	pass_fail "TC1: ls of $3"
  
  	# Check size command on 1MB.file
7c890f149   Tuomas Tynkkynen   fs-test: Add test...
463
  	egrep -A3 "Test Case 2a " "$1" | grep -q "filesize=100000"
6c016485a   Suriyan Ramasami   sandbox: script f...
464
  	pass_fail "TC2: size of $3"
7c890f149   Tuomas Tynkkynen   fs-test: Add test...
465
466
467
  	# Check size command on 1MB.file via a path using '..'
  	egrep -A3 "Test Case 2b " "$1" | grep -q "filesize=100000"
  	pass_fail "TC2: size of $3 via a path using '..'"
6c016485a   Suriyan Ramasami   sandbox: script f...
468
469
470
471
472
473
  
  	# Check size command on 2.5GB.file
  	egrep -A3 "Test Case 3 " "$1" | grep -q "filesize=9c400000"
  	pass_fail "TC3: size of $4"
  
  	# Check read full mb of 1MB.file
d9554b7f4   Stefan Brüns   test/fs: strip no...
474
  	grep -A4 "Test Case 4a " "$1" | grep -q "filesize=100000"
6c016485a   Suriyan Ramasami   sandbox: script f...
475
476
477
478
  	pass_fail "TC4: load of $3 size"
  	check_md5 "Test Case 4b " "$1" "$2" 1 "TC4: load from $3"
  
  	# Check first mb of 2.5GB.file
d9554b7f4   Stefan Brüns   test/fs: strip no...
479
  	grep -A4 "Test Case 5a " "$1" | grep -q "filesize=100000"
6c016485a   Suriyan Ramasami   sandbox: script f...
480
481
482
483
  	pass_fail "TC5: load of 1st MB from $4 size"
  	check_md5 "Test Case 5b " "$1" "$2" 2 "TC5: load of 1st MB from $4"
  
  	# Check last mb of 2.5GB.file
d9554b7f4   Stefan Brüns   test/fs: strip no...
484
  	grep -A4 "Test Case 6a " "$1" | grep -q "filesize=100000"
6c016485a   Suriyan Ramasami   sandbox: script f...
485
486
487
488
  	pass_fail "TC6: load of last MB from $4 size"
  	check_md5 "Test Case 6b " "$1" "$2" 3 "TC6: load of last MB from $4"
  
  	# Check last 1mb chunk of 2gb from 2.5GB file
d9554b7f4   Stefan Brüns   test/fs: strip no...
489
  	grep -A4 "Test Case 7a " "$1" | grep -q "filesize=100000"
6c016485a   Suriyan Ramasami   sandbox: script f...
490
491
492
493
494
  	pass_fail "TC7: load of last 1mb chunk of 2GB from $4 size"
  	check_md5 "Test Case 7b " "$1" "$2" 4 \
  		"TC7: load of last 1mb chunk of 2GB from $4"
  
  	# Check first 1mb chunk after 2gb from 2.5GB file
d9554b7f4   Stefan Brüns   test/fs: strip no...
495
  	grep -A4 "Test Case 8a " "$1" | grep -q "filesize=100000"
6c016485a   Suriyan Ramasami   sandbox: script f...
496
497
498
499
500
  	pass_fail "TC8: load 1st MB chunk after 2GB from $4 size"
  	check_md5 "Test Case 8b " "$1" "$2" 5 \
  		"TC8: load 1st MB chunk after 2GB from $4"
  
  	# Check 1mb chunk crossing the 2gb boundary from 2.5GB file
d9554b7f4   Stefan Brüns   test/fs: strip no...
501
  	grep -A4 "Test Case 9a " "$1" | grep -q "filesize=100000"
6c016485a   Suriyan Ramasami   sandbox: script f...
502
503
504
  	pass_fail "TC9: load 1MB chunk crossing 2GB boundary from $4 size"
  	check_md5 "Test Case 9b " "$1" "$2" 6 \
  		"TC9: load 1MB chunk crossing 2GB boundary from $4"
e8de6d7b4   Tom Rini   test/fs/fs-test.s...
505
  	# Check 2mb chunk from the last 1MB of 2.5GB file loads 1MB
d9554b7f4   Stefan Brüns   test/fs: strip no...
506
  	grep -A5 "Test Case 10 " "$1" | grep -q "filesize=100000"
e8de6d7b4   Tom Rini   test/fs/fs-test.s...
507
  	pass_fail "TC10: load 2MB from the last 1MB of $4 loads 1MB"
6c016485a   Suriyan Ramasami   sandbox: script f...
508
509
  
  	# Check 1mb chunk write
d9554b7f4   Stefan Brüns   test/fs: strip no...
510
  	grep -A2 "Test Case 11a " "$1" | grep -q '1048576 bytes written'
06806e38d   Stefan Brüns   test/fs: remove u...
511
  	pass_fail "TC11: 1MB write to $3.w - write succeeded"
6c016485a   Suriyan Ramasami   sandbox: script f...
512
  	check_md5 "Test Case 11b " "$1" "$2" 1 \
06806e38d   Stefan Brüns   test/fs: remove u...
513
  		"TC11: 1MB write to $3.w - content verified"
14678b3c6   Stefan Brüns   test/fs: Check ex...
514
515
516
517
  
  	# Check lookup of 'dot' directory
  	grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write file'
  	pass_fail "TC12: 1MB write to . - write denied"
2365a4b8e   Stefan Brüns   test/fs: Check wr...
518
519
520
521
522
523
524
525
  
  	# Check directory traversal
  	grep -A2 "Test Case 13a " "$1" | grep -q '1048576 bytes written'
  	pass_fail "TC13: 1MB write to ./$3.w2 - write succeeded"
  	check_md5 "Test Case 13b " "$1" "$2" 1 \
  		"TC13: 1MB read from ./$3.w2 - content verified"
  	check_md5 "Test Case 13c " "$1" "$2" 1 \
  		"TC13: 1MB read from $3.w2 - content verified"
6c016485a   Suriyan Ramasami   sandbox: script f...
526
527
528
529
530
531
532
533
534
  	echo "** End $1"
  }
  
  # Takes in one parameter which is "fs" or "nonfs", which then dictates
  # if a fs test (size/load/save) or a nonfs test (fatread/extread) needs to
  # be performed.
  function test_fs_nonfs() {
  	echo "Creating files in $fs image if not already present."
  	create_files $IMAGE $MD5_FILE_FS
04812605f   Stephen Warren   fs-test.sh: minor...
535
  	OUT_FILE="${OUT}.$1.${fs}.out"
6c016485a   Suriyan Ramasami   sandbox: script f...
536
  	test_image $IMAGE $fs $SMALL_FILE $BIG_FILE $1 "" \
04812605f   Stephen Warren   fs-test.sh: minor...
537
  		> ${OUT_FILE} 2>&1
d9554b7f4   Stefan Brüns   test/fs: strip no...
538
539
540
541
542
543
  	# strip out noise from fs code
  	grep -v -e "File System is consistent\|update journal finished" \
  		-e "reading .*\.file\|writing .*\.file.w" \
  		< ${OUT_FILE} > ${OUT_FILE}_clean
  	check_results ${OUT_FILE}_clean $MD5_FILE_FS $SMALL_FILE \
  		$BIG_FILE
6c016485a   Suriyan Ramasami   sandbox: script f...
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
  	TOTAL_FAIL=$((TOTAL_FAIL + FAIL))
  	TOTAL_PASS=$((TOTAL_PASS + PASS))
  	echo "Summary: PASS: $PASS FAIL: $FAIL"
  	echo "--------------------------------------------"
  }
  
  # ********************
  # * End of functions *
  # ********************
  
  check_clean "$1"
  check_prereq
  compile_sandbox
  prepare_env
  
  # Track TOTAL_FAIL and TOTAL_PASS
  TOTAL_FAIL=0
  TOTAL_PASS=0
  
  # In each loop, for a given file system image, we test both the
  # fs command, like load/size/write, the file system specific command
  # like: ext4load/ext4size/ext4write and the sb load/ls/save commands.
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
566
  for fs in ext4 fat16 fat32; do
6c016485a   Suriyan Ramasami   sandbox: script f...
567
568
569
570
571
572
573
574
575
576
577
578
  
  	echo "Creating $fs image if not already present."
  	IMAGE=${IMG}.${fs}.img
  	MD5_FILE_FS="${MD5_FILE}.${fs}"
  	create_image $IMAGE $fs
  
  	# sb commands test
  	echo "Creating files in $fs image if not already present."
  	create_files $IMAGE $MD5_FILE_FS
  
  	# Lets mount the image and test sb hostfs commands
  	mkdir -p "$MOUNT_DIR"
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
579
580
  	case "$fs" in
  		fat*)
6c016485a   Suriyan Ramasami   sandbox: script f...
581
  		uid="uid=`id -u`"
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
582
583
  		;;
  		*)
6c016485a   Suriyan Ramasami   sandbox: script f...
584
  		uid=""
edce588a4   Tuomas Tynkkynen   fs-test: Add FAT1...
585
586
  		;;
  	esac
6c016485a   Suriyan Ramasami   sandbox: script f...
587
588
589
590
591
  	sudo mount -o loop,rw,$uid "$IMAGE" "$MOUNT_DIR"
  	sudo chmod 777 "$MOUNT_DIR"
  
  	OUT_FILE="${OUT}.sb.${fs}.out"
  	test_image $IMAGE $fs $SMALL_FILE $BIG_FILE sb `pwd`/$MOUNT_DIR \
04812605f   Stephen Warren   fs-test.sh: minor...
592
  		> ${OUT_FILE} 2>&1
6c016485a   Suriyan Ramasami   sandbox: script f...
593
594
  	sudo umount "$MOUNT_DIR"
  	rmdir "$MOUNT_DIR"
06806e38d   Stefan Brüns   test/fs: remove u...
595
  	check_results $OUT_FILE $MD5_FILE_FS $SMALL_FILE $BIG_FILE
6c016485a   Suriyan Ramasami   sandbox: script f...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
  	TOTAL_FAIL=$((TOTAL_FAIL + FAIL))
  	TOTAL_PASS=$((TOTAL_PASS + PASS))
  	echo "Summary: PASS: $PASS FAIL: $FAIL"
  	echo "--------------------------------------------"
  
  	test_fs_nonfs nonfs
  	test_fs_nonfs fs
  done
  
  echo "Total Summary: TOTAL PASS: $TOTAL_PASS TOTAL FAIL: $TOTAL_FAIL"
  echo "--------------------------------------------"
  if [ $TOTAL_FAIL -eq 0 ]; then
  	echo "PASSED"
  	exit 0
  else
  	echo "FAILED"
  	exit 1
  fi