Path: blob/master/tools/net/ynl/tests/test_ynl_ethtool.sh
38189 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02# Test YNL ethtool functionality34# Load KTAP test helpers5KSELFTEST_KTAP_HELPERS="$(dirname "$(realpath "$0")")/../../../testing/selftests/kselftest/ktap_helpers.sh"6# shellcheck source=../../../testing/selftests/kselftest/ktap_helpers.sh7source "$KSELFTEST_KTAP_HELPERS"89# Default ynl-ethtool path for direct execution, can be overridden by make install10ynl_ethtool="../pyynl/ethtool.py"1112readonly NSIM_ID="1337"13readonly NSIM_DEV_NAME="nsim${NSIM_ID}"14readonly VETH_A="veth_a"15readonly VETH_B="veth_b"1617testns="ynl-ethtool-$(mktemp -u XXXXXX)"18TESTS_NO=01920# Uses veth device as netdevsim doesn't support basic ethtool device info21ethtool_device_info()22{23local info_output2425info_output=$(ip netns exec "$testns" $ynl_ethtool "$VETH_A" 2>/dev/null)2627if ! echo "$info_output" | grep -q "Settings for"; then28ktap_test_fail "YNL ethtool device info (device info output missing expected content)"29return30fi3132ktap_test_pass "YNL ethtool device info"33}34TESTS_NO=$((TESTS_NO + 1))3536ethtool_statistics()37{38local stats_output3940stats_output=$(ip netns exec "$testns" $ynl_ethtool --statistics "$NSIM_DEV_NAME" 2>/dev/null)4142if ! echo "$stats_output" | grep -q -E "(NIC statistics|packets|bytes)"; then43ktap_test_fail "YNL ethtool statistics (statistics output missing expected content)"44return45fi4647ktap_test_pass "YNL ethtool statistics"48}49TESTS_NO=$((TESTS_NO + 1))5051ethtool_ring_params()52{53local ring_output5455ring_output=$(ip netns exec "$testns" $ynl_ethtool --show-ring "$NSIM_DEV_NAME" 2>/dev/null)5657if ! echo "$ring_output" | grep -q -E "(Ring parameters|RX|TX)"; then58ktap_test_fail "YNL ethtool ring parameters (ring parameters output missing expected content)"59return60fi6162if ! ip netns exec "$testns" $ynl_ethtool --set-ring "$NSIM_DEV_NAME" rx 64 2>/dev/null; then63ktap_test_fail "YNL ethtool ring parameters (set-ring command failed unexpectedly)"64return65fi6667ktap_test_pass "YNL ethtool ring parameters (show/set)"68}69TESTS_NO=$((TESTS_NO + 1))7071ethtool_coalesce_params()72{73if ! ip netns exec "$testns" $ynl_ethtool --show-coalesce "$NSIM_DEV_NAME" &>/dev/null; then74ktap_test_fail "YNL ethtool coalesce parameters (failed to get coalesce parameters)"75return76fi7778if ! ip netns exec "$testns" $ynl_ethtool --set-coalesce "$NSIM_DEV_NAME" rx-usecs 50 2>/dev/null; then79ktap_test_fail "YNL ethtool coalesce parameters (set-coalesce command failed unexpectedly)"80return81fi8283ktap_test_pass "YNL ethtool coalesce parameters (show/set)"84}85TESTS_NO=$((TESTS_NO + 1))8687ethtool_pause_params()88{89if ! ip netns exec "$testns" $ynl_ethtool --show-pause "$NSIM_DEV_NAME" &>/dev/null; then90ktap_test_fail "YNL ethtool pause parameters (failed to get pause parameters)"91return92fi9394if ! ip netns exec "$testns" $ynl_ethtool --set-pause "$NSIM_DEV_NAME" tx 1 rx 1 2>/dev/null; then95ktap_test_fail "YNL ethtool pause parameters (set-pause command failed unexpectedly)"96return97fi9899ktap_test_pass "YNL ethtool pause parameters (show/set)"100}101TESTS_NO=$((TESTS_NO + 1))102103ethtool_features_info()104{105local features_output106107features_output=$(ip netns exec "$testns" $ynl_ethtool --show-features "$NSIM_DEV_NAME" 2>/dev/null)108109if ! echo "$features_output" | grep -q -E "(Features|offload)"; then110ktap_test_fail "YNL ethtool features info (features output missing expected content)"111return112fi113114ktap_test_pass "YNL ethtool features info (show/set)"115}116TESTS_NO=$((TESTS_NO + 1))117118ethtool_channels_info()119{120local channels_output121122channels_output=$(ip netns exec "$testns" $ynl_ethtool --show-channels "$NSIM_DEV_NAME" 2>/dev/null)123124if ! echo "$channels_output" | grep -q -E "(Channel|Combined|RX|TX)"; then125ktap_test_fail "YNL ethtool channels info (channels output missing expected content)"126return127fi128129if ! ip netns exec "$testns" $ynl_ethtool --set-channels "$NSIM_DEV_NAME" combined-count 1 2>/dev/null; then130ktap_test_fail "YNL ethtool channels info (set-channels command failed unexpectedly)"131return132fi133134ktap_test_pass "YNL ethtool channels info (show/set)"135}136TESTS_NO=$((TESTS_NO + 1))137138ethtool_time_stamping()139{140local ts_output141142ts_output=$(ip netns exec "$testns" $ynl_ethtool --show-time-stamping "$NSIM_DEV_NAME" 2>/dev/null)143144if ! echo "$ts_output" | grep -q -E "(Time stamping|timestamping|SOF_TIMESTAMPING)"; then145ktap_test_fail "YNL ethtool time stamping (time stamping output missing expected content)"146return147fi148149ktap_test_pass "YNL ethtool time stamping"150}151TESTS_NO=$((TESTS_NO + 1))152153setup()154{155modprobe netdevsim &> /dev/null156if ! [ -f /sys/bus/netdevsim/new_device ]; then157ktap_skip_all "netdevsim module not available"158exit "$KSFT_SKIP"159fi160161if ! ip netns add "$testns" 2>/dev/null; then162ktap_skip_all "failed to create test namespace"163exit "$KSFT_SKIP"164fi165166echo "$NSIM_ID 1" | ip netns exec "$testns" tee /sys/bus/netdevsim/new_device >/dev/null 2>&1 || {167ktap_skip_all "failed to create netdevsim device"168exit "$KSFT_SKIP"169}170171local dev172dev=$(ip netns exec "$testns" ls /sys/bus/netdevsim/devices/netdevsim$NSIM_ID/net 2>/dev/null | head -1)173if [[ -z "$dev" ]]; then174ktap_skip_all "failed to find netdevsim device"175exit "$KSFT_SKIP"176fi177178ip -netns "$testns" link set dev "$dev" name "$NSIM_DEV_NAME" 2>/dev/null || {179ktap_skip_all "failed to rename netdevsim device"180exit "$KSFT_SKIP"181}182183ip -netns "$testns" link set dev "$NSIM_DEV_NAME" up 2>/dev/null184185if ! ip -n "$testns" link add "$VETH_A" type veth peer name "$VETH_B" 2>/dev/null; then186ktap_skip_all "failed to create veth pair"187exit "$KSFT_SKIP"188fi189190ip -n "$testns" link set "$VETH_A" up 2>/dev/null191ip -n "$testns" link set "$VETH_B" up 2>/dev/null192}193194cleanup()195{196ip netns exec "$testns" bash -c "echo $NSIM_ID > /sys/bus/netdevsim/del_device" 2>/dev/null || true197ip netns del "$testns" 2>/dev/null || true198}199200# Check if ynl-ethtool command is available201if ! command -v $ynl_ethtool &>/dev/null && [[ ! -x $ynl_ethtool ]]; then202ktap_skip_all "ynl-ethtool command not found: $ynl_ethtool"203exit "$KSFT_SKIP"204fi205206trap cleanup EXIT207208ktap_print_header209setup210ktap_set_plan "${TESTS_NO}"211212ethtool_device_info213ethtool_statistics214ethtool_ring_params215ethtool_coalesce_params216ethtool_pause_params217ethtool_features_info218ethtool_channels_info219ethtool_time_stamping220221ktap_finished222223224