@@ -28,7 +28,7 @@ static int map_flags;
2828
2929static void test_hashmap (int task , void * data )
3030{
31- long long key , next_key , value ;
31+ long long key , next_key , first_key , value ;
3232 int fd ;
3333
3434 fd = bpf_create_map (BPF_MAP_TYPE_HASH , sizeof (key ), sizeof (value ),
@@ -89,10 +89,13 @@ static void test_hashmap(int task, void *data)
8989 assert (bpf_map_delete_elem (fd , & key ) == -1 && errno == ENOENT );
9090
9191 /* Iterate over two elements. */
92+ assert (bpf_map_get_next_key (fd , NULL , & first_key ) == 0 &&
93+ (first_key == 1 || first_key == 2 ));
9294 assert (bpf_map_get_next_key (fd , & key , & next_key ) == 0 &&
93- (next_key == 1 || next_key == 2 ));
95+ (next_key == first_key ));
9496 assert (bpf_map_get_next_key (fd , & next_key , & next_key ) == 0 &&
95- (next_key == 1 || next_key == 2 ));
97+ (next_key == 1 || next_key == 2 ) &&
98+ (next_key != first_key ));
9699 assert (bpf_map_get_next_key (fd , & next_key , & next_key ) == -1 &&
97100 errno == ENOENT );
98101
@@ -105,6 +108,8 @@ static void test_hashmap(int task, void *data)
105108
106109 key = 0 ;
107110 /* Check that map is empty. */
111+ assert (bpf_map_get_next_key (fd , NULL , & next_key ) == -1 &&
112+ errno == ENOENT );
108113 assert (bpf_map_get_next_key (fd , & key , & next_key ) == -1 &&
109114 errno == ENOENT );
110115
@@ -133,7 +138,7 @@ static void test_hashmap_percpu(int task, void *data)
133138{
134139 unsigned int nr_cpus = bpf_num_possible_cpus ();
135140 long long value [nr_cpus ];
136- long long key , next_key ;
141+ long long key , next_key , first_key ;
137142 int expected_key_mask = 0 ;
138143 int fd , i ;
139144
@@ -193,7 +198,13 @@ static void test_hashmap_percpu(int task, void *data)
193198 assert (bpf_map_delete_elem (fd , & key ) == -1 && errno == ENOENT );
194199
195200 /* Iterate over two elements. */
201+ assert (bpf_map_get_next_key (fd , NULL , & first_key ) == 0 &&
202+ ((expected_key_mask & first_key ) == first_key ));
196203 while (!bpf_map_get_next_key (fd , & key , & next_key )) {
204+ if (first_key ) {
205+ assert (next_key == first_key );
206+ first_key = 0 ;
207+ }
197208 assert ((expected_key_mask & next_key ) == next_key );
198209 expected_key_mask &= ~next_key ;
199210
@@ -219,6 +230,8 @@ static void test_hashmap_percpu(int task, void *data)
219230
220231 key = 0 ;
221232 /* Check that map is empty. */
233+ assert (bpf_map_get_next_key (fd , NULL , & next_key ) == -1 &&
234+ errno == ENOENT );
222235 assert (bpf_map_get_next_key (fd , & key , & next_key ) == -1 &&
223236 errno == ENOENT );
224237
@@ -264,6 +277,8 @@ static void test_arraymap(int task, void *data)
264277 assert (bpf_map_lookup_elem (fd , & key , & value ) == -1 && errno == ENOENT );
265278
266279 /* Iterate over two elements. */
280+ assert (bpf_map_get_next_key (fd , NULL , & next_key ) == 0 &&
281+ next_key == 0 );
267282 assert (bpf_map_get_next_key (fd , & key , & next_key ) == 0 &&
268283 next_key == 0 );
269284 assert (bpf_map_get_next_key (fd , & next_key , & next_key ) == 0 &&
@@ -319,6 +334,8 @@ static void test_arraymap_percpu(int task, void *data)
319334 assert (bpf_map_lookup_elem (fd , & key , values ) == -1 && errno == ENOENT );
320335
321336 /* Iterate over two elements. */
337+ assert (bpf_map_get_next_key (fd , NULL , & next_key ) == 0 &&
338+ next_key == 0 );
322339 assert (bpf_map_get_next_key (fd , & key , & next_key ) == 0 &&
323340 next_key == 0 );
324341 assert (bpf_map_get_next_key (fd , & next_key , & next_key ) == 0 &&
@@ -400,6 +417,8 @@ static void test_map_large(void)
400417 errno == E2BIG );
401418
402419 /* Iterate through all elements. */
420+ assert (bpf_map_get_next_key (fd , NULL , & key ) == 0 );
421+ key .c = -1 ;
403422 for (i = 0 ; i < MAP_SIZE ; i ++ )
404423 assert (bpf_map_get_next_key (fd , & key , & key ) == 0 );
405424 assert (bpf_map_get_next_key (fd , & key , & key ) == -1 && errno == ENOENT );
@@ -499,6 +518,7 @@ static void test_map_parallel(void)
499518 errno == EEXIST );
500519
501520 /* Check that all elements were inserted. */
521+ assert (bpf_map_get_next_key (fd , NULL , & key ) == 0 );
502522 key = -1 ;
503523 for (i = 0 ; i < MAP_SIZE ; i ++ )
504524 assert (bpf_map_get_next_key (fd , & key , & key ) == 0 );
@@ -518,6 +538,7 @@ static void test_map_parallel(void)
518538
519539 /* Nothing should be left. */
520540 key = -1 ;
541+ assert (bpf_map_get_next_key (fd , NULL , & key ) == -1 && errno == ENOENT );
521542 assert (bpf_map_get_next_key (fd , & key , & key ) == -1 && errno == ENOENT );
522543}
523544
0 commit comments