Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) #!/bin/sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) # This test is for checking network interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) # For the moment it tests only ethernet interface (but wifi could be easily added)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) # We assume that all network driver are loaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) # if not they probably have failed earlier in the boot process and their logged error will be catched by another test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) # Kselftest framework requirement - SKIP code is 4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) ksft_skip=4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) # this function will try to up the interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) # if already up, nothing done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) # arg1: network interface name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) kci_net_start()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	netdev=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	ip link show "$netdev" |grep -q UP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	if [ $? -eq 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		echo "SKIP: $netdev: interface already up"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	ip link set "$netdev" up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		echo "FAIL: $netdev: Fail to up interface"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		echo "PASS: $netdev: set interface up"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		NETDEV_STARTED=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) # this function will try to setup an IP and MAC address on a network interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) # Doing nothing if the interface was already up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) # arg1: network interface name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) kci_net_setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	netdev=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	# do nothing if the interface was already up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if [ $NETDEV_STARTED -eq 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	MACADDR='02:03:04:05:06:07'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	ip link set dev $netdev address "$MACADDR"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		echo "FAIL: $netdev: Cannot set MAC address"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		ip link show $netdev |grep -q "$MACADDR"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		if [ $? -eq 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			echo "PASS: $netdev: set MAC address"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			echo "FAIL: $netdev: Cannot set MAC address"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	#check that the interface did not already have an IP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	ip address show "$netdev" |grep '^[[:space:]]*inet'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if [ $? -eq 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		echo "SKIP: $netdev: already have an IP"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	# TODO what ipaddr to set ? DHCP ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	echo "SKIP: $netdev: set IP address"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) # test an ethtool command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) # arg1: return code for not supported (see ethtool code source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) # arg2: summary of the command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) # arg3: command to execute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) kci_netdev_ethtool_test()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if [ $# -le 2 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		echo "SKIP: $netdev: ethtool: invalid number of arguments"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	$3 >/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	ret=$?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if [ $ret -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		if [ $ret -eq "$1" ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			echo "SKIP: $netdev: ethtool $2 not supported"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			echo "FAIL: $netdev: ethtool $2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		echo "PASS: $netdev: ethtool $2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) # test ethtool commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) # arg1: network interface name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) kci_netdev_ethtool()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	netdev=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	#check presence of ethtool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	ethtool --version 2>/dev/null >/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		echo "SKIP: ethtool not present"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	TMP_ETHTOOL_FEATURES="$(mktemp)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if [ ! -e "$TMP_ETHTOOL_FEATURES" ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		echo "SKIP: Cannot create a tmp file"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	ethtool -k "$netdev" > "$TMP_ETHTOOL_FEATURES"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		echo "FAIL: $netdev: ethtool list features"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		rm "$TMP_ETHTOOL_FEATURES"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	echo "PASS: $netdev: ethtool list features"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	#TODO for each non fixed features, try to turn them on/off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	rm "$TMP_ETHTOOL_FEATURES"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	kci_netdev_ethtool_test 74 'dump' "ethtool -d $netdev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	kci_netdev_ethtool_test 94 'stats' "ethtool -S $netdev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) # stop a netdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) # arg1: network interface name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) kci_netdev_stop()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	netdev=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if [ $NETDEV_STARTED -eq 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		echo "SKIP: $netdev: interface kept up"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	ip link set "$netdev" down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		echo "FAIL: $netdev: stop interface"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	echo "PASS: $netdev: stop interface"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) # run all test on a netdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) # arg1: network interface name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) kci_test_netdev()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	NETDEV_STARTED=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	IFACE_TO_UPDOWN="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	IFACE_TO_TEST="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	#check for VLAN interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	MASTER_IFACE="$(echo $1 | cut -d@ -f2)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if [ ! -z "$MASTER_IFACE" ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		IFACE_TO_UPDOWN="$MASTER_IFACE"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		IFACE_TO_TEST="$(echo $1 | cut -d@ -f1)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	NETDEV_STARTED=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	kci_net_start "$IFACE_TO_UPDOWN"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	kci_net_setup "$IFACE_TO_TEST"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	kci_netdev_ethtool "$IFACE_TO_TEST"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	kci_netdev_stop "$IFACE_TO_UPDOWN"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #check for needed privileges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if [ "$(id -u)" -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	echo "SKIP: Need root privileges"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	exit $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ip link show 2>/dev/null >/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if [ $? -ne 0 ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	echo "SKIP: Could not run test without the ip tool"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	exit $ksft_skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) TMP_LIST_NETDEV="$(mktemp)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if [ ! -e "$TMP_LIST_NETDEV" ];then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	echo "FAIL: Cannot create a tmp file"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ip link show |grep '^[0-9]' | grep -oE '[[:space:]].*eth[0-9]*:|[[:space:]].*enp[0-9]s[0-9]:' | cut -d\  -f2 | cut -d: -f1> "$TMP_LIST_NETDEV"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) while read netdev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	kci_test_netdev "$netdev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) done < "$TMP_LIST_NETDEV"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) rm "$TMP_LIST_NETDEV"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) exit 0