fs-test.sh 18 KB

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