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 if (!ASSERT_ERR(err, "struct_ops_private_stack_fail__load"))
58 goto cleanup;
59 return;
60
61 cleanup:
62 struct_ops_private_stack_fail__destroy(skel);
63 }
64
test_private_stack_recur(void)65 static void test_private_stack_recur(void)
66 {
67 struct struct_ops_private_stack_recur *skel;
68 struct bpf_link *link;
69 int err;
70
71 skel = struct_ops_private_stack_recur__open();
72 if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_recur__open"))
73 return;
74
75 if (skel->data->skip) {
76 test__skip();
77 goto cleanup;
78 }
79
80 err = struct_ops_private_stack_recur__load(skel);
81 if (!ASSERT_OK(err, "struct_ops_private_stack_recur__load"))
82 goto cleanup;
83
84 link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
85 if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
86 goto cleanup;
87
88 ASSERT_OK(trigger_module_test_read(256), "trigger_read");
89
90 ASSERT_EQ(skel->bss->val_j, 3, "val_j");
91
92 bpf_link__destroy(link);
93
94 cleanup:
95 struct_ops_private_stack_recur__destroy(skel);
96 }
97
test_struct_ops_private_stack(void)98 void test_struct_ops_private_stack(void)
99 {
100 if (test__start_subtest("private_stack"))
101 test_private_stack();
102 if (test__start_subtest("private_stack_fail"))
103 test_private_stack_fail();
104 if (test__start_subtest("private_stack_recur"))
105 test_private_stack_recur();
106 }
107