#!/bin/sh1# SPDX-License-Identifier: GPL-2.02#3# test types can be passed on the command line:4#5# - control: any device can do this6# - out, in: out needs 'bulk sink' firmware, in needs 'bulk src'7# - iso-out, iso-in: out needs 'iso sink' firmware, in needs 'iso src'8# - halt: needs bulk sink+src, tests halt set/clear from host9# - unlink: needs bulk sink and/or src, test HCD unlink processing10# - loop: needs firmware that will buffer N transfers11#12# run it for hours, days, weeks.13#1415#16# this default provides a steady test load for a bulk device17#18TYPES='control out in'19#TYPES='control out in halt'2021#22# to test HCD code23#24# - include unlink tests25# - add some ${RANDOM}ness26# - connect several devices concurrently (same HC)27# - keep HC's IRQ lines busy with unrelated traffic (IDE, net, ...)28# - add other concurrent system loads29#3031declare -i COUNT BUFLEN3233COUNT=5000034BUFLEN=20483536# NOTE: the 'in' and 'out' cases are usually bulk, but can be37# set up to use interrupt transfers by 'usbtest' module options383940if [ "$DEVICE" = "" ]; then41echo "testing ALL recognized usbtest devices"42echo ""43TEST_ARGS="-a"44else45TEST_ARGS=""46fi4748do_test ()49{50if ! ./testusb $TEST_ARGS -s $BUFLEN -c $COUNT $* 2>/dev/null51then52echo "FAIL"53exit 154fi55}5657ARGS="$*"5859if [ "$ARGS" = "" ];60then61ARGS="$TYPES"62fi6364# FIXME use /sys/bus/usb/device/$THIS/bConfigurationValue to65# check and change configs6667CONFIG=''6869check_config ()70{71if [ "$CONFIG" = "" ]; then72CONFIG=$173echo "assuming $CONFIG configuration"74return75fi76if [ "$CONFIG" = $1 ]; then77return78fi7980echo "** device must be in $1 config, but it's $CONFIG instead"81exit 182}838485echo "TESTING: $ARGS"8687while : true88do89echo $(date)9091for TYPE in $ARGS92do93# restore defaults94COUNT=500095BUFLEN=20489697# FIXME automatically multiply COUNT by 10 when98# /sys/bus/usb/device/$THIS/speed == "480"99100# COUNT=50000101102case $TYPE in103control)104# any device, in any configuration, can use this.105echo '** Control test cases:'106107echo "test 9: ch9 postconfig"108do_test -t 9 -c 5000109echo "test 10: control queueing"110do_test -t 10 -c 5000111112# this relies on some vendor-specific commands113echo "test 14: control writes"114do_test -t 14 -c 15000 -s 256 -v 1115116echo "test 21: control writes, unaligned"117do_test -t 21 -c 100 -s 256 -v 1118119;;120121out)122check_config sink-src123echo '** Host Write (OUT) test cases:'124125echo "test 1: $COUNT transfers, same size"126do_test -t 1127echo "test 3: $COUNT transfers, variable/short size"128do_test -t 3 -v 421129130COUNT=100131echo "test 17: $COUNT transfers, unaligned DMA map by core"132do_test -t 17133134echo "test 19: $COUNT transfers, unaligned DMA map by usb_alloc_coherent"135do_test -t 19136137COUNT=2000138echo "test 5: $COUNT scatterlists, same size entries"139do_test -t 5140141# try to trigger short OUT processing bugs142echo "test 7a: $COUNT scatterlists, variable size/short entries"143do_test -t 7 -v 579144BUFLEN=4096145echo "test 7b: $COUNT scatterlists, variable size/bigger entries"146do_test -t 7 -v 41147BUFLEN=64148echo "test 7c: $COUNT scatterlists, variable size/micro entries"149do_test -t 7 -v 63150;;151152iso-out)153check_config sink-src154echo '** Host ISOCHRONOUS Write (OUT) test cases:'155156# at peak iso transfer rates:157# - usb 2.0 high bandwidth, this is one frame.158# - usb 1.1, it's twenty-four frames.159BUFLEN=24500160161COUNT=1000162163# COUNT=10000164165echo "test 15: $COUNT transfers, same size"166# do_test -t 15 -g 3 -v 0167BUFLEN=32768168do_test -t 15 -g 8 -v 0169170# FIXME it'd make sense to have an iso OUT test issuing171# short writes on more packets than the last one172173COUNT=100174echo "test 22: $COUNT transfers, non aligned"175do_test -t 22 -g 8 -v 0176177;;178179in)180check_config sink-src181echo '** Host Read (IN) test cases:'182183# NOTE: these "variable size" reads are just multiples184# of 512 bytes, no EOVERFLOW testing is done yet185186echo "test 2: $COUNT transfers, same size"187do_test -t 2188echo "test 4: $COUNT transfers, variable size"189do_test -t 4190191COUNT=100192echo "test 18: $COUNT transfers, unaligned DMA map by core"193do_test -t 18194195echo "test 20: $COUNT transfers, unaligned DMA map by usb_alloc_coherent"196do_test -t 20197198COUNT=2000199echo "test 6: $COUNT scatterlists, same size entries"200do_test -t 6201echo "test 8: $COUNT scatterlists, variable size entries"202do_test -t 8203;;204205iso-in)206check_config sink-src207echo '** Host ISOCHRONOUS Read (IN) test cases:'208209# at peak iso transfer rates:210# - usb 2.0 high bandwidth, this is one frame.211# - usb 1.1, it's twenty-four frames.212BUFLEN=24500213214COUNT=1000215216# COUNT=10000217218echo "test 16: $COUNT transfers, same size"219# do_test -t 16 -g 3 -v 0220BUFLEN=32768221do_test -t 16 -g 8 -v 0222223# FIXME since iso expects faults, it'd make sense224# to have an iso IN test issuing short reads ...225226COUNT=100227echo "test 23: $COUNT transfers, unaligned"228do_test -t 23 -g 8 -v 0229230;;231232halt)233# NOTE: sometimes hardware doesn't cooperate well with halting234# endpoints from the host side. so long as mass-storage class235# firmware can halt them from the device, don't worry much if236# you can't make this test work on your device.237COUNT=2000238echo "test 13: $COUNT halt set/clear"239do_test -t 13240;;241242unlink)243COUNT=2000244echo "test 11: $COUNT read unlinks"245do_test -t 11246247echo "test 12: $COUNT write unlinks"248do_test -t 12249;;250251loop)252# defaults need too much buffering for ez-usb devices253BUFLEN=2048254COUNT=32255256# modprobe g_zero qlen=$COUNT buflen=$BUFLEN loopdefault257check_config loopback258259# FIXME someone needs to write and merge a version of this260261echo "write $COUNT buffers of $BUFLEN bytes, read them back"262263echo "write $COUNT variable size buffers, read them back"264265;;266267*)268echo "Don't understand test type $TYPE"269exit 1;270esac271echo ''272done273done274275276