* [PATCH] selftests: xfrm: put cleanup code into a exit trap
@ 2021-04-15 7:18 Po-Hsu Lin
0 siblings, 0 replies; only message in thread
From: Po-Hsu Lin @ 2021-04-15 7:18 UTC (permalink / raw)
To: linux-kernel, netdev; +Cc: shuah, davem
If the xfrm_policy.sh script takes longer than the default kselftest
framework 45 seconds timeout to run, it will be terminated and thus
leave those netns namespace files created by the test alone.
In this case a second attempt will fail with:
# Cannot create namespace file "/run/netns/ns1": File exists
It might affect the outcome of other tests as well.
Move the netns cleanup code into an exit trap so that we can ensure
these namespace files will be removed after the test.
Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
tools/testing/selftests/net/xfrm_policy.sh | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/net/xfrm_policy.sh b/tools/testing/selftests/net/xfrm_policy.sh
index bdf450e..bb4632b 100755
--- a/tools/testing/selftests/net/xfrm_policy.sh
+++ b/tools/testing/selftests/net/xfrm_policy.sh
@@ -28,6 +28,11 @@ KEY_AES=0x0123456789abcdef0123456789012345
SPI1=0x1
SPI2=0x2
+cleanup() {
+ for i in 1 2 3 4;do ip netns del ns$i 2>/dev/null ;done
+}
+trap cleanup EXIT
+
do_esp_policy() {
local ns=$1
local me=$2
@@ -481,6 +486,4 @@ check_hthresh_repeat "policies with repeated htresh change"
check_random_order ns3 "policies inserted in random order"
-for i in 1 2 3 4;do ip netns del ns$i;done
-
exit $ret
--
2.7.4
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-15 7:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-15 7:18 [PATCH] selftests: xfrm: put cleanup code into a exit trap Po-Hsu Lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).