Path: blob/master/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
26299 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.0-only23NSIM_ID=$((RANDOM % 1024))4NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID5NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID/ports/06NSIM_NETDEV=7num_passes=08num_errors=0910function cleanup_nsim {11if [ -e $NSIM_DEV_SYS ]; then12echo $NSIM_ID > /sys/bus/netdevsim/del_device13fi14}1516function cleanup {17cleanup_nsim18}1920trap cleanup EXIT2122function check {23local code=$124local str=$225local exp_str=$326local exp_fail=$42728[ -z "$exp_fail" ] && cop="-ne" || cop="-eq"2930if [ $code $cop 0 ]; then31((num_errors++))32return33fi3435if [ "$str" != "$exp_str" ]; then36echo -e "Expected: '$exp_str', got '$str'"37((num_errors++))38return39fi4041((num_passes++))42}4344function make_netdev {45# Make a netdevsim46old_netdevs=$(ls /sys/class/net)4748if ! $(lsmod | grep -q netdevsim); then49modprobe netdevsim50fi5152echo $NSIM_ID $@ > /sys/bus/netdevsim/new_device53udevadm settle54# get new device name55ls /sys/bus/netdevsim/devices/netdevsim${NSIM_ID}/net/56}575859