All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/1] net/route: Rewrite route-rmmod to new API
@ 2020-11-16 22:03 Petr Vorel
  2020-11-17 14:30 ` Alexey Kodanev
  0 siblings, 1 reply; 8+ messages in thread
From: Petr Vorel @ 2020-11-16 22:03 UTC (permalink / raw)
  To: ltp

Use network namespaces and veth only, therefore no need to use ethtool for
defining a driver.

Add reset_ltp_netspace() in tst_net.sh.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 runtest/net_stress.route                      |   2 +
 testcases/lib/tst_net.sh                      |  12 +-
 testcases/network/stress/route/route-rmmod.sh |  46 +++
 testcases/network/stress/route/route4-rmmod   | 283 ------------------
 testcases/network/stress/route/route6-rmmod   | 279 -----------------
 5 files changed, 59 insertions(+), 563 deletions(-)
 create mode 100644 testcases/network/stress/route/route-rmmod.sh
 delete mode 100644 testcases/network/stress/route/route4-rmmod
 delete mode 100644 testcases/network/stress/route/route6-rmmod

diff --git a/runtest/net_stress.route b/runtest/net_stress.route
index b60e55bd6..9e1343e0f 100644
--- a/runtest/net_stress.route
+++ b/runtest/net_stress.route
@@ -5,6 +5,7 @@ route4-change-if route-change-if.sh
 route4-change-netlink-dst route-change-netlink-dst.sh
 route4-change-netlink-gw route-change-netlink-gw.sh
 route4-change-netlink-if route-change-netlink-if.sh
+route4-rmmod route-rmmod.sh
 
 route6-change-dst route-change-dst.sh -6
 route6-change-gw route-change-gw.sh -6
@@ -12,3 +13,4 @@ route6-change-if route-change-if.sh -6
 route6-change-netlink-dst route-change-netlink-dst.sh -6
 route6-change-netlink-gw route-change-netlink-gw.sh -6
 route6-change-netlink-if route-change-netlink-if.sh -6
+route6-rmmod route-rmmod.sh -6
diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
index 46d3fb88e..30514ebaf 100644
--- a/testcases/lib/tst_net.sh
+++ b/testcases/lib/tst_net.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) 2016-2019 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2016-2020 Petr Vorel <pvorel@suse.cz>
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
 [ -n "$TST_LIB_NET_LOADED" ] && return 0
@@ -130,6 +130,16 @@ init_ltp_netspace()
 	tst_restore_ipaddr rhost
 }
 
+reset_ltp_netspace()
+{
+	tst_require_cmds pkill
+
+	rm -f /var/run/netns/ltp_ns
+	pkill ns_create
+	unset LTP_NETNS
+	init_ltp_netspace
+}
+
 # Run command on remote host.
 # tst_rhost_run -c CMD [-b] [-s] [-u USER]
 # Options:
diff --git a/testcases/network/stress/route/route-rmmod.sh b/testcases/network/stress/route/route-rmmod.sh
new file mode 100644
index 000000000..8067d9094
--- /dev/null
+++ b/testcases/network/stress/route/route-rmmod.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) International Business Machines Corp., 2006
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
+# Rewrite into new shell API: Petr Vorel
+
+TST_SETUP="setup"
+TST_CLEANUP="cleanup"
+TST_TESTFUNC="do_test"
+
+module='veth'
+TST_NEEDS_DRIVERS="$module"
+
+. route-lib.sh
+TST_CNT=$ROUTE_CHANGE_IP
+
+setup()
+{
+	tst_res TINFO "adding IPv$TST_IPVER route destination and delete network driver $ROUTE_CHANGE_IP times"
+}
+
+cleanup()
+{
+	modprobe $module
+	route_cleanup
+}
+
+do_test()
+{
+	local iface="$(tst_iface)"
+	local rt="$(tst_ipaddr_un -p $1)"
+	local rhost="$(tst_ipaddr_un $1 1)"
+
+	tst_res TINFO "testing route '$rt'"
+
+	tst_add_ipaddr -s -q -a $rhost rhost
+	ROD ip route add $rt dev $iface
+	EXPECT_PASS_BRK ping$TST_IPV6 -c1 -I $(tst_ipaddr) $rhost \>/dev/null
+
+	ROD rmmod $module
+	ROD modprobe $module
+	reset_ltp_netspace
+}
+
+tst_run
diff --git a/testcases/network/stress/route/route4-rmmod b/testcases/network/stress/route/route4-rmmod
deleted file mode 100644
index 7aa195810..000000000
--- a/testcases/network/stress/route/route4-rmmod
+++ /dev/null
@@ -1,283 +0,0 @@
-#!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   route4-rmmod
-#
-# Description:
-#   Verify the kernel is not crashed when IPv4 route is add then it is deleted
-#   by the removing network driver
-#
-# Setup:
-#   See testcases/network/stress/README
-#
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
-#
-# History:
-#	Apr 8 2006 - Created (Mitsuru Chinen)
-#
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
-
-# Total number of the test case
-TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route4-rmmod
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where IPv4 route is add/delete
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-IPV4_NETWORK=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of for the tested network
-IPV4_NETMASK="255.255.255.0"
-IPV4_NETMASK_NUM=24
-
-# Broadcast address of the tested network
-IPV4_BROADCAST=${IPV4_NETWORK}.255
-
-# Host portion of the IPv4 address
-LHOST_IPV4_HOST=${LHOST_IPV4_HOST:-"2"}	# src
-RHOST_IPV4_HOST=${RHOST_IPV4_HOST:-"1"}	# gateway
-
-# The destination network
-DST_NETWORK="10.10.10"	# destination network would be 10.10.10.0/24
-DST_HOST="5"
-DST_PORT="7"
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    # Make sure to load the network driver
-    if [ x${lhost_module} != x ]; then
-	modprobe $lhost_module
-    fi
-
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Make a IPv4 connectivity
-#
-#-----------------------------------------------------------------------
-do_setup()
-{
-    # Check the local host has ethtool utility
-    which ethtool >/dev/null
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "This test case requires ethtool utility"
-	exit $TST_TOTAL
-    fi
-
-    # The module name of the interface at the local host
-    lhost_module=
-
-    # Make sure to clean up
-    do_cleanup
-
-    # Set IPv4 address to the interfaces of the remote host
-    set_ipv4addr rhost ${LINK_NUM} ${IPV4_NETWORK} ${RHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add an IPv4 address the remote host"
-	exit $TST_TOTAL
-    fi
-    rhost_ipv4addr="${IPV4_NETWORK}.${RHOST_IPV4_HOST}"
-
-    # Assign IPv4 address to the interface of the local host
-    set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to assign an IPv4 address at the local host"
-	return 1
-    fi
-    lhost_ipv4addr="${IPV4_NETWORK}.${LHOST_IPV4_HOST}"
-
-    # Get the Interface names
-    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Get the module name of the interface at the local host
-    lhost_module=`ethtool -i $lhost_ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
-
-    # Chack the other active interface uses the same driver
-    for ifname in `ifconfig | grep ^eth | awk '{ print $1}'`; do
-	if [ $lhost_ifname = $ifname ]; then
-	    continue
-	fi
-
-	module=`ethtool -i $ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
-	if [ $lhost_module = $module ]; then
-	    tst_resm TBROK "An active interface $ifname uses the same network deriver $module with the test intreface."
-	    exit $TST_TOTAL
-	fi
-    done
-
-    # Set the variables for destination network
-    dst_addr=${DST_NETWORK}.${DST_HOST}
-    dst_network=${DST_NETWORK}.0
-}
-
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#	1 - route command case
-#	2 - ip command case
-#
-#-----------------------------------------------------------------------
-test_body()
-{
-    test_type=$1
-
-    TCID=route4-rmmod0${test_type}
-    TST_COUNT=$test_type
-
-    case $test_type in
-	1)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by route command then it is deleted by removing network driver in $NS_TIMES times"
-	;;
-	2)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv4 route is add by ip command then it is deleted by removing network driver in $NS_TIMES times"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
-
-    # Start the loop
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	# Check the connectivity to the gateway
-	check_icmpv4_connectivity $lhost_ifname $rhost_ipv4addr
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
-	    return 1
-	fi
-
-	# Add the route
-	case $test_type in
-	    1)
-	    route add -net $dst_network netmask 255.255.255.0 gw $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	    2)
-	    ip route add ${dst_network}/24 via $rhost_ipv4addr dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to add the route to ${dst_network}/24"
-	    return 1
-	fi
-
-	# Load the route with UDP datagram
-	ns-udpsender -f 4 -D $dst_addr -p $DST_PORT -o -s 1472
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to run a UDP datagram sender"
-	    return 1
-	fi
-
-	# Remove and reload the network driver
-	rmmod $lhost_module && modprobe $lhost_module
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to unload/reload the network driver"
-	    return 1
-	fi
-
-	# Make sure to assing the IPv4 address
-	set_ipv4addr lhost ${LINK_NUM} ${IPV4_NETWORK} ${LHOST_IPV4_HOST} >/dev/null 2>&1
-
-	cnt=`expr $cnt + 1`
-    done
-
-    tst_resm TPASS "Test is finished correctly."
-    return 0
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
-
-RC=0
-do_setup
-test_body 1 || RC=`expr $RC + 1`      # Case of route command
-test_body 2 || RC=`expr $RC + 1`      # Case of ip command
-do_cleanup
-
-exit $RC
diff --git a/testcases/network/stress/route/route6-rmmod b/testcases/network/stress/route/route6-rmmod
deleted file mode 100644
index 765a57ae6..000000000
--- a/testcases/network/stress/route/route6-rmmod
+++ /dev/null
@@ -1,279 +0,0 @@
-#!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   route6-rmmod
-#
-# Description:
-#   Verify the kernel is not crashed when IPv6 route is add then it is deleted
-#   by the removing network driver
-#
-# Setup:
-#   See testcases/network/stress/README
-#
-# Author:
-#   Mitsuru Chinen <mitch@jp.ibm.com>
-#
-# History:
-#	Apr 8 2006 - Created (Mitsuru Chinen)
-#
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../ ; pwd)`}
-export LTPROOT
-
-# Total number of the test case
-TST_TOTAL=2
-export TST_TOTAL
-
-# Default of the test case ID and the test case count
-TCID=route6-rmmod
-TST_COUNT=0
-export TCID
-export TST_COUNT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# The number of times where IPv6 route is add/delete
-NS_TIMES=${NS_TIMES:-10000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv6 address
-IPV6_NETWORK="fec0:1:1:1"
-
-# Netmask of for the tested network
-IPV6_NETMASK_NUM=64
-
-# Host portion of the IPv6 address
-LHOST_IPV6_HOST=":2"	# src
-RHOST_IPV6_HOST=":1"	# gateway
-
-# The destination network
-DST_NETWORK="fec0:100:100:100"  # destination network
-DST_HOST=":5"
-DST_PORT="7"
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_cleanup
-#
-# DESCRIPTION:
-#   Recover the tested interfaces
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    # Make sure to load the network driver
-    if [ x${lhost_module} != x ]; then
-	modprobe $lhost_module
-    fi
-
-    # Initialize the interfaces
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
-#
-# NAME:
-#   do_setup
-#
-# DESCRIPTION:
-#   Make a IPv6 connectivity
-#
-#-----------------------------------------------------------------------
-do_setup()
-{
-    # Check the local host has ethtool utility
-    which ethtool >/dev/null
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "This test case requires ethtool utility"
-	exit $TST_TOTAL
-    fi
-
-    # The module name of the interface at the local host
-    lhost_module=
-
-    # Make sure to clean up
-    do_cleanup
-
-    # Assign IPv6 address to the interface of the local host
-    add_ipv6addr lhost ${LINK_NUM} ${IPV6_NETWORK} ${LHOST_IPV6_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to assign an IPv6 address at the local host"
-	return 1
-    fi
-    lhost_ipv6addr="${IPV6_NETWORK}:${LHOST_IPV6_HOST}"
-
-    # Set IPv6 address to the interfaces of the remote host
-    add_ipv6addr rhost ${LINK_NUM} ${IPV6_NETWORK} ${RHOST_IPV6_HOST}
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add an IPv6 address the remote host"
-	exit $TST_TOTAL
-    fi
-    rhost_ipv6addr="${IPV6_NETWORK}:${RHOST_IPV6_HOST}"
-
-    # Get the Interface names
-    lhost_ifname=`get_ifname lhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    rhost_ifname=`get_ifname rhost ${LINK_NUM}`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Get the module name of the interface at the local host
-    lhost_module=`ethtool -i $lhost_ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
-
-    # Chack the other active interface uses the same driver
-    for ifname in `ifconfig | grep ^eth | awk '{ print $1}'`; do
-	if [ $lhost_ifname = $ifname ]; then
-	    continue
-	fi
-
-	module=`ethtool -i $ifname | grep driver | sed "s/driver:[[:blank:]]*//"`
-	if [ $lhost_module = $module ]; then
-	    tst_resm TBROK "An active interface $ifname uses the same network deriver $module with the test intreface."
-	    exit $TST_TOTAL
-	fi
-    done
-
-    # Set the variables for destination network
-    dst_addr=${DST_NETWORK}:${DST_HOST}
-    dst_network=${DST_NETWORK}::
-}
-
-
-#-----------------------------------------------------------------------
-#
-# FUNCTION:
-#   test_body
-#
-# DESCRIPTION:
-#   main code of the test
-#
-# Arguments:
-#   $1: define the test type
-#	1 - route command case
-#	2 - ip command case
-#
-#-----------------------------------------------------------------------
-test_body()
-{
-    test_type=$1
-
-    TCID=route6-rmmod0${test_type}
-    TST_COUNT=$test_type
-
-    case $test_type in
-	1)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv6 route is add by route command then it is deleted by removing network driver in $NS_TIMES times"
-	;;
-	2)
-	tst_resm TINFO "Verify the kernel is not crashed when IPv6 route is add by ip command then it is deleted by removing network driver in $NS_TIMES times"
-	;;
-	*)
-	tst_resm TBROK "unspecified case"
-	return 1
-	;;
-    esac
-
-    # Start the loop
-    cnt=0
-    while [ $cnt -lt $NS_TIMES ]; do
-	# Check the connectivity to the gateway
-	check_icmpv6_connectivity $lhost_ifname $rhost_ipv6addr
-	if [ $? -ne 0 ]; then
-	    tst_resm TBROK "Test Link $LINK_NUM is somthing wrong."
-	    return 1
-	fi
-
-	# Add the route
-	case $test_type in
-	    1)
-	    route -A inet6 add ${dst_network}/64 gw $rhost_ipv6addr dev $lhost_ifname
-	    ;;
-	    2)
-	    ip -f inet6 route add ${dst_network}/64 via $rhost_ipv6addr dev $lhost_ifname
-	    ;;
-	esac
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to add the route to ${dst_network}/64"
-	    return 1
-	fi
-
-	# Load the route with UDP datagram
-	ns-udpsender -f 6 -D $dst_addr -p $DST_PORT -o -s 1452
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to run a UDP datagram sender"
-	    return 1
-	fi
-
-	# Remove and reload the network driver
-	rmmod $lhost_module && modprobe $lhost_module
-	if [ $? -ne 0 ]; then
-	    tst_resm TFAIL "Failed to unload/reload the network driver"
-	    return 1
-	fi
-
-	# Make sure to assing the IPv6 address
-	add_ipv6addr lhost ${LINK_NUM} ${IPV6_NETWORK} ${LHOST_IPV6_HOST} >/dev/null 2>&1
-
-	cnt=`expr $cnt + 1`
-    done
-
-    tst_resm TPASS "Test is finished correctly."
-    return 0
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-# Exit Value:
-#   The number of the failure
-#
-#-----------------------------------------------------------------------
-
-RC=0
-do_setup
-test_body 1 || RC=`expr $RC + 1`      # Case of route command
-test_body 2 || RC=`expr $RC + 1`      # Case of ip command
-do_cleanup
-
-exit $RC
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH 1/1] net/route: Rewrite route-rmmod to new API
  2020-11-16 22:03 [LTP] [PATCH 1/1] net/route: Rewrite route-rmmod to new API Petr Vorel
