Commit ba0cc3c1 authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by David S. Miller

samples/bpf: add bpf_map_update_elem() tests

increase test coverage to check previously missing 'update when full'
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a6ed3ea6
...@@ -68,7 +68,16 @@ static void test_hashmap_sanity(int i, void *data) ...@@ -68,7 +68,16 @@ static void test_hashmap_sanity(int i, void *data)
assert(bpf_update_elem(map_fd, &key, &value, BPF_NOEXIST) == -1 && assert(bpf_update_elem(map_fd, &key, &value, BPF_NOEXIST) == -1 &&
errno == E2BIG); 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 */ /* check that key = 0 doesn't exist */
key = 0;
assert(bpf_delete_elem(map_fd, &key) == -1 && errno == ENOENT); assert(bpf_delete_elem(map_fd, &key) == -1 && errno == ENOENT);
/* iterate over two elements */ /* iterate over two elements */
...@@ -413,11 +422,13 @@ static void do_work(int fn, void *data) ...@@ -413,11 +422,13 @@ static void do_work(int fn, void *data)
for (i = fn; i < MAP_SIZE; i += TASKS) { for (i = fn; i < MAP_SIZE; i += TASKS) {
key = value = i; key = value = i;
if (do_update) if (do_update) {
assert(bpf_update_elem(map_fd, &key, &value, BPF_NOEXIST) == 0); 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); assert(bpf_delete_elem(map_fd, &key) == 0);
} }
}
} }
static void test_map_parallel(void) static void test_map_parallel(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment