WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / netdevsim / ethtool-common.sh
blob9f64d5c7107b14ce56ecf1e730f76332579f7117
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0-only
4 NSIM_ID=$((RANDOM % 1024))
5 NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID
6 NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID/ports/0
7 NSIM_NETDEV=
8 num_passes=0
9 num_errors=0
11 function cleanup_nsim {
12 if [ -e $NSIM_DEV_SYS ]; then
13 echo $NSIM_ID > /sys/bus/netdevsim/del_device
17 function cleanup {
18 cleanup_nsim
21 trap cleanup EXIT
23 function check {
24 local code=$1
25 local str=$2
26 local exp_str=$3
28 if [ $code -ne 0 ]; then
29 ((num_errors++))
30 return
33 if [ "$str" != "$exp_str" ]; then
34 echo -e "Expected: '$exp_str', got '$str'"
35 ((num_errors++))
36 return
39 ((num_passes++))
42 function make_netdev {
43 # Make a netdevsim
44 old_netdevs=$(ls /sys/class/net)
46 if ! $(lsmod | grep -q netdevsim); then
47 modprobe netdevsim
50 echo $NSIM_ID > /sys/bus/netdevsim/new_device
51 # get new device name
52 ls /sys/bus/netdevsim/devices/netdevsim${NSIM_ID}/net/