@ 2020-11-17 14:30 ` Alexey Kodanev
  2020-11-17 16:16   ` Petr Vorel
  2021-09-01 12:15   ` Petr Vorel
  0 siblings, 2 replies; 8+ messages in thread
From: Alexey Kodanev @ 2020-11-17 14:30 UTC (permalink / raw)
  To: ltp

On 17.11.2020 01:03, Petr Vorel wrote:
> Use network namespaces and veth only, therefore no need to use ethtool for
> defining a driver.
> 
> Add reset_ltp_netspace() in tst_net.sh.
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  runtest/net_stress.route                      |   2 +
>  testcases/lib/tst_net.sh                      |  12 +-
>  testcases/network/stress/route/route-rmmod.sh |  46 +++
>  testcases/network/stress/route/route4-rmmod   | 283 ------------------
>  testcases/network/stress/route/route6-rmmod   | 279 -----------------
>  5 files changed, 59 insertions(+), 563 deletions(-)
>  create mode 100644 testcases/network/stress/route/route-rmmod.sh
>  delete mode 100644 testcases/network/stress/route/route4-rmmod
>  delete mode 100644 testcases/network/stress/route/route6-rmmod
> 
> diff --git a/runtest/net_stress.route b/runtest/net_stress.route
> index b60e55bd6..9e1343e0f 100644
> --- a/runtest/net_stress.route
> +++ b/runtest/net_stress.route
> @@ -5,6 +5,7 @@ route4-change-if route-change-if.sh
>  route4-change-netlink-dst route-change-netlink-dst.sh
>  route4-change-netlink-gw route-change-netlink-gw.sh
>  route4-change-netlink-if route-change-netlink-if.sh
> +route4-rmmod route-rmmod.sh
>  
>  route6-change-dst route-change-dst.sh -6
>  route6-change-gw route-change-gw.sh -6
> @@ -12,3 +13,4 @@ route6-change-if route-change-if.sh -6
>  route6-change-netlink-dst route-change-netlink-dst.sh -6
>  route6-change-netlink-gw route-change-netlink-gw.sh -6
>  route6-change-netlink-if route-change-netlink-if.sh -6
> +route6-rmmod route-rmmod.sh -6
> diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
> index 46d3fb88e..30514ebaf 100644
> --- a/testcases/lib/tst_net.sh
> +++ b/testcases/lib/tst_net.sh
> @@ -1,7 +1,7 @@
>  #!/bin/sh
>  # SPDX-License-Identifier: GPL-2.0-or-later
>  # Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
> -# Copyright (c) 2016-2019 Petr Vorel <pvorel@suse.cz>
> +# Copyright (c) 2016-2020 Petr Vorel <pvorel@suse.cz>
>  # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
>  
>  [ -n "$TST_LIB_NET_LOADED" ] && return 0
> @@ -130,6 +130,16 @@ init_ltp_netspace()
>  	tst_restore_ipaddr rhost
>  }
>  
> +reset_ltp_netspace()
> +{
> +	tst_require_cmds pkill
> +
> +	rm -f /var/run/netns/ltp_ns
> +	pkill ns_create
> +	unset LTP_NETNS
> +	init_ltp_netspace
> +}
> +
>  # Run command on remote host.
>  # tst_rhost_run -c CMD [-b] [-s] [-u USER]
>  # Options:
> diff --git a/testcases/network/stress/route/route-rmmod.sh b/testcases/network/stress/route/route-rmmod.sh
> new file mode 100644
> index 000000000..8067d9094
> --- /dev/null
> +++ b/testcases/network/stress/route/route-rmmod.sh
> @@ -0,0 +1,46 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
> +# Copyright (c) International Business Machines Corp., 2006
> +# Author: Mitsuru Chinen <mitch@jp.ibm.com>
> +# Rewrite into new shell API: Petr Vorel
> +
> +TST_SETUP="setup"
> +TST_CLEANUP="cleanup"
> +TST_TESTFUNC="do_test"
> +
> +module='veth'
> +TST_NEEDS_DRIVERS="$module"
> +
> +. route-lib.sh
> +TST_CNT=$ROUTE_CHANGE_IP
> +
> +setup()
> +{
> +	tst_res TINFO "adding IPv$TST_IPVER route destination and delete network driver $ROUTE_CHANGE_IP times"
> +}

It is probably unsafe to go straight to the do_test() and removing
the veth... it would be nice to check that it is indeed using default
ltp netns, and veth not used for other interfaces, TCONF otherwise...

Perhaps in init_ltp_netspace(), create a special symlink in the if block,
where the default ltp netns created:

if [ ! -f /var/run/netns/ltp_ns -a -z "$LTP_NETNS" ]; then
   ...
   ROD ln -s /var/run/netns/ltp_ns /var/run/netns/ltp_ns_default
   ...
}

then check via this function:

is_ltp_ns_default()
{
	test -f /var/run/netns/ltp_ns_default
}


BTW, why not using add_macvlan() in route_lib.sh (or gre, vxlan, etc.)
and remove that driver, so that this test can be run with custom setup, and
with remote host setup?


> +
> +cleanup()
> +{
> +	modprobe $module
> +	route_cleanup> +}
> +
> +do_test()
> +{
> +	local iface="$(tst_iface)"
> +	local rt="$(tst_ipaddr_un -p $1)"
> +	local rhost="$(tst_ipaddr_un $1 1)"
> +
> +	tst_res TINFO "testing route '$rt'"
> +
> +	tst_add_ipaddr -s -q -a $rhost rhost
> +	ROD ip route add $rt dev $iface
> +	EXPECT_PASS_BRK ping$TST_IPV6 -c1 -I $(tst_ipaddr) $rhost \>/dev/null
> +
> +	ROD rmmod $module

ROD modprobe -r $module

> +	ROD modprobe $module
> +	reset_ltp_netspace

should be in cleanup too, in case of test timeout or TBROK?

> +}
> +
> +tst_run
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH 1/1] net/route: Rewrite route-rmmod to new API
  2020-11-17 14:30 ` Alexey Kodanev
