Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # Kselftest framework requirement - SKIP code is 4.
0005 ksft_skip=4
0006 
0007 usage() { echo "usbip_test.sh -b <busid> -p <usbip tools path>"; exit 1; }
0008 
0009 while getopts "h:b:p:" arg; do
0010     case "${arg}" in
0011         h)
0012             usage
0013             ;;
0014         b)
0015             busid=${OPTARG}
0016             ;;
0017         p)
0018             tools_path=${OPTARG}
0019             ;;
0020         *)
0021             usage
0022             ;;
0023     esac
0024 done
0025 shift $((OPTIND-1))
0026 
0027 if [ -z "${busid}" ]; then
0028         usage
0029 fi
0030 
0031 echo "Running USB over IP Testing on $busid";
0032 
0033 test_end_msg="End of USB over IP Testing on $busid"
0034 
0035 if [ $UID != 0 ]; then
0036         echo "Please run usbip_test as root [SKIP]"
0037         echo $test_end_msg
0038         exit $ksft_skip
0039 fi
0040 
0041 echo "Load usbip_host module"
0042 if ! /sbin/modprobe -q -n usbip_host; then
0043         echo "usbip_test: module usbip_host is not found [SKIP]"
0044         echo $test_end_msg
0045         exit $ksft_skip
0046 fi
0047 
0048 if /sbin/modprobe -q usbip_host; then
0049         echo "usbip_test: module usbip_host is loaded [OK]"
0050 else
0051         echo "usbip_test: module usbip_host failed to load [FAIL]"
0052         echo $test_end_msg
0053         exit 1
0054 fi
0055 
0056 echo "Load vhci_hcd module"
0057 if /sbin/modprobe -q vhci_hcd; then
0058         echo "usbip_test: module vhci_hcd is loaded [OK]"
0059 else
0060         echo "usbip_test: module vhci_hcd failed to load [FAIL]"
0061         echo $test_end_msg
0062         exit 1
0063 fi
0064 echo "=============================================================="
0065 
0066 cd $tools_path;
0067 
0068 if [ ! -f src/usbip ]; then
0069         echo "Please build usbip tools"
0070         echo $test_end_msg
0071         exit $ksft_skip
0072 fi
0073 
0074 echo "Expect to see export-able devices";
0075 src/usbip list -l;
0076 echo "=============================================================="
0077 
0078 echo "Run lsusb to see all usb devices"
0079 lsusb -t;
0080 echo "=============================================================="
0081 
0082 src/usbipd -D;
0083 
0084 echo "Get exported devices from localhost - expect to see none";
0085 src/usbip list -r localhost;
0086 echo "=============================================================="
0087 
0088 echo "bind devices";
0089 src/usbip bind -b $busid;
0090 echo "=============================================================="
0091 
0092 echo "Run lsusb - bound devices should be under usbip_host control"
0093 lsusb -t;
0094 echo "=============================================================="
0095 
0096 echo "bind devices - expect already bound messages"
0097 src/usbip bind -b $busid;
0098 echo "=============================================================="
0099 
0100 echo "Get exported devices from localhost - expect to see exported devices";
0101 src/usbip list -r localhost;
0102 echo "=============================================================="
0103 
0104 echo "unbind devices";
0105 src/usbip unbind -b $busid;
0106 echo "=============================================================="
0107 
0108 echo "Run lsusb - bound devices should be rebound to original drivers"
0109 lsusb -t;
0110 echo "=============================================================="
0111 
0112 echo "unbind devices - expect no devices bound message";
0113 src/usbip unbind -b $busid;
0114 echo "=============================================================="
0115 
0116 echo "Get exported devices from localhost - expect to see none";
0117 src/usbip list -r localhost;
0118 echo "=============================================================="
0119 
0120 echo "List imported devices - expect to see none";
0121 src/usbip port;
0122 echo "=============================================================="
0123 
0124 echo "Import devices from localhost - should fail with no devices"
0125 src/usbip attach -r localhost -b $busid;
0126 echo "=============================================================="
0127 
0128 echo "bind devices";
0129 src/usbip bind -b $busid;
0130 echo "=============================================================="
0131 
0132 echo "List imported devices - expect to see exported devices";
0133 src/usbip list -r localhost;
0134 echo "=============================================================="
0135 
0136 echo "List imported devices - expect to see none";
0137 src/usbip port;
0138 echo "=============================================================="
0139 
0140 echo "Import devices from localhost - should work"
0141 src/usbip attach -r localhost -b $busid;
0142 echo "=============================================================="
0143 
0144 # Wait for sysfs file to be updated. Without this sleep, usbip port
0145 # shows no imported devices.
0146 sleep 3;
0147 
0148 echo "List imported devices - expect to see imported devices";
0149 src/usbip port;
0150 echo "=============================================================="
0151 
0152 echo "Import devices from localhost - expect already imported messages"
0153 src/usbip attach -r localhost -b $busid;
0154 echo "=============================================================="
0155 
0156 echo "Un-import devices";
0157 src/usbip detach -p 00;
0158 src/usbip detach -p 01;
0159 echo "=============================================================="
0160 
0161 echo "List imported devices - expect to see none";
0162 src/usbip port;
0163 echo "=============================================================="
0164 
0165 echo "Un-import devices - expect no devices to detach messages";
0166 src/usbip detach -p 00;
0167 src/usbip detach -p 01;
0168 echo "=============================================================="
0169 
0170 echo "Detach invalid port tests - expect invalid port error message";
0171 src/usbip detach -p 100;
0172 echo "=============================================================="
0173 
0174 echo "Expect to see export-able devices";
0175 src/usbip list -l;
0176 echo "=============================================================="
0177 
0178 echo "Remove usbip_host module";
0179 rmmod usbip_host;
0180 
0181 echo "Run lsusb - bound devices should be rebound to original drivers"
0182 lsusb -t;
0183 echo "=============================================================="
0184 
0185 echo "Run bind without usbip_host - expect fail"
0186 src/usbip bind -b $busid;
0187 echo "=============================================================="
0188 
0189 echo "Run lsusb - devices that failed to bind aren't bound to any driver"
0190 lsusb -t;
0191 echo "=============================================================="
0192 
0193 echo "modprobe usbip_host - does it work?"
0194 /sbin/modprobe usbip_host
0195 echo "Should see -busid- is not in match_busid table... skip! dmesg"
0196 echo "=============================================================="
0197 dmesg | grep "is not in match_busid table"
0198 echo "=============================================================="
0199 
0200 echo $test_end_msg