1 // SPDX-License-Identifier: GPL-2.0
2
3 #include <test_progs.h>
4 #include "struct_ops_private_stack.skel.h"
5 #include "struct_ops_private_stack_fail.skel.h"
6 #include "struct_ops_private_stack_recur.skel.h"
7
test_private_stack(void)8 static void test_private_stack(void)
9 {
10 struct struct_ops_private_stack *skel;
11 struct bpf_link *link;
12 int err;
13
14 skel = struct_ops_private_stack__open();
15 if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack__open"))
16 return;
17
18 if (skel->data->skip) {
19 test__skip();
20 goto cleanup;
21 }
22
23 err = struct_ops_private_stack__load(skel);
24 if (!ASSERT_OK(err, "struct_ops_private_stack__load"))
25 goto cleanup;
26
27 link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
28 if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
29 goto cleanup;
30
31 ASSERT_OK(trigger_module_test_read(256), "trigger_read");
32
33 ASSERT_EQ(skel->bss->val_i, 3, "val_i");
34 ASSERT_EQ(skel->bss->val_j, 8, "val_j");
35
36 bpf_link__destroy(link);
37
38 cleanup:
39 struct_ops_private_stack__destroy(skel);
40 }
41
test_private_stack_fail(void)42 static void test_private_stack_fail(void)
43 {
44 struct struct_ops_private_stack_fail *skel;
45 int err;
46
47 skel = struct_ops_private_stack_fail__open();
48 if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_fail__open"))
49 return;
50
51 if (skel->data->skip) {
52 test__skip();
53 goto cleanup;
54 }
55
56 err = struct_ops_private_stack_fail__load(skel);
57 ASSERT_ERR(err, "struct_ops_private_stack_fail__load");
58
59 cleanup:
60 struct_ops_private_stack_fail__destroy(skel);
61 }
62
test_private_stack_recur(void)63 static void test_private_stack_recur(void)
64 {
65 struct struct_ops_private_stack_recur *skel;
66 struct bpf_link *link;
67 int err;
68
69 skel = struct_ops_private_stack_recur__open();
70 if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_recur__open"))
71 return;
72
73 if (skel->data->skip) {
74 test__skip();
75 goto cleanup;
76 }
77
78 err = struct_ops_private_stack_recur__load(skel);
79 if (!ASSERT_OK(err, "struct_ops_private_stack_recur__load"))
80 goto cleanup;
81
82 link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
83 if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
84 goto cleanup;
85
86 ASSERT_OK(trigger_module_test_read(256), "trigger_read");
87
88 ASSERT_EQ(skel->bss->val_j, 3, "val_j");
89
90 bpf_link__destroy(link);
91
92 cleanup:
93 struct_ops_private_stack_recur__destroy(skel);
94 }
95
test_struct_ops_private_stack(void)96 void test_struct_ops_private_stack(void)
97 {
98 if (test__start_subtest("private_stack"))
99 test_private_stack();
100 if (test__start_subtest("private_stack_fail"))
101 test_private_stack_fail();
102 if (test__start_subtest("private_stack_recur"))
103 test_private_stack_recur();
104 }
105