File Index
Files and directories
Sign in
FILE

usbip_test.sh

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/drivers/usb/usbip/usbip_test.sh BASH
  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	echo "usbip_test: module usbip_host is loaded [OK]"
 50else
 51	echo "usbip_test: module usbip_host failed to load [FAIL]"
 52	echo $test_end_msg
 53	exit 1
 54fi
 55
 56echo "Load vhci_hcd module"
 57if /sbin/modprobe -q vhci_hcd; then
 58	echo "usbip_test: module vhci_hcd is loaded [OK]"
 59else
 60	echo "usbip_test: module vhci_hcd failed to load [FAIL]"
 61	echo $test_end_msg
 62	exit 1
 63fi
 64echo "=============================================================="
 65
 66cd $tools_path;
 67
 68if [ ! -f src/usbip ]; then
 69	echo "Please build usbip tools"
 70	echo $test_end_msg
 71	exit $ksft_skip
 72fi
 73
 74echo "Expect to see export-able devices";
 75src/usbip list -l;
 76echo "=============================================================="
 77
 78echo "Run lsusb to see all usb devices"
 79lsusb -t;
 80echo "=============================================================="
 81
 82src/usbipd -D;
 83
 84echo "Get exported devices from localhost - expect to see none";
 85src/usbip list -r localhost;
 86echo "=============================================================="
 87
 88echo "bind devices";
 89src/usbip bind -b $busid;
 90echo "=============================================================="
 91
 92echo "Run lsusb - bound devices should be under usbip_host control"
 93lsusb -t;
 94echo "=============================================================="
 95
 96echo "bind devices - expect already bound messages"
 97src/usbip bind -b $busid;
 98echo "=============================================================="
 99
100echo "Get exported devices from localhost - expect to see exported devices";
101src/usbip list -r localhost;
102echo "=============================================================="
103
104echo "unbind devices";
105src/usbip unbind -b $busid;
106echo "=============================================================="
107
108echo "Run lsusb - bound devices should be rebound to original drivers"
109lsusb -t;
110echo "=============================================================="
111
112echo "unbind devices - expect no devices bound message";
113src/usbip unbind -b $busid;
114echo "=============================================================="
115
116echo "Get exported devices from localhost - expect to see none";
117src/usbip list -r localhost;
118echo "=============================================================="
119
120echo "List imported devices - expect to see none";
121src/usbip port;
122echo "=============================================================="
123
124echo "Import devices from localhost - should fail with no devices"
125src/usbip attach -r localhost -b $busid;
126echo "=============================================================="
127
128echo "bind devices";
129src/usbip bind -b $busid;
130echo "=============================================================="
131
132echo "List imported devices - expect to see exported devices";
133src/usbip list -r localhost;
134echo "=============================================================="
135
136echo "List imported devices - expect to see none";
137src/usbip port;
138echo "=============================================================="
139
140echo "Import devices from localhost - should work"
141src/usbip attach -r localhost -b $busid;
142echo "=============================================================="
143
144# Wait for sysfs file to be updated. Without this sleep, usbip port
145# shows no imported devices.
146sleep 3;
147
148echo "List imported devices - expect to see imported devices";
149src/usbip port;
150echo "=============================================================="
151
152echo "Import devices from localhost - expect already imported messages"
153src/usbip attach -r localhost -b $busid;
154echo "=============================================================="
155
156echo "Un-import devices";
157src/usbip detach -p 00;
158src/usbip detach -p 01;
159echo "=============================================================="
160
161echo "List imported devices - expect to see none";
162src/usbip port;
163echo "=============================================================="
164
165echo "Un-import devices - expect no devices to detach messages";
166src/usbip detach -p 00;
167src/usbip detach -p 01;
168echo "=============================================================="
169
170echo "Detach invalid port tests - expect invalid port error message";
171src/usbip detach -p 100;
172echo "=============================================================="
173
174echo "Expect to see export-able devices";
175src/usbip list -l;
176echo "=============================================================="
177
178echo "Remove usbip_host module";
179rmmod usbip_host;
180
181echo "Run lsusb - bound devices should be rebound to original drivers"
182lsusb -t;
183echo "=============================================================="
184
185echo "Run bind without usbip_host - expect fail"
186src/usbip bind -b $busid;
187echo "=============================================================="
188
189echo "Run lsusb - devices that failed to bind aren't bound to any driver"
190lsusb -t;
191echo "=============================================================="
192
193echo "modprobe usbip_host - does it work?"
194/sbin/modprobe usbip_host
195echo "Should see -busid- is not in match_busid table... skip! dmesg"
196echo "=============================================================="
197dmesg | grep "is not in match_busid table"
198echo "=============================================================="
199
200echo $test_end_msg
~/ Read-only file preview.