Skip to content

Commit e3dfa0f

Browse files
bastien-curutchetAlexei Starovoitov
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. Reviewed-by: Maciej Fijalkowski <[email protected]> Signed-off-by: Bastien Curutchet (eBPF Foundation) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent bea4f03 commit e3dfa0f

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
@@ -1679,6 +1679,27 @@ static void xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_
16791679
xsk_reattach_xdp(ifobj_tx, test->xdp_prog_tx, test->xskmap_tx, test->mode);
16801680
}
16811681

1682+
static void clean_sockets(struct test_spec *test, struct ifobject *ifobj)
1683+
{
1684+
u32 i;
1685+
1686+
if (!ifobj || !test)
1687+
return;
1688+
1689+
for (i = 0; i < test->nb_sockets; i++)
1690+
xsk_socket__delete(ifobj->xsk_arr[i].xsk);
1691+
}
1692+
1693+
static void clean_umem(struct test_spec *test, struct ifobject *ifobj1, struct ifobject *ifobj2)
1694+
{
1695+
if (!ifobj1)
1696+
return;
1697+
1698+
testapp_clean_xsk_umem(ifobj1);
1699+
if (ifobj2 && !ifobj2->shared_umem)
1700+
testapp_clean_xsk_umem(ifobj2);
1701+
}
1702+
16821703
static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *ifobj1,
16831704
struct ifobject *ifobj2)
16841705
{
@@ -1734,18 +1755,9 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i
17341755
pthread_join(t0, NULL);
17351756

17361757
if (test->total_steps == test->current_step || test->fail) {
1737-
u32 i;
1738-
1739-
if (ifobj2)
1740-
for (i = 0; i < test->nb_sockets; i++)
1741-
xsk_socket__delete(ifobj2->xsk_arr[i].xsk);
1742-
1743-
for (i = 0; i < test->nb_sockets; i++)
1744-
xsk_socket__delete(ifobj1->xsk_arr[i].xsk);
1745-
1746-
testapp_clean_xsk_umem(ifobj1);
1747-
if (ifobj2 && !ifobj2->shared_umem)
1748-
testapp_clean_xsk_umem(ifobj2);
1758+
clean_sockets(test, ifobj1);
1759+
clean_sockets(test, ifobj2);
1760+
clean_umem(test, ifobj1, ifobj2);
17491761
}
17501762

17511763
if (test->fail)

0 commit comments

Comments
 (0)