@@ -106,15 +106,18 @@ static int create_sys_heap_dmabuf(void)
106
106
return -1 ;
107
107
}
108
108
109
- static int create_test_buffers (void )
109
+ static int create_test_buffers (int map_fd )
110
110
{
111
+ bool f = false;
112
+
111
113
udmabuf = create_udmabuf ();
112
114
sysheap_dmabuf = create_sys_heap_dmabuf ();
113
115
114
116
if (udmabuf < 0 || sysheap_dmabuf < 0 )
115
117
return -1 ;
116
118
117
- return 0 ;
119
+ return bpf_map_update_elem (map_fd , udmabuf_test_buffer_name , & f , BPF_ANY ) ||
120
+ bpf_map_update_elem (map_fd , sysheap_test_buffer_name , & f , BPF_ANY );
118
121
}
119
122
120
123
static void destroy_test_buffers (void )
@@ -215,15 +218,45 @@ static void subtest_dmabuf_iter_check_default_iter(struct dmabuf_iter *skel)
215
218
close (iter_fd );
216
219
}
217
220
221
+ static void subtest_dmabuf_iter_check_open_coded (struct dmabuf_iter * skel , int map_fd )
222
+ {
223
+ LIBBPF_OPTS (bpf_test_run_opts , topts );
224
+ char key [DMA_BUF_NAME_LEN ];
225
+ int err , fd ;
226
+ bool found ;
227
+
228
+ /* No need to attach it, just run it directly */
229
+ fd = bpf_program__fd (skel -> progs .iter_dmabuf_for_each );
230
+
231
+ err = bpf_prog_test_run_opts (fd , & topts );
232
+ if (!ASSERT_OK (err , "test_run_opts err" ))
233
+ return ;
234
+ if (!ASSERT_OK (topts .retval , "test_run_opts retval" ))
235
+ return ;
236
+
237
+ if (!ASSERT_OK (bpf_map_get_next_key (map_fd , NULL , key ), "get next key" ))
238
+ return ;
239
+
240
+ do {
241
+ ASSERT_OK (bpf_map_lookup_elem (map_fd , key , & found ), "lookup" );
242
+ ASSERT_TRUE (found , "found test buffer" );
243
+ } while (bpf_map_get_next_key (map_fd , key , key ));
244
+ }
245
+
218
246
void test_dmabuf_iter (void )
219
247
{
220
248
struct dmabuf_iter * skel = NULL ;
249
+ int map_fd ;
221
250
222
251
skel = dmabuf_iter__open_and_load ();
223
252
if (!ASSERT_OK_PTR (skel , "dmabuf_iter__open_and_load" ))
224
253
return ;
225
254
226
- if (!ASSERT_OK (create_test_buffers (), "create_test_buffers" ))
255
+ map_fd = bpf_map__fd (skel -> maps .testbuf_hash );
256
+ if (!ASSERT_OK_FD (map_fd , "map_fd" ))
257
+ goto destroy_skel ;
258
+
259
+ if (!ASSERT_OK (create_test_buffers (map_fd ), "create_test_buffers" ))
227
260
goto destroy ;
228
261
229
262
if (!ASSERT_OK (dmabuf_iter__attach (skel ), "skel_attach" ))
@@ -233,8 +266,11 @@ void test_dmabuf_iter(void)
233
266
subtest_dmabuf_iter_check_no_infinite_reads (skel );
234
267
if (test__start_subtest ("default_iter" ))
235
268
subtest_dmabuf_iter_check_default_iter (skel );
269
+ if (test__start_subtest ("open_coded" ))
270
+ subtest_dmabuf_iter_check_open_coded (skel , map_fd );
236
271
237
272
destroy :
238
273
destroy_test_buffers ();
274
+ destroy_skel :
239
275
dmabuf_iter__destroy (skel );
240
276
}
0 commit comments