hcd-tests.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # test types can be passed on the command line:
  5. #
  6. # - control: any device can do this
  7. # - out, in: out needs 'bulk sink' firmware, in needs 'bulk src'
  8. # - iso-out, iso-in: out needs 'iso sink' firmware, in needs 'iso src'
  9. # - halt: needs bulk sink+src, tests halt set/clear from host
  10. # - unlink: needs bulk sink and/or src, test HCD unlink processing
  11. # - loop: needs firmware that will buffer N transfers
  12. #
  13. # run it for hours, days, weeks.
  14. #
  15. #
  16. # this default provides a steady test load for a bulk device
  17. #
  18. TYPES='control out in'
  19. #TYPES='control out in halt'
  20. #
  21. # to test HCD code
  22. #
  23. # - include unlink tests
  24. # - add some ${RANDOM}ness
  25. # - connect several devices concurrently (same HC)
  26. # - keep HC's IRQ lines busy with unrelated traffic (IDE, net, ...)
  27. # - add other concurrent system loads
  28. #
  29. declare -i COUNT BUFLEN
  30. COUNT=50000
  31. BUFLEN=2048
  32. # NOTE: the 'in' and 'out' cases are usually bulk, but can be
  33. # set up to use interrupt transfers by 'usbtest' module options
  34. if [ "$DEVICE" = "" ]; then
  35. echo "testing ALL recognized usbtest devices"
  36. echo ""
  37. TEST_ARGS="-a"
  38. else
  39. TEST_ARGS=""
  40. fi
  41. do_test ()
  42. {
  43. if ! ./testusb $TEST_ARGS -s $BUFLEN -c $COUNT $* 2>/dev/null
  44. then
  45. echo "FAIL"
  46. exit 1
  47. fi
  48. }
  49. ARGS="$*"
  50. if [ "$ARGS" = "" ];
  51. then
  52. ARGS="$TYPES"
  53. fi
  54. # FIXME use /sys/bus/usb/device/$THIS/bConfigurationValue to
  55. # check and change configs
  56. CONFIG=''
  57. check_config ()
  58. {
  59. if [ "$CONFIG" = "" ]; then
  60. CONFIG=$1
  61. echo "assuming $CONFIG configuration"
  62. return
  63. fi
  64. if [ "$CONFIG" = $1 ]; then
  65. return
  66. fi
  67. echo "** device must be in $1 config, but it's $CONFIG instead"
  68. exit 1
  69. }
  70. echo "TESTING: $ARGS"
  71. while : true
  72. do
  73. echo $(date)
  74. for TYPE in $ARGS
  75. do
  76. # restore defaults
  77. COUNT=5000
  78. BUFLEN=2048
  79. # FIXME automatically multiply COUNT by 10 when
  80. # /sys/bus/usb/device/$THIS/speed == "480"
  81. # COUNT=50000
  82. case $TYPE in
  83. control)
  84. # any device, in any configuration, can use this.
  85. echo '** Control test cases:'
  86. echo "test 9: ch9 postconfig"
  87. do_test -t 9 -c 5000
  88. echo "test 10: control queueing"
  89. do_test -t 10 -c 5000
  90. # this relies on some vendor-specific commands
  91. echo "test 14: control writes"
  92. do_test -t 14 -c 15000 -s 256 -v 1
  93. echo "test 21: control writes, unaligned"
  94. do_test -t 21 -c 100 -s 256 -v 1
  95. ;;
  96. out)
  97. check_config sink-src
  98. echo '** Host Write (OUT) test cases:'
  99. echo "test 1: $COUNT transfers, same size"
  100. do_test -t 1
  101. echo "test 3: $COUNT transfers, variable/short size"
  102. do_test -t 3 -v 421
  103. COUNT=100
  104. echo "test 17: $COUNT transfers, unaligned DMA map by core"
  105. do_test -t 17
  106. echo "test 19: $COUNT transfers, unaligned DMA map by usb_alloc_coherent"
  107. do_test -t 19
  108. COUNT=2000
  109. echo "test 5: $COUNT scatterlists, same size entries"
  110. do_test -t 5
  111. # try to trigger short OUT processing bugs
  112. echo "test 7a: $COUNT scatterlists, variable size/short entries"
  113. do_test -t 7 -v 579
  114. BUFLEN=4096
  115. echo "test 7b: $COUNT scatterlists, variable size/bigger entries"
  116. do_test -t 7 -v 41
  117. BUFLEN=64
  118. echo "test 7c: $COUNT scatterlists, variable size/micro entries"
  119. do_test -t 7 -v 63
  120. ;;
  121. iso-out)
  122. check_config sink-src
  123. echo '** Host ISOCHRONOUS Write (OUT) test cases:'
  124. # at peak iso transfer rates:
  125. # - usb 2.0 high bandwidth, this is one frame.
  126. # - usb 1.1, it's twenty-four frames.
  127. BUFLEN=24500
  128. COUNT=1000
  129. # COUNT=10000
  130. echo "test 15: $COUNT transfers, same size"
  131. # do_test -t 15 -g 3 -v 0
  132. BUFLEN=32768
  133. do_test -t 15 -g 8 -v 0
  134. # FIXME it'd make sense to have an iso OUT test issuing
  135. # short writes on more packets than the last one
  136. COUNT=100
  137. echo "test 22: $COUNT transfers, non aligned"
  138. do_test -t 22 -g 8 -v 0
  139. ;;
  140. in)
  141. check_config sink-src
  142. echo '** Host Read (IN) test cases:'
  143. # NOTE: these "variable size" reads are just multiples
  144. # of 512 bytes, no EOVERFLOW testing is done yet
  145. echo "test 2: $COUNT transfers, same size"
  146. do_test -t 2
  147. echo "test 4: $COUNT transfers, variable size"
  148. do_test -t 4
  149. COUNT=100
  150. echo "test 18: $COUNT transfers, unaligned DMA map by core"
  151. do_test -t 18
  152. echo "test 20: $COUNT transfers, unaligned DMA map by usb_alloc_coherent"
  153. do_test -t 20
  154. COUNT=2000
  155. echo "test 6: $COUNT scatterlists, same size entries"
  156. do_test -t 6
  157. echo "test 8: $COUNT scatterlists, variable size entries"
  158. do_test -t 8
  159. ;;
  160. iso-in)
  161. check_config sink-src
  162. echo '** Host ISOCHRONOUS Read (IN) test cases:'
  163. # at peak iso transfer rates:
  164. # - usb 2.0 high bandwidth, this is one frame.
  165. # - usb 1.1, it's twenty-four frames.
  166. BUFLEN=24500
  167. COUNT=1000
  168. # COUNT=10000
  169. echo "test 16: $COUNT transfers, same size"
  170. # do_test -t 16 -g 3 -v 0
  171. BUFLEN=32768
  172. do_test -t 16 -g 8 -v 0
  173. # FIXME since iso expects faults, it'd make sense
  174. # to have an iso IN test issuing short reads ...
  175. COUNT=100
  176. echo "test 23: $COUNT transfers, unaligned"
  177. do_test -t 23 -g 8 -v 0
  178. ;;
  179. halt)
  180. # NOTE: sometimes hardware doesn't cooperate well with halting
  181. # endpoints from the host side. so long as mass-storage class
  182. # firmware can halt them from the device, don't worry much if
  183. # you can't make this test work on your device.
  184. COUNT=2000
  185. echo "test 13: $COUNT halt set/clear"
  186. do_test -t 13
  187. ;;
  188. unlink)
  189. COUNT=2000
  190. echo "test 11: $COUNT read unlinks"
  191. do_test -t 11
  192. echo "test 12: $COUNT write unlinks"
  193. do_test -t 12
  194. ;;
  195. loop)
  196. # defaults need too much buffering for ez-usb devices
  197. BUFLEN=2048
  198. COUNT=32
  199. # modprobe g_zero qlen=$COUNT buflen=$BUFLEN loopdefault
  200. check_config loopback
  201. # FIXME someone needs to write and merge a version of this
  202. echo "write $COUNT buffers of $BUFLEN bytes, read them back"
  203. echo "write $COUNT variable size buffers, read them back"
  204. ;;
  205. *)
  206. echo "Don't understand test type $TYPE"
  207. exit 1;
  208. esac
  209. echo ''
  210. done
  211. done
  212. # vim: sw=4