usbip_test.sh 5.8 KB

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