Commit fa6fde35 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Andrii Nakryiko

bpf: selftests: Get rid of CHECK macro in xdp_bpf2bpf.c

Rely on ASSERT* macros and get rid of deprecated CHECK ones in
xdp_bpf2bpf bpf selftest.
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/df7e5098465016e27d91f2c69a376a35d63a7621.1642679130.git.lorenzo@kernel.org
parent 791cad02
...@@ -12,26 +12,14 @@ struct meta { ...@@ -12,26 +12,14 @@ struct meta {
static void on_sample(void *ctx, int cpu, void *data, __u32 size) static void on_sample(void *ctx, int cpu, void *data, __u32 size)
{ {
int duration = 0;
struct meta *meta = (struct meta *)data; struct meta *meta = (struct meta *)data;
struct ipv4_packet *trace_pkt_v4 = data + sizeof(*meta); struct ipv4_packet *trace_pkt_v4 = data + sizeof(*meta);
if (CHECK(size < sizeof(pkt_v4) + sizeof(*meta), ASSERT_GE(size, sizeof(pkt_v4) + sizeof(*meta), "check_size");
"check_size", "size %u < %zu\n", ASSERT_EQ(meta->ifindex, if_nametoindex("lo"), "check_meta_ifindex");
size, sizeof(pkt_v4) + sizeof(*meta))) ASSERT_EQ(meta->pkt_len, sizeof(pkt_v4), "check_meta_pkt_len");
return; ASSERT_EQ(memcmp(trace_pkt_v4, &pkt_v4, sizeof(pkt_v4)), 0,
"check_packet_content");
if (CHECK(meta->ifindex != if_nametoindex("lo"), "check_meta_ifindex",
"meta->ifindex = %d\n", meta->ifindex))
return;
if (CHECK(meta->pkt_len != sizeof(pkt_v4), "check_meta_pkt_len",
"meta->pkt_len = %zd\n", sizeof(pkt_v4)))
return;
if (CHECK(memcmp(trace_pkt_v4, &pkt_v4, sizeof(pkt_v4)),
"check_packet_content", "content not the same\n"))
return;
*(bool *)ctx = true; *(bool *)ctx = true;
} }
...@@ -52,7 +40,7 @@ void test_xdp_bpf2bpf(void) ...@@ -52,7 +40,7 @@ void test_xdp_bpf2bpf(void)
/* Load XDP program to introspect */ /* Load XDP program to introspect */
pkt_skel = test_xdp__open_and_load(); pkt_skel = test_xdp__open_and_load();
if (CHECK(!pkt_skel, "pkt_skel_load", "test_xdp skeleton failed\n")) if (!ASSERT_OK_PTR(pkt_skel, "test_xdp__open_and_load"))
return; return;
pkt_fd = bpf_program__fd(pkt_skel->progs._xdp_tx_iptunnel); pkt_fd = bpf_program__fd(pkt_skel->progs._xdp_tx_iptunnel);
...@@ -62,7 +50,7 @@ void test_xdp_bpf2bpf(void) ...@@ -62,7 +50,7 @@ void test_xdp_bpf2bpf(void)
/* Load trace program */ /* Load trace program */
ftrace_skel = test_xdp_bpf2bpf__open(); ftrace_skel = test_xdp_bpf2bpf__open();
if (CHECK(!ftrace_skel, "__open", "ftrace skeleton failed\n")) if (!ASSERT_OK_PTR(ftrace_skel, "test_xdp_bpf2bpf__open"))
goto out; goto out;
/* Demonstrate the bpf_program__set_attach_target() API rather than /* Demonstrate the bpf_program__set_attach_target() API rather than
...@@ -77,11 +65,11 @@ void test_xdp_bpf2bpf(void) ...@@ -77,11 +65,11 @@ void test_xdp_bpf2bpf(void)
bpf_program__set_attach_target(prog, pkt_fd, "_xdp_tx_iptunnel"); bpf_program__set_attach_target(prog, pkt_fd, "_xdp_tx_iptunnel");
err = test_xdp_bpf2bpf__load(ftrace_skel); err = test_xdp_bpf2bpf__load(ftrace_skel);
if (CHECK(err, "__load", "ftrace skeleton failed\n")) if (!ASSERT_OK(err, "test_xdp_bpf2bpf__load"))
goto out; goto out;
err = test_xdp_bpf2bpf__attach(ftrace_skel); err = test_xdp_bpf2bpf__attach(ftrace_skel);
if (CHECK(err, "ftrace_attach", "ftrace attach failed: %d\n", err)) if (!ASSERT_OK(err, "test_xdp_bpf2bpf__attach"))
goto out; goto out;
/* Set up perf buffer */ /* Set up perf buffer */
...@@ -94,32 +82,24 @@ void test_xdp_bpf2bpf(void) ...@@ -94,32 +82,24 @@ void test_xdp_bpf2bpf(void)
err = bpf_prog_test_run(pkt_fd, 1, &pkt_v4, sizeof(pkt_v4), err = bpf_prog_test_run(pkt_fd, 1, &pkt_v4, sizeof(pkt_v4),
buf, &size, &retval, &duration); buf, &size, &retval, &duration);
memcpy(&iph, buf + sizeof(struct ethhdr), sizeof(iph)); memcpy(&iph, buf + sizeof(struct ethhdr), sizeof(iph));
if (CHECK(err || retval != XDP_TX || size != 74 ||
iph.protocol != IPPROTO_IPIP, "ipv4", ASSERT_OK(err, "ipv4");
"err %d errno %d retval %d size %d\n", ASSERT_EQ(retval, XDP_TX, "ipv4 retval");
err, errno, retval, size)) ASSERT_EQ(size, 74, "ipv4 size");
goto out; ASSERT_EQ(iph.protocol, IPPROTO_IPIP, "ipv4 proto");
/* Make sure bpf_xdp_output() was triggered and it sent the expected /* Make sure bpf_xdp_output() was triggered and it sent the expected
* data to the perf ring buffer. * data to the perf ring buffer.
*/ */
err = perf_buffer__poll(pb, 100); err = perf_buffer__poll(pb, 100);
if (CHECK(err < 0, "perf_buffer__poll", "err %d\n", err))
goto out;
CHECK_FAIL(!passed);
ASSERT_GE(err, 0, "perf_buffer__poll");
ASSERT_TRUE(passed, "test passed");
/* Verify test results */ /* Verify test results */
if (CHECK(ftrace_skel->bss->test_result_fentry != if_nametoindex("lo"), ASSERT_EQ(ftrace_skel->bss->test_result_fentry, if_nametoindex("lo"),
"result", "fentry failed err %llu\n", "fentry result");
ftrace_skel->bss->test_result_fentry)) ASSERT_EQ(ftrace_skel->bss->test_result_fexit, XDP_TX, "fexit result");
goto out;
CHECK(ftrace_skel->bss->test_result_fexit != XDP_TX, "result",
"fexit failed err %llu\n", ftrace_skel->bss->test_result_fexit);
out: out:
if (pb)
perf_buffer__free(pb); perf_buffer__free(pb);
test_xdp__destroy(pkt_skel); test_xdp__destroy(pkt_skel);
test_xdp_bpf2bpf__destroy(ftrace_skel); test_xdp_bpf2bpf__destroy(ftrace_skel);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment