test_ynl_ethtool.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Test YNL ethtool functionality
  4. # Load KTAP test helpers
  5. KSELFTEST_KTAP_HELPERS="$(dirname "$(realpath "$0")")/../../../testing/selftests/kselftest/ktap_helpers.sh"
  6. # shellcheck source=../../../testing/selftests/kselftest/ktap_helpers.sh
  7. source "$KSELFTEST_KTAP_HELPERS"
  8. # Default ynl-ethtool path for direct execution, can be overridden by make install
  9. ynl_ethtool="../pyynl/ethtool.py"
  10. readonly NSIM_ID="1337"
  11. readonly NSIM_DEV_NAME="nsim${NSIM_ID}"
  12. readonly VETH_A="veth_a"
  13. readonly VETH_B="veth_b"
  14. testns="ynl-ethtool-$(mktemp -u XXXXXX)"
  15. TESTS_NO=0
  16. # Uses veth device as netdevsim doesn't support basic ethtool device info
  17. ethtool_device_info()
  18. {
  19. local info_output
  20. info_output=$(ip netns exec "$testns" $ynl_ethtool "$VETH_A" 2>/dev/null)
  21. if ! echo "$info_output" | grep -q "Settings for"; then
  22. ktap_test_fail "YNL ethtool device info (device info output missing expected content)"
  23. return
  24. fi
  25. ktap_test_pass "YNL ethtool device info"
  26. }
  27. TESTS_NO=$((TESTS_NO + 1))
  28. ethtool_statistics()
  29. {
  30. local stats_output
  31. stats_output=$(ip netns exec "$testns" $ynl_ethtool --statistics "$NSIM_DEV_NAME" 2>/dev/null)
  32. if ! echo "$stats_output" | grep -q -E "(NIC statistics|packets|bytes)"; then
  33. ktap_test_fail "YNL ethtool statistics (statistics output missing expected content)"
  34. return
  35. fi
  36. ktap_test_pass "YNL ethtool statistics"
  37. }
  38. TESTS_NO=$((TESTS_NO + 1))
  39. ethtool_ring_params()
  40. {
  41. local ring_output
  42. ring_output=$(ip netns exec "$testns" $ynl_ethtool --show-ring "$NSIM_DEV_NAME" 2>/dev/null)
  43. if ! echo "$ring_output" | grep -q -E "(Ring parameters|RX|TX)"; then
  44. ktap_test_fail "YNL ethtool ring parameters (ring parameters output missing expected content)"
  45. return
  46. fi
  47. if ! ip netns exec "$testns" $ynl_ethtool --set-ring "$NSIM_DEV_NAME" rx 64 2>/dev/null; then
  48. ktap_test_fail "YNL ethtool ring parameters (set-ring command failed unexpectedly)"
  49. return
  50. fi
  51. ktap_test_pass "YNL ethtool ring parameters (show/set)"
  52. }
  53. TESTS_NO=$((TESTS_NO + 1))
  54. ethtool_coalesce_params()
  55. {
  56. if ! ip netns exec "$testns" $ynl_ethtool --show-coalesce "$NSIM_DEV_NAME" &>/dev/null; then
  57. ktap_test_fail "YNL ethtool coalesce parameters (failed to get coalesce parameters)"
  58. return
  59. fi
  60. if ! ip netns exec "$testns" $ynl_ethtool --set-coalesce "$NSIM_DEV_NAME" rx-usecs 50 2>/dev/null; then
  61. ktap_test_fail "YNL ethtool coalesce parameters (set-coalesce command failed unexpectedly)"
  62. return
  63. fi
  64. ktap_test_pass "YNL ethtool coalesce parameters (show/set)"
  65. }
  66. TESTS_NO=$((TESTS_NO + 1))
  67. ethtool_pause_params()
  68. {
  69. if ! ip netns exec "$testns" $ynl_ethtool --show-pause "$NSIM_DEV_NAME" &>/dev/null; then
  70. ktap_test_fail "YNL ethtool pause parameters (failed to get pause parameters)"
  71. return
  72. fi
  73. if ! ip netns exec "$testns" $ynl_ethtool --set-pause "$NSIM_DEV_NAME" tx 1 rx 1 2>/dev/null; then
  74. ktap_test_fail "YNL ethtool pause parameters (set-pause command failed unexpectedly)"
  75. return
  76. fi
  77. ktap_test_pass "YNL ethtool pause parameters (show/set)"
  78. }
  79. TESTS_NO=$((TESTS_NO + 1))
  80. ethtool_features_info()
  81. {
  82. local features_output
  83. features_output=$(ip netns exec "$testns" $ynl_ethtool --show-features "$NSIM_DEV_NAME" 2>/dev/null)
  84. if ! echo "$features_output" | grep -q -E "(Features|offload)"; then
  85. ktap_test_fail "YNL ethtool features info (features output missing expected content)"
  86. return
  87. fi
  88. ktap_test_pass "YNL ethtool features info (show/set)"
  89. }
  90. TESTS_NO=$((TESTS_NO + 1))
  91. ethtool_channels_info()
  92. {
  93. local channels_output
  94. channels_output=$(ip netns exec "$testns" $ynl_ethtool --show-channels "$NSIM_DEV_NAME" 2>/dev/null)
  95. if ! echo "$channels_output" | grep -q -E "(Channel|Combined|RX|TX)"; then
  96. ktap_test_fail "YNL ethtool channels info (channels output missing expected content)"
  97. return
  98. fi
  99. if ! ip netns exec "$testns" $ynl_ethtool --set-channels "$NSIM_DEV_NAME" combined-count 1 2>/dev/null; then
  100. ktap_test_fail "YNL ethtool channels info (set-channels command failed unexpectedly)"
  101. return
  102. fi
  103. ktap_test_pass "YNL ethtool channels info (show/set)"
  104. }
  105. TESTS_NO=$((TESTS_NO + 1))
  106. ethtool_time_stamping()
  107. {
  108. local ts_output
  109. ts_output=$(ip netns exec "$testns" $ynl_ethtool --show-time-stamping "$NSIM_DEV_NAME" 2>/dev/null)
  110. if ! echo "$ts_output" | grep -q -E "(Time stamping|timestamping|SOF_TIMESTAMPING)"; then
  111. ktap_test_fail "YNL ethtool time stamping (time stamping output missing expected content)"
  112. return
  113. fi
  114. ktap_test_pass "YNL ethtool time stamping"
  115. }
  116. TESTS_NO=$((TESTS_NO + 1))
  117. setup()
  118. {
  119. modprobe netdevsim &> /dev/null
  120. if ! [ -f /sys/bus/netdevsim/new_device ]; then
  121. ktap_skip_all "netdevsim module not available"
  122. exit "$KSFT_SKIP"
  123. fi
  124. if ! ip netns add "$testns" 2>/dev/null; then
  125. ktap_skip_all "failed to create test namespace"
  126. exit "$KSFT_SKIP"
  127. fi
  128. echo "$NSIM_ID 1" | ip netns exec "$testns" tee /sys/bus/netdevsim/new_device >/dev/null 2>&1 || {
  129. ktap_skip_all "failed to create netdevsim device"
  130. exit "$KSFT_SKIP"
  131. }
  132. local dev
  133. dev=$(ip netns exec "$testns" ls /sys/bus/netdevsim/devices/netdevsim$NSIM_ID/net 2>/dev/null | head -1)
  134. if [[ -z "$dev" ]]; then
  135. ktap_skip_all "failed to find netdevsim device"
  136. exit "$KSFT_SKIP"
  137. fi
  138. ip -netns "$testns" link set dev "$dev" name "$NSIM_DEV_NAME" 2>/dev/null || {
  139. ktap_skip_all "failed to rename netdevsim device"
  140. exit "$KSFT_SKIP"
  141. }
  142. ip -netns "$testns" link set dev "$NSIM_DEV_NAME" up 2>/dev/null
  143. if ! ip -n "$testns" link add "$VETH_A" type veth peer name "$VETH_B" 2>/dev/null; then
  144. ktap_skip_all "failed to create veth pair"
  145. exit "$KSFT_SKIP"
  146. fi
  147. ip -n "$testns" link set "$VETH_A" up 2>/dev/null
  148. ip -n "$testns" link set "$VETH_B" up 2>/dev/null
  149. }
  150. cleanup()
  151. {
  152. ip netns exec "$testns" bash -c "echo $NSIM_ID > /sys/bus/netdevsim/del_device" 2>/dev/null || true
  153. ip netns del "$testns" 2>/dev/null || true
  154. }
  155. # Check if ynl-ethtool command is available
  156. if ! command -v $ynl_ethtool &>/dev/null && [[ ! -x $ynl_ethtool ]]; then
  157. ktap_skip_all "ynl-ethtool command not found: $ynl_ethtool"
  158. exit "$KSFT_SKIP"
  159. fi
  160. trap cleanup EXIT
  161. ktap_print_header
  162. setup
  163. ktap_set_plan "${TESTS_NO}"
  164. ethtool_device_info
  165. ethtool_statistics
  166. ethtool_ring_params
  167. ethtool_coalesce_params
  168. ethtool_pause_params
  169. ethtool_features_info
  170. ethtool_channels_info
  171. ethtool_time_stamping
  172. ktap_finished