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