Lines Matching refs:key

39 	long long key, next_key, first_key, value;  in test_hashmap()  local
42 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), 2, &map_opts); in test_hashmap()
48 key = 1; in test_hashmap()
51 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
55 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
60 assert(bpf_map_update_elem(fd, &key, &value, -1) < 0 && in test_hashmap()
64 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234); in test_hashmap()
66 key = 2; in test_hashmap()
69 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
72 assert(bpf_map_lookup_and_delete_elem(fd, &key, &value) == 0 && value == 1234); in test_hashmap()
75 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_hashmap()
78 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) < 0 && in test_hashmap()
83 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0); in test_hashmap()
88 key = 0; in test_hashmap()
89 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
93 key = 1; in test_hashmap()
94 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == 0); in test_hashmap()
95 key = 2; in test_hashmap()
96 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
97 key = 3; in test_hashmap()
98 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
102 key = 0; in test_hashmap()
103 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap()
108 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_hashmap()
117 key = 1; in test_hashmap()
118 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap()
119 key = 2; in test_hashmap()
120 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap()
121 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap()
123 key = 0; in test_hashmap()
127 assert(bpf_map_get_next_key(fd, &key, &next_key) < 0 && in test_hashmap()
156 long long key, next_key, first_key; in test_hashmap_percpu() local
160 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_HASH, NULL, sizeof(key), in test_hashmap_percpu()
170 key = 1; in test_hashmap_percpu()
172 assert(!(expected_key_mask & key)); in test_hashmap_percpu()
173 assert(bpf_map_update_elem(fd, &key, value, BPF_ANY) == 0); in test_hashmap_percpu()
176 assert(bpf_map_lookup_and_delete_elem(fd, &key, value) == 0 && in test_hashmap_percpu()
183 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0); in test_hashmap_percpu()
184 expected_key_mask |= key; in test_hashmap_percpu()
187 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) < 0 && in test_hashmap_percpu()
192 assert(bpf_map_update_elem(fd, &key, value, -1) < 0 && in test_hashmap_percpu()
199 assert(bpf_map_lookup_elem(fd, &key, value) == 0 && in test_hashmap_percpu()
202 key = 2; in test_hashmap_percpu()
204 assert(bpf_map_lookup_elem(fd, &key, value) < 0 && errno == ENOENT); in test_hashmap_percpu()
207 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) < 0 && in test_hashmap_percpu()
212 assert(!(expected_key_mask & key)); in test_hashmap_percpu()
213 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0); in test_hashmap_percpu()
214 expected_key_mask |= key; in test_hashmap_percpu()
219 key = 0; in test_hashmap_percpu()
220 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) < 0 && in test_hashmap_percpu()
224 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap_percpu()
229 while (!bpf_map_get_next_key(fd, &key, &next_key)) { in test_hashmap_percpu()
242 key = next_key; in test_hashmap_percpu()
247 key = 1; in test_hashmap_percpu()
248 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0); in test_hashmap_percpu()
251 key = 1; in test_hashmap_percpu()
252 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap_percpu()
253 key = 2; in test_hashmap_percpu()
254 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap_percpu()
255 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap_percpu()
257 key = 0; in test_hashmap_percpu()
261 assert(bpf_map_get_next_key(fd, &key, &next_key) < 0 && in test_hashmap_percpu()
271 long long key, value[VALUE_SIZE] = {}; in helper_fill_hashmap() local
273 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in helper_fill_hashmap()
280 key = i; value[0] = key; in helper_fill_hashmap()
281 ret = bpf_map_update_elem(fd, &key, value, BPF_NOEXIST); in helper_fill_hashmap()
293 long long key, value[VALUE_SIZE], next_key; in test_hashmap_walk() local
298 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, in test_hashmap_walk()
300 key = next_key; in test_hashmap_walk()
301 assert(bpf_map_lookup_elem(fd, &key, value) == 0); in test_hashmap_walk()
306 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_hashmap_walk()
308 next_key_valid = bpf_map_get_next_key(fd, &key, &next_key) == 0; in test_hashmap_walk()
309 assert(bpf_map_lookup_elem(fd, &key, value) == 0); in test_hashmap_walk()
311 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0); in test_hashmap_walk()
312 key = next_key; in test_hashmap_walk()
317 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, in test_hashmap_walk()
319 key = next_key; in test_hashmap_walk()
320 assert(bpf_map_lookup_elem(fd, &key, value) == 0); in test_hashmap_walk()
321 assert(value[0] - 1 == key); in test_hashmap_walk()
331 long long key, next_first, next_second; in test_hashmap_zero_seed() local
340 void *key_ptr = !i ? NULL : &key; in test_hashmap_zero_seed()
353 key = next_first; in test_hashmap_zero_seed()
363 int key, next_key, fd; in test_arraymap() local
366 fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(key), sizeof(value), 2, NULL); in test_arraymap()
372 key = 1; in test_arraymap()
375 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_arraymap()
378 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_arraymap()
382 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234); in test_arraymap()
384 key = 0; in test_arraymap()
386 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); in test_arraymap()
391 key = 2; in test_arraymap()
392 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) < 0 && in test_arraymap()
396 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_arraymap()
401 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_arraymap()
409 key = 1; in test_arraymap()
410 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == EINVAL); in test_arraymap()
419 int key, next_key, fd, i; in test_arraymap_percpu() local
421 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_ARRAY, NULL, sizeof(key), in test_arraymap_percpu()
431 key = 1; in test_arraymap_percpu()
433 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0); in test_arraymap_percpu()
436 assert(bpf_map_update_elem(fd, &key, values, BPF_NOEXIST) < 0 && in test_arraymap_percpu()
440 assert(bpf_map_lookup_elem(fd, &key, values) == 0 && in test_arraymap_percpu()
443 key = 0; in test_arraymap_percpu()
445 assert(bpf_map_lookup_elem(fd, &key, values) == 0 && in test_arraymap_percpu()
450 key = 2; in test_arraymap_percpu()
451 assert(bpf_map_update_elem(fd, &key, values, BPF_EXIST) < 0 && in test_arraymap_percpu()
455 assert(bpf_map_lookup_elem(fd, &key, values) < 0 && errno == ENOENT); in test_arraymap_percpu()
460 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_arraymap_percpu()
468 key = 1; in test_arraymap_percpu()
469 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == EINVAL); in test_arraymap_percpu()
482 int key, fd, i; in test_arraymap_percpu_many_keys() local
484 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_ARRAY, NULL, sizeof(key), in test_arraymap_percpu_many_keys()
495 for (key = 0; key < nr_keys; key++) in test_arraymap_percpu_many_keys()
496 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0); in test_arraymap_percpu_many_keys()
498 for (key = 0; key < nr_keys; key++) { in test_arraymap_percpu_many_keys()
502 assert(bpf_map_lookup_elem(fd, &key, values) == 0); in test_arraymap_percpu_many_keys()
514 __u32 key, value; in test_devmap() local
516 fd = bpf_map_create(BPF_MAP_TYPE_DEVMAP, NULL, sizeof(key), sizeof(value), 2, NULL); in test_devmap()
528 __u32 key, value; in test_devmap_hash() local
530 fd = bpf_map_create(BPF_MAP_TYPE_DEVMAP_HASH, NULL, sizeof(key), sizeof(value), 2, NULL); in test_devmap_hash()
670 __u32 key, value; in test_sockmap() local
739 sizeof(key), sizeof(value), in test_sockmap()
1315 } key; in test_map_large() local
1318 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_large()
1326 key = (struct bigkey) { .c = i }; in test_map_large()
1329 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0); in test_map_large()
1332 key.c = -1; in test_map_large()
1333 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_map_large()
1337 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_map_large()
1338 key.c = -1; in test_map_large()
1340 assert(bpf_map_get_next_key(fd, &key, &key) == 0); in test_map_large()
1341 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_large()
1343 key.c = 0; in test_map_large()
1344 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); in test_map_large()
1345 key.a = 1; in test_map_large()
1346 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_map_large()
1403 static int map_update_retriable(int map_fd, const void *key, const void *value, in map_update_retriable() argument
1408 while (bpf_map_update_elem(map_fd, key, value, flags)) { in map_update_retriable()
1422 static int map_delete_retriable(int map_fd, const void *key, int attempts) in map_delete_retriable() argument
1426 while (bpf_map_delete_elem(map_fd, key)) { in map_delete_retriable()
1444 int i, key, value, err; in test_update_delete() local
1449 key = value = i; in test_update_delete()
1452 err = map_update_retriable(fd, &key, &value, BPF_NOEXIST, MAP_RETRIES); in test_update_delete()
1456 err = map_update_retriable(fd, &key, &value, BPF_EXIST, MAP_RETRIES); in test_update_delete()
1461 err = map_delete_retriable(fd, &key, MAP_RETRIES); in test_update_delete()
1471 int i, fd, key = 0, value = 0, j = 0; in test_map_parallel() local
1474 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_parallel()
1493 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_map_parallel()
1497 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_map_parallel()
1498 key = -1; in test_map_parallel()
1500 assert(bpf_map_get_next_key(fd, &key, &key) == 0); in test_map_parallel()
1501 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_parallel()
1505 key = MAP_SIZE - i - 1; in test_map_parallel()
1507 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && in test_map_parallel()
1508 value == key); in test_map_parallel()
1516 key = -1; in test_map_parallel()
1517 assert(bpf_map_get_next_key(fd, NULL, &key) < 0 && errno == ENOENT); in test_map_parallel()
1518 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_parallel()
1520 key = 0; in test_map_parallel()
1521 bpf_map_delete_elem(fd, &key); in test_map_parallel()
1529 int fd, key = 0, value = 0; in test_map_rdonly() local
1534 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_rdonly()
1543 key = 1; in test_map_rdonly()
1546 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) < 0 && in test_map_rdonly()
1550 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_map_rdonly()
1551 assert(bpf_map_get_next_key(fd, &key, &value) < 0 && errno == ENOENT); in test_map_rdonly()
1558 int fd, key = 0, value = 0; in test_map_wronly_hash() local
1563 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_wronly_hash()
1572 key = 1; in test_map_wronly_hash()
1575 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_map_wronly_hash()
1578 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == EPERM); in test_map_wronly_hash()
1579 assert(bpf_map_get_next_key(fd, &key, &value) < 0 && errno == EPERM); in test_map_wronly_hash()