Skip to content

Commit

Permalink
Merge branch 'bpf-misc-test-fixes'
Browse files Browse the repository at this point in the history
Stanislav Fomichev says:

====================
* add test__skip to indicate skipped tests
* remove global success/error counts (use environment)
* remove asserts from the tests
* remove unused ret from send_signal test

v3:
* QCHECK -> CHECK_FAIL (Daniel Borkmann)

v2:
* drop patch that changes output to keep consistent with test_verifier
  (Alexei Starovoitov)
* QCHECK instead of test__fail (Andrii Nakryiko)
* test__skip count number of subtests (Andrii Nakryiko)
====================

Cc: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
Daniel Borkmann committed Aug 27, 2019
2 parents 08eea4f + 86ccc38 commit 7bc7d83
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 172 deletions.
20 changes: 12 additions & 8 deletions tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ void test_bpf_obj_id(void)
/* test_obj_id.o is a dumb prog. It should never fail
* to load.
*/
if (err)
error_cnt++;
assert(!err);
if (CHECK_FAIL(err))
continue;

/* Insert a magic value to the map */
map_fds[i] = bpf_find_map(__func__, objs[i], "test_map_id");
assert(map_fds[i] >= 0);
if (CHECK_FAIL(map_fds[i] < 0))
goto done;
err = bpf_map_update_elem(map_fds[i], &array_key,
&array_magic_value, 0);
assert(!err);
if (CHECK_FAIL(err))
goto done;

/* Check getting map info */
info_len = sizeof(struct bpf_map_info) * 2;
Expand Down Expand Up @@ -96,9 +97,11 @@ void test_bpf_obj_id(void)
prog_infos[i].map_ids = ptr_to_u64(map_ids + i);
prog_infos[i].nr_map_ids = 2;
err = clock_gettime(CLOCK_REALTIME, &real_time_ts);
assert(!err);
if (CHECK_FAIL(err))
goto done;
err = clock_gettime(CLOCK_BOOTTIME, &boot_time_ts);
assert(!err);
if (CHECK_FAIL(err))
goto done;
err = bpf_obj_get_info_by_fd(prog_fds[i], &prog_infos[i],
&info_len);
load_time = (real_time_ts.tv_sec - boot_time_ts.tv_sec)
Expand Down Expand Up @@ -224,7 +227,8 @@ void test_bpf_obj_id(void)
nr_id_found++;

err = bpf_map_lookup_elem(map_fd, &array_key, &array_value);
assert(!err);
if (CHECK_FAIL(err))
goto done;

err = bpf_obj_get_info_by_fd(map_fd, &map_info, &info_len);
CHECK(err || info_len != sizeof(struct bpf_map_info) ||
Expand Down
9 changes: 1 addition & 8 deletions tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ static int check_load(const char *file, enum bpf_prog_type type)
attr.prog_flags = BPF_F_TEST_RND_HI32;
err = bpf_prog_load_xattr(&attr, &obj, &prog_fd);
bpf_object__close(obj);
if (err)
error_cnt++;
return err;
}

Expand Down Expand Up @@ -105,12 +103,7 @@ void test_bpf_verif_scale(void)
continue;

err = check_load(test->file, test->attach_type);
if (test->fails) { /* expected to fail */
if (err)
error_cnt--;
else
error_cnt++;
}
CHECK_FAIL(err && !test->fails);
}

if (env.verifier_stats)
Expand Down
4 changes: 1 addition & 3 deletions tools/testing/selftests/bpf/prog_tests/flow_dissector.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,8 @@ void test_flow_dissector(void)

err = bpf_flow_load(&obj, "./bpf_flow.o", "flow_dissector",
"jmp_table", "last_dissection", &prog_fd, &keys_fd);
if (err) {
error_cnt++;
if (CHECK_FAIL(err))
return;
}

for (i = 0; i < ARRAY_SIZE(tests); i++) {
struct bpf_flow_keys flow_keys;
Expand Down
3 changes: 0 additions & 3 deletions tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ void test_get_stack_raw_tp(void)
exp_cnt -= err;
}

