xref: /linux/tools/testing/selftests/bpf/prog_tests/fentry_test.c (revision d9c00c3b1639a3c8f46663cc042a3768d222021f)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 Facebook */
3 #include <test_progs.h>
4 #include "test_pkt_access.skel.h"
5 #include "fentry_test.skel.h"
6 
7 BPF_EMBED_OBJ_DECLARE(pkt_access);
8 BPF_EMBED_OBJ_DECLARE(fentry);
9 
10 void test_fentry_test(void)
11 {
12 	struct test_pkt_access *pkt_skel = NULL;
13 	struct fentry_test *fentry_skel = NULL;
14 	int err, pkt_fd, i;
15 	__u32 duration, retval;
16 	__u64 *result;
17 
18 	pkt_skel = test_pkt_access__open_and_load(&pkt_access_embed);
19 	if (CHECK(!pkt_skel, "pkt_skel_load", "pkt_access skeleton failed\n"))
20 		return;
21 	fentry_skel = fentry_test__open_and_load(&fentry_embed);
22 	if (CHECK(!fentry_skel, "fentry_skel_load", "fentry skeleton failed\n"))
23 		goto cleanup;
24 
25 	err = fentry_test__attach(fentry_skel);
26 	if (CHECK(err, "fentry_attach", "fentry attach failed: %d\n", err))
27 		goto cleanup;
28 
29 	pkt_fd = bpf_program__fd(pkt_skel->progs.test_pkt_access);
30 	err = bpf_prog_test_run(pkt_fd, 1, &pkt_v6, sizeof(pkt_v6),
31 				NULL, NULL, &retval, &duration);
32 	CHECK(err || retval, "ipv6",
33 	      "err %d errno %d retval %d duration %d\n",
34 	      err, errno, retval, duration);
35 
36 	result = (__u64 *)fentry_skel->bss;
37 	for (i = 0; i < 6; i++) {
38 		if (CHECK(result[i] != 1, "result",
39 			  "fentry_test%d failed err %lld\n", i + 1, result[i]))
40 			goto cleanup;
41 	}
42 
43 cleanup:
44 	fentry_test__destroy(fentry_skel);
45 	test_pkt_access__destroy(pkt_skel);
46 }
47