1
0
Fork 0

samples/bpf: add bpf_map_update_elem() tests

increase test coverage to check previously missing 'update when full'

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
steinar/wifi_calib_4_9_kernel
Alexei Starovoitov 2016-08-05 14:01:28 -07:00 committed by David S. Miller
parent a6ed3ea65d
commit ba0cc3c153
1 changed files with 13 additions and 2 deletions

View File

@ -68,7 +68,16 @@ static void test_hashmap_sanity(int i, void *data)
assert(bpf_update_elem(map_fd, &key, &value, BPF_NOEXIST) == -1 &&
errno == E2BIG);
/* update existing element, thought the map is full */
key = 1;
assert(bpf_update_elem(map_fd, &key, &value, BPF_EXIST) == 0);
key = 2;
assert(bpf_update_elem(map_fd, &key, &value, BPF_ANY) == 0);
key = 1;
assert(bpf_update_elem(map_fd, &key, &value, BPF_ANY) == 0);
/* check that key = 0 doesn't exist */
key = 0;
assert(bpf_delete_elem(map_fd, &key) == -1 && errno == ENOENT);
/* iterate over two elements */
@ -413,10 +422,12 @@ static void do_work(int fn, void *data)
for (i = fn; i < MAP_SIZE; i += TASKS) {
key = value = i;
if (do_update)
if (do_update) {
assert(bpf_update_elem(map_fd, &key, &value, BPF_NOEXIST) == 0);
else
assert(bpf_update_elem(map_fd, &key, &value, BPF_EXIST) == 0);
} else {
assert(bpf_delete_elem(map_fd, &key) == 0);
}
}
}