Skip to content

Commit aed092e

Browse files
bastien-curutchetKernel Patches Daemon
authored andcommitted
selftests/bpf: test_xsk: Don't exit immediately when xsk_attach fails
xsk_reattach_xdp calls exit_with_error() on failures. This exits the program immediately. It prevents the following tests from being run and isn't compliant with the CI. Add a return value to the functions handling XDP attachments to handle errors more smoothly. Signed-off-by: Bastien Curutchet (eBPF Foundation) <[email protected]>
1 parent 47e96a1 commit aed092e

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tools/testing/selftests/bpf/test_xsk.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ static bool xdp_prog_changed_tx(struct test_spec *test)
16531653
return ifobj->xdp_prog != test->xdp_prog_tx || ifobj->mode != test->mode;
16541654
}
16551655

1656-
static void xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_prog,
1656+
static int xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_prog,
16571657
struct bpf_map *xskmap, enum test_mode mode)
16581658
{
16591659
int err;
@@ -1662,31 +1662,40 @@ static void xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_pro
16621662
err = xsk_attach_xdp_program(xdp_prog, ifobj->ifindex, mode_to_xdp_flags(mode));
16631663
if (err) {
16641664
ksft_print_msg("Error attaching XDP program\n");
1665-
exit_with_error(-err);
1665+
return err;
16661666
}
16671667

16681668
if (ifobj->mode != mode && (mode == TEST_MODE_DRV || mode == TEST_MODE_ZC))
16691669
if (!xsk_is_in_mode(ifobj->ifindex, XDP_FLAGS_DRV_MODE)) {
16701670
ksft_print_msg("ERROR: XDP prog not in DRV mode\n");
1671-
exit_with_error(EINVAL);
1671+
return -EINVAL;
16721672
}
16731673

16741674
ifobj->xdp_prog = xdp_prog;
16751675
ifobj->xskmap = xskmap;
16761676
ifobj->mode = mode;
1677+
1678+
return 0;
16771679
}
16781680

1679-
static void xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_rx,
1681+
static int xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_rx,
16801682
struct ifobject *ifobj_tx)
16811683
{
1682-
if (xdp_prog_changed_rx(test))
1683-
xsk_reattach_xdp(ifobj_rx, test->xdp_prog_rx, test->xskmap_rx, test->mode);
1684+
int err = 0;
1685+
1686+
if (xdp_prog_changed_rx(test)) {
1687+
err = xsk_reattach_xdp(ifobj_rx, test->xdp_prog_rx, test->xskmap_rx, test->mode);
1688+
if (err)
1689+
return err;
1690+
}
16841691

16851692
if (!ifobj_tx || ifobj_tx->shared_umem)
1686-
return;
1693+
return 0;
16871694

16881695
if (xdp_prog_changed_tx(test))
1689-
xsk_reattach_xdp(ifobj_tx, test->xdp_prog_tx, test->xskmap_tx, test->mode);
1696+
err = xsk_reattach_xdp(ifobj_tx, test->xdp_prog_tx, test->xskmap_tx, test->mode);
1697+
1698+
return err;
16901699
}
16911700

16921701
static void clean_sockets(struct test_spec *test, struct ifobject *ifobj)
@@ -1796,7 +1805,8 @@ static int testapp_validate_traffic(struct test_spec *test)
17961805
}
17971806
}
17981807

1799-
xsk_attach_xdp_progs(test, ifobj_rx, ifobj_tx);
1808+
if (xsk_attach_xdp_progs(test, ifobj_rx, ifobj_tx))
1809+
return TEST_FAILURE;
18001810
return __testapp_validate_traffic(test, ifobj_rx, ifobj_tx);
18011811
}
18021812

0 commit comments

Comments
 (0)