Path: blob/master/tools/testing/selftests/drivers/usb/usbip/usbip_test.sh
26298 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.023# Kselftest framework requirement - SKIP code is 4.4ksft_skip=456usage() { echo "usbip_test.sh -b <busid> -p <usbip tools path>"; exit 1; }78while getopts "h:b:p:" arg; do9case "${arg}" in10h)11usage12;;13b)14busid=${OPTARG}15;;16p)17tools_path=${OPTARG}18;;19*)20usage21;;22esac23done24shift $((OPTIND-1))2526if [ -z "${busid}" ]; then27usage28fi2930echo "Running USB over IP Testing on $busid";3132test_end_msg="End of USB over IP Testing on $busid"3334if [ $UID != 0 ]; then35echo "Please run usbip_test as root [SKIP]"36echo $test_end_msg37exit $ksft_skip38fi3940echo "Load usbip_host module"41if ! /sbin/modprobe -q -n usbip_host; then42echo "usbip_test: module usbip_host is not found [SKIP]"43echo $test_end_msg44exit $ksft_skip45fi4647if /sbin/modprobe -q usbip_host; then48echo "usbip_test: module usbip_host is loaded [OK]"49else50echo "usbip_test: module usbip_host failed to load [FAIL]"51echo $test_end_msg52exit 153fi5455echo "Load vhci_hcd module"56if /sbin/modprobe -q vhci_hcd; then57echo "usbip_test: module vhci_hcd is loaded [OK]"58else59echo "usbip_test: module vhci_hcd failed to load [FAIL]"60echo $test_end_msg61exit 162fi63echo "=============================================================="6465cd $tools_path;6667if [ ! -f src/usbip ]; then68echo "Please build usbip tools"69echo $test_end_msg70exit $ksft_skip71fi7273echo "Expect to see export-able devices";74src/usbip list -l;75echo "=============================================================="7677echo "Run lsusb to see all usb devices"78lsusb -t;79echo "=============================================================="8081src/usbipd -D;8283echo "Get exported devices from localhost - expect to see none";84src/usbip list -r localhost;85echo "=============================================================="8687echo "bind devices";88src/usbip bind -b $busid;89echo "=============================================================="9091echo "Run lsusb - bound devices should be under usbip_host control"92lsusb -t;93echo "=============================================================="9495echo "bind devices - expect already bound messages"96src/usbip bind -b $busid;97echo "=============================================================="9899echo "Get exported devices from localhost - expect to see exported devices";100src/usbip list -r localhost;101echo "=============================================================="102103echo "unbind devices";104src/usbip unbind -b $busid;105echo "=============================================================="106107echo "Run lsusb - bound devices should be rebound to original drivers"108lsusb -t;109echo "=============================================================="110111echo "unbind devices - expect no devices bound message";112src/usbip unbind -b $busid;113echo "=============================================================="114115echo "Get exported devices from localhost - expect to see none";116src/usbip list -r localhost;117echo "=============================================================="118119echo "List imported devices - expect to see none";120src/usbip port;121echo "=============================================================="122123echo "Import devices from localhost - should fail with no devices"124src/usbip attach -r localhost -b $busid;125echo "=============================================================="126127echo "bind devices";128src/usbip bind -b $busid;129echo "=============================================================="130131echo "List imported devices - expect to see exported devices";132src/usbip list -r localhost;133echo "=============================================================="134135echo "List imported devices - expect to see none";136src/usbip port;137echo "=============================================================="138139echo "Import devices from localhost - should work"140src/usbip attach -r localhost -b $busid;141echo "=============================================================="142143# Wait for sysfs file to be updated. Without this sleep, usbip port144# shows no imported devices.145sleep 3;146147echo "List imported devices - expect to see imported devices";148src/usbip port;149echo "=============================================================="150151echo "Import devices from localhost - expect already imported messages"152src/usbip attach -r localhost -b $busid;153echo "=============================================================="154155echo "Un-import devices";156src/usbip detach -p 00;157src/usbip detach -p 01;158echo "=============================================================="159160echo "List imported devices - expect to see none";161src/usbip port;162echo "=============================================================="163164echo "Un-import devices - expect no devices to detach messages";165src/usbip detach -p 00;166src/usbip detach -p 01;167echo "=============================================================="168169echo "Detach invalid port tests - expect invalid port error message";170src/usbip detach -p 100;171echo "=============================================================="172173echo "Expect to see export-able devices";174src/usbip list -l;175echo "=============================================================="176177echo "Remove usbip_host module";178rmmod usbip_host;179180echo "Run lsusb - bound devices should be rebound to original drivers"181lsusb -t;182echo "=============================================================="183184echo "Run bind without usbip_host - expect fail"185src/usbip bind -b $busid;186echo "=============================================================="187188echo "Run lsusb - devices that failed to bind aren't bound to any driver"189lsusb -t;190echo "=============================================================="191192echo "modprobe usbip_host - does it work?"193/sbin/modprobe usbip_host194echo "Should see -busid- is not in match_busid table... skip! dmesg"195echo "=============================================================="196dmesg | grep "is not in match_busid table"197echo "=============================================================="198199echo $test_end_msg200201202