@ 2020-11-17 16:16   ` Petr Vorel
  2021-09-01 12:15   ` Petr Vorel
  1 sibling, 0 replies; 8+ messages in thread
From: Petr Vorel @ 2020-11-17 16:16 UTC (permalink / raw)
  To: ltp

Hi Alexey,

thanks for your comments.

> > +module='veth'
> > +TST_NEEDS_DRIVERS="$module"
> > +
> > +. route-lib.sh
> > +TST_CNT=$ROUTE_CHANGE_IP
> > +
> > +setup()
> > +{
> > +	tst_res TINFO "adding IPv$TST_IPVER route destination and delete network driver $ROUTE_CHANGE_IP times"
> > +}

> It is probably unsafe to go straight to the do_test() and removing
> the veth... it would be nice to check that it is indeed using default
> ltp netns, and veth not used for other interfaces, TCONF otherwise...
I had this in old version and thought it's not necessary. OK, with check (or
better custom setup you suggest later) is safer for paralel run, which LTP
hopefully sooner or later support).

> Perhaps in init_ltp_netspace(), create a special symlink in the if block,
> where the default ltp netns created:

> if [ ! -f /var/run/netns/ltp_ns -a -z "$LTP_NETNS" ]; then
>    ...
>    ROD ln -s /var/run/netns/ltp_ns /var/run/netns/ltp_ns_default
>    ...
> }

