Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 # Copyright(c) 2020 Intel Corporation.
0004 
0005 ksft_pass=0
0006 ksft_fail=1
0007 ksft_xfail=2
0008 ksft_xpass=3
0009 ksft_skip=4
0010 
0011 XSKOBJ=xskxceiver
0012 
0013 validate_root_exec()
0014 {
0015         msg="skip all tests:"
0016         if [ $UID != 0 ]; then
0017                 echo $msg must be run as root >&2
0018                 test_exit $ksft_fail
0019         else
0020                 return $ksft_pass
0021         fi
0022 }
0023 
0024 validate_veth_support()
0025 {
0026         msg="skip all tests:"
0027         if [ $(ip link add $1 type veth 2>/dev/null; echo $?;) != 0 ]; then
0028                 echo $msg veth kernel support not available >&2
0029                 test_exit $ksft_skip
0030         else
0031                 ip link del $1
0032                 return $ksft_pass
0033         fi
0034 }
0035 
0036 test_status()
0037 {
0038         statusval=$1
0039         if [ $statusval -eq $ksft_fail ]; then
0040                 echo "$2: [ FAIL ]"
0041         elif [ $statusval -eq $ksft_skip ]; then
0042                 echo "$2: [ SKIPPED ]"
0043         elif [ $statusval -eq $ksft_pass ]; then
0044                 echo "$2: [ PASS ]"
0045         fi
0046 }
0047 
0048 test_exit()
0049 {
0050         if [ $1 -ne 0 ]; then
0051                 test_status $1 $(basename $0)
0052         fi
0053         exit 1
0054 }
0055 
0056 clear_configs()
0057 {
0058         if [ $(ip netns show | grep $3 &>/dev/null; echo $?;) == 0 ]; then
0059                 [ $(ip netns exec $3 ip link show $2 &>/dev/null; echo $?;) == 0 ] &&
0060                         { ip netns exec $3 ip link del $2; }
0061                 ip netns del $3
0062         fi
0063         #Once we delete a veth pair node, the entire veth pair is removed,
0064         #this is just to be cautious just incase the NS does not exist then
0065         #veth node inside NS won't get removed so we explicitly remove it
0066         [ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] &&
0067                 { ip link del $1; }
0068 }
0069 
0070 cleanup_exit()
0071 {
0072         clear_configs $1 $2 $3
0073 }
0074 
0075 validate_ip_utility()
0076 {
0077         [ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip; }
0078 }
0079 
0080 exec_xskxceiver()
0081 {
0082         if [[ $busy_poll -eq 1 ]]; then
0083                 ARGS+="-b "
0084         fi
0085 
0086         ./${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} ${ARGS}
0087 
0088         retval=$?
0089         test_status $retval "${TEST_NAME}"
0090         statusList+=($retval)
0091         nameList+=(${TEST_NAME})
0092 }