]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: test_xsk: Wrap test clean-up in functions
authorBastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
Fri, 31 Oct 2025 08:04:42 +0000 (09:04 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 31 Oct 2025 16:24:38 +0000 (09:24 -0700)
The clean-up done at the end of a test in __testapp_validate_traffic()
isn't wrapped in a function. It isn't convenient if we want to use it
somewhere else in the code.

Wrap the clean-up in two new functions : the first deletes the sockets,
the second releases the umem.

Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
Link: https://lore.kernel.org/r/20251031-xsk-v7-6-39fe486593a3@bootlin.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/test_xsk.c

index d7cb2821469c62abd0d532821e836336a2177eb5..84b724731e26d0c7e67131ec1bd562e223d3d09d 100644 (file)
@@ -1679,6 +1679,27 @@ static void xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_
                xsk_reattach_xdp(ifobj_tx, test->xdp_prog_tx, test->xskmap_tx, test->mode);
 }
 
+static void clean_sockets(struct test_spec *test, struct ifobject *ifobj)
+{
+       u32 i;
+
+       if (!ifobj || !test)
+               return;
+
+       for (i = 0; i < test->nb_sockets; i++)
+               xsk_socket__delete(ifobj->xsk_arr[i].xsk);
+}
+
+static void clean_umem(struct test_spec *test, struct ifobject *ifobj1, struct ifobject *ifobj2)
+{
+       if (!ifobj1)
+               return;
+
+       testapp_clean_xsk_umem(ifobj1);
+       if (ifobj2 && !ifobj2->shared_umem)
+               testapp_clean_xsk_umem(ifobj2);
+}
+
 static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *ifobj1,
                                      struct ifobject *ifobj2)
 {
@@ -1734,18 +1755,9 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i
                pthread_join(t0, NULL);
 
        if (test->total_steps == test->current_step || test->fail) {
-               u32 i;
-
-               if (ifobj2)
-                       for (i = 0; i < test->nb_sockets; i++)
-                               xsk_socket__delete(ifobj2->xsk_arr[i].xsk);
-
-               for (i = 0; i < test->nb_sockets; i++)
-                       xsk_socket__delete(ifobj1->xsk_arr[i].xsk);
-
-               testapp_clean_xsk_umem(ifobj1);
-               if (ifobj2 && !ifobj2->shared_umem)
-                       testapp_clean_xsk_umem(ifobj2);
+               clean_sockets(test, ifobj1);
+               clean_sockets(test, ifobj2);
+               clean_umem(test, ifobj1, ifobj2);
        }
 
        if (test->fail)