xref: /linux/tools/testing/selftests/bpf/progs/fexit_test.c (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
1d3b0856eSAlexei Starovoitov // SPDX-License-Identifier: GPL-2.0
2d3b0856eSAlexei Starovoitov /* Copyright (c) 2019 Facebook */
3d3b0856eSAlexei Starovoitov #include <linux/bpf.h>
43e689141SToke Høiland-Jørgensen #include <bpf/bpf_helpers.h>
5df8ff353SAndrii Nakryiko #include <bpf/bpf_tracing.h>
6d3b0856eSAlexei Starovoitov 
7d3b0856eSAlexei Starovoitov char _license[] SEC("license") = "GPL";
8d3b0856eSAlexei Starovoitov 
953f8dd43SAndrii Nakryiko __u64 test1_result = 0;
10ac065870SAndrii Nakryiko SEC("fexit/bpf_fentry_test1")
BPF_PROG(test1,int a,int ret)11ac065870SAndrii Nakryiko int BPF_PROG(test1, int a, int ret)
12d3b0856eSAlexei Starovoitov {
13f9a7cf6eSMartin KaFai Lau 	test1_result = a == 1 && ret == 2;
14d3b0856eSAlexei Starovoitov 	return 0;
15d3b0856eSAlexei Starovoitov }
16d3b0856eSAlexei Starovoitov 
1753f8dd43SAndrii Nakryiko __u64 test2_result = 0;
18ac065870SAndrii Nakryiko SEC("fexit/bpf_fentry_test2")
BPF_PROG(test2,int a,__u64 b,int ret)19ac065870SAndrii Nakryiko int BPF_PROG(test2, int a, __u64 b, int ret)
20d3b0856eSAlexei Starovoitov {
21f9a7cf6eSMartin KaFai Lau 	test2_result = a == 2 && b == 3 && ret == 5;
22d3b0856eSAlexei Starovoitov 	return 0;
23d3b0856eSAlexei Starovoitov }
24d3b0856eSAlexei Starovoitov 
2553f8dd43SAndrii Nakryiko __u64 test3_result = 0;
26ac065870SAndrii Nakryiko SEC("fexit/bpf_fentry_test3")
BPF_PROG(test3,char a,int b,__u64 c,int ret)27ac065870SAndrii Nakryiko int BPF_PROG(test3, char a, int b, __u64 c, int ret)
28d3b0856eSAlexei Starovoitov {
29f9a7cf6eSMartin KaFai Lau 	test3_result = a == 4 && b == 5 && c == 6 && ret == 15;
30d3b0856eSAlexei Starovoitov 	return 0;
31d3b0856eSAlexei Starovoitov }
32d3b0856eSAlexei Starovoitov 
3353f8dd43SAndrii Nakryiko __u64 test4_result = 0;
34ac065870SAndrii Nakryiko SEC("fexit/bpf_fentry_test4")
BPF_PROG(test4,void * a,char b,int c,__u64 d,int ret)35ac065870SAndrii Nakryiko int BPF_PROG(test4, void *a, char b, int c, __u64 d, int ret)
36d3b0856eSAlexei Starovoitov {
37f9a7cf6eSMartin KaFai Lau 	test4_result = a == (void *)7 && b == 8 && c == 9 && d == 10 &&
38f9a7cf6eSMartin KaFai Lau 		ret == 34;
39d3b0856eSAlexei Starovoitov 	return 0;
40d3b0856eSAlexei Starovoitov }
41d3b0856eSAlexei Starovoitov 
4253f8dd43SAndrii Nakryiko __u64 test5_result = 0;
43ac065870SAndrii Nakryiko SEC("fexit/bpf_fentry_test5")
BPF_PROG(test5,__u64 a,void * b,short c,int d,__u64 e,int ret)44ac065870SAndrii Nakryiko int BPF_PROG(test5, __u64 a, void *b, short c, int d, __u64 e, int ret)
45d3b0856eSAlexei Starovoitov {
46f9a7cf6eSMartin KaFai Lau 	test5_result = a == 11 && b == (void *)12 && c == 13 && d == 14 &&
47f9a7cf6eSMartin KaFai Lau 		e == 15 && ret == 65;
48d3b0856eSAlexei Starovoitov 	return 0;
49d3b0856eSAlexei Starovoitov }
50d3b0856eSAlexei Starovoitov 
5153f8dd43SAndrii Nakryiko __u64 test6_result = 0;
52ac065870SAndrii Nakryiko SEC("fexit/bpf_fentry_test6")
BPF_PROG(test6,__u64 a,void * b,short c,int d,void * e,__u64 f,int ret)53ac065870SAndrii Nakryiko int BPF_PROG(test6, __u64 a, void *b, short c, int d, void *e, __u64 f, int ret)
54d3b0856eSAlexei Starovoitov {
55f9a7cf6eSMartin KaFai Lau 	test6_result = a == 16 && b == (void *)17 && c == 18 && d == 19 &&
56f9a7cf6eSMartin KaFai Lau 		e == (void *)20 && f == 21 && ret == 111;
57d3b0856eSAlexei Starovoitov 	return 0;
58d3b0856eSAlexei Starovoitov }
59d923021cSYonghong Song 
60d923021cSYonghong Song struct bpf_fentry_test_t {
61d923021cSYonghong Song 	struct bpf_fentry_test *a;
62d923021cSYonghong Song };
63d923021cSYonghong Song 
64d923021cSYonghong Song __u64 test7_result = 0;
65d923021cSYonghong Song SEC("fexit/bpf_fentry_test7")
BPF_PROG(test7,struct bpf_fentry_test_t * arg)66d923021cSYonghong Song int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
67d923021cSYonghong Song {
68*ebda107eSJiapeng Chong 	if (!arg)
69d923021cSYonghong Song 		test7_result = 1;
70d923021cSYonghong Song 	return 0;
71d923021cSYonghong Song }
72d923021cSYonghong Song 
73d923021cSYonghong Song __u64 test8_result = 0;
74d923021cSYonghong Song SEC("fexit/bpf_fentry_test8")
BPF_PROG(test8,struct bpf_fentry_test_t * arg)75d923021cSYonghong Song int BPF_PROG(test8, struct bpf_fentry_test_t *arg)
76d923021cSYonghong Song {
77*ebda107eSJiapeng Chong 	if (!arg->a)
78d923021cSYonghong Song 		test8_result = 1;
79d923021cSYonghong Song 	return 0;
80d923021cSYonghong Song }
81