Skip to content

Commit 5ef12cb

Browse files
Shuah Khan (Samsung OSG)gregkh
authored andcommitted
selftests: add test for USB over IP driver
Add test for USB over IP driver. This test runs several tests on a device specified in the -b <busid> argument and path to the usbip tools. usbip_test.sh -b <busid> -p <usbip tools path> e.g: cd tools/testing selftests/drivers/usb/usbip sudo ./usbip_test.sh -b 3-10.2 -p <yoursrctree>/tools/usb/usbip This test should be run as root and user should build usbip tools before running the test. The usbip test isn't included in the Kselftest run as it requires user to specify a device to run tests on. Signed-off-by: Shuah Khan (Samsung OSG) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bc9832c commit 5ef12cb

File tree

2 files changed

+199
-0
lines changed

2 files changed

+199
-0
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14670,6 +14670,7 @@ S: Maintained
1467014670
F: Documentation/usb/usbip_protocol.txt
1467114671
F: drivers/usb/usbip/
1467214672
F: tools/usb/usbip/
14673+
F: tools/testing/selftests/drivers/usb/usbip/
1467314674

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

0 commit comments

Comments
 (0)