1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #include <test_progs.h>
4 #include <network_helpers.h>
5 #include "skb_pkt_end.skel.h"
6 
sanity_run(struct bpf_program * prog)7 static int sanity_run(struct bpf_program *prog)
8 {
9 	int err, prog_fd;
10 	LIBBPF_OPTS(bpf_test_run_opts, topts,
11 		.data_in = &pkt_v4,
12 		.data_size_in = sizeof(pkt_v4),
13 		.repeat = 1,
14 		.flags = BPF_F_TEST_SKB_CHECKSUM_COMPLETE,
15 	);
16 
17 	prog_fd = bpf_program__fd(prog);
18 	err = bpf_prog_test_run_opts(prog_fd, &topts);
19 	if (!ASSERT_OK(err, "test_run"))
20 		return -1;
21 	if (!ASSERT_EQ(topts.retval, 123, "test_run retval"))
22 		return -1;
23 	return 0;
24 }
25 
test_test_skb_pkt_end(void)26 void test_test_skb_pkt_end(void)
27 {
28 	struct skb_pkt_end *skb_pkt_end_skel = NULL;
29 	__u32 duration = 0;
30 	int err;
31 
32 	skb_pkt_end_skel = skb_pkt_end__open_and_load();
33 	if (CHECK(!skb_pkt_end_skel, "skb_pkt_end_skel_load", "skb_pkt_end skeleton failed\n"))
34 		goto cleanup;
35 
36 	err = skb_pkt_end__attach(skb_pkt_end_skel);
37 	if (CHECK(err, "skb_pkt_end_attach", "skb_pkt_end attach failed: %d\n", err))
38 		goto cleanup;
39 
40 	if (sanity_run(skb_pkt_end_skel->progs.main_prog))
41 		goto cleanup;
42 
43 cleanup:
44 	skb_pkt_end__destroy(skb_pkt_end_skel);
45 }
46