1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh
Antonio Cardace 9e48ee80ac selftests: refactor get_netdev_name function
As pointed out by Michal Kubecek, getting the name
with the previous approach was racy, it's better
and easier to get the name of the device with this
patch's approach.

Essentialy the function doesn't need to exist
anymore as it's a simple 'ls' command.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-11-20 12:51:54 -08:00

53 lines
989 B
Bash

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
NSIM_ID=$((RANDOM % 1024))
NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID
NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID/ports/0
NSIM_NETDEV=
num_passes=0
num_errors=0
function cleanup_nsim {
if [ -e $NSIM_DEV_SYS ]; then
echo $NSIM_ID > /sys/bus/netdevsim/del_device
fi
}
function cleanup {
cleanup_nsim
}
trap cleanup EXIT
function check {
local code=$1
local str=$2
local exp_str=$3
if [ $code -ne 0 ]; then
((num_errors++))
return
fi
if [ "$str" != "$exp_str" ]; then
echo -e "Expected: '$exp_str', got '$str'"
((num_errors++))
return
fi
((num_passes++))
}
function make_netdev {
# Make a netdevsim
old_netdevs=$(ls /sys/class/net)
if ! $(lsmod | grep -q netdevsim); then
modprobe netdevsim
fi
echo $NSIM_ID > /sys/bus/netdevsim/new_device
# get new device name
ls /sys/bus/netdevsim/devices/netdevsim${NSIM_ID}/net/
}