fat-noncontig-test.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0+
  3. # (C) Copyright 2015 Stephen Warren
  4. # This script tests U-Boot's FAT filesystem code's ability to read non-
  5. # contiguous files.
  6. # When porting the ff.c FAT parsing code into U-Boot, it was found that ff.c
  7. # always reads files cluster-by-cluster, which results in poor performance.
  8. # This was solved by adding a patch to ff.c to coalesce reads of adjacent
  9. # clusters. Since this patch needed to correctly handle non-contiguous files,
  10. # this test was written to validate that.
  11. #
  12. # To execute the test, simply run it from the U-Boot source root directory:
  13. #
  14. # cd u-boot
  15. # ./test/fs/fat-noncontig-test.sh
  16. #
  17. # The test will create a FAT filesystem image, record the CRC of a randomly
  18. # generated file in the image, build U-Boot sandbox, invoke U-Boot sandbox to
  19. # read the file and validate that the CRCs match. Expected output is shown
  20. # below. The important part of the log is the penultimate line that contains
  21. # either "PASS" or "FAILURE".
  22. #
  23. # mkfs.fat 3.0.26 (2014-03-07)
  24. #
  25. #
  26. # U-Boot 2015.10-rc4-00018-g4b22a3e5513f (Oct 03 2015 - 13:49:23 -0600)
  27. #
  28. # DRAM: 128 MiB
  29. # Using default environment
  30. #
  31. # In: serial
  32. # Out: lcd
  33. # Err: lcd
  34. # Net: No ethernet found.
  35. # => host bind 0 sandbox/fat-noncontig.img
  36. # => load host 0:0 1000 noncontig.img
  37. # 33584964 bytes read in 18 ms (1.7 GiB/s)
  38. # => crc32 1000 $filesize 0
  39. # crc32 for 00001000 ... 02008743 ==> 6a080523
  40. # => if itest.l *0 != 2305086a; then echo FAILURE; else echo PASS; fi
  41. # PASS
  42. # => reset
  43. #
  44. # All temporary files used by this script are created in ./sandbox to avoid
  45. # polluting the source tree. test/fs/fs-test.sh also uses this directory for
  46. # the same purpose.
  47. #
  48. # TODO: Integrate this (and many other corner-cases e.g. different types of
  49. # FAT) with fs-test.sh so that a single script tests everything filesystem-
  50. # related.
  51. odir=sandbox
  52. img=${odir}/fat-noncontig.img
  53. mnt=${odir}/mnt
  54. fill=/dev/urandom
  55. testfn=noncontig.img
  56. mnttestfn=${mnt}/${testfn}
  57. crcaddr=0
  58. loadaddr=1000
  59. for prereq in fallocate mkfs.fat dd crc32; do
  60. if [ ! -x "`which $prereq`" ]; then
  61. echo "Missing $prereq binary. Exiting!"
  62. exit 1
  63. fi
  64. done
  65. make O=${odir} -s sandbox_defconfig && make O=${odir} -s -j8
  66. mkdir -p ${mnt}
  67. if [ ! -f ${img} ]; then
  68. fallocate -l 40M ${img}
  69. if [ $? -ne 0 ]; then
  70. echo fallocate failed - using dd instead
  71. dd if=/dev/zero of=${img} bs=1024 count=$((40 * 1024))
  72. if [ $? -ne 0 ]; then
  73. echo Could not create empty disk image
  74. exit $?
  75. fi
  76. fi
  77. mkfs.fat ${img}
  78. if [ $? -ne 0 ]; then
  79. echo Could not create FAT filesystem
  80. exit $?
  81. fi
  82. sudo mount -o loop,uid=$(id -u) ${img} ${mnt}
  83. if [ $? -ne 0 ]; then
  84. echo Could not mount test filesystem
  85. exit $?
  86. fi
  87. for ((sects=8; sects < 512; sects += 8)); do
  88. fn=${mnt}/keep-${sects}.img
  89. dd if=${fill} of=${fn} bs=512 count=${sects} >/dev/null 2>&1
  90. fn=${mnt}/remove-${sects}.img
  91. dd if=${fill} of=${fn} bs=512 count=${sects} >/dev/null 2>&1
  92. done
  93. rm -f ${mnt}/remove-*.img
  94. # 511 deliberately to trigger a file size that's not a multiple of the
  95. # sector size (ignoring sizes that are multiples of both).
  96. dd if=${fill} of=${mnttestfn} bs=511 >/dev/null 2>&1
  97. sudo umount ${mnt}
  98. if [ $? -ne 0 ]; then
  99. echo Could not unmount test filesystem
  100. exit $?
  101. fi
  102. fi
  103. sudo mount -o ro,loop,uid=$(id -u) ${img} ${mnt}
  104. if [ $? -ne 0 ]; then
  105. echo Could not mount test filesystem
  106. exit $?
  107. fi
  108. crc=0x`crc32 ${mnttestfn}`
  109. sudo umount ${mnt}
  110. if [ $? -ne 0 ]; then
  111. echo Could not unmount test filesystem
  112. exit $?
  113. fi
  114. crc=`printf %02x%02x%02x%02x \
  115. $((${crc} & 0xff)) \
  116. $(((${crc} >> 8) & 0xff)) \
  117. $(((${crc} >> 16) & 0xff)) \
  118. $((${crc} >> 24))`
  119. ./sandbox/u-boot << EOF
  120. host bind 0 ${img}
  121. load host 0:0 ${loadaddr} ${testfn}
  122. crc32 ${loadaddr} \$filesize ${crcaddr}
  123. if itest.l *${crcaddr} != ${crc}; then echo FAILURE; else echo PASS; fi
  124. reset
  125. EOF
  126. if [ $? -ne 0 ]; then
  127. echo U-Boot exit status indicates an error
  128. exit $?
  129. fi