From: Petr Machata <petrm@nvidia.com>
To: Shuah Khan <shuah@kernel.org>, <linux-kselftest@vger.kernel.org>,
<netdev@vger.kernel.org>
Cc: Jakub Kicinski <kuba@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
"Petr Machata" <petrm@nvidia.com>,
Amit Cohen <amcohen@nvidia.com>,
Benjamin Poirier <bpoirier@nvidia.com>,
Hangbin Liu <liuhangbin@gmail.com>,
Vladimir Oltean <vladimir.oltean@nxp.com>, <mlxsw@nvidia.com>
Subject: [RFC PATCH net-next 2/5] selftests: mlxsw: sch_red_core: Use defer for test cleanup
Date: Thu, 22 Aug 2024 15:49:41 +0200 [thread overview]
Message-ID: <bc6a5bf947f0b1fedfed218ae172d823951ef9cb.1724324945.git.petrm@nvidia.com> (raw)
In-Reply-To: <cover.1724324945.git.petrm@nvidia.com>
Instead of having a suite of dedicated cleanup functions, use the defer
framework to schedule cleanups right as their setup functions are run.
This makes a dedicated cleanup() moot, instead fall back to the
lib.sh-provided one, which invokes the necessary defer cleanups as well.
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
.../drivers/net/mlxsw/sch_red_core.sh | 109 ++++++------------
1 file changed, 37 insertions(+), 72 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh b/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh
index 7151b0c7bf8d..117a99fdbba5 100644
--- a/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh
+++ b/tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh
@@ -89,39 +89,31 @@ host_create()
local host=$1; shift
simple_if_init $dev
+ defer simple_if_fini $dev
+
mtu_set $dev 10000
+ defer mtu_restore $dev
vlan_create $dev 10 v$dev $(ipaddr $host 10)/28
+ defer vlan_destroy $dev 10
ip link set dev $dev.10 type vlan egress 0:0
vlan_create $dev 11 v$dev $(ipaddr $host 11)/28
+ defer vlan_destroy $dev 11
ip link set dev $dev.11 type vlan egress 0:1
}
-host_destroy()
-{
- local dev=$1; shift
-
- vlan_destroy $dev 11
- vlan_destroy $dev 10
- mtu_restore $dev
- simple_if_fini $dev
-}
-
h1_create()
{
host_create $h1 1
}
-h1_destroy()
-{
- host_destroy $h1
-}
-
h2_create()
{
host_create $h2 2
+
tc qdisc add dev $h2 clsact
+ defer tc qdisc del dev $h2 clsact
# Some of the tests in this suite use multicast traffic. As this traffic
# enters BR2_10 resp. BR2_11, it is flooded to all other ports. Thus
@@ -139,13 +131,7 @@ h2_create()
tc qdisc replace dev $h2 root handle 10: tbf rate 1gbit \
burst 128K limit 1G
-}
-
-h2_destroy()
-{
- tc qdisc del dev $h2 root handle 10:
- tc qdisc del dev $h2 clsact
- host_destroy $h2
+ defer tc qdisc del dev $h2 root handle 10:
}
h3_create()
@@ -153,40 +139,54 @@ h3_create()
host_create $h3 3
}
-h3_destroy()
-{
- host_destroy $h3
-}
-
switch_create()
{
local intf
local vlan
ip link add dev br1_10 type bridge
+ defer ip link del dev br1_10
+
ip link add dev br1_11 type bridge
+ defer ip link del dev br1_11
ip link add dev br2_10 type bridge
+ defer ip link del dev br2_10
+
ip link add dev br2_11 type bridge
+ defer ip link del dev br2_11
for intf in $swp1 $swp2 $swp3 $swp4 $swp5; do
ip link set dev $intf up
+ defer ip link set dev $intf down
+
mtu_set $intf 10000
+ defer mtu_restore $intf
done
for intf in $swp1 $swp4; do
for vlan in 10 11; do
vlan_create $intf $vlan
+ defer vlan_destroy $intf $vlan
+
ip link set dev $intf.$vlan master br1_$vlan
+ defer ip link set dev $intf.$vlan nomaster
+
ip link set dev $intf.$vlan up
+ defer ip link set dev $intf.$vlan up
done
done
for intf in $swp2 $swp3 $swp5; do
for vlan in 10 11; do
vlan_create $intf $vlan
+ defer vlan_destroy $intf $vlan
+
ip link set dev $intf.$vlan master br2_$vlan
+ defer ip link set dev $intf.$vlan nomaster
+
ip link set dev $intf.$vlan up
+ defer ip link set dev $intf.$vlan up
done
done
@@ -201,49 +201,25 @@ switch_create()
for intf in $swp3 $swp4; do
tc qdisc replace dev $intf root handle 1: tbf rate 1gbit \
burst 128K limit 1G
+ defer tc qdisc del dev $intf root handle 1:
done
ip link set dev br1_10 up
+ defer ip link set dev br1_10 down
+
ip link set dev br1_11 up
+ defer ip link set dev br1_11 down
+
ip link set dev br2_10 up
+ defer ip link set dev br2_10 down
+
ip link set dev br2_11 up
+ defer ip link set dev br2_11 down
local size=$(devlink_pool_size_thtype 0 | cut -d' ' -f 1)
devlink_port_pool_th_save $swp3 8
devlink_port_pool_th_set $swp3 8 $size
-}
-
-switch_destroy()
-{
- local intf
- local vlan
-
- devlink_port_pool_th_restore $swp3 8
-
- ip link set dev br2_11 down
- ip link set dev br2_10 down
- ip link set dev br1_11 down
- ip link set dev br1_10 down
-
- for intf in $swp4 $swp3; do
- tc qdisc del dev $intf root handle 1:
- done
-
- for intf in $swp5 $swp3 $swp2 $swp4 $swp1; do
- for vlan in 11 10; do
- ip link set dev $intf.$vlan down
- ip link set dev $intf.$vlan nomaster
- vlan_destroy $intf $vlan
- done
-
- mtu_restore $intf
- ip link set dev $intf down
- done
-
- ip link del dev br2_11
- ip link del dev br2_10
- ip link del dev br1_11
- ip link del dev br1_10
+ defer devlink_port_pool_th_restore $swp3 8
}
setup_prepare()
@@ -263,6 +239,7 @@ setup_prepare()
h3_mac=$(mac_get $h3)
vrf_prepare
+ defer vrf_cleanup
h1_create
h2_create
@@ -270,18 +247,6 @@ setup_prepare()
switch_create
}
-cleanup()
-{
- pre_cleanup
-
- switch_destroy
- h3_destroy
- h2_destroy
- h1_destroy
-
- vrf_cleanup
-}
-
ping_ipv4()
{
ping_test $h1.10 $(ipaddr 3 10) " from host 1, vlan 10"
--
2.45.0
next prev parent reply other threads:[~2024-08-22 13:52 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-22 13:49 [RFC PATCH net-next 0/5] selftests: forwarding: Introduce deferred commands Petr Machata
2024-08-22 13:49 ` [RFC PATCH net-next 1/5] " Petr Machata
2024-08-26 10:35 ` Ido Schimmel
2024-08-26 14:25 ` Petr Machata
2024-08-26 20:03 ` Jakub Kicinski
2024-08-26 20:04 ` Jakub Kicinski
2024-08-26 13:09 ` Przemek Kitszel
2024-08-26 15:20 ` Petr Machata
2024-08-27 6:21 ` Przemek Kitszel
2024-08-27 8:53 ` Petr Machata
2024-08-27 14:17 ` Jakub Kicinski
2024-08-27 15:37 ` Petr Machata
2024-08-22 13:49 ` Petr Machata [this message]
2024-08-26 11:37 ` [RFC PATCH net-next 2/5] selftests: mlxsw: sch_red_core: Use defer for test cleanup Ido Schimmel
2024-08-22 13:49 ` [RFC PATCH net-next 3/5] selftests: mlxsw: sch_red_core: Use defer for stopping traffic Petr Machata
2024-08-26 12:01 ` Ido Schimmel
2024-08-22 13:49 ` [RFC PATCH net-next 4/5] selftests: mlxsw: sch_red_*: Use defer for qdisc management Petr Machata
2024-08-26 12:03 ` Ido Schimmel
2024-08-22 13:49 ` [RFC PATCH net-next 5/5] selftests: sch_tbf_core: Use defer for stopping traffic Petr Machata
2024-08-26 12:07 ` Ido Schimmel
2024-08-26 14:31 ` Petr Machata
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bc6a5bf947f0b1fedfed218ae172d823951ef9cb.1724324945.git.petrm@nvidia.com \
--to=petrm@nvidia.com \
--cc=amcohen@nvidia.com \
--cc=bpoirier@nvidia.com \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=liuhangbin@gmail.com \
--cc=mlxsw@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=vladimir.oltean@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox