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