> then check via this function:

> is_ltp_ns_default()
> {
> 	test -f /var/run/netns/ltp_ns_default
> }

Interesting.

> BTW, why not using add_macvlan() in route_lib.sh (or gre, vxlan, etc.)
> and remove that driver, so that this test can be run with custom setup, and
> with remote host setup?
I actually had version with add_macvlan(), but than I thought using netns is
enough. OK, I'll move back to that version (paralel run).

I also had a concert, that only virtualized drivers are tested.
Hope this simplification is ok.

> > +
> > +cleanup()
> > +{
> > +	modprobe $module
> > +	route_cleanup
> > +}
> > +
> > +do_test()
> > +{
> > +	local iface="$(tst_iface)"
> > +	local rt="$(tst_ipaddr_un -p $1)"
> > +	local rhost="$(tst_ipaddr_un $1 1)"
> > +
> > +	tst_res TINFO "testing route '$rt'"
> > +
> > +	tst_add_ipaddr -s -q -a $rhost rhost
> > +	ROD ip route add $rt dev $iface
> > +	EXPECT_PASS_BRK ping$TST_IPV6 -c1 -I $(tst_ipaddr) $rhost \>/dev/null
> > +
> > +	ROD rmmod $module

> ROD modprobe -r $module

+1, thanks!

> > +	ROD modprobe $module
> > +	reset_ltp_netspace

> should be in cleanup too, in case of test timeout or TBROK?
You mean reset_ltp_netspace? IMHO route_cleanup is enough, but I'll have a
closer look.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH 1/1] net/route: Rewrite route-rmmod to new API
  2020-11-17 14:30 ` Alexey Kodanev
  2020-11-17 16:16   ` Petr Vorel
