1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# Kselftest framework requirement - SKIP code is 4. 5ksft_skip=4 6 7usage() { echo "usbip_test.sh -b <busid> -p <usbip tools path>"; exit 1; } 8 9while getopts "h:b:p:" arg; do 10 case "${arg}" in 11 h) 12 usage 13 ;; 14 b) 15 busid=${OPTARG} 16 ;; 17 p) 18 tools_path=${OPTARG} 19 ;; 20 *) 21 usage 22 ;; 23 esac 24done 25shift $((OPTIND-1)) 26 27if [ -z "${busid}" ]; then 28 usage 29fi 30 31echo "Running USB over IP Testing on $busid"; 32 33test_end_msg="End of USB over IP Testing on $busid" 34 35if [ $UID != 0 ]; then 36 echo "Please run usbip_test as root [SKIP]" 37 echo $test_end_msg 38 exit $ksft_skip 39fi 40 41echo "Load usbip_host module" 42if ! /sbin/modprobe -q -n usbip_host; then 43 echo "usbip_test: module usbip_host is not found [SKIP]" 44 echo $test_end_msg 45 exit $ksft_skip 46fi 47 48if /sbin/modprobe -q usbip_host; then 49 /sbin/modprobe -q -r test_bitmap 50 echo "usbip_test: module usbip_host is loaded [OK]" 51else 52 echo "usbip_test: module usbip_host failed to load [FAIL]" 53 echo $test_end_msg 54 exit 1 55fi 56 57echo "Load vhci_hcd module" 58if /sbin/modprobe -q vhci_hcd; then 59 /sbin/modprobe -q -r test_bitmap 60 echo "usbip_test: module vhci_hcd is loaded [OK]" 61else 62 echo "usbip_test: module vhci_hcd failed to load [FAIL]" 63 echo $test_end_msg 64 exit 1 65fi 66echo "==============================================================" 67 68cd $tools_path; 69 70if [ ! -f src/usbip ]; then 71 echo "Please build usbip tools" 72 echo $test_end_msg 73 exit $ksft_skip 74fi 75 76echo "Expect to see export-able devices"; 77src/usbip list -l; 78echo "==============================================================" 79 80echo "Run lsusb to see all usb devices" 81lsusb -t; 82echo "==============================================================" 83 84src/usbipd -D; 85 86echo "Get exported devices from localhost - expect to see none"; 87src/usbip list -r localhost; 88echo "==============================================================" 89 90echo "bind devices"; 91src/usbip bind -b $busid; 92echo "==============================================================" 93 94echo "Run lsusb - bound devices should be under usbip_host control" 95lsusb -t; 96echo "==============================================================" 97 98echo "bind devices - expect already bound messages" 99src/usbip bind -b $busid; 100echo "==============================================================" 101 102echo "Get exported devices from localhost - expect to see exported devices"; 103src/usbip list -r localhost; 104echo "==============================================================" 105 106echo "unbind devices"; 107src/usbip unbind -b $busid; 108echo "==============================================================" 109 110echo "Run lsusb - bound devices should be rebound to original drivers" 111lsusb -t; 112echo "==============================================================" 113 114echo "unbind devices - expect no devices bound message"; 115src/usbip unbind -b $busid; 116echo "==============================================================" 117 118echo "Get exported devices from localhost - expect to see none"; 119src/usbip list -r localhost; 120echo "==============================================================" 121 122echo "List imported devices - expect to see none"; 123src/usbip port; 124echo "==============================================================" 125 126echo "Import devices from localhost - should fail with no devices" 127src/usbip attach -r localhost -b $busid; 128echo "==============================================================" 129 130echo "bind devices"; 131src/usbip bind -b $busid; 132echo "==============================================================" 133 134echo "List imported devices - expect to see exported devices"; 135src/usbip list -r localhost; 136echo "==============================================================" 137 138echo "List imported devices - expect to see none"; 139src/usbip port; 140echo "==============================================================" 141 142echo "Import devices from localhost - should work" 143src/usbip attach -r localhost -b $busid; 144echo "==============================================================" 145 146echo "List imported devices - expect to see imported devices"; 147src/usbip port; 148echo "==============================================================" 149 150echo "Import devices from localhost - expect already imported messages" 151src/usbip attach -r localhost -b $busid; 152echo "==============================================================" 153 154echo "Un-import devices"; 155src/usbip detach -p 00; 156src/usbip detach -p 01; 157echo "==============================================================" 158 159echo "List imported devices - expect to see none"; 160src/usbip port; 161echo "==============================================================" 162 163echo "Un-import devices - expect no devices to detach messages"; 164src/usbip detach -p 00; 165src/usbip detach -p 01; 166echo "==============================================================" 167 168echo "Detach invalid port tests - expect invalid port error message"; 169src/usbip detach -p 100; 170echo "==============================================================" 171 172echo "Expect to see export-able devices"; 173src/usbip list -l; 174echo "==============================================================" 175 176echo "Remove usbip_host module"; 177rmmod usbip_host; 178 179echo "Run lsusb - bound devices should be rebound to original drivers" 180lsusb -t; 181echo "==============================================================" 182 183echo "Run bind without usbip_host - expect fail" 184src/usbip bind -b $busid; 185echo "==============================================================" 186 187echo "Run lsusb - devices that failed to bind aren't bound to any driver" 188lsusb -t; 189echo "==============================================================" 190 191echo "modprobe usbip_host - does it work?" 192/sbin/modprobe usbip_host 193echo "Should see -busid- is not in match_busid table... skip! dmesg" 194echo "==============================================================" 195dmesg | grep "is not in match_busid table" 196echo "==============================================================" 197 198echo $test_end_msg 199