xref: /kernel/linux/linux-5.10/tools/usb/hcd-tests.sh (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci#!/bin/sh
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# test types can be passed on the command line:
58c2ecf20Sopenharmony_ci#
68c2ecf20Sopenharmony_ci# - control: any device can do this
78c2ecf20Sopenharmony_ci# - out, in:  out needs 'bulk sink' firmware, in needs 'bulk src'
88c2ecf20Sopenharmony_ci# - iso-out, iso-in:  out needs 'iso sink' firmware, in needs 'iso src'
98c2ecf20Sopenharmony_ci# - halt: needs bulk sink+src, tests halt set/clear from host
108c2ecf20Sopenharmony_ci# - unlink: needs bulk sink and/or src, test HCD unlink processing
118c2ecf20Sopenharmony_ci# - loop: needs firmware that will buffer N transfers
128c2ecf20Sopenharmony_ci#
138c2ecf20Sopenharmony_ci# run it for hours, days, weeks.
148c2ecf20Sopenharmony_ci#
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#
178c2ecf20Sopenharmony_ci# this default provides a steady test load for a bulk device
188c2ecf20Sopenharmony_ci#
198c2ecf20Sopenharmony_ciTYPES='control out in'
208c2ecf20Sopenharmony_ci#TYPES='control out in halt'
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#
238c2ecf20Sopenharmony_ci# to test HCD code
248c2ecf20Sopenharmony_ci#
258c2ecf20Sopenharmony_ci#  - include unlink tests
268c2ecf20Sopenharmony_ci#  - add some ${RANDOM}ness
278c2ecf20Sopenharmony_ci#  - connect several devices concurrently (same HC)
288c2ecf20Sopenharmony_ci#  - keep HC's IRQ lines busy with unrelated traffic (IDE, net, ...)
298c2ecf20Sopenharmony_ci#  - add other concurrent system loads
308c2ecf20Sopenharmony_ci#
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cideclare -i COUNT BUFLEN
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciCOUNT=50000
358c2ecf20Sopenharmony_ciBUFLEN=2048
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci# NOTE:  the 'in' and 'out' cases are usually bulk, but can be
388c2ecf20Sopenharmony_ci# set up to use interrupt transfers by 'usbtest' module options
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciif [ "$DEVICE" = "" ]; then
428c2ecf20Sopenharmony_ci	echo "testing ALL recognized usbtest devices"
438c2ecf20Sopenharmony_ci	echo ""
448c2ecf20Sopenharmony_ci	TEST_ARGS="-a"
458c2ecf20Sopenharmony_cielse
468c2ecf20Sopenharmony_ci	TEST_ARGS=""
478c2ecf20Sopenharmony_cifi
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cido_test ()
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci    if ! ./testusb $TEST_ARGS -s $BUFLEN -c $COUNT $* 2>/dev/null
528c2ecf20Sopenharmony_ci    then
538c2ecf20Sopenharmony_ci	echo "FAIL"
548c2ecf20Sopenharmony_ci	exit 1
558c2ecf20Sopenharmony_ci    fi
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciARGS="$*"
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciif [ "$ARGS" = "" ];
618c2ecf20Sopenharmony_cithen
628c2ecf20Sopenharmony_ci    ARGS="$TYPES"
638c2ecf20Sopenharmony_cifi
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci# FIXME use /sys/bus/usb/device/$THIS/bConfigurationValue to
668c2ecf20Sopenharmony_ci# check and change configs
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciCONFIG=''
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cicheck_config ()
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci    if [ "$CONFIG" = "" ]; then
738c2ecf20Sopenharmony_ci	CONFIG=$1
748c2ecf20Sopenharmony_ci	echo "assuming $CONFIG configuration"
758c2ecf20Sopenharmony_ci	return
768c2ecf20Sopenharmony_ci    fi
778c2ecf20Sopenharmony_ci    if [ "$CONFIG" = $1 ]; then
788c2ecf20Sopenharmony_ci	return
798c2ecf20Sopenharmony_ci    fi
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci    echo "** device must be in $1 config, but it's $CONFIG instead"
828c2ecf20Sopenharmony_ci    exit 1
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciecho "TESTING:  $ARGS"
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ciwhile : true
898c2ecf20Sopenharmony_cido
908c2ecf20Sopenharmony_ci    echo $(date)
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci    for TYPE in $ARGS
938c2ecf20Sopenharmony_ci    do
948c2ecf20Sopenharmony_ci	# restore defaults
958c2ecf20Sopenharmony_ci	COUNT=5000
968c2ecf20Sopenharmony_ci	BUFLEN=2048
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	# FIXME automatically multiply COUNT by 10 when
998c2ecf20Sopenharmony_ci	# /sys/bus/usb/device/$THIS/speed == "480"
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#	COUNT=50000
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	case $TYPE in
1048c2ecf20Sopenharmony_ci	control)
1058c2ecf20Sopenharmony_ci	    # any device, in any configuration, can use this.
1068c2ecf20Sopenharmony_ci	    echo '** Control test cases:'
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	    echo "test 9: ch9 postconfig"
1098c2ecf20Sopenharmony_ci	    do_test -t 9 -c 5000
1108c2ecf20Sopenharmony_ci	    echo "test 10: control queueing"
1118c2ecf20Sopenharmony_ci	    do_test -t 10 -c 5000
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	    # this relies on some vendor-specific commands
1148c2ecf20Sopenharmony_ci	    echo "test 14: control writes"
1158c2ecf20Sopenharmony_ci	    do_test -t 14 -c 15000 -s 256 -v 1
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	    echo "test 21: control writes, unaligned"
1188c2ecf20Sopenharmony_ci	    do_test -t 21 -c 100 -s 256 -v 1
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	    ;;
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	out)
1238c2ecf20Sopenharmony_ci	    check_config sink-src
1248c2ecf20Sopenharmony_ci	    echo '** Host Write (OUT) test cases:'
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	    echo "test 1: $COUNT transfers, same size"
1278c2ecf20Sopenharmony_ci	    do_test -t 1
1288c2ecf20Sopenharmony_ci	    echo "test 3: $COUNT transfers, variable/short size"
1298c2ecf20Sopenharmony_ci	    do_test -t 3 -v 421
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	    COUNT=100
1328c2ecf20Sopenharmony_ci	    echo "test 17: $COUNT transfers, unaligned DMA map by core"
1338c2ecf20Sopenharmony_ci	    do_test -t 17
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	    echo "test 19: $COUNT transfers, unaligned DMA map by usb_alloc_coherent"
1368c2ecf20Sopenharmony_ci	    do_test -t 19
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	    COUNT=2000
1398c2ecf20Sopenharmony_ci	    echo "test 5: $COUNT scatterlists, same size entries"
1408c2ecf20Sopenharmony_ci	    do_test -t 5
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	    # try to trigger short OUT processing bugs
1438c2ecf20Sopenharmony_ci	    echo "test 7a: $COUNT scatterlists, variable size/short entries"
1448c2ecf20Sopenharmony_ci	    do_test -t 7 -v 579
1458c2ecf20Sopenharmony_ci	    BUFLEN=4096
1468c2ecf20Sopenharmony_ci	    echo "test 7b: $COUNT scatterlists, variable size/bigger entries"
1478c2ecf20Sopenharmony_ci	    do_test -t 7 -v 41
1488c2ecf20Sopenharmony_ci	    BUFLEN=64
1498c2ecf20Sopenharmony_ci	    echo "test 7c: $COUNT scatterlists, variable size/micro entries"
1508c2ecf20Sopenharmony_ci	    do_test -t 7 -v 63
1518c2ecf20Sopenharmony_ci	    ;;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	iso-out)
1548c2ecf20Sopenharmony_ci	    check_config sink-src
1558c2ecf20Sopenharmony_ci	    echo '** Host ISOCHRONOUS Write (OUT) test cases:'
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	    # at peak iso transfer rates:
1588c2ecf20Sopenharmony_ci	    # - usb 2.0 high bandwidth, this is one frame.
1598c2ecf20Sopenharmony_ci	    # - usb 1.1, it's twenty-four frames.
1608c2ecf20Sopenharmony_ci	    BUFLEN=24500
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	    COUNT=1000
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci# COUNT=10000
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	    echo "test 15: $COUNT transfers, same size"
1678c2ecf20Sopenharmony_ci	    # do_test -t 15 -g 3 -v 0
1688c2ecf20Sopenharmony_ci	    BUFLEN=32768
1698c2ecf20Sopenharmony_ci	    do_test -t 15 -g 8 -v 0
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	    # FIXME it'd make sense to have an iso OUT test issuing
1728c2ecf20Sopenharmony_ci	    # short writes on more packets than the last one
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	    COUNT=100
1758c2ecf20Sopenharmony_ci	    echo "test 22: $COUNT transfers, non aligned"
1768c2ecf20Sopenharmony_ci	    do_test -t 22 -g 8 -v 0
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	    ;;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	in)
1818c2ecf20Sopenharmony_ci	    check_config sink-src
1828c2ecf20Sopenharmony_ci	    echo '** Host Read (IN) test cases:'
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	    # NOTE:  these "variable size" reads are just multiples
1858c2ecf20Sopenharmony_ci	    # of 512 bytes, no EOVERFLOW testing is done yet
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci	    echo "test 2: $COUNT transfers, same size"
1888c2ecf20Sopenharmony_ci	    do_test -t 2
1898c2ecf20Sopenharmony_ci	    echo "test 4: $COUNT transfers, variable size"
1908c2ecf20Sopenharmony_ci	    do_test -t 4
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	    COUNT=100
1938c2ecf20Sopenharmony_ci	    echo "test 18: $COUNT transfers, unaligned DMA map by core"
1948c2ecf20Sopenharmony_ci	    do_test -t 18
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	    echo "test 20: $COUNT transfers, unaligned DMA map by usb_alloc_coherent"
1978c2ecf20Sopenharmony_ci	    do_test -t 20
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	    COUNT=2000
2008c2ecf20Sopenharmony_ci	    echo "test 6: $COUNT scatterlists, same size entries"
2018c2ecf20Sopenharmony_ci	    do_test -t 6
2028c2ecf20Sopenharmony_ci	    echo "test 8: $COUNT scatterlists, variable size entries"
2038c2ecf20Sopenharmony_ci	    do_test -t 8
2048c2ecf20Sopenharmony_ci	    ;;
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci	iso-in)
2078c2ecf20Sopenharmony_ci	    check_config sink-src
2088c2ecf20Sopenharmony_ci	    echo '** Host ISOCHRONOUS Read (IN) test cases:'
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci	    # at peak iso transfer rates:
2118c2ecf20Sopenharmony_ci	    # - usb 2.0 high bandwidth, this is one frame.
2128c2ecf20Sopenharmony_ci	    # - usb 1.1, it's twenty-four frames.
2138c2ecf20Sopenharmony_ci	    BUFLEN=24500
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	    COUNT=1000
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci# COUNT=10000
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	    echo "test 16: $COUNT transfers, same size"
2208c2ecf20Sopenharmony_ci	    # do_test -t 16 -g 3 -v 0
2218c2ecf20Sopenharmony_ci	    BUFLEN=32768
2228c2ecf20Sopenharmony_ci	    do_test -t 16 -g 8 -v 0
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	    # FIXME since iso expects faults, it'd make sense
2258c2ecf20Sopenharmony_ci	    # to have an iso IN test issuing short reads ...
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	    COUNT=100
2288c2ecf20Sopenharmony_ci	    echo "test 23: $COUNT transfers, unaligned"
2298c2ecf20Sopenharmony_ci	    do_test -t 23 -g 8 -v 0
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci	    ;;
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci	halt)
2348c2ecf20Sopenharmony_ci	    # NOTE:  sometimes hardware doesn't cooperate well with halting
2358c2ecf20Sopenharmony_ci	    # endpoints from the host side.  so long as mass-storage class
2368c2ecf20Sopenharmony_ci	    # firmware can halt them from the device, don't worry much if
2378c2ecf20Sopenharmony_ci	    # you can't make this test work on your device.
2388c2ecf20Sopenharmony_ci	    COUNT=2000
2398c2ecf20Sopenharmony_ci	    echo "test 13: $COUNT halt set/clear"
2408c2ecf20Sopenharmony_ci	    do_test -t 13
2418c2ecf20Sopenharmony_ci	    ;;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	unlink)
2448c2ecf20Sopenharmony_ci	    COUNT=2000
2458c2ecf20Sopenharmony_ci	    echo "test 11: $COUNT read unlinks"
2468c2ecf20Sopenharmony_ci	    do_test -t 11
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	    echo "test 12: $COUNT write unlinks"
2498c2ecf20Sopenharmony_ci	    do_test -t 12
2508c2ecf20Sopenharmony_ci	    ;;
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	loop)
2538c2ecf20Sopenharmony_ci	    # defaults need too much buffering for ez-usb devices
2548c2ecf20Sopenharmony_ci	    BUFLEN=2048
2558c2ecf20Sopenharmony_ci	    COUNT=32
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	    # modprobe g_zero qlen=$COUNT buflen=$BUFLEN loopdefault
2588c2ecf20Sopenharmony_ci	    check_config loopback
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	    # FIXME someone needs to write and merge a version of this
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci	    echo "write $COUNT buffers of $BUFLEN bytes, read them back"
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	    echo "write $COUNT variable size buffers, read them back"
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci	    ;;
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	*)
2698c2ecf20Sopenharmony_ci	    echo "Don't understand test type $TYPE"
2708c2ecf20Sopenharmony_ci	    exit 1;
2718c2ecf20Sopenharmony_ci	esac
2728c2ecf20Sopenharmony_ci	echo ''
2738c2ecf20Sopenharmony_ci    done
2748c2ecf20Sopenharmony_cidone
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci# vim: sw=4
277