@ 2021-09-01 12:15   ` Petr Vorel
  2021-09-02  9:07     ` Alexey Kodanev
  1 sibling, 1 reply; 8+ messages in thread
From: Petr Vorel @ 2021-09-01 12:15 UTC (permalink / raw)
  To: ltp

Hi Alexey,

...
> > diff --git a/testcases/network/stress/route/route-rmmod.sh b/testcases/network/stress/route/route-rmmod.sh
...
> > +setup()
> > +{
> > +	tst_res TINFO "adding IPv$TST_IPVER route destination and delete network driver $ROUTE_CHANGE_IP times"
> > +}

> It is probably unsafe to go straight to the do_test() and removing
> the veth... it would be nice to check that it is indeed using default
> ltp netns, and veth not used for other interfaces, TCONF otherwise...

> Perhaps in init_ltp_netspace(), create a special symlink in the if block,
> where the default ltp netns created:

> if [ ! -f /var/run/netns/ltp_ns -a -z "$LTP_NETNS" ]; then
>    ...
>    ROD ln -s /var/run/netns/ltp_ns /var/run/netns/ltp_ns_default
>    ...
> }

> then check via this function:

> is_ltp_ns_default()
> {
> 	test -f /var/run/netns/ltp_ns_default
> }


> BTW, why not using add_macvlan() in route_lib.sh (or gre, vxlan, etc.)
> and remove that driver, so that this test can be run with custom setup, and
> with remote host setup?

