summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/prog_tests/test_skb_pkt_end.c
blob: cf1215531920f28433f26c40456d6ef3159d8522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2020 Facebook */
#include <test_progs.h>
#include <network_helpers.h>
#include "skb_pkt_end.skel.h"

static int sanity_run(struct bpf_program *prog)
{
	__u32 duration, retval;
	int err, prog_fd;

	prog_fd = bpf_program__fd(prog);
	err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4),
				NULL, NULL, &retval, &duration);
	if (CHECK(err || retval != 123, "test_run",
		  "err %d errno %d retval %d duration %d\n",
		  err, errno, retval, duration))
		return -1;
	return 0;
}

void test_test_skb_pkt_end(void)
{
	struct skb_pkt_end *skb_pkt_end_skel = NULL;
	__u32 duration = 0;
	int err;

	skb_pkt_end_skel = skb_pkt_end__open_and_load();
	if (CHECK(!skb_pkt_end_skel, "skb_pkt_end_skel_load", "skb_pkt_end skeleton failed\n"))
		goto cleanup;

	err = skb_pkt_end__attach(skb_pkt_end_skel);
	if (CHECK(err, "skb_pkt_end_attach", "skb_pkt_end attach failed: %d\n", err))
		goto cleanup;

	if (sanity_run(skb_pkt_end_skel->progs.main_prog))
		goto cleanup;

cleanup:
	skb_pkt_end__destroy(skb_pkt_end_skel);
}