blob: b6b9461a107391df712e951a49df8a414f03f9ae [file] [log] [blame]
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -08001#!/bin/bash
Tom Rini70df9d62018-05-07 17:02:21 -04002# SPDX-License-Identifier: GPL-2.0+
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -08003#
4# (C) Copyright 2014 Suriyan Ramasami
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -08005
6# Invoke this test script from U-Boot base directory as ./test/fs/fs-test.sh
7# It currently tests the fs/sb and native commands for ext4 and fat partitions
8# Expected results are as follows:
9# EXT4 tests:
Tuomas Tynkkynend1c9e802017-09-25 22:06:34 +030010# fs-test.sb.ext4.out: Summary: PASS: 24 FAIL: 0
11# fs-test.ext4.out: Summary: PASS: 24 FAIL: 0
12# fs-test.fs.ext4.out: Summary: PASS: 24 FAIL: 0
Tuomas Tynkkynene304b022017-09-25 22:06:32 +030013# FAT16 tests:
Tuomas Tynkkynend1c9e802017-09-25 22:06:34 +030014# fs-test.sb.fat16.out: Summary: PASS: 24 FAIL: 0
15# fs-test.fat16.out: Summary: PASS: 21 FAIL: 3
16# fs-test.fs.fat16.out: Summary: PASS: 21 FAIL: 3
Tuomas Tynkkynene304b022017-09-25 22:06:32 +030017# FAT32 tests:
Tuomas Tynkkynend1c9e802017-09-25 22:06:34 +030018# fs-test.sb.fat32.out: Summary: PASS: 24 FAIL: 0
19# fs-test.fat32.out: Summary: PASS: 21 FAIL: 3
20# fs-test.fs.fat32.out: Summary: PASS: 21 FAIL: 3
21# Total Summary: TOTAL PASS: 204 TOTAL FAIL: 12
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -080022
23# pre-requisite binaries list.
24PREREQ_BINS="md5sum mkfs mount umount dd fallocate mkdir"
25
26# All generated output files from this test will be in $OUT_DIR
27# Hence everything is sandboxed.
28OUT_DIR="sandbox/test/fs"
29
30# Location of generated sandbox u-boot
31UBOOT="./sandbox/u-boot"
32
33# Our mount directory will be in the sandbox
34MOUNT_DIR="${OUT_DIR}/mnt"
35
36# The file system image we create will have the $IMG prefix.
37IMG="${OUT_DIR}/3GB"
38
39# $SMALL_FILE is the name of the 1MB file in the file system image
40SMALL_FILE="1MB.file"
41
42# $BIG_FILE is the name of the 2.5GB file in the file system image
43BIG_FILE="2.5GB.file"
44
45# $MD5_FILE will have the expected md5s when we do the test
Tuomas Tynkkynene304b022017-09-25 22:06:32 +030046# They shall have a suffix which represents their file system (ext4/fat16/...)
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -080047MD5_FILE="${OUT_DIR}/md5s.list"
48
49# $OUT shall be the prefix of the test output. Their suffix will be .out
50OUT="${OUT_DIR}/fs-test"
51
52# Full Path of the 1 MB file that shall be created in the fs image.
53MB1="${MOUNT_DIR}/${SMALL_FILE}"
54GB2p5="${MOUNT_DIR}/${BIG_FILE}"
55
56# ************************
57# * Functions start here *
58# ************************
59
60# Check if the prereq binaries exist, or exit
61function check_prereq() {
62 for prereq in $PREREQ_BINS; do
Stephen Warren86b30bd2015-10-03 13:56:48 -060063 if [ ! -x "`which $prereq`" ]; then
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -080064 echo "Missing $prereq binary. Exiting!"
65 exit
66 fi
67 done
68
69 # We use /dev/urandom to create files. Check if it exists.
70 if [ ! -c /dev/urandom ]; then
71 echo "Missing character special /dev/urandom. Exiting!"
72 exit
73 fi
74}
75
76# If 1st param is "clean", then clean out the generated files and exit
77function check_clean() {
78 if [ "$1" = "clean" ]; then
79 rm -rf "$OUT_DIR"
80 echo "Cleaned up generated files. Exiting"
81 exit
82 fi
83}
84
85# Generate sandbox U-Boot - gleaned from /test/dm/test-dm.sh
86function compile_sandbox() {
87 unset CROSS_COMPILE
88 NUM_CPUS=$(cat /proc/cpuinfo |grep -c processor)
89 make O=sandbox sandbox_config
90 make O=sandbox -s -j${NUM_CPUS}
91
92 # Check if U-Boot exists
93 if [ ! -x "$UBOOT" ]; then
94 echo "$UBOOT does not exist or is not executable"
95 echo "Build error?"
96 echo "Please run this script as ./test/fs/`basename $0`"
97 exit
98 fi
99}
100
101# Clean out all generated files other than the file system images
102# We save time by not deleting and recreating the file system images
103function prepare_env() {
104 rm -f ${MD5_FILE}.* ${OUT}.*
Stephen Warrenb2a30002015-12-14 15:01:15 -0700105 mkdir -p ${OUT_DIR}
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800106}
107
108# 1st parameter is the name of the image file to be created
Tuomas Tynkkynene304b022017-09-25 22:06:32 +0300109# 2nd parameter is the filesystem - fat16 ext4 etc
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800110# -F cant be used with fat as it means something else.
111function create_image() {
112 # Create image if not already present - saves time, while debugging
Tuomas Tynkkynene304b022017-09-25 22:06:32 +0300113 case "$2" in
114 fat16)
115 MKFS_OPTION="-F 16"
116 FS_TYPE="fat"
117 ;;
118 fat32)
119 MKFS_OPTION="-F 32"
120 FS_TYPE="fat"
121 ;;
122 ext4)
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800123 MKFS_OPTION="-F"
Tuomas Tynkkynene304b022017-09-25 22:06:32 +0300124 FS_TYPE="ext4"
125 ;;
126 esac
127
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800128 if [ ! -f "$1" ]; then
129 fallocate -l 3G "$1" &> /dev/null
Stephen Warrenb2a30002015-12-14 15:01:15 -0700130 if [ $? -ne 0 ]; then
131 echo fallocate failed - using dd instead
132 dd if=/dev/zero of=$1 bs=1024 count=$((3 * 1024 * 1024))
133 if [ $? -ne 0 ]; then
134 echo Could not create empty disk image
135 exit $?
136 fi
137 fi
Tuomas Tynkkynene304b022017-09-25 22:06:32 +0300138 mkfs -t "$FS_TYPE" $MKFS_OPTION "$1" &> /dev/null
139 if [ $? -ne 0 -a "$FS_TYPE" = "fat" ]; then
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800140 # If we fail and we did fat, try vfat.
141 mkfs -t vfat $MKFS_OPTION "$1" &> /dev/null
142 fi
Stephen Warrenb2a30002015-12-14 15:01:15 -0700143 if [ $? -ne 0 ]; then
144 echo Could not create filesystem
145 exit $?
146 fi
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800147 fi
148}
149
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800150# 1st parameter is image file
Tuomas Tynkkynene304b022017-09-25 22:06:32 +0300151# 2nd parameter is file system type - fat16/ext4/...
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800152# 3rd parameter is name of small file
153# 4th parameter is name of big file
154# 5th parameter is fs/nonfs/sb - to dictate generic fs commands or
155# otherwise or sb hostfs
156# 6th parameter is the directory path for the files. Its "" for generic
157# fs and ext4/fat and full patch for sb hostfs
158# UBOOT is set in env
159function test_image() {
160 addr="0x01000008"
161 length="0x00100000"
162
163 case "$2" in
Tuomas Tynkkynene304b022017-09-25 22:06:32 +0300164 fat*)
Stefan Brüns24d84802016-09-14 01:01:27 +0200165 FPATH=""
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800166 PREFIX="fat"
167 WRITE="write"
168 ;;
169
170 ext4)
Stefan Brüns24d84802016-09-14 01:01:27 +0200171 # ext4 needs absolute path
172 FPATH="/"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800173 PREFIX="ext4"
174 WRITE="write"
175 ;;
176
177 *)
178 echo "Unhandled filesystem $2. Exiting!"
179 exit
180 ;;
181 esac
182
183 case "$5" in
184 fs)
185 PREFIX=""
186 WRITE="save"
187 SUFFIX=" 0:0"
188 ;;
189
190 nonfs)
191 SUFFIX=" 0:0"
192 ;;
193
194 sb)
195 PREFIX="sb "
196 WRITE="save"
197 SUFFIX="fs -"
198 ;;
199
200 *)
201 echo "Unhandled mode $5. Exiting!"
202 exit
203 ;;
204
205 esac
206
Stefan Brüns24d84802016-09-14 01:01:27 +0200207 # sb always uses full path to mointpoint, irrespective of filesystem
208 if [ "$5" = "sb" ]; then
209 FPATH=${6}/
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800210 fi
211
Stefan Brüns24d84802016-09-14 01:01:27 +0200212 FILE_WRITE=${3}.w
213 FILE_SMALL=$3
214 FILE_BIG=$4
215
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800216 # In u-boot commands, <interface> stands for host or hostfs
217 # hostfs maps to the host fs.
218 # host maps to the "sb bind" that we do
219
220 $UBOOT << EOF
221sb=$5
222setenv bind 'if test "\$sb" != sb; then sb bind 0 "$1"; fi'
223run bind
224# Test Case 1 - ls
225${PREFIX}ls host${SUFFIX} $6
226#
227# We want ${PREFIX}size host 0:0 $3 for host commands and
228# sb size hostfs - $3 for hostfs commands.
229# 1MB is 0x0010 0000
Tuomas Tynkkynend1c9e802017-09-25 22:06:34 +0300230# Test Case 2a - size of small file
Stefan Brüns24d84802016-09-14 01:01:27 +0200231${PREFIX}size host${SUFFIX} ${FPATH}$FILE_SMALL
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800232printenv filesize
233setenv filesize
Tuomas Tynkkynend1c9e802017-09-25 22:06:34 +0300234# Test Case 2b - size of small file via a path using '..'
235${PREFIX}size host${SUFFIX} ${FPATH}SUBDIR/../$FILE_SMALL
236printenv filesize
237setenv filesize
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800238
239# 2.5GB (1024*1024*2500) is 0x9C40 0000
240# Test Case 3 - size of big file
Stefan Brüns24d84802016-09-14 01:01:27 +0200241${PREFIX}size host${SUFFIX} ${FPATH}$FILE_BIG
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800242printenv filesize
243setenv filesize
244
245# Notes about load operation
246# If I use 0x01000000 I get DMA misaligned error message
247# Last two parameters are size and offset.
248
249# Test Case 4a - Read full 1MB of small file
Stefan Brüns24d84802016-09-14 01:01:27 +0200250${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800251printenv filesize
252# Test Case 4b - Read full 1MB of small file
253md5sum $addr \$filesize
254setenv filesize
255
256# Test Case 5a - First 1MB of big file
Stefan Brüns24d84802016-09-14 01:01:27 +0200257${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x0
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800258printenv filesize
259# Test Case 5b - First 1MB of big file
260md5sum $addr \$filesize
261setenv filesize
262
263# fails for ext as no offset support
264# Test Case 6a - Last 1MB of big file
Stefan Brüns24d84802016-09-14 01:01:27 +0200265${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x9C300000
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800266printenv filesize
267# Test Case 6b - Last 1MB of big file
268md5sum $addr \$filesize
269setenv filesize
270
271# fails for ext as no offset support
272# Test Case 7a - One from the last 1MB chunk of 2GB
Stefan Brüns24d84802016-09-14 01:01:27 +0200273${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x7FF00000
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800274printenv filesize
275# Test Case 7b - One from the last 1MB chunk of 2GB
276md5sum $addr \$filesize
277setenv filesize
278
279# fails for ext as no offset support
280# Test Case 8a - One from the start 1MB chunk from 2GB
Stefan Brüns24d84802016-09-14 01:01:27 +0200281${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x80000000
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800282printenv filesize
283# Test Case 8b - One from the start 1MB chunk from 2GB
284md5sum $addr \$filesize
285setenv filesize
286
287# fails for ext as no offset support
288# Test Case 9a - One 1MB chunk crossing the 2GB boundary
Stefan Brüns24d84802016-09-14 01:01:27 +0200289${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x7FF80000
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800290printenv filesize
291# Test Case 9b - One 1MB chunk crossing the 2GB boundary
292md5sum $addr \$filesize
293setenv filesize
294
295# Generic failure case
296# Test Case 10 - 2MB chunk from the last 1MB of big file
Stefan Brüns24d84802016-09-14 01:01:27 +0200297${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG 0x00200000 0x9C300000
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800298printenv filesize
299#
300
301# Read 1MB from small file
Stefan Brüns24d84802016-09-14 01:01:27 +0200302${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800303# Write it back to test the writes
304# Test Case 11a - Check that the write succeeded
Stefan Brüns24d84802016-09-14 01:01:27 +0200305${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}$FILE_WRITE \$filesize
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800306mw.b $addr 00 100
Stefan Brüns24d84802016-09-14 01:01:27 +0200307${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_WRITE
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800308# Test Case 11b - Check md5 of written to is same as the one read from
309md5sum $addr \$filesize
310setenv filesize
311#
Stefan Brüns6771dd02016-09-14 01:01:30 +0200312
313# Next test case checks writing a file whose dirent
314# is the first in the block, which is always true for "."
315# The write should fail, but the lookup should work
316# Test Case 12 - Check directory traversal
317${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}. 0x10
Stefan Brüns67a47e82016-09-14 01:01:31 +0200318
319# Read 1MB from small file
320${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
321# Write it via "same directory", i.e. "." dirent
322# Test Case 13a - Check directory traversal
323${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}./${FILE_WRITE}2 \$filesize
324mw.b $addr 00 100
325${PREFIX}load host${SUFFIX} $addr ${FPATH}./${FILE_WRITE}2
326# Test Case 13b - Check md5 of written to is same as the one read from
327md5sum $addr \$filesize
328setenv filesize
329mw.b $addr 00 100
330${PREFIX}load host${SUFFIX} $addr ${FPATH}${FILE_WRITE}2
331# Test Case 13c - Check md5 of written to is same as the one read from
332md5sum $addr \$filesize
333setenv filesize
334#
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800335reset
336
337EOF
338}
339
340# 1st argument is the name of the image file.
341# 2nd argument is the file where we generate the md5s of the files
342# generated with the appropriate start and length that we use to test.
343# It creates the necessary files in the image to test.
344# $GB2p5 is the path of the big file (2.5 GB)
345# $MB1 is the path of the small file (1 MB)
346# $MOUNT_DIR is the path we can use to mount the image file.
347function create_files() {
348 # Mount the image so we can populate it.
349 mkdir -p "$MOUNT_DIR"
350 sudo mount -o loop,rw "$1" "$MOUNT_DIR"
351
Tuomas Tynkkynend1c9e802017-09-25 22:06:34 +0300352 # Create a subdirectory.
353 sudo mkdir -p "$MOUNT_DIR/SUBDIR"
354
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800355 # Create big file in this image.
356 # Note that we work only on the start 1MB, couple MBs in the 2GB range
357 # and the last 1 MB of the huge 2.5GB file.
358 # So, just put random values only in those areas.
359 if [ ! -f "${GB2p5}" ]; then
360 sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 \
361 &> /dev/null
362 sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=2 seek=2047 \
363 &> /dev/null
364 sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 seek=2499 \
365 &> /dev/null
366 fi
367
368 # Create a small file in this image.
369 if [ ! -f "${MB1}" ]; then
370 sudo dd if=/dev/urandom of="${MB1}" bs=1M count=1 \
371 &> /dev/null
372 fi
373
Stefan Brüns67a47e82016-09-14 01:01:31 +0200374 # Delete the small file copies which possibly are written as part of a
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800375 # previous test.
376 sudo rm -f "${MB1}.w"
Stefan Brüns67a47e82016-09-14 01:01:31 +0200377 sudo rm -f "${MB1}.w2"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800378
379 # Generate the md5sums of reads that we will test against small file
380 dd if="${MB1}" bs=1M skip=0 count=1 2> /dev/null | md5sum > "$2"
381
382 # Generate the md5sums of reads that we will test against big file
383 # One from beginning of file.
384 dd if="${GB2p5}" bs=1M skip=0 count=1 \
385 2> /dev/null | md5sum >> "$2"
386
387 # One from end of file.
388 dd if="${GB2p5}" bs=1M skip=2499 count=1 \
389 2> /dev/null | md5sum >> "$2"
390
391 # One from the last 1MB chunk of 2GB
392 dd if="${GB2p5}" bs=1M skip=2047 count=1 \
393 2> /dev/null | md5sum >> "$2"
394
395 # One from the start 1MB chunk from 2GB
396 dd if="${GB2p5}" bs=1M skip=2048 count=1 \
397 2> /dev/null | md5sum >> "$2"
398
399 # One 1MB chunk crossing the 2GB boundary
400 dd if="${GB2p5}" bs=512K skip=4095 count=2 \
401 2> /dev/null | md5sum >> "$2"
402
403 sync
404 sudo umount "$MOUNT_DIR"
405 rmdir "$MOUNT_DIR"
406}
407
408# 1st parameter is the text to print
409# if $? is 0 its a pass, else a fail
410# As a side effect it shall update env variable PASS and FAIL
411function pass_fail() {
412 if [ $? -eq 0 ]; then
413 echo pass - "$1"
414 PASS=$((PASS + 1))
415 else
416 echo FAIL - "$1"
417 FAIL=$((FAIL + 1))
418 fi
419}
420
421# 1st parameter is the string which leads to an md5 generation
422# 2nd parameter is the file we grep, for that string
423# 3rd parameter is the name of the file which has md5s in it
424# 4th parameter is the line # in the md5 file that we match it against
425# This function checks if the md5 of the file in the sandbox matches
426# that calculated while generating the file
427# 5th parameter is the string to print with the result
428check_md5() {
429 # md5sum in u-boot has output of form:
430 # md5 for 01000008 ... 01100007 ==> <md5>
431 # the 7th field is the actual md5
Stefan Brüns4171e9b2016-09-14 01:01:29 +0200432 md5_src=`grep -A2 "$1" "$2" | grep "md5 for" | tr -d '\r'`
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800433 md5_src=($md5_src)
434 md5_src=${md5_src[6]}
435
436 # The md5 list, each line is of the form:
437 # - <md5>
438 # the 2nd field is the actual md5
439 md5_dst=`sed -n $4p $3`
440 md5_dst=($md5_dst)
441 md5_dst=${md5_dst[0]}
442
443 # For a pass they should match.
444 [ "$md5_src" = "$md5_dst" ]
445 pass_fail "$5"
446}
447
448# 1st parameter is the name of the output file to check
449# 2nd parameter is the name of the file containing the md5 expected
450# 3rd parameter is the name of the small file
451# 4th parameter is the name of the big file
452# 5th paramter is the name of the written file
453# This function checks the output file for correct results.
454function check_results() {
455 echo "** Start $1"
456
457 PASS=0
458 FAIL=0
459
460 # Check if the ls is showing correct results for 2.5 gb file
Tuomas Tynkkynend1c9e802017-09-25 22:06:34 +0300461 grep -A7 "Test Case 1 " "$1" | egrep -iq "2621440000 *$4"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800462 pass_fail "TC1: ls of $4"
463
464 # Check if the ls is showing correct results for 1 mb file
Tuomas Tynkkynend1c9e802017-09-25 22:06:34 +0300465 grep -A7 "Test Case 1 " "$1" | egrep -iq "1048576 *$3"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800466 pass_fail "TC1: ls of $3"
467
468 # Check size command on 1MB.file
Tuomas Tynkkynend1c9e802017-09-25 22:06:34 +0300469 egrep -A3 "Test Case 2a " "$1" | grep -q "filesize=100000"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800470 pass_fail "TC2: size of $3"
Tuomas Tynkkynend1c9e802017-09-25 22:06:34 +0300471 # Check size command on 1MB.file via a path using '..'
472 egrep -A3 "Test Case 2b " "$1" | grep -q "filesize=100000"
473 pass_fail "TC2: size of $3 via a path using '..'"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800474
475 # Check size command on 2.5GB.file
476 egrep -A3 "Test Case 3 " "$1" | grep -q "filesize=9c400000"
477 pass_fail "TC3: size of $4"
478
479 # Check read full mb of 1MB.file
Stefan Brüns4171e9b2016-09-14 01:01:29 +0200480 grep -A4 "Test Case 4a " "$1" | grep -q "filesize=100000"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800481 pass_fail "TC4: load of $3 size"
482 check_md5 "Test Case 4b " "$1" "$2" 1 "TC4: load from $3"
483
484 # Check first mb of 2.5GB.file
Stefan Brüns4171e9b2016-09-14 01:01:29 +0200485 grep -A4 "Test Case 5a " "$1" | grep -q "filesize=100000"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800486 pass_fail "TC5: load of 1st MB from $4 size"
487 check_md5 "Test Case 5b " "$1" "$2" 2 "TC5: load of 1st MB from $4"
488
489 # Check last mb of 2.5GB.file
Stefan Brüns4171e9b2016-09-14 01:01:29 +0200490 grep -A4 "Test Case 6a " "$1" | grep -q "filesize=100000"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800491 pass_fail "TC6: load of last MB from $4 size"
492 check_md5 "Test Case 6b " "$1" "$2" 3 "TC6: load of last MB from $4"
493
494 # Check last 1mb chunk of 2gb from 2.5GB file
Stefan Brüns4171e9b2016-09-14 01:01:29 +0200495 grep -A4 "Test Case 7a " "$1" | grep -q "filesize=100000"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800496 pass_fail "TC7: load of last 1mb chunk of 2GB from $4 size"
497 check_md5 "Test Case 7b " "$1" "$2" 4 \
498 "TC7: load of last 1mb chunk of 2GB from $4"
499
500 # Check first 1mb chunk after 2gb from 2.5GB file
Stefan Brüns4171e9b2016-09-14 01:01:29 +0200501 grep -A4 "Test Case 8a " "$1" | grep -q "filesize=100000"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800502 pass_fail "TC8: load 1st MB chunk after 2GB from $4 size"
503 check_md5 "Test Case 8b " "$1" "$2" 5 \
504 "TC8: load 1st MB chunk after 2GB from $4"
505
506 # Check 1mb chunk crossing the 2gb boundary from 2.5GB file
Stefan Brüns4171e9b2016-09-14 01:01:29 +0200507 grep -A4 "Test Case 9a " "$1" | grep -q "filesize=100000"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800508 pass_fail "TC9: load 1MB chunk crossing 2GB boundary from $4 size"
509 check_md5 "Test Case 9b " "$1" "$2" 6 \
510 "TC9: load 1MB chunk crossing 2GB boundary from $4"
511
Tom Rini94d3ce42015-10-11 16:48:36 -0400512 # Check 2mb chunk from the last 1MB of 2.5GB file loads 1MB
Stefan Brüns4171e9b2016-09-14 01:01:29 +0200513 grep -A5 "Test Case 10 " "$1" | grep -q "filesize=100000"
Tom Rini94d3ce42015-10-11 16:48:36 -0400514 pass_fail "TC10: load 2MB from the last 1MB of $4 loads 1MB"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800515
516 # Check 1mb chunk write
Stefan Brüns4171e9b2016-09-14 01:01:29 +0200517 grep -A2 "Test Case 11a " "$1" | grep -q '1048576 bytes written'
Stefan Brünsb2381602016-09-14 01:01:28 +0200518 pass_fail "TC11: 1MB write to $3.w - write succeeded"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800519 check_md5 "Test Case 11b " "$1" "$2" 1 \
Stefan Brünsb2381602016-09-14 01:01:28 +0200520 "TC11: 1MB write to $3.w - content verified"
Stefan Brüns6771dd02016-09-14 01:01:30 +0200521
522 # Check lookup of 'dot' directory
523 grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write file'
524 pass_fail "TC12: 1MB write to . - write denied"
Stefan Brüns67a47e82016-09-14 01:01:31 +0200525
526 # Check directory traversal
527 grep -A2 "Test Case 13a " "$1" | grep -q '1048576 bytes written'
528 pass_fail "TC13: 1MB write to ./$3.w2 - write succeeded"
529 check_md5 "Test Case 13b " "$1" "$2" 1 \
530 "TC13: 1MB read from ./$3.w2 - content verified"
531 check_md5 "Test Case 13c " "$1" "$2" 1 \
532 "TC13: 1MB read from $3.w2 - content verified"
533
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800534 echo "** End $1"
535}
536
537# Takes in one parameter which is "fs" or "nonfs", which then dictates
538# if a fs test (size/load/save) or a nonfs test (fatread/extread) needs to
539# be performed.
540function test_fs_nonfs() {
541 echo "Creating files in $fs image if not already present."
542 create_files $IMAGE $MD5_FILE_FS
543
Stephen Warren09e8f182015-08-10 22:45:14 -0600544 OUT_FILE="${OUT}.$1.${fs}.out"
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800545 test_image $IMAGE $fs $SMALL_FILE $BIG_FILE $1 "" \
Stephen Warren09e8f182015-08-10 22:45:14 -0600546 > ${OUT_FILE} 2>&1
Stefan Brüns4171e9b2016-09-14 01:01:29 +0200547 # strip out noise from fs code
548 grep -v -e "File System is consistent\|update journal finished" \
549 -e "reading .*\.file\|writing .*\.file.w" \
550 < ${OUT_FILE} > ${OUT_FILE}_clean
551 check_results ${OUT_FILE}_clean $MD5_FILE_FS $SMALL_FILE \
552 $BIG_FILE
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800553 TOTAL_FAIL=$((TOTAL_FAIL + FAIL))
554 TOTAL_PASS=$((TOTAL_PASS + PASS))
555 echo "Summary: PASS: $PASS FAIL: $FAIL"
556 echo "--------------------------------------------"
557}
558
559# ********************
560# * End of functions *
561# ********************
562
563check_clean "$1"
564check_prereq
565compile_sandbox
566prepare_env
567
568# Track TOTAL_FAIL and TOTAL_PASS
569TOTAL_FAIL=0
570TOTAL_PASS=0
571
572# In each loop, for a given file system image, we test both the
573# fs command, like load/size/write, the file system specific command
574# like: ext4load/ext4size/ext4write and the sb load/ls/save commands.
Tuomas Tynkkynene304b022017-09-25 22:06:32 +0300575for fs in ext4 fat16 fat32; do
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800576
577 echo "Creating $fs image if not already present."
578 IMAGE=${IMG}.${fs}.img
579 MD5_FILE_FS="${MD5_FILE}.${fs}"
580 create_image $IMAGE $fs
581
582 # sb commands test
583 echo "Creating files in $fs image if not already present."
584 create_files $IMAGE $MD5_FILE_FS
585
586 # Lets mount the image and test sb hostfs commands
587 mkdir -p "$MOUNT_DIR"
Tuomas Tynkkynene304b022017-09-25 22:06:32 +0300588 case "$fs" in
589 fat*)
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800590 uid="uid=`id -u`"
Tuomas Tynkkynene304b022017-09-25 22:06:32 +0300591 ;;
592 *)
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800593 uid=""
Tuomas Tynkkynene304b022017-09-25 22:06:32 +0300594 ;;
595 esac
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800596 sudo mount -o loop,rw,$uid "$IMAGE" "$MOUNT_DIR"
597 sudo chmod 777 "$MOUNT_DIR"
598
599 OUT_FILE="${OUT}.sb.${fs}.out"
600 test_image $IMAGE $fs $SMALL_FILE $BIG_FILE sb `pwd`/$MOUNT_DIR \
Stephen Warren09e8f182015-08-10 22:45:14 -0600601 > ${OUT_FILE} 2>&1
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800602 sudo umount "$MOUNT_DIR"
603 rmdir "$MOUNT_DIR"
604
Stefan Brünsb2381602016-09-14 01:01:28 +0200605 check_results $OUT_FILE $MD5_FILE_FS $SMALL_FILE $BIG_FILE
Suriyan Ramasamiac1cf362014-11-17 14:39:39 -0800606 TOTAL_FAIL=$((TOTAL_FAIL + FAIL))
607 TOTAL_PASS=$((TOTAL_PASS + PASS))
608 echo "Summary: PASS: $PASS FAIL: $FAIL"
609 echo "--------------------------------------------"
610
611 test_fs_nonfs nonfs
612 test_fs_nonfs fs
613done
614
615echo "Total Summary: TOTAL PASS: $TOTAL_PASS TOTAL FAIL: $TOTAL_FAIL"
616echo "--------------------------------------------"
617if [ $TOTAL_FAIL -eq 0 ]; then
618 echo "PASSED"
619 exit 0
620else
621 echo "FAILED"
622 exit 1
623fi