Looking into this old patch, it looked to me quite bad approach to move
add_macvlan() into tst_net.sh to be reused (you didn't suggested that, that's
what I'd do to prevent the duplicity).

But much better approach would be IMHO to move virt_add() and virt_add_rhost()
from virt_lib.sh to tst_net.sh and adjust it not to be too tight to virt_lib.sh.
I suppose $virt_type should became $2 (second parameter).

Also there could be moved from virt_lib.sh to tst_net.sh: e.g. add flag
TST_NET_ADD_VIRT_TYPE (e.g. macvlan, gre, ...) and doing setup and cleanup
there. We could reduce code and document which virt drivers are used.

route-change-netlink-if is the only test which needs to call tst_init_iface()
(to add routes), virt_lib.sh does not need it.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH 1/1] net/route: Rewrite route-rmmod to new API
  2021-09-01 12:15   ` Petr Vorel
@ 2021-09-02  9:07     ` Alexey Kodanev
  2021-09-02 16:45       ` Petr Vorel
  0 siblings, 1 reply; 8+ messages in thread
From: Alexey Kodanev @ 2021-09-02  9:07 UTC (permalink / raw)
  To: ltp

Hi Petr,
On 01.09.2021 15:15, Petr Vorel wrote:
> Hi Alexey,
> 
> ...
>>> diff --git a/testcases/network/stress/route/route-rmmod.sh b/testcases/network/stress/route/route-rmmod.sh
> ...
>>> +setup()
>>> +{
>>> +	tst_res TINFO "adding IPv$TST_IPVER route destination and delete network driver $ROUTE_CHANGE_IP times"
>>> +}
> 
>> It is probably unsafe to go straight to the do_test() and removing
>> the veth... it would be nice to check that it is indeed using default
>> ltp netns, and veth not used for other interfaces, TCONF otherwise...
> 
>> Perhaps in init_ltp_netspace(), create a special symlink in the if block,
>> where the default ltp netns created:
> 
>> if [ ! -f /var/run/netns/ltp_ns -a -z "$LTP_NETNS" ]; then
>>    ...
>>    ROD ln -s /var/run/netns/ltp_ns /var/run/netns/ltp_ns_default
>>    ...
>> }
> 
>> then check via this function:
> 
>> is_ltp_ns_default()
>> {
>> 	test -f /var/run/netns/ltp_ns_default
>> }
> 
> 
>> BTW, why not using add_macvlan() in route_lib.sh (or gre, vxlan, etc.)
>> and remove that driver, so that this test can be run with custom setup, and
>> with remote host setup?
> 
> Looking into this old patch, it looked to me quite bad approach to move
> add_macvlan() into tst_net.sh to be reused (you didn't suggested that, that's
> what I'd do to prevent the duplicity).

Why not move add_macvlan() to the virt_lib.sh, I think this lib is better
suited for creating macvlan?

> 
> But much better approach would be IMHO to move virt_add() and virt_add_rhost()
> from virt_lib.sh to tst_net.sh and adjust it not to be too tight to virt_lib.sh.
> I suppose $virt_type should became $2 (second parameter).
> 
> Also there could be moved from virt_lib.sh to tst_net.sh: e.g. add flag
> TST_NET_ADD_VIRT_TYPE (e.g. macvlan, gre, ...) and doing setup and cleanup
> there. We could reduce code and document which virt drivers are used.
> 
> route-change-netlink-if is the only test which needs to call tst_init_iface()
> (to add routes), virt_lib.sh does not need it.
> 
> Kind regards,
> Petr
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH 1/1] net/route: Rewrite route-rmmod to new API
  2021-09-02  9:07     ` Alexey Kodanev
