fs-test.sh 17 KB

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