goto close_prog_noerr;
close_prog:
error_cnt++;
close_prog_noerr:
if (!IS_ERR_OR_NULL(link))
bpf_link__destroy(link);
if (!IS_ERR_OR_NULL(pb))
Expand Down
20 changes: 5 additions & 15 deletions tools/testing/selftests/bpf/prog_tests/global_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ static void test_global_data_number(struct bpf_object *obj, __u32 duration)
uint64_t num;

map_fd = bpf_find_map(__func__, obj, "result_number");
if (map_fd < 0) {
error_cnt++;
if (CHECK_FAIL(map_fd < 0))
return;
}

struct {
char *name;
Expand Down Expand Up @@ -44,10 +42,8 @@ static void test_global_data_string(struct bpf_object *obj, __u32 duration)
char str[32];

map_fd = bpf_find_map(__func__, obj, "result_string");
if (map_fd < 0) {
error_cnt++;
if (CHECK_FAIL(map_fd < 0))
return;
}

struct {
char *name;
Expand Down Expand Up @@ -81,10 +77,8 @@ static void test_global_data_struct(struct bpf_object *obj, __u32 duration)
struct foo val;

map_fd = bpf_find_map(__func__, obj, "result_struct");
if (map_fd < 0) {
error_cnt++;
if (CHECK_FAIL(map_fd < 0))
return;
}

struct {
char *name;
Expand Down Expand Up @@ -112,16 +106,12 @@ static void test_global_data_rdonly(struct bpf_object *obj, __u32 duration)
__u8 *buff;

map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
if (!map || !bpf_map__is_internal(map)) {
error_cnt++;
if (CHECK_FAIL(!map || !bpf_map__is_internal(map)))
return;
}

map_fd = bpf_map__fd(map);
if (map_fd < 0) {
error_cnt++;
if (CHECK_FAIL(map_fd < 0))
return;
}

buff = malloc(bpf_map__def(map)->value_size);
if (buff)
Expand Down
9 changes: 3 additions & 6 deletions tools/testing/selftests/bpf/prog_tests/l4lb_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ static void test_l4lb(const char *file)
u32 *magic = (u32 *)buf;

err = bpf_prog_load(file, BPF_PROG_TYPE_SCHED_CLS, &obj, &prog_fd);
if (err) {
error_cnt++;
if (CHECK_FAIL(err))
return;
}

map_fd = bpf_find_map(__func__, obj, "vip_map");
if (map_fd < 0)
Expand Down Expand Up @@ -72,10 +70,9 @@ static void test_l4lb(const char *file)
bytes += stats[i].bytes;
pkts += stats[i].pkts;
}
if (bytes != MAGIC_BYTES * NUM_ITER * 2 || pkts != NUM_ITER * 2) {
error_cnt++;
if (CHECK_FAIL(bytes != MAGIC_BYTES * NUM_ITER * 2 ||
pkts != NUM_ITER * 2))
printf("test_l4lb:FAIL:stats %lld %lld\n", bytes, pkts);
}
out:
bpf_object__close(obj);
}
Expand Down
38 changes: 19 additions & 19 deletions tools/testing/selftests/bpf/prog_tests/map_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ static void *parallel_map_access(void *arg)

for (i = 0; i < 10000; i++) {
err = bpf_map_lookup_elem_flags(map_fd, &key, vars, BPF_F_LOCK);
if (err) {
if (CHECK_FAIL(err)) {
printf("lookup failed\n");
error_cnt++;
goto out;
}
if (vars[0] != 0) {
if (CHECK_FAIL(vars[0] != 0)) {
printf("lookup #%d var[0]=%d\n", i, vars[0]);
error_cnt++;
goto out;
}
rnd = vars[1];
Expand All @@ -24,7 +22,7 @@ static void *parallel_map_access(void *arg)
continue;
printf("lookup #%d var[1]=%d var[%d]=%d\n",
i, rnd, j, vars[j]);
error_cnt++;
CHECK_FAIL(vars[j] != rnd);
goto out;
}
}
Expand All @@ -42,34 +40,36 @@ void test_map_lock(void)
void *ret;

err = bpf_prog_load(file, BPF_PROG_TYPE_CGROUP_SKB, &obj, &prog_fd);
if (err) {
if (CHECK_FAIL(err)) {
printf("test_map_lock:bpf_prog_load errno %d\n", errno);
goto close_prog;
}
map_fd[0] = bpf_find_map(__func__, obj, "hash_map");
if (map_fd[0] < 0)
if (CHECK_FAIL(map_fd[0] < 0))
goto close_prog;
map_fd[1] = bpf_find_map(__func__, obj, "array_map");
if (map_fd[1] < 0)
if (CHECK_FAIL(map_fd[1] < 0))
goto close_prog;

bpf_map_update_elem(map_fd[0], &key, vars, BPF_F_LOCK);

for (i = 0; i < 4; i++)
assert(pthread_create(&thread_id[i], NULL,
&spin_lock_thread, &prog_fd) == 0);
if (CHECK_FAIL(pthread_create(&thread_id[i], NULL,
&spin_lock_thread, &prog_fd)))
goto close_prog;
for (i = 4; i < 6; i++)
assert(pthread_create(&thread_id[i], NULL,
&parallel_map_access, &map_fd[i - 4]) == 0);
if (CHECK_FAIL(pthread_create(&thread_id[i], NULL,
&parallel_map_access,
&map_fd[i - 4])))
goto close_prog;
for (i = 0; i < 4; i++)
assert(pthread_join(thread_id[i], &ret) == 0 &&
ret == (void *)&prog_fd);
if (CHECK_FAIL(pthread_join(thread_id[i], &ret) ||
ret != (void *)&prog_fd))
goto close_prog;
for (i = 4; i < 6; i++)
assert(pthread_join(thread_id[i], &ret) == 0 &&
ret == (void *)&map_fd[i - 4]);
goto close_prog_noerr;
if (CHECK_FAIL(pthread_join(thread_id[i], &ret) ||
ret != (void *)&map_fd[i - 4]))
goto close_prog;
close_prog:
error_cnt++;
close_prog_noerr:
bpf_object__close(obj);
}
4 changes: 1 addition & 3 deletions tools/testing/selftests/bpf/prog_tests/pkt_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ void test_pkt_access(void)
int err, prog_fd;

err = bpf_prog_load(file, BPF_PROG_TYPE_SCHED_CLS, &obj, &prog_fd);
if (err) {
error_cnt++;
if (CHECK_FAIL(err))
return;
}

err = bpf_prog_test_run(prog_fd, 100000, &pkt_v4, sizeof(pkt_v4),
NULL, NULL, &retval, &duration);
Expand Down
4 changes: 1 addition & 3 deletions tools/testing/selftests/bpf/prog_tests/pkt_md_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ void test_pkt_md_access(void)
int err, prog_fd;

err = bpf_prog_load(file, BPF_PROG_TYPE_SCHED_CLS, &obj, &prog_fd);
if (err) {
error_cnt++;
if (CHECK_FAIL(err))
return;
}

err = bpf_prog_test_run(prog_fd, 10, &pkt_v4, sizeof(pkt_v4),
NULL, NULL, &retval, &duration);
Expand Down
8 changes: 2 additions & 6 deletions tools/testing/selftests/bpf/prog_tests/queue_stack_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ static void test_queue_stack_map_by_type(int type)
return;

err = bpf_prog_load(file, BPF_PROG_TYPE_SCHED_CLS, &obj, &prog_fd);
if (err) {
error_cnt++;
if (CHECK_FAIL(err))
return;
}

map_in_fd = bpf_find_map(__func__, obj, "map_in");
if (map_in_fd < 0)
Expand All @@ -43,10 +41,8 @@ static void test_queue_stack_map_by_type(int type)
/* Push 32 elements to the input map */
for (i = 0; i < MAP_SIZE; i++) {
err = bpf_map_update_elem(map_in_fd, NULL, &vals[i], 0);
if (err) {
error_cnt++;
if (CHECK_FAIL(err))
goto out;
}
}

/* The eBPF program pushes iph.saddr in the output map,
Expand Down
4 changes: 1 addition & 3 deletions tools/testing/selftests/bpf/prog_tests/reference_tracking.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ void test_reference_tracking(void)
int err = 0;

obj = bpf_object__open(file);
if (IS_ERR(obj)) {
error_cnt++;
if (CHECK_FAIL(IS_ERR(obj)))
return;
}

bpf_object__for_each_program(prog, obj) {
const char *title;
Expand Down
Loading

0 comments on commit 7bc7d83

Please sign in to comment.