Commit 62d69f24 authored by Stanislav Fomichev's avatar Stanislav Fomichev Committed by Daniel Borkmann

selftests/bpf: test_progs: remove asserts from subtests

Otherwise they can bring the whole process down.

Cc: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: default avatarStanislav Fomichev <sdf@google.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent d38835b7
...@@ -48,15 +48,17 @@ void test_bpf_obj_id(void) ...@@ -48,15 +48,17 @@ void test_bpf_obj_id(void)
/* test_obj_id.o is a dumb prog. It should never fail /* test_obj_id.o is a dumb prog. It should never fail
* to load. * to load.
*/ */
CHECK_FAIL(err); if (CHECK_FAIL(err))
assert(!err); continue;
/* Insert a magic value to the map */ /* Insert a magic value to the map */
map_fds[i] = bpf_find_map(__func__, objs[i], "test_map_id"); 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, err = bpf_map_update_elem(map_fds[i], &array_key,
&array_magic_value, 0); &array_magic_value, 0);
assert(!err); if (CHECK_FAIL(err))
goto done;
/* Check getting map info */ /* Check getting map info */
info_len = sizeof(struct bpf_map_info) * 2; info_len = sizeof(struct bpf_map_info) * 2;
...@@ -95,9 +97,11 @@ void test_bpf_obj_id(void) ...@@ -95,9 +97,11 @@ void test_bpf_obj_id(void)
prog_infos[i].map_ids = ptr_to_u64(map_ids + i); prog_infos[i].map_ids = ptr_to_u64(map_ids + i);
prog_infos[i].nr_map_ids = 2; prog_infos[i].nr_map_ids = 2;
err = clock_gettime(CLOCK_REALTIME, &real_time_ts); err = clock_gettime(CLOCK_REALTIME, &real_time_ts);
assert(!err); if (CHECK_FAIL(err))
goto done;
err = clock_gettime(CLOCK_BOOTTIME, &boot_time_ts); 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], err = bpf_obj_get_info_by_fd(prog_fds[i], &prog_infos[i],
&info_len); &info_len);
load_time = (real_time_ts.tv_sec - boot_time_ts.tv_sec) load_time = (real_time_ts.tv_sec - boot_time_ts.tv_sec)
...@@ -223,7 +227,8 @@ void test_bpf_obj_id(void) ...@@ -223,7 +227,8 @@ void test_bpf_obj_id(void)
nr_id_found++; nr_id_found++;
err = bpf_map_lookup_elem(map_fd, &array_key, &array_value); 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); err = bpf_obj_get_info_by_fd(map_fd, &map_info, &info_len);
CHECK(err || info_len != sizeof(struct bpf_map_info) || CHECK(err || info_len != sizeof(struct bpf_map_info) ||
......
...@@ -54,17 +54,22 @@ void test_map_lock(void) ...@@ -54,17 +54,22 @@ void test_map_lock(void)
bpf_map_update_elem(map_fd[0], &key, vars, BPF_F_LOCK); bpf_map_update_elem(map_fd[0], &key, vars, BPF_F_LOCK);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
assert(pthread_create(&thread_id[i], NULL, if (CHECK_FAIL(pthread_create(&thread_id[i], NULL,
&spin_lock_thread, &prog_fd) == 0); &spin_lock_thread, &prog_fd)))
goto close_prog;
for (i = 4; i < 6; i++) for (i = 4; i < 6; i++)
assert(pthread_create(&thread_id[i], NULL, if (CHECK_FAIL(pthread_create(&thread_id[i], NULL,
&parallel_map_access, &map_fd[i - 4]) == 0); &parallel_map_access,
&map_fd[i - 4])))
goto close_prog;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
assert(pthread_join(thread_id[i], &ret) == 0 && if (CHECK_FAIL(pthread_join(thread_id[i], &ret) ||
ret == (void *)&prog_fd); ret != (void *)&prog_fd))
goto close_prog;
for (i = 4; i < 6; i++) for (i = 4; i < 6; i++)
assert(pthread_join(thread_id[i], &ret) == 0 && if (CHECK_FAIL(pthread_join(thread_id[i], &ret) ||
ret == (void *)&map_fd[i - 4]); ret != (void *)&map_fd[i - 4]))
goto close_prog;
close_prog: close_prog:
bpf_object__close(obj); bpf_object__close(obj);
} }
...@@ -16,12 +16,14 @@ void test_spinlock(void) ...@@ -16,12 +16,14 @@ void test_spinlock(void)
goto close_prog; goto close_prog;
} }
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
assert(pthread_create(&thread_id[i], NULL, if (CHECK_FAIL(pthread_create(&thread_id[i], NULL,
&spin_lock_thread, &prog_fd) == 0); &spin_lock_thread, &prog_fd)))
for (i = 0; i < 4; i++) goto close_prog;
assert(pthread_join(thread_id[i], &ret) == 0 &&
ret == (void *)&prog_fd);
for (i = 0; i < 4; i++)
if (CHECK_FAIL(pthread_join(thread_id[i], &ret) ||
ret != (void *)&prog_fd))
goto close_prog;
close_prog: close_prog:
bpf_object__close(obj); bpf_object__close(obj);
} }
...@@ -51,9 +51,10 @@ void test_stacktrace_build_id(void) ...@@ -51,9 +51,10 @@ void test_stacktrace_build_id(void)
"err %d errno %d\n", err, errno)) "err %d errno %d\n", err, errno))
goto disable_pmu; goto disable_pmu;
assert(system("dd if=/dev/urandom of=/dev/zero count=4 2> /dev/null") if (CHECK_FAIL(system("dd if=/dev/urandom of=/dev/zero count=4 2> /dev/null")))
== 0); goto disable_pmu;
assert(system("./urandom_read") == 0); if (CHECK_FAIL(system("./urandom_read")))
goto disable_pmu;
/* disable stack trace collection */ /* disable stack trace collection */
key = 0; key = 0;
val = 1; val = 1;
......
...@@ -82,9 +82,10 @@ void test_stacktrace_build_id_nmi(void) ...@@ -82,9 +82,10 @@ void test_stacktrace_build_id_nmi(void)
"err %d errno %d\n", err, errno)) "err %d errno %d\n", err, errno))
goto disable_pmu; goto disable_pmu;
assert(system("dd if=/dev/urandom of=/dev/zero count=4 2> /dev/null") if (CHECK_FAIL(system("dd if=/dev/urandom of=/dev/zero count=4 2> /dev/null")))
== 0); goto disable_pmu;
assert(system("taskset 0x1 ./urandom_read 100000") == 0); if (CHECK_FAIL(system("taskset 0x1 ./urandom_read 100000")))
goto disable_pmu;
/* disable stack trace collection */ /* disable stack trace collection */
key = 0; key = 0;
val = 1; val = 1;
......
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