Skip to content

Commit

Permalink
samples/bpf: add bpf_map_update_elem() tests
Browse files Browse the repository at this point in the history
increase test coverage to check previously missing 'update when full'

Signed-off-by: Alexei Starovoitov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
4ast authored and davem330 committed Aug 7, 2016
1 parent a6ed3ea commit ba0cc3c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions samples/bpf/test_maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit ba0cc3c

Please sign in to comment.