Skip to content

Commit

Permalink
Merge branch 'selftests-net-introduce-deferred-commands'
Browse files Browse the repository at this point in the history
Petr Machata says:

====================
selftests: net: Introduce deferred commands

Recently, a defer helper was added to Python selftests. The idea is to keep
cleanup commands close to their dirtying counterparts, thereby making it
more transparent what is cleaning up what, making it harder to miss a
cleanup, and make the whole cleanup business exception safe. All these
benefits are applicable to bash as well, exception safety can be
interpreted in terms of safety vs. a SIGINT.

This patchset therefore introduces a framework of several helpers that
serve to schedule cleanups in bash selftests.

- Patch gregkh#1 has more details about the primitives being introduced.
  Patch gregkh#2 adds a fallback cleanup() function to lib.sh, because ideally
  selftests wouldn't need to introduce a dedicated cleanup function at all.

- Patch gregkh#3 adds a parameter to stop_traffic(), which makes it possible to
  start other background processes after the traffic is started without
  confusing the cleanup.

- Patches gregkh#4 to gregkh#10 convert a number of selftests.

  The goal was to convert all tests that use start_traffic / stop_traffic
  to the defer framework. Leftover traffic generators are a particularly
  painful sort of a missed cleanup. Normal unfinished cleanups can usually
  be cleaned up simply by rerunning the test and interrupting it early to
  let the cleanups run again / in full. This does not work with
  stop_traffic, because it is only issued at the end of the test case that
  starts the traffic. At the same time, leftover traffic generators
  influence follow-up test runs, and are hard to notice.

  The tests were however converted whole-sale, not just their traffic bits.
  Thus they form a proof of concept of the defer framework.
====================

Link: https://patch.msgid.link/[email protected]
Signed-off-by: Paolo Abeni <[email protected]>
  • Loading branch information
Paolo Abeni committed Oct 22, 2024
2 parents c797cb9 + cebd281 commit 66ffef3
Show file tree
Hide file tree
Showing 19 changed files with 591 additions and 609 deletions.
85 changes: 36 additions & 49 deletions tools/testing/selftests/drivers/net/mlxsw/devlink_trap_policer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,63 +45,52 @@ source $lib_dir/devlink_lib.sh
h1_create()
{
simple_if_init $h1 192.0.2.1/24
defer simple_if_fini $h1 192.0.2.1/24

mtu_set $h1 10000
defer mtu_restore $h1

ip -4 route add default vrf v$h1 nexthop via 192.0.2.2
}

h1_destroy()
{
ip -4 route del default vrf v$h1 nexthop via 192.0.2.2

mtu_restore $h1
simple_if_fini $h1 192.0.2.1/24
defer ip -4 route del default vrf v$h1 nexthop via 192.0.2.2
}

h2_create()
{
simple_if_init $h2 198.51.100.1/24
defer simple_if_fini $h2 198.51.100.1/24

mtu_set $h2 10000
defer mtu_restore $h2

ip -4 route add default vrf v$h2 nexthop via 198.51.100.2
}

h2_destroy()
{
ip -4 route del default vrf v$h2 nexthop via 198.51.100.2

mtu_restore $h2
simple_if_fini $h2 198.51.100.1/24
defer ip -4 route del default vrf v$h2 nexthop via 198.51.100.2
}

router_create()
{
ip link set dev $rp1 up
defer ip link set dev $rp1 down

ip link set dev $rp2 up
defer ip link set dev $rp2 down

__addr_add_del $rp1 add 192.0.2.2/24
defer __addr_add_del $rp1 del 192.0.2.2/24

__addr_add_del $rp2 add 198.51.100.2/24
defer __addr_add_del $rp2 del 198.51.100.2/24

mtu_set $rp1 10000
defer mtu_restore $rp1

mtu_set $rp2 10000
defer mtu_restore $rp2

ip -4 route add blackhole 198.51.100.100
defer ip -4 route del blackhole 198.51.100.100

devlink trap set $DEVLINK_DEV trap blackhole_route action trap
}

router_destroy()
{
devlink trap set $DEVLINK_DEV trap blackhole_route action drop

ip -4 route del blackhole 198.51.100.100

mtu_restore $rp2
mtu_restore $rp1
__addr_add_del $rp2 del 198.51.100.2/24
__addr_add_del $rp1 del 192.0.2.2/24

ip link set dev $rp2 down
ip link set dev $rp1 down
defer devlink trap set $DEVLINK_DEV trap blackhole_route action drop
}

setup_prepare()
Expand All @@ -114,29 +103,18 @@ setup_prepare()

rp1_mac=$(mac_get $rp1)

# Reload to ensure devlink-trap settings are back to default.
defer devlink_reload

vrf_prepare
defer vrf_cleanup

h1_create
h2_create

router_create
}

cleanup()
{
pre_cleanup

router_destroy

h2_destroy
h1_destroy

vrf_cleanup

# Reload to ensure devlink-trap settings are back to default.
devlink_reload
}

rate_limits_test()
{
RET=0
Expand Down Expand Up @@ -214,7 +192,10 @@ __rate_test()
# by the policer. Make sure measured received rate is about 1000 pps
log_info "=== Tx rate: Highest, Policer rate: 1000 pps ==="

defer_scope_push

start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac
defer stop_traffic $!

sleep 5 # Take measurements when rate is stable

Expand All @@ -229,13 +210,16 @@ __rate_test()
check_err $? "Expected non-zero policer drop rate, got 0"
log_info "Measured policer drop rate of $drop_rate pps"

stop_traffic
defer_scope_pop

# Send packets at a rate of 1000 pps and make sure they are not dropped
# by the policer
log_info "=== Tx rate: 1000 pps, Policer rate: 1000 pps ==="

defer_scope_push

start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac -d 1msec
defer stop_traffic $!

sleep 5 # Take measurements when rate is stable

Expand All @@ -244,7 +228,7 @@ __rate_test()
check_err $? "Expected zero policer drop rate, got a drop rate of $drop_rate pps"
log_info "Measured policer drop rate of $drop_rate pps"

stop_traffic
defer_scope_pop

# Unbind the policer and send packets at highest possible rate. Make
# sure they are not dropped by the policer and that the measured
Expand All @@ -253,7 +237,10 @@ __rate_test()

devlink trap group set $DEVLINK_DEV group l3_drops nopolicer

defer_scope_push

start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac
defer stop_traffic $!

rate=$(trap_rate_get)
(( rate > 1000 ))
Expand All @@ -265,7 +252,7 @@ __rate_test()
check_err $? "Expected zero policer drop rate, got a drop rate of $drop_rate pps"
log_info "Measured policer drop rate of $drop_rate pps"

stop_traffic
defer_scope_pop

log_test "Trap policer rate"
}
Expand Down
Loading

0 comments on commit 66ffef3

Please sign in to comment.