selftests: xsk: cleanup veth pair at ctrl-c
authorMagnus Karlsson <magnus.karlsson@intel.com>
Tue, 10 May 2022 11:56:01 +0000 (13:56 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 11 May 2022 15:03:16 +0000 (08:03 -0700)
Remove the veth pair when the tests are aborted by pressing
ctrl-c. Currently in this situation, the veth pair is left on the
system polluting the netdev space.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/r/20220510115604.8717-7-magnus.karlsson@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/test_xsk.sh

index d06215ee843d9e2dcbab106389a99f8b7a7bef8e..56750029923185763a257f5ee3fb3f2f02457417 100755 (executable)
@@ -97,6 +97,13 @@ NS0=root
 NS1=af_xdp${VETH1_POSTFIX}
 MTU=1500
 
+trap ctrl_c INT
+
+function ctrl_c() {
+        cleanup_exit ${VETH0} ${VETH1} ${NS1}
+       exit 1
+}
+
 setup_vethPairs() {
        if [[ $verbose -eq 1 ]]; then
                echo "setting up ${VETH0}: namespace: ${NS0}"