Skip to content

Commit

Permalink
xdp-bench/tests: skip xdp_load_bytes test if the kernel doesn't suppo…
Browse files Browse the repository at this point in the history
…rt it

Add detection of whether the kernel supports the xdp_load_bytes helper and
skip the test if it isn't supported.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
  • Loading branch information
tohojo committed Jun 8, 2023
1 parent 81a198d commit 95b813f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/testing/test-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ static struct prog_option load_options[] = {

enum probe_action {
PROBE_CPUMAP_PROGRAM,
PROBE_XDP_LOAD_BYTES,
};

struct enum_val probe_actions[] = {
{"cpumap-prog", PROBE_CPUMAP_PROGRAM},
{"xdp-load-bytes", PROBE_XDP_LOAD_BYTES},
{NULL, 0}
};

Expand All @@ -205,6 +207,9 @@ int do_probe(const void *cfg, __unused const char *pin_root_path)
case PROBE_CPUMAP_PROGRAM:
res = sample_probe_cpumap_compat();
break;
case PROBE_XDP_LOAD_BYTES:
res = sample_probe_xdp_load_bytes();
break;
default:
return EXIT_FAILURE;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/testing/test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ skip_if_missing_cpumap_attach()
fi
}

skip_if_missing_xdp_load_bytes()
{
if ! $TEST_PROG_DIR/test-tool probe xdp-load-bytes; then
exit "$SKIPPED_TEST"
fi
}

skip_if_missing_kernel_symbol()
{
if ! grep -q "$1" /proc/kallsyms; then
Expand Down
2 changes: 1 addition & 1 deletion lib/util/util.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
UTIL_OBJS := params.o logging.o util.o stats.o xpcapng.o xdp_sample.o
UTIL_BPF_OBJS := xdp_sample.bpf.o
UTIL_BPF_OBJS := xdp_sample.bpf.o xdp_load_bytes.bpf.o
23 changes: 23 additions & 0 deletions lib/util/xdp_load_bytes.bpf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>

#ifndef HAVE_LIBBPF_BPF_PROGRAM__TYPE
static long (*bpf_xdp_load_bytes)(struct xdp_md *xdp_md, __u32 offset, void *buf, __u32 len) = (void *) 189;
#endif

SEC("xdp")
int xdp_probe_prog(struct xdp_md *ctx)
{
__u8 buf[10];
int err;

err = bpf_xdp_load_bytes(ctx, 0, buf, sizeof(buf));
if (err)
return XDP_ABORTED;

return XDP_PASS;
}

char _license[] SEC("license") = "GPL";
13 changes: 13 additions & 0 deletions lib/util/xdp_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "logging.h"

#include "xdp_sample.skel.h"
#include "xdp_load_bytes.skel.h"

#define __sample_print(fmt, cond, ...) \
({ \
Expand Down Expand Up @@ -184,6 +185,18 @@ bool sample_probe_cpumap_compat(void)
return res;
}

bool sample_probe_xdp_load_bytes(void)
{
struct xdp_load_bytes *skel;
bool res;

skel = xdp_load_bytes__open_and_load();
res = !!skel;
xdp_load_bytes__destroy(skel);

return res;
}

void sample_check_cpumap_compat(struct bpf_program *prog,
struct bpf_program *prog_compat)
{
Expand Down
1 change: 1 addition & 0 deletions lib/util/xdp_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void sample_teardown(void);
int sample_run(int interval, void (*post_cb)(void *), void *ctx);
bool sample_is_compat(enum sample_compat compat_value);
bool sample_probe_cpumap_compat(void);
bool sample_probe_xdp_load_bytes(void);
void sample_check_cpumap_compat(struct bpf_program *prog,
struct bpf_program *prog_compat);

Expand Down
14 changes: 12 additions & 2 deletions xdp-bench/tests/test-xdp-bench.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
XDP_LOADER=${XDP_LOADER:-./xdp-loader}
XDP_BENCH=${XDP_BENCH:-./xdp-bench}
ALL_TESTS="test_drop test_pass test_tx test_rxq_stats test_redirect test_redirect_cpu test_redirect_map test_redirect_map_egress test_redirect_multi test_redirect_multi_egress"
ALL_TESTS="test_drop test_pass test_tx test_xdp_load_bytes test_rxq_stats test_redirect test_redirect_cpu test_redirect_map test_redirect_map_egress test_redirect_multi test_redirect_multi_egress"

test_basic()
{
Expand All @@ -10,7 +10,6 @@ test_basic()
check_run $XDP_BENCH $action $NS -vv
check_run $XDP_BENCH $action $NS -p read-data -vv
check_run $XDP_BENCH $action $NS -p parse-ip -vv
check_run $XDP_BENCH $action $NS -p parse-ip -l -vv
check_run $XDP_BENCH $action $NS -p swap-macs -vv
check_run $XDP_BENCH $action $NS -m skb -vv
check_run $XDP_BENCH $action $NS -e -vv
Expand All @@ -29,6 +28,17 @@ test_tx()
test_basic tx
}

test_xdp_load_bytes()
{
skip_if_missing_xdp_load_bytes

export XDP_SAMPLE_IMMEDIATE_EXIT=1

for action in drop pass tx; do
check_run $XDP_BENCH $action $NS -p parse-ip -l -vv
done
}

test_rxq_stats()
{
skip_if_missing_veth_rxq
Expand Down

0 comments on commit 95b813f

Please sign in to comment.