@ 2021-09-02 16:45       ` Petr Vorel
  2021-09-03  8:53         ` Alexey Kodanev
  0 siblings, 1 reply; 8+ messages in thread
From: Petr Vorel @ 2021-09-02 16:45 UTC (permalink / raw)
  To: ltp

Hi Alexey,

<snip>
> >> BTW, why not using add_macvlan() in route_lib.sh (or gre, vxlan, etc.)
> >> and remove that driver, so that this test can be run with custom setup, and
> >> with remote host setup?

> > Looking into this old patch, it looked to me quite bad approach to move
> > add_macvlan() into tst_net.sh to be reused (you didn't suggested that, that's
> > what I'd do to prevent the duplicity).

> Why not move add_macvlan() to the virt_lib.sh, I think this lib is better
> suited for creating macvlan?
Well, route-change-if.sh and route-change-netlink-if.sh depends on helpers from
route-lib.sh. Using both libraries would require little changes, but sure it's
possible (+ add obviously add $virt_type).

It's just a bit strange to add this special purpose function when there is
virt_add() and virt_add_rhost(). Best will be probably to add macvlan to these
functions and migrate router tests which needs macvlan to use virt_lib.sh before
route-rmmod.sh using it.

In the long term I'd really prefer to add some TST_NET* variable (due doc
generation via docparse), but that can be postponed as another effort after the
release (I thought it'd have to be in tst_net.sh so that tests does not care
about including virt_lib.sh when declaring it, but variable could also have
prefix TST_NET_VIRT_ to make it obvious, that virt_lib.sh must be loaded. But I
still prefer moving to tst_net.sh when implementing this approach).

BTW you consider ok to use macvlan for testing this? I suppose this test was
intended to be used on the real hardware not on virtualization. But I don't have
proper setup and give up on this approach.

Kind regards,
Petr

> > But much better approach would be IMHO to move virt_add() and virt_add_rhost()
> > from virt_lib.sh to tst_net.sh and adjust it not to be too tight to virt_lib.sh.
> > I suppose $virt_type should became $2 (second parameter).

> > Also there could be moved from virt_lib.sh to tst_net.sh: e.g. add flag
> > TST_NET_ADD_VIRT_TYPE (e.g. macvlan, gre, ...) and doing setup and cleanup
> > there. We could reduce code and document which virt drivers are used.

> > route-change-netlink-if is the only test which needs to call tst_init_iface()
> > (to add routes), virt_lib.sh does not need it.

