fs-test.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0+
  3. #
  4. # (C) Copyright 2014 Suriyan Ramasami
  5. # Invoke this test script from U-Boot base directory as ./test/fs/fs-test.sh
  6. # It currently tests the fs/sb and native commands for ext4 and fat partitions
  7. # Expected results are as follows:
  8. # EXT4 tests:
  9. # fs-test.sb.ext4.out: Summary: PASS: 24 FAIL: 0
  10. # fs-test.ext4.out: Summary: PASS: 24 FAIL: 0
  11. # fs-test.fs.ext4.out: Summary: PASS: 24 FAIL: 0
  12. # FAT16 tests:
  13. # fs-test.sb.fat16.out: Summary: PASS: 24 FAIL: 0
  14. # fs-test.fat16.out: Summary: PASS: 21 FAIL: 3
  15. # fs-test.fs.fat16.out: Summary: PASS: 21 FAIL: 3
  16. # FAT32 tests:
  17. # fs-test.sb.fat32.out: Summary: PASS: 24 FAIL: 0
  18. # fs-test.fat32.out: Summary: PASS: 21 FAIL: 3
  19. # fs-test.fs.fat32.out: Summary: PASS: 21 FAIL: 3
  20. # Total Summary: TOTAL PASS: 204 TOTAL FAIL: 12
  21. # pre-requisite binaries list.
  22. PREREQ_BINS="md5sum mkfs mount umount dd fallocate mkdir"
  23. # All generated output files from this test will be in $OUT_DIR
  24. # Hence everything is sandboxed.
  25. OUT_DIR="sandbox/test/fs"
  26. # Location of generated sandbox u-boot
  27. UBOOT="./sandbox/u-boot"
  28. # Our mount directory will be in the sandbox
  29. MOUNT_DIR="${OUT_DIR}/mnt"
  30. # The file system image we create will have the $IMG prefix.
  31. IMG="${OUT_DIR}/3GB"
  32. # $SMALL_FILE is the name of the 1MB file in the file system image
  33. SMALL_FILE="1MB.file"
  34. # $BIG_FILE is the name of the 2.5GB file in the file system image
  35. BIG_FILE="2.5GB.file"
  36. # $MD5_FILE will have the expected md5s when we do the test
  37. # They shall have a suffix which represents their file system (ext4/fat16/...)
  38. MD5_FILE="${OUT_DIR}/md5s.list"
  39. # $OUT shall be the prefix of the test output. Their suffix will be .out
  40. OUT="${OUT_DIR}/fs-test"
  41. # Full Path of the 1 MB file that shall be created in the fs image.
  42. MB1="${MOUNT_DIR}/${SMALL_FILE}"
  43. GB2p5="${MOUNT_DIR}/${BIG_FILE}"
  44. # ************************
  45. # * Functions start here *
  46. # ************************
  47. # Check if the prereq binaries exist, or exit
  48. function check_prereq() {
  49. for prereq in $PREREQ_BINS; do
  50. if [ ! -x "`which $prereq`" ]; then
  51. echo "Missing $prereq binary. Exiting!"
  52. exit
  53. fi
  54. done
  55. # We use /dev/urandom to create files. Check if it exists.
  56. if [ ! -c /dev/urandom ]; then
  57. echo "Missing character special /dev/urandom. Exiting!"
  58. exit
  59. fi
  60. }
  61. # If 1st param is "clean", then clean out the generated files and exit
  62. function check_clean() {
  63. if [ "$1" = "clean" ]; then
  64. rm -rf "$OUT_DIR"
  65. echo "Cleaned up generated files. Exiting"
  66. exit
  67. fi
  68. }
  69. # Generate sandbox U-Boot - gleaned from /test/dm/test-dm.sh
  70. function compile_sandbox() {
  71. unset CROSS_COMPILE
  72. NUM_CPUS=$(cat /proc/cpuinfo |grep -c processor)
  73. make O=sandbox sandbox_config
  74. make O=sandbox -s -j${NUM_CPUS}
  75. # Check if U-Boot exists
  76. if [ ! -x "$UBOOT" ]; then
  77. echo "$UBOOT does not exist or is not executable"
  78. echo "Build error?"
  79. echo "Please run this script as ./test/fs/`basename $0`"
  80. exit
  81. fi
  82. }
  83. # Clean out all generated files other than the file system images
  84. # We save time by not deleting and recreating the file system images
  85. function prepare_env() {
  86. rm -f ${MD5_FILE}.* ${OUT}.*
  87. mkdir -p ${OUT_DIR}
  88. }
  89. # 1st parameter is the name of the image file to be created
  90. # 2nd parameter is the filesystem - fat16 ext4 etc
  91. # -F cant be used with fat as it means something else.
  92. function create_image() {
  93. # Create image if not already present - saves time, while debugging
  94. case "$2" in
  95. fat16)
  96. MKFS_OPTION="-F 16"
  97. FS_TYPE="fat"
  98. ;;
  99. fat32)
  100. MKFS_OPTION="-F 32"
  101. FS_TYPE="fat"
  102. ;;
  103. ext4)
  104. MKFS_OPTION="-F"
  105. FS_TYPE="ext4"
  106. ;;
  107. esac
  108. if [ ! -f "$1" ]; then
  109. fallocate -l 3G "$1" &> /dev/null
  110. if [ $? -ne 0 ]; then
  111. echo fallocate failed - using dd instead
  112. dd if=/dev/zero of=$1 bs=1024 count=$((3 * 1024 * 1024))
  113. if [ $? -ne 0 ]; then
  114. echo Could not create empty disk image
  115. exit $?
  116. fi
  117. fi
  118. mkfs -t "$FS_TYPE" $MKFS_OPTION "$1" &> /dev/null
  119. if [ $? -ne 0 -a "$FS_TYPE" = "fat" ]; then
  120. # If we fail and we did fat, try vfat.
  121. mkfs -t vfat $MKFS_OPTION "$1" &> /dev/null
  122. fi
  123. if [ $? -ne 0 ]; then
  124. echo Could not create filesystem
  125. exit $?
  126. fi
  127. fi
  128. }
  129. # 1st parameter is image file
  130. # 2nd parameter is file system type - fat16/ext4/...
  131. # 3rd parameter is name of small file
  132. # 4th parameter is name of big file
  133. # 5th parameter is fs/nonfs/sb - to dictate generic fs commands or
  134. # otherwise or sb hostfs
  135. # 6th parameter is the directory path for the files. Its "" for generic
  136. # fs and ext4/fat and full patch for sb hostfs
  137. # UBOOT is set in env
  138. function test_image() {
  139. addr="0x01000008"
  140. length="0x00100000"
  141. case "$2" in
  142. fat*)
  143. FPATH=""
  144. PREFIX="fat"
  145. WRITE="write"
  146. ;;
  147. ext4)
  148. # ext4 needs absolute path
  149. FPATH="/"
  150. PREFIX="ext4"
  151. WRITE="write"
  152. ;;
  153. *)
  154. echo "Unhandled filesystem $2. Exiting!"
  155. exit
  156. ;;
  157. esac
  158. case "$5" in
  159. fs)
  160. PREFIX=""
  161. WRITE="save"
  162. SUFFIX=" 0:0"
  163. ;;
  164. nonfs)
  165. SUFFIX=" 0:0"
  166. ;;
  167. sb)
  168. PREFIX="sb "
  169. WRITE="save"
  170. SUFFIX="fs -"
  171. ;;
  172. *)
  173. echo "Unhandled mode $5. Exiting!"
  174. exit
  175. ;;
  176. esac
  177. # sb always uses full path to mointpoint, irrespective of filesystem
  178. if [ "$5" = "sb" ]; then
  179. FPATH=${6}/
  180. fi
  181. FILE_WRITE=${3}.w
  182. FILE_SMALL=$3
  183. FILE_BIG=$4
  184. # In u-boot commands, <interface> stands for host or hostfs
  185. # hostfs maps to the host fs.
  186. # host maps to the "sb bind" that we do
  187. $UBOOT << EOF
  188. sb=$5
  189. setenv bind 'if test "\$sb" != sb; then sb bind 0 "$1"; fi'
  190. run bind
  191. # Test Case 1 - ls
  192. ${PREFIX}ls host${SUFFIX} $6
  193. #
  194. # We want ${PREFIX}size host 0:0 $3 for host commands and
  195. # sb size hostfs - $3 for hostfs commands.
  196. # 1MB is 0x0010 0000
  197. # Test Case 2a - size of small file
  198. ${PREFIX}size host${SUFFIX} ${FPATH}$FILE_SMALL
  199. printenv filesize
  200. setenv filesize
  201. # Test Case 2b - size of small file via a path using '..'
  202. ${PREFIX}size host${SUFFIX} ${FPATH}SUBDIR/../$FILE_SMALL
  203. printenv filesize
  204. setenv filesize
  205. # 2.5GB (1024*1024*2500) is 0x9C40 0000
  206. # Test Case 3 - size of big file
  207. ${PREFIX}size host${SUFFIX} ${FPATH}$FILE_BIG
  208. printenv filesize
  209. setenv filesize
  210. # Notes about load operation
  211. # If I use 0x01000000 I get DMA misaligned error message
  212. # Last two parameters are size and offset.
  213. # Test Case 4a - Read full 1MB of small file
  214. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
  215. printenv filesize
  216. # Test Case 4b - Read full 1MB of small file
  217. md5sum $addr \$filesize
  218. setenv filesize
  219. # Test Case 5a - First 1MB of big file
  220. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x0
  221. printenv filesize
  222. # Test Case 5b - First 1MB of big file
  223. md5sum $addr \$filesize
  224. setenv filesize
  225. # fails for ext as no offset support
  226. # Test Case 6a - Last 1MB of big file
  227. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x9C300000
  228. printenv filesize
  229. # Test Case 6b - Last 1MB of big file
  230. md5sum $addr \$filesize
  231. setenv filesize
  232. # fails for ext as no offset support
  233. # Test Case 7a - One from the last 1MB chunk of 2GB
  234. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x7FF00000
  235. printenv filesize
  236. # Test Case 7b - One from the last 1MB chunk of 2GB
  237. md5sum $addr \$filesize
  238. setenv filesize
  239. # fails for ext as no offset support
  240. # Test Case 8a - One from the start 1MB chunk from 2GB
  241. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x80000000
  242. printenv filesize
  243. # Test Case 8b - One from the start 1MB chunk from 2GB
  244. md5sum $addr \$filesize
  245. setenv filesize
  246. # fails for ext as no offset support
  247. # Test Case 9a - One 1MB chunk crossing the 2GB boundary
  248. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x7FF80000
  249. printenv filesize
  250. # Test Case 9b - One 1MB chunk crossing the 2GB boundary
  251. md5sum $addr \$filesize
  252. setenv filesize
  253. # Generic failure case
  254. # Test Case 10 - 2MB chunk from the last 1MB of big file
  255. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG 0x00200000 0x9C300000
  256. printenv filesize
  257. #
  258. # Read 1MB from small file
  259. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
  260. # Write it back to test the writes
  261. # Test Case 11a - Check that the write succeeded
  262. ${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}$FILE_WRITE \$filesize
  263. mw.b $addr 00 100
  264. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_WRITE
  265. # Test Case 11b - Check md5 of written to is same as the one read from
  266. md5sum $addr \$filesize
  267. setenv filesize
  268. #
  269. # Next test case checks writing a file whose dirent
  270. # is the first in the block, which is always true for "."
  271. # The write should fail, but the lookup should work
  272. # Test Case 12 - Check directory traversal
  273. ${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}. 0x10
  274. # Read 1MB from small file
  275. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
  276. # Write it via "same directory", i.e. "." dirent
  277. # Test Case 13a - Check directory traversal
  278. ${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}./${FILE_WRITE}2 \$filesize
  279. mw.b $addr 00 100
  280. ${PREFIX}load host${SUFFIX} $addr ${FPATH}./${FILE_WRITE}2
  281. # Test Case 13b - Check md5 of written to is same as the one read from
  282. md5sum $addr \$filesize
  283. setenv filesize
  284. mw.b $addr 00 100
  285. ${PREFIX}load host${SUFFIX} $addr ${FPATH}${FILE_WRITE}2
  286. # Test Case 13c - Check md5 of written to is same as the one read from
  287. md5sum $addr \$filesize
  288. setenv filesize
  289. #
  290. reset
  291. EOF
  292. }
  293. # 1st argument is the name of the image file.
  294. # 2nd argument is the file where we generate the md5s of the files
  295. # generated with the appropriate start and length that we use to test.
  296. # It creates the necessary files in the image to test.
  297. # $GB2p5 is the path of the big file (2.5 GB)
  298. # $MB1 is the path of the small file (1 MB)
  299. # $MOUNT_DIR is the path we can use to mount the image file.
  300. function create_files() {
  301. # Mount the image so we can populate it.
  302. mkdir -p "$MOUNT_DIR"
  303. sudo mount -o loop,rw "$1" "$MOUNT_DIR"
  304. # Create a subdirectory.
  305. sudo mkdir -p "$MOUNT_DIR/SUBDIR"
  306. # Create big file in this image.
  307. # Note that we work only on the start 1MB, couple MBs in the 2GB range
  308. # and the last 1 MB of the huge 2.5GB file.
  309. # So, just put random values only in those areas.
  310. if [ ! -f "${GB2p5}" ]; then
  311. sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 \
  312. &> /dev/null
  313. sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=2 seek=2047 \
  314. &> /dev/null
  315. sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 seek=2499 \
  316. &> /dev/null
  317. fi
  318. # Create a small file in this image.
  319. if [ ! -f "${MB1}" ]; then
  320. sudo dd if=/dev/urandom of="${MB1}" bs=1M count=1 \
  321. &> /dev/null
  322. fi
  323. # Delete the small file copies which possibly are written as part of a
  324. # previous test.
  325. sudo rm -f "${MB1}.w"
  326. sudo rm -f "${MB1}.w2"
  327. # Generate the md5sums of reads that we will test against small file
  328. dd if="${MB1}" bs=1M skip=0 count=1 2> /dev/null | md5sum > "$2"
  329. # Generate the md5sums of reads that we will test against big file
  330. # One from beginning of file.
  331. dd if="${GB2p5}" bs=1M skip=0 count=1 \
  332. 2> /dev/null | md5sum >> "$2"
  333. # One from end of file.
  334. dd if="${GB2p5}" bs=1M skip=2499 count=1 \
  335. 2> /dev/null | md5sum >> "$2"
  336. # One from the last 1MB chunk of 2GB
  337. dd if="${GB2p5}" bs=1M skip=2047 count=1 \
  338. 2> /dev/null | md5sum >> "$2"
  339. # One from the start 1MB chunk from 2GB
  340. dd if="${GB2p5}" bs=1M skip=2048 count=1 \
  341. 2> /dev/null | md5sum >> "$2"
  342. # One 1MB chunk crossing the 2GB boundary
  343. dd if="${GB2p5}" bs=512K skip=4095 count=2 \
  344. 2> /dev/null | md5sum >> "$2"
  345. sync
  346. sudo umount "$MOUNT_DIR"
  347. rmdir "$MOUNT_DIR"
  348. }
  349. # 1st parameter is the text to print
  350. # if $? is 0 its a pass, else a fail
  351. # As a side effect it shall update env variable PASS and FAIL
  352. function pass_fail() {
  353. if [ $? -eq 0 ]; then
  354. echo pass - "$1"
  355. PASS=$((PASS + 1))
  356. else
  357. echo FAIL - "$1"
  358. FAIL=$((FAIL + 1))
  359. fi
  360. }
  361. # 1st parameter is the string which leads to an md5 generation
  362. # 2nd parameter is the file we grep, for that string
  363. # 3rd parameter is the name of the file which has md5s in it
  364. # 4th parameter is the line # in the md5 file that we match it against
  365. # This function checks if the md5 of the file in the sandbox matches
  366. # that calculated while generating the file
  367. # 5th parameter is the string to print with the result
  368. check_md5() {
  369. # md5sum in u-boot has output of form:
  370. # md5 for 01000008 ... 01100007 ==> <md5>
  371. # the 7th field is the actual md5
  372. md5_src=`grep -A2 "$1" "$2" | grep "md5 for" | tr -d '\r'`
  373. md5_src=($md5_src)
  374. md5_src=${md5_src[6]}
  375. # The md5 list, each line is of the form:
  376. # - <md5>
  377. # the 2nd field is the actual md5
  378. md5_dst=`sed -n $4p $3`
  379. md5_dst=($md5_dst)
  380. md5_dst=${md5_dst[0]}
  381. # For a pass they should match.
  382. [ "$md5_src" = "$md5_dst" ]
  383. pass_fail "$5"
  384. }
  385. # 1st parameter is the name of the output file to check
  386. # 2nd parameter is the name of the file containing the md5 expected
  387. # 3rd parameter is the name of the small file
  388. # 4th parameter is the name of the big file
  389. # 5th paramter is the name of the written file
  390. # This function checks the output file for correct results.
  391. function check_results() {
  392. echo "** Start $1"
  393. PASS=0
  394. FAIL=0
  395. # Check if the ls is showing correct results for 2.5 gb file
  396. grep -A7 "Test Case 1 " "$1" | egrep -iq "2621440000 *$4"
  397. pass_fail "TC1: ls of $4"
  398. # Check if the ls is showing correct results for 1 mb file
  399. grep -A7 "Test Case 1 " "$1" | egrep -iq "1048576 *$3"
  400. pass_fail "TC1: ls of $3"
  401. # Check size command on 1MB.file
  402. egrep -A3 "Test Case 2a " "$1" | grep -q "filesize=100000"
  403. pass_fail "TC2: size of $3"
  404. # Check size command on 1MB.file via a path using '..'
  405. egrep -A3 "Test Case 2b " "$1" | grep -q "filesize=100000"
  406. pass_fail "TC2: size of $3 via a path using '..'"
  407. # Check size command on 2.5GB.file
  408. egrep -A3 "Test Case 3 " "$1" | grep -q "filesize=9c400000"
  409. pass_fail "TC3: size of $4"
  410. # Check read full mb of 1MB.file
  411. grep -A4 "Test Case 4a " "$1" | grep -q "filesize=100000"
  412. pass_fail "TC4: load of $3 size"
  413. check_md5 "Test Case 4b " "$1" "$2" 1 "TC4: load from $3"
  414. # Check first mb of 2.5GB.file
  415. grep -A4 "Test Case 5a " "$1" | grep -q "filesize=100000"
  416. pass_fail "TC5: load of 1st MB from $4 size"
  417. check_md5 "Test Case 5b " "$1" "$2" 2 "TC5: load of 1st MB from $4"
  418. # Check last mb of 2.5GB.file
  419. grep -A4 "Test Case 6a " "$1" | grep -q "filesize=100000"
  420. pass_fail "TC6: load of last MB from $4 size"
  421. check_md5 "Test Case 6b " "$1" "$2" 3 "TC6: load of last MB from $4"
  422. # Check last 1mb chunk of 2gb from 2.5GB file
  423. grep -A4 "Test Case 7a " "$1" | grep -q "filesize=100000"
  424. pass_fail "TC7: load of last 1mb chunk of 2GB from $4 size"
  425. check_md5 "Test Case 7b " "$1" "$2" 4 \
  426. "TC7: load of last 1mb chunk of 2GB from $4"
  427. # Check first 1mb chunk after 2gb from 2.5GB file
  428. grep -A4 "Test Case 8a " "$1" | grep -q "filesize=100000"
  429. pass_fail "TC8: load 1st MB chunk after 2GB from $4 size"
  430. check_md5 "Test Case 8b " "$1" "$2" 5 \
  431. "TC8: load 1st MB chunk after 2GB from $4"
  432. # Check 1mb chunk crossing the 2gb boundary from 2.5GB file
  433. grep -A4 "Test Case 9a " "$1" | grep -q "filesize=100000"
  434. pass_fail "TC9: load 1MB chunk crossing 2GB boundary from $4 size"
  435. check_md5 "Test Case 9b " "$1" "$2" 6 \
  436. "TC9: load 1MB chunk crossing 2GB boundary from $4"
  437. # Check 2mb chunk from the last 1MB of 2.5GB file loads 1MB
  438. grep -A5 "Test Case 10 " "$1" | grep -q "filesize=100000"
  439. pass_fail "TC10: load 2MB from the last 1MB of $4 loads 1MB"
  440. # Check 1mb chunk write
  441. grep -A2 "Test Case 11a " "$1" | grep -q '1048576 bytes written'
  442. pass_fail "TC11: 1MB write to $3.w - write succeeded"
  443. check_md5 "Test Case 11b " "$1" "$2" 1 \
  444. "TC11: 1MB write to $3.w - content verified"
  445. # Check lookup of 'dot' directory
  446. grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write file'
  447. pass_fail "TC12: 1MB write to . - write denied"
  448. # Check directory traversal
  449. grep -A2 "Test Case 13a " "$1" | grep -q '1048576 bytes written'
  450. pass_fail "TC13: 1MB write to ./$3.w2 - write succeeded"
  451. check_md5 "Test Case 13b " "$1" "$2" 1 \
  452. "TC13: 1MB read from ./$3.w2 - content verified"
  453. check_md5 "Test Case 13c " "$1" "$2" 1 \
  454. "TC13: 1MB read from $3.w2 - content verified"
  455. echo "** End $1"
  456. }
  457. # Takes in one parameter which is "fs" or "nonfs", which then dictates
  458. # if a fs test (size/load/save) or a nonfs test (fatread/extread) needs to
  459. # be performed.
  460. function test_fs_nonfs() {
  461. echo "Creating files in $fs image if not already present."
  462. create_files $IMAGE $MD5_FILE_FS
  463. OUT_FILE="${OUT}.$1.${fs}.out"
  464. test_image $IMAGE $fs $SMALL_FILE $BIG_FILE $1 "" \
  465. > ${OUT_FILE} 2>&1
  466. # strip out noise from fs code
  467. grep -v -e "File System is consistent\|update journal finished" \
  468. -e "reading .*\.file\|writing .*\.file.w" \
  469. < ${OUT_FILE} > ${OUT_FILE}_clean
  470. check_results ${OUT_FILE}_clean $MD5_FILE_FS $SMALL_FILE \
  471. $BIG_FILE
  472. TOTAL_FAIL=$((TOTAL_FAIL + FAIL))
  473. TOTAL_PASS=$((TOTAL_PASS + PASS))
  474. echo "Summary: PASS: $PASS FAIL: $FAIL"
  475. echo "--------------------------------------------"
  476. }
  477. # ********************
  478. # * End of functions *
  479. # ********************
  480. check_clean "$1"
  481. check_prereq
  482. compile_sandbox
  483. prepare_env
  484. # Track TOTAL_FAIL and TOTAL_PASS
  485. TOTAL_FAIL=0
  486. TOTAL_PASS=0
  487. # In each loop, for a given file system image, we test both the
  488. # fs command, like load/size/write, the file system specific command
  489. # like: ext4load/ext4size/ext4write and the sb load/ls/save commands.
  490. for fs in ext4 fat16 fat32; do
  491. echo "Creating $fs image if not already present."
  492. IMAGE=${IMG}.${fs}.img
  493. MD5_FILE_FS="${MD5_FILE}.${fs}"
  494. create_image $IMAGE $fs
  495. # sb commands test
  496. echo "Creating files in $fs image if not already present."
  497. create_files $IMAGE $MD5_FILE_FS
  498. # Lets mount the image and test sb hostfs commands
  499. mkdir -p "$MOUNT_DIR"
  500. case "$fs" in
  501. fat*)
  502. uid="uid=`id -u`"
  503. ;;
  504. *)
  505. uid=""
  506. ;;
  507. esac
  508. sudo mount -o loop,rw,$uid "$IMAGE" "$MOUNT_DIR"
  509. sudo chmod 777 "$MOUNT_DIR"
  510. OUT_FILE="${OUT}.sb.${fs}.out"
  511. test_image $IMAGE $fs $SMALL_FILE $BIG_FILE sb `pwd`/$MOUNT_DIR \
  512. > ${OUT_FILE} 2>&1
  513. sudo umount "$MOUNT_DIR"
  514. rmdir "$MOUNT_DIR"
  515. check_results $OUT_FILE $MD5_FILE_FS $SMALL_FILE $BIG_FILE
  516. TOTAL_FAIL=$((TOTAL_FAIL + FAIL))
  517. TOTAL_PASS=$((TOTAL_PASS + PASS))
  518. echo "Summary: PASS: $PASS FAIL: $FAIL"
  519. echo "--------------------------------------------"
  520. test_fs_nonfs nonfs
  521. test_fs_nonfs fs
  522. done
  523. echo "Total Summary: TOTAL PASS: $TOTAL_PASS TOTAL FAIL: $TOTAL_FAIL"
  524. echo "--------------------------------------------"
  525. if [ $TOTAL_FAIL -eq 0 ]; then
  526. echo "PASSED"
  527. exit 0
  528. else
  529. echo "FAILED"
  530. exit 1
  531. fi