usbip_test.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. /sbin/modprobe -q -r test_bitmap
  41. echo "usbip_test: module usbip_host is loaded [OK]"
  42. else
  43. echo "usbip_test: module usbip_host failed to load [FAIL]"
  44. echo $test_end_msg
  45. exit 1
  46. fi
  47. echo "Load vhci_hcd module"
  48. if /sbin/modprobe -q vhci_hcd; then
  49. /sbin/modprobe -q -r test_bitmap
  50. echo "usbip_test: module vhci_hcd is loaded [OK]"
  51. else
  52. echo "usbip_test: module vhci_hcd failed to load [FAIL]"
  53. echo $test_end_msg
  54. exit 1
  55. fi
  56. echo "=============================================================="
  57. cd $tools_path;
  58. if [ ! -f src/usbip ]; then
  59. echo "Please build usbip tools"
  60. echo $test_end_msg
  61. exit $ksft_skip
  62. fi
  63. echo "Expect to see export-able devices";
  64. src/usbip list -l;
  65. echo "=============================================================="
  66. echo "Run lsusb to see all usb devices"
  67. lsusb -t;
  68. echo "=============================================================="
  69. src/usbipd -D;
  70. echo "Get exported devices from localhost - expect to see none";
  71. src/usbip list -r localhost;
  72. echo "=============================================================="
  73. echo "bind devices";
  74. src/usbip bind -b $busid;
  75. echo "=============================================================="
  76. echo "Run lsusb - bound devices should be under usbip_host control"
  77. lsusb -t;
  78. echo "=============================================================="
  79. echo "bind devices - expect already bound messages"
  80. src/usbip bind -b $busid;
  81. echo "=============================================================="
  82. echo "Get exported devices from localhost - expect to see exported devices";
  83. src/usbip list -r localhost;
  84. echo "=============================================================="
  85. echo "unbind devices";
  86. src/usbip unbind -b $busid;
  87. echo "=============================================================="
  88. echo "Run lsusb - bound devices should be rebound to original drivers"
  89. lsusb -t;
  90. echo "=============================================================="
  91. echo "unbind devices - expect no devices bound message";
  92. src/usbip unbind -b $busid;
  93. echo "=============================================================="
  94. echo "Get exported devices from localhost - expect to see none";
  95. src/usbip list -r localhost;
  96. echo "=============================================================="
  97. echo "List imported devices - expect to see none";
  98. src/usbip port;
  99. echo "=============================================================="
  100. echo "Import devices from localhost - should fail with no devices"
  101. src/usbip attach -r localhost -b $busid;
  102. echo "=============================================================="
  103. echo "bind devices";
  104. src/usbip bind -b $busid;
  105. echo "=============================================================="
  106. echo "List imported devices - expect to see exported devices";
  107. src/usbip list -r localhost;
  108. echo "=============================================================="
  109. echo "List imported devices - expect to see none";
  110. src/usbip port;
  111. echo "=============================================================="
  112. echo "Import devices from localhost - should work"
  113. src/usbip attach -r localhost -b $busid;
  114. echo "=============================================================="
  115. echo "List imported devices - expect to see imported devices";
  116. src/usbip port;
  117. echo "=============================================================="
  118. echo "Import devices from localhost - expect already imported messages"
  119. src/usbip attach -r localhost -b $busid;
  120. echo "=============================================================="
  121. echo "Un-import devices";
  122. src/usbip detach -p 00;
  123. src/usbip detach -p 01;
  124. echo "=============================================================="
  125. echo "List imported devices - expect to see none";
  126. src/usbip port;
  127. echo "=============================================================="
  128. echo "Un-import devices - expect no devices to detach messages";
  129. src/usbip detach -p 00;
  130. src/usbip detach -p 01;
  131. echo "=============================================================="
  132. echo "Detach invalid port tests - expect invalid port error message";
  133. src/usbip detach -p 100;
  134. echo "=============================================================="
  135. echo "Expect to see export-able devices";
  136. src/usbip list -l;
  137. echo "=============================================================="
  138. echo "Remove usbip_host module";
  139. rmmod usbip_host;
  140. echo "Run lsusb - bound devices should be rebound to original drivers"
  141. lsusb -t;
  142. echo "=============================================================="
  143. echo "Run bind without usbip_host - expect fail"
  144. src/usbip bind -b $busid;
  145. echo "=============================================================="
  146. echo "Run lsusb - devices that failed to bind aren't bound to any driver"
  147. lsusb -t;
  148. echo "=============================================================="
  149. echo "modprobe usbip_host - does it work?"
  150. /sbin/modprobe usbip_host
  151. echo "Should see -busid- is not in match_busid table... skip! dmesg"
  152. echo "=============================================================="
  153. dmesg | grep "is not in match_busid table"
  154. echo "=============================================================="
  155. echo $test_end_msg