fs-test.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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. # In addition, test with a nonexistent directory to see if we crash.
  194. ${PREFIX}ls host${SUFFIX} invalid_d
  195. #
  196. # We want ${PREFIX}size host 0:0 $3 for host commands and
  197. # sb size hostfs - $3 for hostfs commands.
  198. # 1MB is 0x0010 0000
  199. # Test Case 2a - size of small file
  200. ${PREFIX}size host${SUFFIX} ${FPATH}$FILE_SMALL
  201. printenv filesize
  202. setenv filesize
  203. # Test Case 2b - size of small file via a path using '..'
  204. ${PREFIX}size host${SUFFIX} ${FPATH}SUBDIR/../$FILE_SMALL
  205. printenv filesize
  206. setenv filesize
  207. # 2.5GB (1024*1024*2500) is 0x9C40 0000
  208. # Test Case 3 - size of big file
  209. ${PREFIX}size host${SUFFIX} ${FPATH}$FILE_BIG
  210. printenv filesize
  211. setenv filesize
  212. # Notes about load operation
  213. # If I use 0x01000000 I get DMA misaligned error message
  214. # Last two parameters are size and offset.
  215. # Test Case 4a - Read full 1MB of small file
  216. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
  217. printenv filesize
  218. # Test Case 4b - Read full 1MB of small file
  219. md5sum $addr \$filesize
  220. setenv filesize
  221. # Test Case 5a - First 1MB of big file
  222. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x0
  223. printenv filesize
  224. # Test Case 5b - First 1MB of big file
  225. md5sum $addr \$filesize
  226. setenv filesize
  227. # fails for ext as no offset support
  228. # Test Case 6a - Last 1MB of big file
  229. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x9C300000
  230. printenv filesize
  231. # Test Case 6b - Last 1MB of big file
  232. md5sum $addr \$filesize
  233. setenv filesize
  234. # fails for ext as no offset support
  235. # Test Case 7a - One from the last 1MB chunk of 2GB
  236. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x7FF00000
  237. printenv filesize
  238. # Test Case 7b - One from the last 1MB chunk of 2GB
  239. md5sum $addr \$filesize
  240. setenv filesize
  241. # fails for ext as no offset support
  242. # Test Case 8a - One from the start 1MB chunk from 2GB
  243. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x80000000
  244. printenv filesize
  245. # Test Case 8b - One from the start 1MB chunk from 2GB
  246. md5sum $addr \$filesize
  247. setenv filesize
  248. # fails for ext as no offset support
  249. # Test Case 9a - One 1MB chunk crossing the 2GB boundary
  250. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG $length 0x7FF80000
  251. printenv filesize
  252. # Test Case 9b - One 1MB chunk crossing the 2GB boundary
  253. md5sum $addr \$filesize
  254. setenv filesize
  255. # Generic failure case
  256. # Test Case 10 - 2MB chunk from the last 1MB of big file
  257. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_BIG 0x00200000 0x9C300000
  258. printenv filesize
  259. #
  260. # Read 1MB from small file
  261. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
  262. # Write it back to test the writes
  263. # Test Case 11a - Check that the write succeeded
  264. ${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}$FILE_WRITE \$filesize
  265. mw.b $addr 00 100
  266. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_WRITE
  267. # Test Case 11b - Check md5 of written to is same as the one read from
  268. md5sum $addr \$filesize
  269. setenv filesize
  270. #
  271. # Next test case checks writing a file whose dirent
  272. # is the first in the block, which is always true for "."
  273. # The write should fail, but the lookup should work
  274. # Test Case 12 - Check directory traversal
  275. ${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}. 0x10
  276. # Read 1MB from small file
  277. ${PREFIX}load host${SUFFIX} $addr ${FPATH}$FILE_SMALL
  278. # Write it via "same directory", i.e. "." dirent
  279. # Test Case 13a - Check directory traversal
  280. ${PREFIX}${WRITE} host${SUFFIX} $addr ${FPATH}./${FILE_WRITE}2 \$filesize
  281. mw.b $addr 00 100
  282. ${PREFIX}load host${SUFFIX} $addr ${FPATH}./${FILE_WRITE}2
  283. # Test Case 13b - Check md5 of written to is same as the one read from
  284. md5sum $addr \$filesize
  285. setenv filesize
  286. mw.b $addr 00 100
  287. ${PREFIX}load host${SUFFIX} $addr ${FPATH}${FILE_WRITE}2
  288. # Test Case 13c - Check md5 of written to is same as the one read from
  289. md5sum $addr \$filesize
  290. setenv filesize
  291. #
  292. reset
  293. EOF
  294. }
  295. # 1st argument is the name of the image file.
  296. # 2nd argument is the file where we generate the md5s of the files
  297. # generated with the appropriate start and length that we use to test.
  298. # It creates the necessary files in the image to test.
  299. # $GB2p5 is the path of the big file (2.5 GB)
  300. # $MB1 is the path of the small file (1 MB)
  301. # $MOUNT_DIR is the path we can use to mount the image file.
  302. function create_files() {
  303. # Mount the image so we can populate it.
  304. mkdir -p "$MOUNT_DIR"
  305. sudo mount -o loop,rw "$1" "$MOUNT_DIR"
  306. # Create a subdirectory.
  307. sudo mkdir -p "$MOUNT_DIR/SUBDIR"
  308. # Create big file in this image.
  309. # Note that we work only on the start 1MB, couple MBs in the 2GB range
  310. # and the last 1 MB of the huge 2.5GB file.
  311. # So, just put random values only in those areas.
  312. if [ ! -f "${GB2p5}" ]; then
  313. sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 \
  314. &> /dev/null
  315. sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=2 seek=2047 \
  316. &> /dev/null
  317. sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 seek=2499 \
  318. &> /dev/null
  319. fi
  320. # Create a small file in this image.
  321. if [ ! -f "${MB1}" ]; then
  322. sudo dd if=/dev/urandom of="${MB1}" bs=1M count=1 \
  323. &> /dev/null
  324. fi
  325. # Delete the small file copies which possibly are written as part of a
  326. # previous test.
  327. sudo rm -f "${MB1}.w"
  328. sudo rm -f "${MB1}.w2"
  329. # Generate the md5sums of reads that we will test against small file
  330. dd if="${MB1}" bs=1M skip=0 count=1 2> /dev/null | md5sum > "$2"
  331. # Generate the md5sums of reads that we will test against big file
  332. # One from beginning of file.
  333. dd if="${GB2p5}" bs=1M skip=0 count=1 \
  334. 2> /dev/null | md5sum >> "$2"
  335. # One from end of file.
  336. dd if="${GB2p5}" bs=1M skip=2499 count=1 \
  337. 2> /dev/null | md5sum >> "$2"
  338. # One from the last 1MB chunk of 2GB
  339. dd if="${GB2p5}" bs=1M skip=2047 count=1 \
  340. 2> /dev/null | md5sum >> "$2"
  341. # One from the start 1MB chunk from 2GB
  342. dd if="${GB2p5}" bs=1M skip=2048 count=1 \
  343. 2> /dev/null | md5sum >> "$2"
  344. # One 1MB chunk crossing the 2GB boundary
  345. dd if="${GB2p5}" bs=512K skip=4095 count=2 \
  346. 2> /dev/null | md5sum >> "$2"
  347. sync
  348. sudo umount "$MOUNT_DIR"
  349. rmdir "$MOUNT_DIR"
  350. }
  351. # 1st parameter is the text to print
  352. # if $? is 0 its a pass, else a fail
  353. # As a side effect it shall update env variable PASS and FAIL
  354. function pass_fail() {
  355. if [ $? -eq 0 ]; then
  356. echo pass - "$1"
  357. PASS=$((PASS + 1))
  358. else
  359. echo FAIL - "$1"
  360. FAIL=$((FAIL + 1))
  361. fi
  362. }
  363. # 1st parameter is the string which leads to an md5 generation
  364. # 2nd parameter is the file we grep, for that string
  365. # 3rd parameter is the name of the file which has md5s in it
  366. # 4th parameter is the line # in the md5 file that we match it against
  367. # This function checks if the md5 of the file in the sandbox matches
  368. # that calculated while generating the file
  369. # 5th parameter is the string to print with the result
  370. check_md5() {
  371. # md5sum in u-boot has output of form:
  372. # md5 for 01000008 ... 01100007 ==> <md5>
  373. # the 7th field is the actual md5
  374. md5_src=`grep -A2 "$1" "$2" | grep "md5 for" | tr -d '\r'`
  375. md5_src=($md5_src)
  376. md5_src=${md5_src[6]}
  377. # The md5 list, each line is of the form:
  378. # - <md5>
  379. # the 2nd field is the actual md5
  380. md5_dst=`sed -n $4p $3`
  381. md5_dst=($md5_dst)
  382. md5_dst=${md5_dst[0]}
  383. # For a pass they should match.
  384. [ "$md5_src" = "$md5_dst" ]
  385. pass_fail "$5"
  386. }
  387. # 1st parameter is the name of the output file to check
  388. # 2nd parameter is the name of the file containing the md5 expected
  389. # 3rd parameter is the name of the small file
  390. # 4th parameter is the name of the big file
  391. # 5th paramter is the name of the written file
  392. # This function checks the output file for correct results.
  393. function check_results() {
  394. echo "** Start $1"
  395. PASS=0
  396. FAIL=0
  397. # Check if the ls is showing correct results for 2.5 gb file
  398. grep -A7 "Test Case 1 " "$1" | egrep -iq "2621440000 *$4"
  399. pass_fail "TC1: ls of $4"
  400. # Check if the ls is showing correct results for 1 mb file
  401. grep -A7 "Test Case 1 " "$1" | egrep -iq "1048576 *$3"
  402. pass_fail "TC1: ls of $3"
  403. # Check size command on 1MB.file
  404. egrep -A3 "Test Case 2a " "$1" | grep -q "filesize=100000"
  405. pass_fail "TC2: size of $3"
  406. # Check size command on 1MB.file via a path using '..'
  407. egrep -A3 "Test Case 2b " "$1" | grep -q "filesize=100000"
  408. pass_fail "TC2: size of $3 via a path using '..'"
  409. # Check size command on 2.5GB.file
  410. egrep -A3 "Test Case 3 " "$1" | grep -q "filesize=9c400000"
  411. pass_fail "TC3: size of $4"
  412. # Check read full mb of 1MB.file
  413. grep -A4 "Test Case 4a " "$1" | grep -q "filesize=100000"
  414. pass_fail "TC4: load of $3 size"
  415. check_md5 "Test Case 4b " "$1" "$2" 1 "TC4: load from $3"
  416. # Check first mb of 2.5GB.file
  417. grep -A4 "Test Case 5a " "$1" | grep -q "filesize=100000"
  418. pass_fail "TC5: load of 1st MB from $4 size"
  419. check_md5 "Test Case 5b " "$1" "$2" 2 "TC5: load of 1st MB from $4"
  420. # Check last mb of 2.5GB.file
  421. grep -A4 "Test Case 6a " "$1" | grep -q "filesize=100000"
  422. pass_fail "TC6: load of last MB from $4 size"
  423. check_md5 "Test Case 6b " "$1" "$2" 3 "TC6: load of last MB from $4"
  424. # Check last 1mb chunk of 2gb from 2.5GB file
  425. grep -A4 "Test Case 7a " "$1" | grep -q "filesize=100000"
  426. pass_fail "TC7: load of last 1mb chunk of 2GB from $4 size"
  427. check_md5 "Test Case 7b " "$1" "$2" 4 \
  428. "TC7: load of last 1mb chunk of 2GB from $4"
  429. # Check first 1mb chunk after 2gb from 2.5GB file
  430. grep -A4 "Test Case 8a " "$1" | grep -q "filesize=100000"
  431. pass_fail "TC8: load 1st MB chunk after 2GB from $4 size"
  432. check_md5 "Test Case 8b " "$1" "$2" 5 \
  433. "TC8: load 1st MB chunk after 2GB from $4"
  434. # Check 1mb chunk crossing the 2gb boundary from 2.5GB file
  435. grep -A4 "Test Case 9a " "$1" | grep -q "filesize=100000"
  436. pass_fail "TC9: load 1MB chunk crossing 2GB boundary from $4 size"
  437. check_md5 "Test Case 9b " "$1" "$2" 6 \
  438. "TC9: load 1MB chunk crossing 2GB boundary from $4"
  439. # Check 2mb chunk from the last 1MB of 2.5GB file loads 1MB
  440. grep -A5 "Test Case 10 " "$1" | grep -q "filesize=100000"
  441. pass_fail "TC10: load 2MB from the last 1MB of $4 loads 1MB"
  442. # Check 1mb chunk write
  443. grep -A2 "Test Case 11a " "$1" | grep -q '1048576 bytes written'
  444. pass_fail "TC11: 1MB write to $3.w - write succeeded"
  445. check_md5 "Test Case 11b " "$1" "$2" 1 \
  446. "TC11: 1MB write to $3.w - content verified"
  447. # Check lookup of 'dot' directory
  448. grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write file'
  449. pass_fail "TC12: 1MB write to . - write denied"
  450. # Check directory traversal
  451. grep -A2 "Test Case 13a " "$1" | grep -q '1048576 bytes written'
  452. pass_fail "TC13: 1MB write to ./$3.w2 - write succeeded"
  453. check_md5 "Test Case 13b " "$1" "$2" 1 \
  454. "TC13: 1MB read from ./$3.w2 - content verified"
  455. check_md5 "Test Case 13c " "$1" "$2" 1 \
  456. "TC13: 1MB read from $3.w2 - content verified"
  457. echo "** End $1"
  458. }
  459. # Takes in one parameter which is "fs" or "nonfs", which then dictates
  460. # if a fs test (size/load/save) or a nonfs test (fatread/extread) needs to
  461. # be performed.
  462. function test_fs_nonfs() {
  463. echo "Creating files in $fs image if not already present."
  464. create_files $IMAGE $MD5_FILE_FS
  465. OUT_FILE="${OUT}.$1.${fs}.out"
  466. test_image $IMAGE $fs $SMALL_FILE $BIG_FILE $1 "" \
  467. > ${OUT_FILE} 2>&1
  468. # strip out noise from fs code
  469. grep -v -e "File System is consistent\|update journal finished" \
  470. -e "reading .*\.file\|writing .*\.file.w" \
  471. < ${OUT_FILE} > ${OUT_FILE}_clean
  472. check_results ${OUT_FILE}_clean $MD5_FILE_FS $SMALL_FILE \
  473. $BIG_FILE
  474. TOTAL_FAIL=$((TOTAL_FAIL + FAIL))
  475. TOTAL_PASS=$((TOTAL_PASS + PASS))
  476. echo "Summary: PASS: $PASS FAIL: $FAIL"
  477. echo "--------------------------------------------"
  478. }
  479. # ********************
  480. # * End of functions *
  481. # ********************
  482. check_clean "$1"
  483. check_prereq
  484. compile_sandbox
  485. prepare_env
  486. # Track TOTAL_FAIL and TOTAL_PASS
  487. TOTAL_FAIL=0
  488. TOTAL_PASS=0
  489. # In each loop, for a given file system image, we test both the
  490. # fs command, like load/size/write, the file system specific command
  491. # like: ext4load/ext4size/ext4write and the sb load/ls/save commands.
  492. for fs in ext4 fat16 fat32; do
  493. echo "Creating $fs image if not already present."
  494. IMAGE=${IMG}.${fs}.img
  495. MD5_FILE_FS="${MD5_FILE}.${fs}"
  496. create_image $IMAGE $fs
  497. # sb commands test
  498. echo "Creating files in $fs image if not already present."
  499. create_files $IMAGE $MD5_FILE_FS
  500. # Lets mount the image and test sb hostfs commands
  501. mkdir -p "$MOUNT_DIR"
  502. case "$fs" in
  503. fat*)
  504. uid="uid=`id -u`"
  505. ;;
  506. *)
  507. uid=""
  508. ;;
  509. esac
  510. sudo mount -o loop,rw,$uid "$IMAGE" "$MOUNT_DIR"
  511. sudo chmod 777 "$MOUNT_DIR"
  512. OUT_FILE="${OUT}.sb.${fs}.out"
  513. test_image $IMAGE $fs $SMALL_FILE $BIG_FILE sb `pwd`/$MOUNT_DIR \
  514. > ${OUT_FILE} 2>&1
  515. sudo umount "$MOUNT_DIR"
  516. rmdir "$MOUNT_DIR"
  517. check_results $OUT_FILE $MD5_FILE_FS $SMALL_FILE $BIG_FILE
  518. TOTAL_FAIL=$((TOTAL_FAIL + FAIL))
  519. TOTAL_PASS=$((TOTAL_PASS + PASS))
  520. echo "Summary: PASS: $PASS FAIL: $FAIL"
  521. echo "--------------------------------------------"
  522. test_fs_nonfs nonfs
  523. test_fs_nonfs fs
  524. done
  525. echo "Total Summary: TOTAL PASS: $TOTAL_PASS TOTAL FAIL: $TOTAL_FAIL"
  526. echo "--------------------------------------------"
  527. if [ $TOTAL_FAIL -eq 0 ]; then
  528. echo "PASSED"
  529. exit 0
  530. else
  531. echo "FAILED"
  532. exit 1
  533. fi