Skip to content

Commit 1f172de

Browse files
bastien-curutchetKernel Patches Daemon
authored andcommitted
selftests/bpf: test_xsk: Wrap test clean-up in functions
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. Signed-off-by: Bastien Curutchet (eBPF Foundation) <[email protected]>
1 parent 8022ccd commit 1f172de

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

tools/testing/selftests/bpf/test_xsk.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,27 @@ static void xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_
16891689
xsk_reattach_xdp(ifobj_tx, test->xdp_prog_tx, test->xskmap_tx, test->mode);
16901690
}
16911691

1692+
static void clean_sockets(struct test_spec *test, struct ifobject *ifobj)
1693+
{
1694+
u32 i;
1695+
1696+
if (!ifobj || !test)
1697+
return;
1698+
1699+
for (i = 0; i < test->nb_sockets; i++)
1700+
xsk_socket__delete(ifobj->xsk_arr[i].xsk);
1701+
}
1702+
1703+
static void clean_umem(struct test_spec *test, struct ifobject *ifobj1, struct ifobject *ifobj2)
1704+
{
1705+
if (!ifobj1)
1706+
return;
1707+
1708+
testapp_clean_xsk_umem(ifobj1);
1709+
if (ifobj2 && !ifobj2->shared_umem)
1710+
testapp_clean_xsk_umem(ifobj2);
1711+
}
1712+
16921713
static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *ifobj1,
16931714
struct ifobject *ifobj2)
16941715
{
@@ -1744,18 +1765,9 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i
17441765
pthread_join(t0, NULL);
17451766

17461767
if (test->total_steps == test->current_step || test->fail) {
1747-
u32 i;
1748-
1749-
if (ifobj2)
1750-
for (i = 0; i < test->nb_sockets; i++)
1751-
xsk_socket__delete(ifobj2->xsk_arr[i].xsk);
1752-
1753-
for (i = 0; i < test->nb_sockets; i++)
1754-
xsk_socket__delete(ifobj1->xsk_arr[i].xsk);
1755-
1756-
testapp_clean_xsk_umem(ifobj1);
1757-
if (ifobj2 && !ifobj2->shared_umem)
1758-
testapp_clean_xsk_umem(ifobj2);
1768+
clean_sockets(test, ifobj1);
1769+
clean_sockets(test, ifobj2);
1770+
clean_umem(test, ifobj1, ifobj2);
17591771
}
17601772

17611773
return !!test->fail;

0 commit comments

Comments
 (0)