@@ -28,7 +28,7 @@ static int map_flags;
28
28
29
29
static void test_hashmap (int task , void * data )
30
30
{
31
- long long key , next_key , value ;
31
+ long long key , next_key , first_key , value ;
32
32
int fd ;
33
33
34
34
fd = bpf_create_map (BPF_MAP_TYPE_HASH , sizeof (key ), sizeof (value ),
@@ -89,10 +89,13 @@ static void test_hashmap(int task, void *data)
89
89
assert (bpf_map_delete_elem (fd , & key ) == -1 && errno == ENOENT );
90
90
91
91
/* Iterate over two elements. */
92
+ assert (bpf_map_get_next_key (fd , NULL , & first_key ) == 0 &&
93
+ (first_key == 1 || first_key == 2 ));
92
94
assert (bpf_map_get_next_key (fd , & key , & next_key ) == 0 &&
93
- (next_key == 1 || next_key == 2 ));
95
+ (next_key == first_key ));
94
96
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 ));
96
99
assert (bpf_map_get_next_key (fd , & next_key , & next_key ) == -1 &&
97
100
errno == ENOENT );
98
101
@@ -105,6 +108,8 @@ static void test_hashmap(int task, void *data)
105
108
106
109
key = 0 ;
107
110
/* Check that map is empty. */
111
+ assert (bpf_map_get_next_key (fd , NULL , & next_key ) == -1 &&
112
+ errno == ENOENT );
108
113
assert (bpf_map_get_next_key (fd , & key , & next_key ) == -1 &&
109
114
errno == ENOENT );
110
115
@@ -133,7 +138,7 @@ static void test_hashmap_percpu(int task, void *data)
133
138
{
134
139
unsigned int nr_cpus = bpf_num_possible_cpus ();
135
140
long long value [nr_cpus ];
136
- long long key , next_key ;
141
+ long long key , next_key , first_key ;
137
142
int expected_key_mask = 0 ;
138
143
int fd , i ;
139
144
@@ -193,7 +198,13 @@ static void test_hashmap_percpu(int task, void *data)
193
198
assert (bpf_map_delete_elem (fd , & key ) == -1 && errno == ENOENT );
194
199
195
200
/* Iterate over two elements. */
201
+ assert (bpf_map_get_next_key (fd , NULL , & first_key ) == 0 &&
202
+ ((expected_key_mask & first_key ) == first_key ));
196
203
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
+ }
197
208
assert ((expected_key_mask & next_key ) == next_key );
198
209
expected_key_mask &= ~next_key ;
199
210
@@ -219,6 +230,8 @@ static void test_hashmap_percpu(int task, void *data)
219
230
220
231
key = 0 ;
221
232
/* Check that map is empty. */
233
+ assert (bpf_map_get_next_key (fd , NULL , & next_key ) == -1 &&
234
+ errno == ENOENT );
222
235
assert (bpf_map_get_next_key (fd , & key , & next_key ) == -1 &&
223
236
errno == ENOENT );
224
237
@@ -264,6 +277,8 @@ static void test_arraymap(int task, void *data)
264
277
assert (bpf_map_lookup_elem (fd , & key , & value ) == -1 && errno == ENOENT );
265
278
266
279
/* Iterate over two elements. */
280
+ assert (bpf_map_get_next_key (fd , NULL , & next_key ) == 0 &&
281
+ next_key == 0 );
267
282
assert (bpf_map_get_next_key (fd , & key , & next_key ) == 0 &&
268
283
next_key == 0 );
269
284
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)
319
334
assert (bpf_map_lookup_elem (fd , & key , values ) == -1 && errno == ENOENT );
320
335
321
336
/* Iterate over two elements. */
337
+ assert (bpf_map_get_next_key (fd , NULL , & next_key ) == 0 &&
338
+ next_key == 0 );
322
339
assert (bpf_map_get_next_key (fd , & key , & next_key ) == 0 &&
323
340
next_key == 0 );
324
341
assert (bpf_map_get_next_key (fd , & next_key , & next_key ) == 0 &&
@@ -400,6 +417,8 @@ static void test_map_large(void)
400
417
errno == E2BIG );
401
418
402
419
/* Iterate through all elements. */
420
+ assert (bpf_map_get_next_key (fd , NULL , & key ) == 0 );
421
+ key .c = -1 ;
403
422
for (i = 0 ; i < MAP_SIZE ; i ++ )
404
423
assert (bpf_map_get_next_key (fd , & key , & key ) == 0 );
405
424
assert (bpf_map_get_next_key (fd , & key , & key ) == -1 && errno == ENOENT );
@@ -499,6 +518,7 @@ static void test_map_parallel(void)
499
518
errno == EEXIST );
500
519
501
520
/* Check that all elements were inserted. */
521
+ assert (bpf_map_get_next_key (fd , NULL , & key ) == 0 );
502
522
key = -1 ;
503
523
for (i = 0 ; i < MAP_SIZE ; i ++ )
504
524
assert (bpf_map_get_next_key (fd , & key , & key ) == 0 );
@@ -518,6 +538,7 @@ static void test_map_parallel(void)
518
538
519
539
/* Nothing should be left. */
520
540
key = -1 ;
541
+ assert (bpf_map_get_next_key (fd , NULL , & key ) == -1 && errno == ENOENT );
521
542
assert (bpf_map_get_next_key (fd , & key , & key ) == -1 && errno == ENOENT );
522
543
}
523
544
0 commit comments