4
4
#define _GNU_SOURCE
5
5
#include <cgroup_helpers.h>
6
6
#include <test_progs.h>
7
+ #include <sched.h>
7
8
8
9
#include "cgrp_kfunc_failure.skel.h"
9
10
#include "cgrp_kfunc_success.skel.h"
@@ -87,6 +88,78 @@ static const char * const success_tests[] = {
87
88
"test_cgrp_from_id" ,
88
89
};
89
90
91
+ static void test_cgrp_from_id_ns (void )
92
+ {
93
+ LIBBPF_OPTS (bpf_test_run_opts , opts );
94
+ struct cgrp_kfunc_success * skel ;
95
+ struct bpf_program * prog ;
96
+ int fd , pid , pipe_fd [2 ];
97
+
98
+ skel = open_load_cgrp_kfunc_skel ();
99
+ if (!ASSERT_OK_PTR (skel , "open_load_skel" ))
100
+ return ;
101
+
102
+ if (!ASSERT_OK (skel -> bss -> err , "pre_mkdir_err" ))
103
+ goto cleanup ;
104
+
105
+ prog = bpf_object__find_program_by_name (skel -> obj , "test_cgrp_from_id_ns" );
106
+ if (!ASSERT_OK_PTR (prog , "bpf_object__find_program_by_name" ))
107
+ goto cleanup ;
108
+
109
+ if (!ASSERT_OK (pipe (pipe_fd ), "pipe" ))
110
+ goto cleanup ;
111
+
112
+ pid = fork ();
113
+ if (!ASSERT_GE (pid , 0 , "fork result" ))
114
+ goto pipe_cleanup ;
115
+
116
+ if (pid == 0 ) {
117
+ int ret = 1 ;
118
+
119
+ close (pipe_fd [0 ]);
120
+ fd = create_and_get_cgroup ("cgrp_from_id_ns" );
121
+ if (!ASSERT_GE (fd , 0 , "cgrp_fd" ))
122
+ _exit (1 );
123
+
124
+ if (!ASSERT_OK (join_cgroup ("cgrp_from_id_ns" ), "join cgrp" ))
125
+ goto fail ;
126
+
127
+ if (!ASSERT_OK (unshare (CLONE_NEWCGROUP ), "unshare cgns" ))
128
+ goto fail ;
129
+
130
+ ret = bpf_prog_test_run_opts (bpf_program__fd (prog ), & opts );
131
+ if (!ASSERT_OK (ret , "test run ret" ))
132
+ goto fail ;
133
+
134
+ remove_cgroup ("cgrp_from_id_ns" );
135
+
136
+ if (!ASSERT_OK (opts .retval , "test run retval" ))
137
+ _exit (1 );
138
+ ret = 0 ;
139
+ close (fd );
140
+ if (!ASSERT_EQ (write (pipe_fd [1 ], & ret , sizeof (ret )), sizeof (ret ), "write pipe" ))
141
+ _exit (1 );
142
+
143
+ _exit (0 );
144
+ fail :
145
+ remove_cgroup ("cgrp_from_id_ns" );
146
+ _exit (1 );
147
+ } else {
148
+ int res ;
149
+
150
+ close (pipe_fd [1 ]);
151
+ if (!ASSERT_EQ (read (pipe_fd [0 ], & res , sizeof (res )), sizeof (res ), "read res" ))
152
+ goto pipe_cleanup ;
153
+ if (!ASSERT_OK (res , "result from run" ))
154
+ goto pipe_cleanup ;
155
+ }
156
+
157
+ pipe_cleanup :
158
+ close (pipe_fd [1 ]);
159
+ cleanup :
160
+ cgrp_kfunc_success__destroy (skel );
161
+ }
162
+
90
163
void test_cgrp_kfunc (void )
91
164
{
92
165
int i , err ;
@@ -102,6 +175,9 @@ void test_cgrp_kfunc(void)
102
175
run_success_test (success_tests [i ]);
103
176
}
104
177
178
+ if (test__start_subtest ("test_cgrp_from_id_ns" ))
179
+ test_cgrp_from_id_ns ();
180
+
105
181
RUN_TESTS (cgrp_kfunc_failure );
106
182
107
183
cleanup :
0 commit comments