> > Kind regards,
> > Petr



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH 1/1] net/route: Rewrite route-rmmod to new API
  2021-09-02 16:45       ` Petr Vorel
@ 2021-09-03  8:53         ` Alexey Kodanev
  2021-09-03  8:55           ` Petr Vorel
  0 siblings, 1 reply; 8+ messages in thread
From: Alexey Kodanev @ 2021-09-03  8:53 UTC (permalink / raw)
  To: ltp

Hi Petr,
On 02.09.2021 19:45, Petr Vorel wrote:
> Hi Alexey,
> 
> <snip>
>>>> BTW, why not using add_macvlan() in route_lib.sh (or gre, vxlan, etc.)
>>>> and remove that driver, so that this test can be run with custom setup, and
>>>> with remote host setup?
> 
>>> Looking into this old patch, it looked to me quite bad approach to move
>>> add_macvlan() into tst_net.sh to be reused (you didn't suggested that, that's
>>> what I'd do to prevent the duplicity).
> 
>> Why not move add_macvlan() to the virt_lib.sh, I think this lib is better
>> suited for creating macvlan?
> Well, route-change-if.sh and route-change-netlink-if.sh depends on helpers from
> route-lib.sh. Using both libraries would require little changes, but sure it's
> possible (+ add obviously add $virt_type).
> 
> It's just a bit strange to add this special purpose function when there is
> virt_add() and virt_add_rhost(). Best will be probably to add macvlan to these
> functions and migrate router tests which needs macvlan to use virt_lib.sh before
> route-rmmod.sh using it.

Yes, it would be better to have the generic ones, moreover macvlan01/macvlan02
tests are already calling virt_add().

> 
> In the long term I'd really prefer to add some TST_NET* variable (due doc
> generation via docparse), but that can be postponed as another effort after the
> release (I thought it'd have to be in tst_net.sh so that tests does not care
> about including virt_lib.sh when declaring it, but variable could also have
> prefix TST_NET_VIRT_ to make it obvious, that virt_lib.sh must be loaded. But I
> still prefer moving to tst_net.sh when implementing this approach).
> 
> BTW you consider ok to use macvlan for testing this? I suppose this test was
> intended to be used on the real hardware not on virtualization. But I don't have
> proper setup and give up on this approach.

I think we are not changing the purpose of this test using a virtual
driver. Using the real drivers would complicate the test setup
unnecessarily considering what it does with the driver...

> 
> Kind regards,
> Petr
> 
>>> But much better approach would be IMHO to move virt_add() and virt_add_rhost()
>>> from virt_lib.sh to tst_net.sh and adjust it not to be too tight to virt_lib.sh.
>>> I suppose $virt_type should became $2 (second parameter).
> 
>>> Also there could be moved from virt_lib.sh to tst_net.sh: e.g. add flag
>>> TST_NET_ADD_VIRT_TYPE (e.g. macvlan, gre, ...) and doing setup and cleanup
>>> there. We could reduce code and document which virt drivers are used.
> 
>>> route-change-netlink-if is the only test which needs to call tst_init_iface()
>>> (to add routes), virt_lib.sh does not need it.
> 
>>> Kind regards,
>>> Petr
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH 1/1] net/route: Rewrite route-rmmod to new API
  2021-09-03  8:53         ` Alexey Kodanev
@ 2021-09-03  8:55           ` Petr Vorel
  0 siblings, 0 replies; 8+ messages in thread
From: Petr Vorel @ 2021-09-03  8:55 UTC (permalink / raw)
  To: ltp

Hi Alexey,

...
> >> Why not move add_macvlan() to the virt_lib.sh, I think this lib is better
> >> suited for creating macvlan?
> > Well, route-change-if.sh and route-change-netlink-if.sh depends on helpers from
> > route-lib.sh. Using both libraries would require little changes, but sure it's
> > possible (+ add obviously add $virt_type).

> > It's just a bit strange to add this special purpose function when there is
> > virt_add() and virt_add_rhost(). Best will be probably to add macvlan to these
> > functions and migrate router tests which needs macvlan to use virt_lib.sh before
> > route-rmmod.sh using it.

> Yes, it would be better to have the generic ones, moreover macvlan01/macvlan02
> tests are already calling virt_add().
+1.

> > In the long term I'd really prefer to add some TST_NET* variable (due doc
> > generation via docparse), but that can be postponed as another effort after the
> > release (I thought it'd have to be in tst_net.sh so that tests does not care
> > about including virt_lib.sh when declaring it, but variable could also have
> > prefix TST_NET_VIRT_ to make it obvious, that virt_lib.sh must be loaded. But I
> > still prefer moving to tst_net.sh when implementing this approach).

> > BTW you consider ok to use macvlan for testing this? I suppose this test was
> > intended to be used on the real hardware not on virtualization. But I don't have
> > proper setup and give up on this approach.

> I think we are not changing the purpose of this test using a virtual
> driver. Using the real drivers would complicate the test setup
> unnecessarily considering what it does with the driver...

+1

Thanks for your input!

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-09-03  8:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-16 22:03 [LTP] [PATCH 1/1] net/route: Rewrite route-rmmod to new API Petr Vorel
2020-11-17 14:30 ` Alexey Kodanev
2020-11-17 16:16   ` Petr Vorel
2021-09-01 12:15   ` Petr Vorel
2021-09-02  9:07     ` Alexey Kodanev
2021-09-02 16:45       ` Petr Vorel
2021-09-03  8:53         ` Alexey Kodanev
2021-09-03  8:55           ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.