1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0-only 3 4NSIM_ID=$((RANDOM % 1024)) 5NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID 6NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID/ports/0 7NSIM_NETDEV= 8num_passes=0 9num_errors=0 10 11function cleanup_nsim { 12 if [ -e $NSIM_DEV_SYS ]; then 13 echo $NSIM_ID > /sys/bus/netdevsim/del_device 14 fi 15} 16 17function cleanup { 18 cleanup_nsim 19} 20 21trap cleanup EXIT 22 23function check { 24 local code=$1 25 local str=$2 26 local exp_str=$3 27 28 if [ $code -ne 0 ]; then 29 ((num_errors++)) 30 return 31 fi 32 33 if [ "$str" != "$exp_str" ]; then 34 echo -e "Expected: '$exp_str', got '$str'" 35 ((num_errors++)) 36 return 37 fi 38 39 ((num_passes++)) 40} 41 42function make_netdev { 43 # Make a netdevsim 44 old_netdevs=$(ls /sys/class/net) 45 46 if ! $(lsmod | grep -q netdevsim); then 47 modprobe netdevsim 48 fi 49 50 echo $NSIM_ID > /sys/bus/netdevsim/new_device 51 # get new device name 52 ls /sys/bus/netdevsim/devices/netdevsim${NSIM_ID}/net/ 53} 54