ubi-stress-test.sh.in 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #!/bin/sh -euf
  2. prefix=@prefix@
  3. exec_prefix=@exec_prefix@
  4. bindir=@bindir@
  5. libexecpath=@libexecdir@/mtd-utils
  6. TESTBINDIR=@testbindir@
  7. fatal()
  8. {
  9. echo "Error: $1" 1>&2
  10. exit 1
  11. }
  12. usage()
  13. {
  14. cat 1>&2 <<EOF
  15. Stress-test an UBI device. This test is basically built on top of
  16. 'runubitests.sh' and runs it several times for different configurations.
  17. The nandsim and mtdram drivers have to be compiled as kernel modules.
  18. Usage:
  19. ${0##*/} run
  20. EOF
  21. }
  22. cleanup_handler()
  23. {
  24. local ret="$1"
  25. rmmod ubi >/dev/null 2>&1 ||:
  26. rmmod nandsim >/dev/null 2>&1 ||:
  27. rmmod mtdram >/dev/null 2>&1 ||:
  28. # Below is magic to exit with correct exit code
  29. if [ "$ret" != "0" ]; then
  30. trap false EXIT
  31. else
  32. trap true EXIT
  33. fi
  34. }
  35. trap 'cleanup_handler $?' EXIT
  36. trap 'cleanup_handler 1' HUP PIPE INT QUIT TERM
  37. # Find MTD device number by pattern in /proc/mtd
  38. # Usage: find_mtd_device <pattern>
  39. find_mtd_device()
  40. {
  41. printf "%s" "$(grep "$1" /proc/mtd | sed -e "s/^mtd\([0-9]\+\):.*$/\1/")"
  42. }
  43. # Just print parameters of the 'run_test' funcion in a user-friendly form.
  44. print_params()
  45. {
  46. local module="$1"; shift
  47. local size="$1"; shift
  48. local peb_size="$1"; shift
  49. local page_size="$1"; shift
  50. local vid_offs="$1"; shift
  51. local fastmap="$1"; shift
  52. printf "%s" "$module: ${size}MiB, PEB size ${peb_size}KiB, "
  53. if [ "$module" = "nandsim" ]; then
  54. printf "%s" "page size ${page_size}KiB, VID offset $vid_offs, "
  55. fi
  56. printf "%s\n" "fastmap $fastmap"
  57. }
  58. # Load mtdram with specified size and PEB size
  59. # Usage: load_mtdram <flash size> <PEB size>
  60. # 1. Flash size is specified in MiB
  61. # 2. PEB size is specified in KiB
  62. load_mtdram()
  63. {
  64. local size="$1"; shift
  65. local peb_size="$1"; shift
  66. size="$(($size * 1024))"
  67. modprobe mtdram total_size="$size" erase_size="$peb_size" ||
  68. echo "Error: cannot load $size MiB mtdram"
  69. }
  70. print_separator()
  71. {
  72. echo "======================================================================"
  73. }
  74. # Run a test on nandsim or mtdram with certain geometry.
  75. # Usage: run_test <nandsim|mtdram> <flash size> <PEB size> \
  76. # <Page size> <VID hdr offs> <enable fastmap>
  77. # 1. Simulator type (nandsim or mtdram)
  78. # 2. Flash size is specified in MiB
  79. # 3. PEB size is specified in KiB
  80. # 4. Page size is specified in bytes (mtdram ingores this)
  81. # 5. VID header offset (mtdram ingores this)
  82. # 6. Whether fast-map should be enabled (pass "enabled" or "disabled")
  83. run_test()
  84. {
  85. local module="$1";
  86. local size="$2";
  87. local peb_size="$3";
  88. local page_size="$4";
  89. local vid_offs="$5"
  90. local fastmap="$6";
  91. local fm_supported fm_param mtdnum
  92. print_separator
  93. # Check if fastmap is supported by UBI
  94. if modinfo ubi | grep -q fm_auto; then
  95. fm_supported="yes"
  96. else
  97. fm_supported="no"
  98. fi
  99. if [ "$fastmap" = "enabled" ]; then
  100. fm_param=
  101. elif [ "$fm_supported" = "yes" ]; then
  102. fastmap="disabled"
  103. fm_param="fm_autoconvert"
  104. else
  105. echo "Fastmap is not supported, skip"
  106. return 0
  107. fi
  108. if [ "$module" = "nandsim" ]; then
  109. print_params "$@"
  110. $TESTBINDIR/load_nandsim.sh "$size" "$peb_size" "$page_size" ||
  111. echo "Cannot load nandsim, test skipped"
  112. mtdnum="$(find_mtd_device "$nandsim_patt")"
  113. elif [ "$module" = "mtdram" ]; then
  114. print_params "$@"
  115. load_mtdram "$size" "$peb_size"
  116. mtdnum="$(find_mtd_device "$mtdram_patt")"
  117. else
  118. fatal "$module is not supported" ||
  119. echo "Cannot load nandsim, test skipped"
  120. fi
  121. modprobe ubi mtd="$mtdnum,$vid_offs" $fm_param
  122. $TESTBINDIR/runubitests.sh /dev/ubi0 ||:
  123. sudo rmmod ubi
  124. sudo rmmod "$module"
  125. }
  126. if [ "$#" -lt 1 ] || [ "$1" != "run" ]; then
  127. usage
  128. exit 1
  129. fi
  130. # Make sure neither mtdram nor nandsim are used
  131. nandsim_patt="NAND simulator"
  132. mtdram_patt="mtdram test device"
  133. if [ -e /proc/mtd ]; then
  134. ! grep -q "$nandsim_patt" /proc/mtd ||
  135. fatal "the nandsim driver is already used"
  136. ! grep -q "$mtdram_patt" /proc/mtd ||
  137. fatal "the mtdram driver is already used"
  138. fi
  139. rmmod ubi >/dev/null 2>&1 ||:
  140. for module in "mtdram" "nandsim"; do
  141. for fm in "enabled" "disabled"; do
  142. for vid_factor in 1 0; do
  143. print_separator
  144. print_separator
  145. print_separator
  146. echo "Test on $module, fastmap $fm, VID header offset factor $vid_factor"
  147. print_separator
  148. print_separator
  149. pg_size="512"
  150. vid_offs="$(($pg_size * $vid_factor))"
  151. run_test "$module" "16" "16" "$pg_size" "$vid_offs" "$fm"
  152. run_test "$module" "32" "16" "$pg_size" "$vid_offs" "$fm"
  153. run_test "$module" "64" "16" "$pg_size" "$vid_offs" "$fm"
  154. run_test "$module" "128" "16" "$pg_size" "$vid_offs" "$fm"
  155. run_test "$module" "256" "16" "$pg_size" "$vid_offs" "$fm"
  156. pg_size="2048"
  157. vid_offs="$(($pg_size * $vid_factor))"
  158. run_test "$module" "64" "64" "$pg_size" "$vid_offs" "$fm"
  159. run_test "$module" "128" "64" "$pg_size" "$vid_offs" "$fm"
  160. run_test "$module" "256" "64" "$pg_size" "$vid_offs" "$fm"
  161. run_test "$module" "512" "64" "$pg_size" "$vid_offs" "$fm"
  162. run_test "$module" "1024" "64" "$pg_size" "$vid_offs" "$fm"
  163. run_test "$module" "64" "128" "$pg_size" "$vid_offs" "$fm"
  164. run_test "$module" "128" "128" "$pg_size" "$vid_offs" "$fm"
  165. run_test "$module" "256" "128" "$pg_size" "$vid_offs" "$fm"
  166. run_test "$module" "512" "128" "$pg_size" "$vid_offs" "$fm"
  167. run_test "$module" "1024" "128" "$pg_size" "$vid_offs" "$fm"
  168. run_test "$module" "64" "256" "$pg_size" "$vid_offs" "$fm"
  169. run_test "$module" "128" "256" "$pg_size" "$vid_offs" "$fm"
  170. run_test "$module" "256" "256" "$pg_size" "$vid_offs" "$fm"
  171. run_test "$module" "512" "256" "$pg_size" "$vid_offs" "$fm"
  172. run_test "$module" "1024" "256" "$pg_size" "$vid_offs" "$fm"
  173. run_test "$module" "64" "512" "$pg_size" "$vid_offs" "$fm"
  174. run_test "$module" "128" "512" "$pg_size" "$vid_offs" "$fm"
  175. run_test "$module" "256" "512" "$pg_size" "$vid_offs" "$fm"
  176. run_test "$module" "512" "512" "$pg_size" "$vid_offs" "$fm"
  177. run_test "$module" "1024" "512" "$pg_size" "$vid_offs" "$fm"
  178. done
  179. done
  180. done