mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 21:21:41 +00:00
selftests: net: lib: Add kill_process
A number of selftests run processes in the background and need to kill them afterwards. Instead for everyone to open-code the kill / wait / redirect mantra, add a helper in net/lib.sh. Convert existing open-code sites. Signed-off-by: Petr Machata <petrm@nvidia.com> Acked-by: Shuah Khan <skhan@linuxfoundation.org> Reviewed-by: Amit Cohen <amcohen@nvidia.com> Link: https://patch.msgid.link/a9db102067d741c118f0bd93b10c75e2a34665ea.1731589511.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
af76b44318
commit
46f6569cf0
@ -116,7 +116,7 @@ dev_del_test()
|
|||||||
|
|
||||||
log_test "Device delete"
|
log_test "Device delete"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
}
|
}
|
||||||
|
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
@ -595,7 +595,7 @@ irif_disabled_test()
|
|||||||
|
|
||||||
log_test "Ingress RIF disabled"
|
log_test "Ingress RIF disabled"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
ip link set dev $rp1 nomaster
|
ip link set dev $rp1 nomaster
|
||||||
__addr_add_del $rp1 add 192.0.2.2/24 2001:db8:1::2/64
|
__addr_add_del $rp1 add 192.0.2.2/24 2001:db8:1::2/64
|
||||||
ip link del dev br0 type bridge
|
ip link del dev br0 type bridge
|
||||||
@ -645,7 +645,7 @@ erif_disabled_test()
|
|||||||
|
|
||||||
log_test "Egress RIF disabled"
|
log_test "Egress RIF disabled"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
__addr_add_del $rp1 add 192.0.2.2/24 2001:db8:1::2/64
|
__addr_add_del $rp1 add 192.0.2.2/24 2001:db8:1::2/64
|
||||||
ip link del dev br0 type bridge
|
ip link del dev br0 type bridge
|
||||||
devlink_trap_action_set $trap_name "drop"
|
devlink_trap_action_set $trap_name "drop"
|
||||||
|
@ -202,7 +202,7 @@ mtu_value_is_too_small_test()
|
|||||||
|
|
||||||
mtu_restore $rp2
|
mtu_restore $rp2
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $h1 ingress protocol ip pref 1 handle 101 flower
|
tc filter del dev $h1 ingress protocol ip pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ __ttl_value_is_too_small_test()
|
|||||||
|
|
||||||
log_test "TTL value is too small: TTL=$ttl_val"
|
log_test "TTL value is too small: TTL=$ttl_val"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $h1 ingress protocol ip pref 1 handle 101 flower
|
tc filter del dev $h1 ingress protocol ip pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ __mc_reverse_path_forwarding_test()
|
|||||||
|
|
||||||
log_test "Multicast reverse path forwarding: $desc"
|
log_test "Multicast reverse path forwarding: $desc"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $rp2 egress protocol $proto pref 1 handle 101 flower
|
tc filter del dev $rp2 egress protocol $proto pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,7 +347,7 @@ __reject_route_test()
|
|||||||
|
|
||||||
log_test "Reject route: $desc"
|
log_test "Reject route: $desc"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
ip route del unreachable $unreachable
|
ip route del unreachable $unreachable
|
||||||
tc filter del dev $h1 ingress protocol $proto pref 1 handle 101 flower
|
tc filter del dev $h1 ingress protocol $proto pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
@ -542,7 +542,7 @@ ipv4_lpm_miss_test()
|
|||||||
|
|
||||||
log_test "LPM miss: IPv4"
|
log_test "LPM miss: IPv4"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
vrf_without_routes_destroy
|
vrf_without_routes_destroy
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -569,7 +569,7 @@ ipv6_lpm_miss_test()
|
|||||||
|
|
||||||
log_test "LPM miss: IPv6"
|
log_test "LPM miss: IPv6"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
vrf_without_routes_destroy
|
vrf_without_routes_destroy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ ecn_decap_test()
|
|||||||
|
|
||||||
log_test "$desc: Inner ECN is not ECT and outer is $ecn_desc"
|
log_test "$desc: Inner ECN is not ECT and outer is $ecn_desc"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $swp1 egress protocol ip pref 1 handle 101 flower
|
tc filter del dev $swp1 egress protocol ip pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ no_matching_tunnel_test()
|
|||||||
|
|
||||||
log_test "$desc"
|
log_test "$desc"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $swp1 egress protocol ip pref 1 handle 101 flower
|
tc filter del dev $swp1 egress protocol ip pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ ecn_decap_test()
|
|||||||
|
|
||||||
log_test "$desc: Inner ECN is not ECT and outer is $ecn_desc"
|
log_test "$desc: Inner ECN is not ECT and outer is $ecn_desc"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $swp1 egress protocol ipv6 pref 1 handle 101 flower
|
tc filter del dev $swp1 egress protocol ipv6 pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ no_matching_tunnel_test()
|
|||||||
|
|
||||||
log_test "$desc"
|
log_test "$desc"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $swp1 egress protocol ipv6 pref 1 handle 101 flower
|
tc filter del dev $swp1 egress protocol ipv6 pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ ecn_decap_test()
|
|||||||
|
|
||||||
log_test "$desc: Inner ECN is not ECT and outer is $ecn_desc"
|
log_test "$desc: Inner ECN is not ECT and outer is $ecn_desc"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $swp1 egress protocol ip pref 1 handle 101 flower
|
tc filter del dev $swp1 egress protocol ip pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ corrupted_packet_test()
|
|||||||
|
|
||||||
log_test "$desc"
|
log_test "$desc"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $swp1 egress protocol ip pref 1 handle 101 flower
|
tc filter del dev $swp1 egress protocol ip pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ ecn_decap_test()
|
|||||||
|
|
||||||
log_test "$desc: Inner ECN is not ECT and outer is $ecn_desc"
|
log_test "$desc: Inner ECN is not ECT and outer is $ecn_desc"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $swp1 egress protocol ipv6 pref 1 handle 101 flower
|
tc filter del dev $swp1 egress protocol ipv6 pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ corrupted_packet_test()
|
|||||||
|
|
||||||
log_test "$desc"
|
log_test "$desc"
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $swp1 egress protocol ipv6 pref 1 handle 101 flower
|
tc filter del dev $swp1 egress protocol ipv6 pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ psample_capture_start()
|
|||||||
|
|
||||||
psample_capture_stop()
|
psample_capture_stop()
|
||||||
{
|
{
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
}
|
}
|
||||||
|
|
||||||
__tc_sample_rate_test()
|
__tc_sample_rate_test()
|
||||||
@ -499,7 +499,7 @@ tc_sample_md_out_tc_occ_test()
|
|||||||
backlog=$(tc -j -p -s qdisc show dev $rp2 | jq '.[0]["backlog"]')
|
backlog=$(tc -j -p -s qdisc show dev $rp2 | jq '.[0]["backlog"]')
|
||||||
|
|
||||||
# Kill mausezahn.
|
# Kill mausezahn.
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
|
|
||||||
psample_capture_stop
|
psample_capture_stop
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ route_addition_check()
|
|||||||
sleep 1
|
sleep 1
|
||||||
$IP route add $route dev dummy1
|
$IP route add $route dev dummy1
|
||||||
sleep 1
|
sleep 1
|
||||||
kill %% && wait %% &> /dev/null
|
kill_process %%
|
||||||
|
|
||||||
route_notify_check $outfile $expected_num_notifications $offload_failed
|
route_notify_check $outfile $expected_num_notifications $offload_failed
|
||||||
rm -f $outfile
|
rm -f $outfile
|
||||||
@ -148,7 +148,7 @@ route_deletion_check()
|
|||||||
sleep 1
|
sleep 1
|
||||||
$IP route del $route dev dummy1
|
$IP route del $route dev dummy1
|
||||||
sleep 1
|
sleep 1
|
||||||
kill %% && wait %% &> /dev/null
|
kill_process %%
|
||||||
|
|
||||||
route_notify_check $outfile $expected_num_notifications
|
route_notify_check $outfile $expected_num_notifications
|
||||||
rm -f $outfile
|
rm -f $outfile
|
||||||
@ -191,7 +191,7 @@ route_replacement_check()
|
|||||||
sleep 1
|
sleep 1
|
||||||
$IP route replace $route dev dummy2
|
$IP route replace $route dev dummy2
|
||||||
sleep 1
|
sleep 1
|
||||||
kill %% && wait %% &> /dev/null
|
kill_process %%
|
||||||
|
|
||||||
route_notify_check $outfile $expected_num_notifications
|
route_notify_check $outfile $expected_num_notifications
|
||||||
rm -f $outfile
|
rm -f $outfile
|
||||||
|
@ -77,7 +77,7 @@ sw_drops_test()
|
|||||||
|
|
||||||
rm ${dir}/packets.pcap
|
rm ${dir}/packets.pcap
|
||||||
|
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
timeout 5 dwdump -o sw -w ${dir}/packets.pcap
|
timeout 5 dwdump -o sw -w ${dir}/packets.pcap
|
||||||
(( $(tshark -r ${dir}/packets.pcap \
|
(( $(tshark -r ${dir}/packets.pcap \
|
||||||
-Y 'ip.dst == 192.0.2.10' 2> /dev/null | wc -l) == 0))
|
-Y 'ip.dst == 192.0.2.10' 2> /dev/null | wc -l) == 0))
|
||||||
|
@ -689,7 +689,7 @@ fib6_notify_test()
|
|||||||
|
|
||||||
log_test $ret 0 "ipv6 route add notify"
|
log_test $ret 0 "ipv6 route add notify"
|
||||||
|
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
|
|
||||||
#rm errors.txt
|
#rm errors.txt
|
||||||
|
|
||||||
@ -736,7 +736,7 @@ fib_notify_test()
|
|||||||
|
|
||||||
log_test $ret 0 "ipv4 route add notify"
|
log_test $ret 0 "ipv4 route add notify"
|
||||||
|
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
|
|
||||||
rm errors.txt
|
rm errors.txt
|
||||||
|
|
||||||
@ -2328,7 +2328,7 @@ ipv4_mangle_test()
|
|||||||
$IP route del table 123 172.16.101.0/24 dev veth1
|
$IP route del table 123 172.16.101.0/24 dev veth1
|
||||||
$IP rule del pref 100
|
$IP rule del pref 100
|
||||||
|
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
rm $tmp_file
|
rm $tmp_file
|
||||||
|
|
||||||
route_cleanup
|
route_cleanup
|
||||||
@ -2386,7 +2386,7 @@ ipv6_mangle_test()
|
|||||||
$IP -6 route del table 123 2001:db8:101::/64 dev veth1
|
$IP -6 route del table 123 2001:db8:101::/64 dev veth1
|
||||||
$IP -6 rule del pref 100
|
$IP -6 rule del pref 100
|
||||||
|
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
rm $tmp_file
|
rm $tmp_file
|
||||||
|
|
||||||
route_cleanup
|
route_cleanup
|
||||||
|
@ -501,7 +501,7 @@ devlink_trap_drop_cleanup()
|
|||||||
local pref=$1; shift
|
local pref=$1; shift
|
||||||
local handle=$1; shift
|
local handle=$1; shift
|
||||||
|
|
||||||
kill $mz_pid && wait $mz_pid &> /dev/null
|
kill_process $mz_pid
|
||||||
tc filter del dev $dev egress protocol $proto pref $pref handle $handle flower
|
tc filter del dev $dev egress protocol $proto pref $pref handle $handle flower
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1574,8 +1574,7 @@ stop_traffic()
|
|||||||
{
|
{
|
||||||
local pid=${1-%%}; shift
|
local pid=${1-%%}; shift
|
||||||
|
|
||||||
# Suppress noise from killing mausezahn.
|
kill_process "$pid"
|
||||||
{ kill $pid && wait $pid; } 2>/dev/null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare -A cappid
|
declare -A cappid
|
||||||
|
@ -148,7 +148,7 @@ police_common_test()
|
|||||||
|
|
||||||
log_test "$test_name"
|
log_test "$test_name"
|
||||||
|
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
|
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ police_shared_common_test()
|
|||||||
|
|
||||||
log_test "$test_name"
|
log_test "$test_name"
|
||||||
|
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
}
|
}
|
||||||
|
|
||||||
police_shared_test()
|
police_shared_test()
|
||||||
@ -278,7 +278,7 @@ police_mirror_common_test()
|
|||||||
|
|
||||||
log_test "$test_name"
|
log_test "$test_name"
|
||||||
|
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
tc filter del dev $pol_if $dir protocol ip pref 1 handle 101 flower
|
tc filter del dev $pol_if $dir protocol ip pref 1 handle 101 flower
|
||||||
tc filter del dev $h3 ingress protocol ip pref 1 handle 101 flower
|
tc filter del dev $h3 ingress protocol ip pref 1 handle 101 flower
|
||||||
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
|
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
|
||||||
@ -320,7 +320,7 @@ police_pps_common_test()
|
|||||||
|
|
||||||
log_test "$test_name"
|
log_test "$test_name"
|
||||||
|
|
||||||
{ kill %% && wait %%; } 2>/dev/null
|
kill_process %%
|
||||||
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
|
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,3 +434,11 @@ xfail_on_veth()
|
|||||||
"$@"
|
"$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kill_process()
|
||||||
|
{
|
||||||
|
local pid=$1; shift
|
||||||
|
|
||||||
|
# Suppress noise from killing the process.
|
||||||
|
{ kill $pid && wait $pid; } 2>/dev/null
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user