1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include "struct_ops_private_stack.skel.h"
#include "struct_ops_private_stack_fail.skel.h"
#include "struct_ops_private_stack_recur.skel.h"
#include "struct_ops_private_stack_large.skel.h"
#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__)
static void test_private_stack(void)
{
struct struct_ops_private_stack *skel;
struct bpf_link *link;
int err;
skel = struct_ops_private_stack__open();
if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack__open"))
return;
err = struct_ops_private_stack__load(skel);
if (!ASSERT_OK(err, "struct_ops_private_stack__load"))
goto cleanup;
link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
goto cleanup;
ASSERT_OK(trigger_module_test_read(256), "trigger_read");
ASSERT_EQ(skel->bss->val_i, 3, "val_i");
ASSERT_EQ(skel->bss->val_j, 8, "val_j");
bpf_link__destroy(link);
cleanup:
struct_ops_private_stack__destroy(skel);
}
static void test_private_stack_fail(void)
{
struct struct_ops_private_stack_fail *skel;
int err;
skel = struct_ops_private_stack_fail__open();
if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_fail__open"))
return;
err = struct_ops_private_stack_fail__load(skel);
ASSERT_ERR(err, "struct_ops_private_stack_fail__load");
struct_ops_private_stack_fail__destroy(skel);
}
static void test_private_stack_recur(void)
{
struct struct_ops_private_stack_recur *skel;
struct bpf_link *link;
int err;
skel = struct_ops_private_stack_recur__open();
if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_recur__open"))
return;
err = struct_ops_private_stack_recur__load(skel);
if (!ASSERT_OK(err, "struct_ops_private_stack_recur__load"))
goto cleanup;
link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
goto cleanup;
ASSERT_OK(trigger_module_test_read(256), "trigger_read");
ASSERT_EQ(skel->bss->val_j, 3, "val_j");
bpf_link__destroy(link);
cleanup:
struct_ops_private_stack_recur__destroy(skel);
}
/* Two frames of 2 KiB each on the private stack */
static void test_private_stack_large(void)
{
struct struct_ops_private_stack_large *skel;
struct bpf_link *link;
if (!is_large_stack_supported()) {
test__skip();
return;
}
skel = struct_ops_private_stack_large__open_and_load();
if (!ASSERT_OK_PTR(skel, "struct_ops_private_stack_large__open_and_load"))
return;
link = bpf_map__attach_struct_ops(skel->maps.testmod_1);
if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
goto cleanup;
ASSERT_OK(trigger_module_test_read(256), "trigger_read");
ASSERT_EQ(skel->bss->val, 100 + 30 + 12, "val");
bpf_link__destroy(link);
cleanup:
struct_ops_private_stack_large__destroy(skel);
}
static void __test_struct_ops_private_stack(void)
{
if (test__start_subtest("private_stack"))
test_private_stack();
if (test__start_subtest("private_stack_fail"))
test_private_stack_fail();
if (test__start_subtest("private_stack_recur"))
test_private_stack_recur();
if (test__start_subtest("private_stack_large"))
test_private_stack_large();
}
#else
static void __test_struct_ops_private_stack(void)
{
test__skip();
}
#endif
void test_struct_ops_private_stack(void)
{
__test_struct_ops_private_stack();
}
|