Commit 8526f0d6 authored by Andrii Nakryiko's avatar Andrii Nakryiko

Merge branch 'bpf/selftests: convert some tests to ASSERT_* macros'

Wang Yufen says:

====================

Convert some tests to use the preferred ASSERT_* macros instead of the
deprecated CHECK().
====================
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
parents aa55dfd3 1fddca3d
...@@ -27,21 +27,21 @@ static int connected_socket_v4(void) ...@@ -27,21 +27,21 @@ static int connected_socket_v4(void)
int s, repair, err; int s, repair, err;
s = socket(AF_INET, SOCK_STREAM, 0); s = socket(AF_INET, SOCK_STREAM, 0);
if (CHECK_FAIL(s == -1)) if (!ASSERT_GE(s, 0, "socket"))
goto error; goto error;
repair = TCP_REPAIR_ON; repair = TCP_REPAIR_ON;
err = setsockopt(s, SOL_TCP, TCP_REPAIR, &repair, sizeof(repair)); err = setsockopt(s, SOL_TCP, TCP_REPAIR, &repair, sizeof(repair));
if (CHECK_FAIL(err)) if (!ASSERT_OK(err, "setsockopt(TCP_REPAIR)"))
goto error; goto error;
err = connect(s, (struct sockaddr *)&addr, len); err = connect(s, (struct sockaddr *)&addr, len);
if (CHECK_FAIL(err)) if (!ASSERT_OK(err, "connect"))
goto error; goto error;
repair = TCP_REPAIR_OFF_NO_WP; repair = TCP_REPAIR_OFF_NO_WP;
err = setsockopt(s, SOL_TCP, TCP_REPAIR, &repair, sizeof(repair)); err = setsockopt(s, SOL_TCP, TCP_REPAIR, &repair, sizeof(repair));
if (CHECK_FAIL(err)) if (!ASSERT_OK(err, "setsockopt(TCP_REPAIR)"))
goto error; goto error;
return s; return s;
...@@ -54,7 +54,7 @@ static int connected_socket_v4(void) ...@@ -54,7 +54,7 @@ static int connected_socket_v4(void)
static void compare_cookies(struct bpf_map *src, struct bpf_map *dst) static void compare_cookies(struct bpf_map *src, struct bpf_map *dst)
{ {
__u32 i, max_entries = bpf_map__max_entries(src); __u32 i, max_entries = bpf_map__max_entries(src);
int err, duration = 0, src_fd, dst_fd; int err, src_fd, dst_fd;
src_fd = bpf_map__fd(src); src_fd = bpf_map__fd(src);
dst_fd = bpf_map__fd(dst); dst_fd = bpf_map__fd(dst);
...@@ -65,20 +65,18 @@ static void compare_cookies(struct bpf_map *src, struct bpf_map *dst) ...@@ -65,20 +65,18 @@ static void compare_cookies(struct bpf_map *src, struct bpf_map *dst)
err = bpf_map_lookup_elem(src_fd, &i, &src_cookie); err = bpf_map_lookup_elem(src_fd, &i, &src_cookie);
if (err && errno == ENOENT) { if (err && errno == ENOENT) {
err = bpf_map_lookup_elem(dst_fd, &i, &dst_cookie); err = bpf_map_lookup_elem(dst_fd, &i, &dst_cookie);
CHECK(!err, "map_lookup_elem(dst)", "element %u not deleted\n", i); ASSERT_ERR(err, "map_lookup_elem(dst)");
CHECK(err && errno != ENOENT, "map_lookup_elem(dst)", "%s\n", ASSERT_EQ(errno, ENOENT, "map_lookup_elem(dst)");
strerror(errno));
continue; continue;
} }
if (CHECK(err, "lookup_elem(src)", "%s\n", strerror(errno))) if (!ASSERT_OK(err, "lookup_elem(src)"))
continue; continue;
err = bpf_map_lookup_elem(dst_fd, &i, &dst_cookie); err = bpf_map_lookup_elem(dst_fd, &i, &dst_cookie);
if (CHECK(err, "lookup_elem(dst)", "%s\n", strerror(errno))) if (!ASSERT_OK(err, "lookup_elem(dst)"))
continue; continue;
CHECK(dst_cookie != src_cookie, "cookie mismatch", ASSERT_EQ(dst_cookie, src_cookie, "cookie mismatch");
"%llu != %llu (pos %u)\n", dst_cookie, src_cookie, i);
} }
} }
...@@ -89,20 +87,16 @@ static void test_sockmap_create_update_free(enum bpf_map_type map_type) ...@@ -89,20 +87,16 @@ static void test_sockmap_create_update_free(enum bpf_map_type map_type)
int s, map, err; int s, map, err;
s = connected_socket_v4(); s = connected_socket_v4();
if (CHECK_FAIL(s < 0)) if (!ASSERT_GE(s, 0, "connected_socket_v4"))
return; return;
map = bpf_map_create(map_type, NULL, sizeof(int), sizeof(int), 1, NULL); map = bpf_map_create(map_type, NULL, sizeof(int), sizeof(int), 1, NULL);
if (CHECK_FAIL(map < 0)) { if (!ASSERT_GE(map, 0, "bpf_map_create"))
perror("bpf_cmap_create");
goto out; goto out;
}
err = bpf_map_update_elem(map, &zero, &s, BPF_NOEXIST); err = bpf_map_update_elem(map, &zero, &s, BPF_NOEXIST);
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "bpf_map_update"))
perror("bpf_map_update");
goto out; goto out;
}
out: out:
close(map); close(map);
...@@ -115,32 +109,26 @@ static void test_skmsg_helpers(enum bpf_map_type map_type) ...@@ -115,32 +109,26 @@ static void test_skmsg_helpers(enum bpf_map_type map_type)
int err, map, verdict; int err, map, verdict;
skel = test_skmsg_load_helpers__open_and_load(); skel = test_skmsg_load_helpers__open_and_load();
if (CHECK_FAIL(!skel)) { if (!ASSERT_OK_PTR(skel, "test_skmsg_load_helpers__open_and_load"))
perror("test_skmsg_load_helpers__open_and_load");
return; return;
}
verdict = bpf_program__fd(skel->progs.prog_msg_verdict); verdict = bpf_program__fd(skel->progs.prog_msg_verdict);
map = bpf_map__fd(skel->maps.sock_map); map = bpf_map__fd(skel->maps.sock_map);
err = bpf_prog_attach(verdict, map, BPF_SK_MSG_VERDICT, 0); err = bpf_prog_attach(verdict, map, BPF_SK_MSG_VERDICT, 0);
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "bpf_prog_attach"))
perror("bpf_prog_attach");
goto out; goto out;
}
err = bpf_prog_detach2(verdict, map, BPF_SK_MSG_VERDICT); err = bpf_prog_detach2(verdict, map, BPF_SK_MSG_VERDICT);
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "bpf_prog_detach2"))
perror("bpf_prog_detach2");
goto out; goto out;
}
out: out:
test_skmsg_load_helpers__destroy(skel); test_skmsg_load_helpers__destroy(skel);
} }
static void test_sockmap_update(enum bpf_map_type map_type) static void test_sockmap_update(enum bpf_map_type map_type)
{ {
int err, prog, src, duration = 0; int err, prog, src;
struct test_sockmap_update *skel; struct test_sockmap_update *skel;
struct bpf_map *dst_map; struct bpf_map *dst_map;
const __u32 zero = 0; const __u32 zero = 0;
...@@ -153,11 +141,11 @@ static void test_sockmap_update(enum bpf_map_type map_type) ...@@ -153,11 +141,11 @@ static void test_sockmap_update(enum bpf_map_type map_type)
__s64 sk; __s64 sk;
sk = connected_socket_v4(); sk = connected_socket_v4();
if (CHECK(sk == -1, "connected_socket_v4", "cannot connect\n")) if (!ASSERT_NEQ(sk, -1, "connected_socket_v4"))
return; return;
skel = test_sockmap_update__open_and_load(); skel = test_sockmap_update__open_and_load();
if (CHECK(!skel, "open_and_load", "cannot load skeleton\n")) if (!ASSERT_OK_PTR(skel, "open_and_load"))
goto close_sk; goto close_sk;
prog = bpf_program__fd(skel->progs.copy_sock_map); prog = bpf_program__fd(skel->progs.copy_sock_map);
...@@ -168,7 +156,7 @@ static void test_sockmap_update(enum bpf_map_type map_type) ...@@ -168,7 +156,7 @@ static void test_sockmap_update(enum bpf_map_type map_type)
dst_map = skel->maps.dst_sock_hash; dst_map = skel->maps.dst_sock_hash;
err = bpf_map_update_elem(src, &zero, &sk, BPF_NOEXIST); err = bpf_map_update_elem(src, &zero, &sk, BPF_NOEXIST);
if (CHECK(err, "update_elem(src)", "errno=%u\n", errno)) if (!ASSERT_OK(err, "update_elem(src)"))
goto out; goto out;
err = bpf_prog_test_run_opts(prog, &topts); err = bpf_prog_test_run_opts(prog, &topts);
...@@ -188,17 +176,16 @@ static void test_sockmap_update(enum bpf_map_type map_type) ...@@ -188,17 +176,16 @@ static void test_sockmap_update(enum bpf_map_type map_type)
static void test_sockmap_invalid_update(void) static void test_sockmap_invalid_update(void)
{ {
struct test_sockmap_invalid_update *skel; struct test_sockmap_invalid_update *skel;
int duration = 0;
skel = test_sockmap_invalid_update__open_and_load(); skel = test_sockmap_invalid_update__open_and_load();
if (CHECK(skel, "open_and_load", "verifier accepted map_update\n")) if (!ASSERT_NULL(skel, "open_and_load"))
test_sockmap_invalid_update__destroy(skel); test_sockmap_invalid_update__destroy(skel);
} }
static void test_sockmap_copy(enum bpf_map_type map_type) static void test_sockmap_copy(enum bpf_map_type map_type)
{ {
DECLARE_LIBBPF_OPTS(bpf_iter_attach_opts, opts); DECLARE_LIBBPF_OPTS(bpf_iter_attach_opts, opts);
int err, len, src_fd, iter_fd, duration = 0; int err, len, src_fd, iter_fd;
union bpf_iter_link_info linfo = {}; union bpf_iter_link_info linfo = {};
__u32 i, num_sockets, num_elems; __u32 i, num_sockets, num_elems;
struct bpf_iter_sockmap *skel; struct bpf_iter_sockmap *skel;
...@@ -208,7 +195,7 @@ static void test_sockmap_copy(enum bpf_map_type map_type) ...@@ -208,7 +195,7 @@ static void test_sockmap_copy(enum bpf_map_type map_type)
char buf[64]; char buf[64];
skel = bpf_iter_sockmap__open_and_load(); skel = bpf_iter_sockmap__open_and_load();
if (CHECK(!skel, "bpf_iter_sockmap__open_and_load", "skeleton open_and_load failed\n")) if (!ASSERT_OK_PTR(skel, "bpf_iter_sockmap__open_and_load"))
return; return;
if (map_type == BPF_MAP_TYPE_SOCKMAP) { if (map_type == BPF_MAP_TYPE_SOCKMAP) {
...@@ -222,7 +209,7 @@ static void test_sockmap_copy(enum bpf_map_type map_type) ...@@ -222,7 +209,7 @@ static void test_sockmap_copy(enum bpf_map_type map_type)
} }
sock_fd = calloc(num_sockets, sizeof(*sock_fd)); sock_fd = calloc(num_sockets, sizeof(*sock_fd));
if (CHECK(!sock_fd, "calloc(sock_fd)", "failed to allocate\n")) if (!ASSERT_OK_PTR(sock_fd, "calloc(sock_fd)"))
goto out; goto out;
for (i = 0; i < num_sockets; i++) for (i = 0; i < num_sockets; i++)
...@@ -232,11 +219,11 @@ static void test_sockmap_copy(enum bpf_map_type map_type) ...@@ -232,11 +219,11 @@ static void test_sockmap_copy(enum bpf_map_type map_type)
for (i = 0; i < num_sockets; i++) { for (i = 0; i < num_sockets; i++) {
sock_fd[i] = connected_socket_v4(); sock_fd[i] = connected_socket_v4();
if (CHECK(sock_fd[i] == -1, "connected_socket_v4", "cannot connect\n")) if (!ASSERT_NEQ(sock_fd[i], -1, "connected_socket_v4"))
goto out; goto out;
err = bpf_map_update_elem(src_fd, &i, &sock_fd[i], BPF_NOEXIST); err = bpf_map_update_elem(src_fd, &i, &sock_fd[i], BPF_NOEXIST);
if (CHECK(err, "map_update", "failed: %s\n", strerror(errno))) if (!ASSERT_OK(err, "map_update"))
goto out; goto out;
} }
...@@ -248,22 +235,20 @@ static void test_sockmap_copy(enum bpf_map_type map_type) ...@@ -248,22 +235,20 @@ static void test_sockmap_copy(enum bpf_map_type map_type)
goto out; goto out;
iter_fd = bpf_iter_create(bpf_link__fd(link)); iter_fd = bpf_iter_create(bpf_link__fd(link));
if (CHECK(iter_fd < 0, "create_iter", "create_iter failed\n")) if (!ASSERT_GE(iter_fd, 0, "create_iter"))
goto free_link; goto free_link;
/* do some tests */ /* do some tests */
while ((len = read(iter_fd, buf, sizeof(buf))) > 0) while ((len = read(iter_fd, buf, sizeof(buf))) > 0)
; ;
if (CHECK(len < 0, "read", "failed: %s\n", strerror(errno))) if (!ASSERT_GE(len, 0, "read"))
goto close_iter; goto close_iter;
/* test results */ /* test results */
if (CHECK(skel->bss->elems != num_elems, "elems", "got %u expected %u\n", if (!ASSERT_EQ(skel->bss->elems, num_elems, "elems"))
skel->bss->elems, num_elems))
goto close_iter; goto close_iter;
if (CHECK(skel->bss->socks != num_sockets, "socks", "got %u expected %u\n", if (!ASSERT_EQ(skel->bss->socks, num_sockets, "socks"))
skel->bss->socks, num_sockets))
goto close_iter; goto close_iter;
compare_cookies(src, skel->maps.dst); compare_cookies(src, skel->maps.dst);
...@@ -288,28 +273,22 @@ static void test_sockmap_skb_verdict_attach(enum bpf_attach_type first, ...@@ -288,28 +273,22 @@ static void test_sockmap_skb_verdict_attach(enum bpf_attach_type first,
int err, map, verdict; int err, map, verdict;
skel = test_sockmap_skb_verdict_attach__open_and_load(); skel = test_sockmap_skb_verdict_attach__open_and_load();
if (CHECK_FAIL(!skel)) { if (!ASSERT_OK_PTR(skel, "open_and_load"))
perror("test_sockmap_skb_verdict_attach__open_and_load");
return; return;
}
verdict = bpf_program__fd(skel->progs.prog_skb_verdict); verdict = bpf_program__fd(skel->progs.prog_skb_verdict);
map = bpf_map__fd(skel->maps.sock_map); map = bpf_map__fd(skel->maps.sock_map);
err = bpf_prog_attach(verdict, map, first, 0); err = bpf_prog_attach(verdict, map, first, 0);
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "bpf_prog_attach"))
perror("bpf_prog_attach");
goto out; goto out;
}
err = bpf_prog_attach(verdict, map, second, 0); err = bpf_prog_attach(verdict, map, second, 0);
ASSERT_EQ(err, -EBUSY, "prog_attach_fail"); ASSERT_EQ(err, -EBUSY, "prog_attach_fail");
err = bpf_prog_detach2(verdict, map, first); err = bpf_prog_detach2(verdict, map, first);
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "bpf_prog_detach2"))
perror("bpf_prog_detach2");
goto out; goto out;
}
out: out:
test_sockmap_skb_verdict_attach__destroy(skel); test_sockmap_skb_verdict_attach__destroy(skel);
} }
......
...@@ -15,16 +15,12 @@ static int tcp_server(int family) ...@@ -15,16 +15,12 @@ static int tcp_server(int family)
int err, s; int err, s;
s = socket(family, SOCK_STREAM, 0); s = socket(family, SOCK_STREAM, 0);
if (CHECK_FAIL(s == -1)) { if (!ASSERT_GE(s, 0, "socket"))
perror("socket");
return -1; return -1;
}
err = listen(s, SOMAXCONN); err = listen(s, SOMAXCONN);
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "listen"))
perror("listen");
return -1; return -1;
}
return s; return s;
} }
...@@ -48,44 +44,31 @@ static void test_sockmap_ktls_disconnect_after_delete(int family, int map) ...@@ -48,44 +44,31 @@ static void test_sockmap_ktls_disconnect_after_delete(int family, int map)
return; return;
err = getsockname(srv, (struct sockaddr *)&addr, &len); err = getsockname(srv, (struct sockaddr *)&addr, &len);
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "getsockopt"))
perror("getsockopt");
goto close_srv; goto close_srv;
}
cli = socket(family, SOCK_STREAM, 0); cli = socket(family, SOCK_STREAM, 0);
if (CHECK_FAIL(cli == -1)) { if (!ASSERT_GE(cli, 0, "socket"))
perror("socket");
goto close_srv; goto close_srv;
}
err = connect(cli, (struct sockaddr *)&addr, len); err = connect(cli, (struct sockaddr *)&addr, len);
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "connect"))
perror("connect");
goto close_cli; goto close_cli;
}
err = bpf_map_update_elem(map, &zero, &cli, 0); err = bpf_map_update_elem(map, &zero, &cli, 0);
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "bpf_map_update_elem"))
perror("bpf_map_update_elem");
goto close_cli; goto close_cli;
}
err = setsockopt(cli, IPPROTO_TCP, TCP_ULP, "tls", strlen("tls")); err = setsockopt(cli, IPPROTO_TCP, TCP_ULP, "tls", strlen("tls"));
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "setsockopt(TCP_ULP)"))
perror("setsockopt(TCP_ULP)");
goto close_cli; goto close_cli;
}
err = bpf_map_delete_elem(map, &zero); err = bpf_map_delete_elem(map, &zero);
if (CHECK_FAIL(err)) { if (!ASSERT_OK(err, "bpf_map_delete_elem"))
perror("bpf_map_delete_elem");
goto close_cli; goto close_cli;
}
err = disconnect(cli); err = disconnect(cli);
if (CHECK_FAIL(err)) ASSERT_OK(err, "disconnect");
perror("disconnect");
close_cli: close_cli:
close(cli); close(cli);
...@@ -168,10 +151,8 @@ static void run_tests(int family, enum bpf_map_type map_type) ...@@ -168,10 +151,8 @@ static void run_tests(int family, enum bpf_map_type map_type)
int map; int map;
map = bpf_map_create(map_type, NULL, sizeof(int), sizeof(int), 1, NULL); map = bpf_map_create(map_type, NULL, sizeof(int), sizeof(int), 1, NULL);
if (CHECK_FAIL(map < 0)) { if (!ASSERT_GE(map, 0, "bpf_map_create"))
perror("bpf_map_create");
return; return;
}
if (test__start_subtest(fmt_test_name("disconnect_after_delete", family, map_type))) if (test__start_subtest(fmt_test_name("disconnect_after_delete", family, map_type)))
test_sockmap_ktls_disconnect_after_delete(family, map); test_sockmap_ktls_disconnect_after_delete(family, map);
......
...@@ -972,12 +972,12 @@ void test_sockopt(void) ...@@ -972,12 +972,12 @@ void test_sockopt(void)
int cgroup_fd, i; int cgroup_fd, i;
cgroup_fd = test__join_cgroup("/sockopt"); cgroup_fd = test__join_cgroup("/sockopt");
if (CHECK_FAIL(cgroup_fd < 0)) if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup"))
return; return;
for (i = 0; i < ARRAY_SIZE(tests); i++) { for (i = 0; i < ARRAY_SIZE(tests); i++) {
test__start_subtest(tests[i].descr); test__start_subtest(tests[i].descr);
CHECK_FAIL(run_test(cgroup_fd, &tests[i])); ASSERT_OK(run_test(cgroup_fd, &tests[i]), tests[i].descr);
} }
close(cgroup_fd); close(cgroup_fd);
......
...@@ -76,20 +76,16 @@ static void *server_thread(void *arg) ...@@ -76,20 +76,16 @@ static void *server_thread(void *arg)
pthread_cond_signal(&server_started); pthread_cond_signal(&server_started);
pthread_mutex_unlock(&server_started_mtx); pthread_mutex_unlock(&server_started_mtx);
if (CHECK_FAIL(err < 0)) { if (!ASSERT_GE(err, 0, "listed on socket"))
perror("Failed to listed on socket");
return NULL; return NULL;
}
err += verify_sockopt(fd, CUSTOM_INHERIT1, "listen", 1); err += verify_sockopt(fd, CUSTOM_INHERIT1, "listen", 1);
err += verify_sockopt(fd, CUSTOM_INHERIT2, "listen", 1); err += verify_sockopt(fd, CUSTOM_INHERIT2, "listen", 1);
err += verify_sockopt(fd, CUSTOM_LISTENER, "listen", 1); err += verify_sockopt(fd, CUSTOM_LISTENER, "listen", 1);
client_fd = accept(fd, (struct sockaddr *)&addr, &len); client_fd = accept(fd, (struct sockaddr *)&addr, &len);
if (CHECK_FAIL(client_fd < 0)) { if (!ASSERT_GE(client_fd, 0, "accept client"))
perror("Failed to accept client");
return NULL; return NULL;
}
err += verify_sockopt(client_fd, CUSTOM_INHERIT1, "accept", 1); err += verify_sockopt(client_fd, CUSTOM_INHERIT1, "accept", 1);
err += verify_sockopt(client_fd, CUSTOM_INHERIT2, "accept", 1); err += verify_sockopt(client_fd, CUSTOM_INHERIT2, "accept", 1);
...@@ -183,20 +179,20 @@ static void run_test(int cgroup_fd) ...@@ -183,20 +179,20 @@ static void run_test(int cgroup_fd)
goto close_bpf_object; goto close_bpf_object;
err = prog_attach(obj, cgroup_fd, "cgroup/getsockopt", "_getsockopt"); err = prog_attach(obj, cgroup_fd, "cgroup/getsockopt", "_getsockopt");
if (CHECK_FAIL(err)) if (!ASSERT_OK(err, "prog_attach _getsockopt"))
goto close_bpf_object; goto close_bpf_object;
err = prog_attach(obj, cgroup_fd, "cgroup/setsockopt", "_setsockopt"); err = prog_attach(obj, cgroup_fd, "cgroup/setsockopt", "_setsockopt");
if (CHECK_FAIL(err)) if (!ASSERT_OK(err, "prog_attach _setsockopt"))
goto close_bpf_object; goto close_bpf_object;
server_fd = start_server(); server_fd = start_server();
if (CHECK_FAIL(server_fd < 0)) if (!ASSERT_GE(server_fd, 0, "start_server"))
goto close_bpf_object; goto close_bpf_object;
pthread_mutex_lock(&server_started_mtx); pthread_mutex_lock(&server_started_mtx);
if (CHECK_FAIL(pthread_create(&tid, NULL, server_thread, if (!ASSERT_OK(pthread_create(&tid, NULL, server_thread,
(void *)&server_fd))) { (void *)&server_fd), "pthread_create")) {
pthread_mutex_unlock(&server_started_mtx); pthread_mutex_unlock(&server_started_mtx);
goto close_server_fd; goto close_server_fd;
} }
...@@ -204,17 +200,17 @@ static void run_test(int cgroup_fd) ...@@ -204,17 +200,17 @@ static void run_test(int cgroup_fd)
pthread_mutex_unlock(&server_started_mtx); pthread_mutex_unlock(&server_started_mtx);
client_fd = connect_to_server(server_fd); client_fd = connect_to_server(server_fd);
if (CHECK_FAIL(client_fd < 0)) if (!ASSERT_GE(client_fd, 0, "connect_to_server"))
goto close_server_fd; goto close_server_fd;
CHECK_FAIL(verify_sockopt(client_fd, CUSTOM_INHERIT1, "connect", 0)); ASSERT_OK(verify_sockopt(client_fd, CUSTOM_INHERIT1, "connect", 0), "verify_sockopt1");
CHECK_FAIL(verify_sockopt(client_fd, CUSTOM_INHERIT2, "connect", 0)); ASSERT_OK(verify_sockopt(client_fd, CUSTOM_INHERIT2, "connect", 0), "verify_sockopt2");
CHECK_FAIL(verify_sockopt(client_fd, CUSTOM_LISTENER, "connect", 0)); ASSERT_OK(verify_sockopt(client_fd, CUSTOM_LISTENER, "connect", 0), "verify_sockopt ener");
pthread_join(tid, &server_err); pthread_join(tid, &server_err);
err = (int)(long)server_err; err = (int)(long)server_err;
CHECK_FAIL(err); ASSERT_OK(err, "pthread_join retval");
close(client_fd); close(client_fd);
...@@ -229,7 +225,7 @@ void test_sockopt_inherit(void) ...@@ -229,7 +225,7 @@ void test_sockopt_inherit(void)
int cgroup_fd; int cgroup_fd;
cgroup_fd = test__join_cgroup("/sockopt_inherit"); cgroup_fd = test__join_cgroup("/sockopt_inherit");
if (CHECK_FAIL(cgroup_fd < 0)) if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup"))
return; return;
run_test(cgroup_fd); run_test(cgroup_fd);
......
...@@ -303,11 +303,11 @@ void test_sockopt_multi(void) ...@@ -303,11 +303,11 @@ void test_sockopt_multi(void)
int err = -1; int err = -1;
cg_parent = test__join_cgroup("/parent"); cg_parent = test__join_cgroup("/parent");
if (CHECK_FAIL(cg_parent < 0)) if (!ASSERT_GE(cg_parent, 0, "join_cgroup /parent"))
goto out; goto out;
cg_child = test__join_cgroup("/parent/child"); cg_child = test__join_cgroup("/parent/child");
if (CHECK_FAIL(cg_child < 0)) if (!ASSERT_GE(cg_child, 0, "join_cgroup /parent/child"))
goto out; goto out;
obj = bpf_object__open_file("sockopt_multi.bpf.o", NULL); obj = bpf_object__open_file("sockopt_multi.bpf.o", NULL);
...@@ -319,11 +319,11 @@ void test_sockopt_multi(void) ...@@ -319,11 +319,11 @@ void test_sockopt_multi(void)
goto out; goto out;
sock_fd = socket(AF_INET, SOCK_STREAM, 0); sock_fd = socket(AF_INET, SOCK_STREAM, 0);
if (CHECK_FAIL(sock_fd < 0)) if (!ASSERT_GE(sock_fd, 0, "socket"))
goto out; goto out;
CHECK_FAIL(run_getsockopt_test(obj, cg_parent, cg_child, sock_fd)); ASSERT_OK(run_getsockopt_test(obj, cg_parent, cg_child, sock_fd), "getsockopt_test");
CHECK_FAIL(run_setsockopt_test(obj, cg_parent, cg_child, sock_fd)); ASSERT_OK(run_setsockopt_test(obj, cg_parent, cg_child, sock_fd), "setsockopt_test");
out: out:
close(sock_fd); close(sock_fd);
......
...@@ -223,7 +223,7 @@ void test_sockopt_sk(void) ...@@ -223,7 +223,7 @@ void test_sockopt_sk(void)
int cgroup_fd; int cgroup_fd;
cgroup_fd = test__join_cgroup("/sockopt_sk"); cgroup_fd = test__join_cgroup("/sockopt_sk");
if (CHECK_FAIL(cgroup_fd < 0)) if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup /sockopt_sk"))
return; return;
run_test(cgroup_fd); run_test(cgroup_fd);
......
...@@ -6,11 +6,9 @@ void test_tcp_estats(void) ...@@ -6,11 +6,9 @@ void test_tcp_estats(void)
const char *file = "./test_tcp_estats.bpf.o"; const char *file = "./test_tcp_estats.bpf.o";
int err, prog_fd; int err, prog_fd;
struct bpf_object *obj; struct bpf_object *obj;
__u32 duration = 0;
err = bpf_prog_test_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj, &prog_fd); err = bpf_prog_test_load(file, BPF_PROG_TYPE_TRACEPOINT, &obj, &prog_fd);
CHECK(err, "", "err %d errno %d\n", err, errno); if (!ASSERT_OK(err, ""))
if (err)
return; return;
bpf_object__close(obj); bpf_object__close(obj);
......
...@@ -42,13 +42,10 @@ struct sk_fds { ...@@ -42,13 +42,10 @@ struct sk_fds {
static int create_netns(void) static int create_netns(void)
{ {
if (CHECK(unshare(CLONE_NEWNET), "create netns", if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns"))
"unshare(CLONE_NEWNET): %s (%d)",
strerror(errno), errno))
return -1; return -1;
if (CHECK(system("ip link set dev lo up"), "run ip cmd", if (!ASSERT_OK(system("ip link set dev lo up"), "run ip cmd"))
"failed to bring lo link up\n"))
return -1; return -1;
return 0; return 0;
...@@ -80,16 +77,12 @@ static int sk_fds_shutdown(struct sk_fds *sk_fds) ...@@ -80,16 +77,12 @@ static int sk_fds_shutdown(struct sk_fds *sk_fds)
shutdown(sk_fds->active_fd, SHUT_WR); shutdown(sk_fds->active_fd, SHUT_WR);
ret = read(sk_fds->passive_fd, &abyte, sizeof(abyte)); ret = read(sk_fds->passive_fd, &abyte, sizeof(abyte));
if (CHECK(ret != 0, "read-after-shutdown(passive_fd):", if (!ASSERT_EQ(ret, 0, "read-after-shutdown(passive_fd):"))
"ret:%d %s (%d)\n",
ret, strerror(errno), errno))
return -1; return -1;
shutdown(sk_fds->passive_fd, SHUT_WR); shutdown(sk_fds->passive_fd, SHUT_WR);
ret = read(sk_fds->active_fd, &abyte, sizeof(abyte)); ret = read(sk_fds->active_fd, &abyte, sizeof(abyte));
if (CHECK(ret != 0, "read-after-shutdown(active_fd):", if (!ASSERT_EQ(ret, 0, "read-after-shutdown(active_fd):"))
"ret:%d %s (%d)\n",
ret, strerror(errno), errno))
return -1; return -1;
return 0; return 0;
...@@ -102,8 +95,7 @@ static int sk_fds_connect(struct sk_fds *sk_fds, bool fast_open) ...@@ -102,8 +95,7 @@ static int sk_fds_connect(struct sk_fds *sk_fds, bool fast_open)
socklen_t len; socklen_t len;
sk_fds->srv_fd = start_server(AF_INET6, SOCK_STREAM, LO_ADDR6, 0, 0); sk_fds->srv_fd = start_server(AF_INET6, SOCK_STREAM, LO_ADDR6, 0, 0);
if (CHECK(sk_fds->srv_fd == -1, "start_server", "%s (%d)\n", if (!ASSERT_NEQ(sk_fds->srv_fd, -1, "start_server"))
strerror(errno), errno))
goto error; goto error;
if (fast_open) if (fast_open)
...@@ -112,28 +104,25 @@ static int sk_fds_connect(struct sk_fds *sk_fds, bool fast_open) ...@@ -112,28 +104,25 @@ static int sk_fds_connect(struct sk_fds *sk_fds, bool fast_open)
else else
sk_fds->active_fd = connect_to_fd(sk_fds->srv_fd, 0); sk_fds->active_fd = connect_to_fd(sk_fds->srv_fd, 0);
if (CHECK_FAIL(sk_fds->active_fd == -1)) { if (!ASSERT_NEQ(sk_fds->active_fd, -1, "")) {
close(sk_fds->srv_fd); close(sk_fds->srv_fd);
goto error; goto error;
} }
len = sizeof(addr6); len = sizeof(addr6);
if (CHECK(getsockname(sk_fds->srv_fd, (struct sockaddr *)&addr6, if (!ASSERT_OK(getsockname(sk_fds->srv_fd, (struct sockaddr *)&addr6,
&len), "getsockname(srv_fd)", "%s (%d)\n", &len), "getsockname(srv_fd)"))
strerror(errno), errno))
goto error_close; goto error_close;
sk_fds->passive_lport = ntohs(addr6.sin6_port); sk_fds->passive_lport = ntohs(addr6.sin6_port);
len = sizeof(addr6); len = sizeof(addr6);
if (CHECK(getsockname(sk_fds->active_fd, (struct sockaddr *)&addr6, if (!ASSERT_OK(getsockname(sk_fds->active_fd, (struct sockaddr *)&addr6,
&len), "getsockname(active_fd)", "%s (%d)\n", &len), "getsockname(active_fd)"))
strerror(errno), errno))
goto error_close; goto error_close;
sk_fds->active_lport = ntohs(addr6.sin6_port); sk_fds->active_lport = ntohs(addr6.sin6_port);
sk_fds->passive_fd = accept(sk_fds->srv_fd, NULL, 0); sk_fds->passive_fd = accept(sk_fds->srv_fd, NULL, 0);
if (CHECK(sk_fds->passive_fd == -1, "accept(srv_fd)", "%s (%d)\n", if (!ASSERT_NEQ(sk_fds->passive_fd, -1, "accept(srv_fd)"))
strerror(errno), errno))
goto error_close; goto error_close;
if (fast_open) { if (fast_open) {
...@@ -141,8 +130,7 @@ static int sk_fds_connect(struct sk_fds *sk_fds, bool fast_open) ...@@ -141,8 +130,7 @@ static int sk_fds_connect(struct sk_fds *sk_fds, bool fast_open)
int ret; int ret;
ret = read(sk_fds->passive_fd, bytes_in, sizeof(bytes_in)); ret = read(sk_fds->passive_fd, bytes_in, sizeof(bytes_in));
if (CHECK(ret != sizeof(fast), "read fastopen syn data", if (!ASSERT_EQ(ret, sizeof(fast), "read fastopen syn data")) {
"expected=%lu actual=%d\n", sizeof(fast), ret)) {
close(sk_fds->passive_fd); close(sk_fds->passive_fd);
goto error_close; goto error_close;
} }
...@@ -163,8 +151,7 @@ static int check_hdr_opt(const struct bpf_test_option *exp, ...@@ -163,8 +151,7 @@ static int check_hdr_opt(const struct bpf_test_option *exp,
const struct bpf_test_option *act, const struct bpf_test_option *act,
const char *hdr_desc) const char *hdr_desc)
{ {
if (CHECK(memcmp(exp, act, sizeof(*exp)), if (!ASSERT_OK(memcmp(exp, act, sizeof(*exp)), hdr_desc)) {
"expected-vs-actual", "unexpected %s\n", hdr_desc)) {
print_option(exp, "expected: "); print_option(exp, "expected: ");
print_option(act, " actual: "); print_option(act, " actual: ");
return -1; return -1;
...@@ -178,13 +165,11 @@ static int check_hdr_stg(const struct hdr_stg *exp, int fd, ...@@ -178,13 +165,11 @@ static int check_hdr_stg(const struct hdr_stg *exp, int fd,
{ {
struct hdr_stg act; struct hdr_stg act;
if (CHECK(bpf_map_lookup_elem(hdr_stg_map_fd, &fd, &act), if (!ASSERT_OK(bpf_map_lookup_elem(hdr_stg_map_fd, &fd, &act),
"map_lookup(hdr_stg_map_fd)", "%s %s (%d)\n", "map_lookup(hdr_stg_map_fd)"))
stg_desc, strerror(errno), errno))
return -1; return -1;
if (CHECK(memcmp(exp, &act, sizeof(*exp)), if (!ASSERT_OK(memcmp(exp, &act, sizeof(*exp)), stg_desc)) {
"expected-vs-actual", "unexpected %s\n", stg_desc)) {
print_hdr_stg(exp, "expected: "); print_hdr_stg(exp, "expected: ");
print_hdr_stg(&act, " actual: "); print_hdr_stg(&act, " actual: ");
return -1; return -1;
...@@ -228,9 +213,8 @@ static void check_hdr_and_close_fds(struct sk_fds *sk_fds) ...@@ -228,9 +213,8 @@ static void check_hdr_and_close_fds(struct sk_fds *sk_fds)
if (sk_fds_shutdown(sk_fds)) if (sk_fds_shutdown(sk_fds))
goto check_linum; goto check_linum;
if (CHECK(expected_inherit_cb_flags != skel->bss->inherit_cb_flags, if (!ASSERT_EQ(expected_inherit_cb_flags, skel->bss->inherit_cb_flags,
"Unexpected inherit_cb_flags", "0x%x != 0x%x\n", "inherit_cb_flags"))
skel->bss->inherit_cb_flags, expected_inherit_cb_flags))
goto check_linum; goto check_linum;
if (check_hdr_stg(&exp_passive_hdr_stg, sk_fds->passive_fd, if (check_hdr_stg(&exp_passive_hdr_stg, sk_fds->passive_fd,
...@@ -257,7 +241,7 @@ static void check_hdr_and_close_fds(struct sk_fds *sk_fds) ...@@ -257,7 +241,7 @@ static void check_hdr_and_close_fds(struct sk_fds *sk_fds)
"active_fin_in"); "active_fin_in");
check_linum: check_linum:
CHECK_FAIL(check_error_linum(sk_fds)); ASSERT_FALSE(check_error_linum(sk_fds), "check_error_linum");
sk_fds_close(sk_fds); sk_fds_close(sk_fds);
} }
...@@ -497,26 +481,20 @@ static void misc(void) ...@@ -497,26 +481,20 @@ static void misc(void)
/* MSG_EOR to ensure skb will not be combined */ /* MSG_EOR to ensure skb will not be combined */
ret = send(sk_fds.active_fd, send_msg, sizeof(send_msg), ret = send(sk_fds.active_fd, send_msg, sizeof(send_msg),
MSG_EOR); MSG_EOR);
if (CHECK(ret != sizeof(send_msg), "send(msg)", "ret:%d\n", if (!ASSERT_EQ(ret, sizeof(send_msg), "send(msg)"))
ret))
goto check_linum; goto check_linum;
ret = read(sk_fds.passive_fd, recv_msg, sizeof(recv_msg)); ret = read(sk_fds.passive_fd, recv_msg, sizeof(recv_msg));
if (CHECK(ret != sizeof(send_msg), "read(msg)", "ret:%d\n", if (ASSERT_EQ(ret, sizeof(send_msg), "read(msg)"))
ret))
goto check_linum; goto check_linum;
} }
if (sk_fds_shutdown(&sk_fds)) if (sk_fds_shutdown(&sk_fds))
goto check_linum; goto check_linum;
CHECK(misc_skel->bss->nr_syn != 1, "unexpected nr_syn", ASSERT_EQ(misc_skel->bss->nr_syn, 1, "unexpected nr_syn");
"expected (1) != actual (%u)\n",
misc_skel->bss->nr_syn);
CHECK(misc_skel->bss->nr_data != nr_data, "unexpected nr_data", ASSERT_EQ(misc_skel->bss->nr_data, nr_data, "unexpected nr_data");
"expected (%u) != actual (%u)\n",
nr_data, misc_skel->bss->nr_data);
/* The last ACK may have been delayed, so it is either 1 or 2. */ /* The last ACK may have been delayed, so it is either 1 or 2. */
CHECK(misc_skel->bss->nr_pure_ack != 1 && CHECK(misc_skel->bss->nr_pure_ack != 1 &&
...@@ -525,12 +503,10 @@ static void misc(void) ...@@ -525,12 +503,10 @@ static void misc(void)
"expected (1 or 2) != actual (%u)\n", "expected (1 or 2) != actual (%u)\n",
misc_skel->bss->nr_pure_ack); misc_skel->bss->nr_pure_ack);
CHECK(misc_skel->bss->nr_fin != 1, "unexpected nr_fin", ASSERT_EQ(misc_skel->bss->nr_fin, 1, "unexpected nr_fin");
"expected (1) != actual (%u)\n",
misc_skel->bss->nr_fin);
check_linum: check_linum:
CHECK_FAIL(check_error_linum(&sk_fds)); ASSERT_FALSE(check_error_linum(&sk_fds), "check_error_linum");
sk_fds_close(&sk_fds); sk_fds_close(&sk_fds);
bpf_link__destroy(link); bpf_link__destroy(link);
} }
...@@ -555,15 +531,15 @@ void test_tcp_hdr_options(void) ...@@ -555,15 +531,15 @@ void test_tcp_hdr_options(void)
int i; int i;
skel = test_tcp_hdr_options__open_and_load(); skel = test_tcp_hdr_options__open_and_load();
if (CHECK(!skel, "open and load skel", "failed")) if (!ASSERT_OK_PTR(skel, "open and load skel"))
return; return;
misc_skel = test_misc_tcp_hdr_options__open_and_load(); misc_skel = test_misc_tcp_hdr_options__open_and_load();
if (CHECK(!misc_skel, "open and load misc test skel", "failed")) if (!ASSERT_OK_PTR(misc_skel, "open and load misc test skel"))
goto skel_destroy; goto skel_destroy;
cg_fd = test__join_cgroup(CG_NAME); cg_fd = test__join_cgroup(CG_NAME);
if (CHECK_FAIL(cg_fd < 0)) if (ASSERT_GE(cg_fd, 0, "join_cgroup"))
goto skel_destroy; goto skel_destroy;
for (i = 0; i < ARRAY_SIZE(tests); i++) { for (i = 0; i < ARRAY_SIZE(tests); i++) {
......
...@@ -16,8 +16,7 @@ static void send_byte(int fd) ...@@ -16,8 +16,7 @@ static void send_byte(int fd)
{ {
char b = 0x55; char b = 0x55;
if (CHECK_FAIL(write(fd, &b, sizeof(b)) != 1)) ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte");
perror("Failed to send single byte");
} }
static int wait_for_ack(int fd, int retries) static int wait_for_ack(int fd, int retries)
...@@ -51,10 +50,8 @@ static int verify_sk(int map_fd, int client_fd, const char *msg, __u32 invoked, ...@@ -51,10 +50,8 @@ static int verify_sk(int map_fd, int client_fd, const char *msg, __u32 invoked,
int err = 0; int err = 0;
struct tcp_rtt_storage val; struct tcp_rtt_storage val;
if (CHECK_FAIL(bpf_map_lookup_elem(map_fd, &client_fd, &val) < 0)) { if (!ASSERT_GE(bpf_map_lookup_elem(map_fd, &client_fd, &val), 0, "read socket storage"))
perror("Failed to read socket storage");
return -1; return -1;
}
if (val.invoked != invoked) { if (val.invoked != invoked) {
log_err("%s: unexpected bpf_tcp_sock.invoked %d != %d", log_err("%s: unexpected bpf_tcp_sock.invoked %d != %d",
...@@ -151,14 +148,14 @@ void test_tcp_rtt(void) ...@@ -151,14 +148,14 @@ void test_tcp_rtt(void)
int server_fd, cgroup_fd; int server_fd, cgroup_fd;
cgroup_fd = test__join_cgroup("/tcp_rtt"); cgroup_fd = test__join_cgroup("/tcp_rtt");
if (CHECK_FAIL(cgroup_fd < 0)) if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup /tcp_rtt"))
return; return;
server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0); server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0);
if (CHECK_FAIL(server_fd < 0)) if (!ASSERT_GE(server_fd, 0, "start_server"))
goto close_cgroup_fd; goto close_cgroup_fd;
CHECK_FAIL(run_test(cgroup_fd, server_fd)); ASSERT_OK(run_test(cgroup_fd, server_fd), "run_test");
close(server_fd); close(server_fd);
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#define LO_ADDR6 "::1" #define LO_ADDR6 "::1"
#define CG_NAME "/tcpbpf-user-test" #define CG_NAME "/tcpbpf-user-test"
static __u32 duration;
static void verify_result(struct tcpbpf_globals *result) static void verify_result(struct tcpbpf_globals *result)
{ {
__u32 expected_events = ((1 << BPF_SOCK_OPS_TIMEOUT_INIT) | __u32 expected_events = ((1 << BPF_SOCK_OPS_TIMEOUT_INIT) |
...@@ -22,9 +20,7 @@ static void verify_result(struct tcpbpf_globals *result) ...@@ -22,9 +20,7 @@ static void verify_result(struct tcpbpf_globals *result)
(1 << BPF_SOCK_OPS_TCP_LISTEN_CB)); (1 << BPF_SOCK_OPS_TCP_LISTEN_CB));
/* check global map */ /* check global map */
CHECK(expected_events != result->event_map, "event_map", ASSERT_EQ(expected_events, result->event_map, "event_map");
"unexpected event_map: actual 0x%08x != expected 0x%08x\n",
result->event_map, expected_events);
ASSERT_EQ(result->bytes_received, 501, "bytes_received"); ASSERT_EQ(result->bytes_received, 501, "bytes_received");
ASSERT_EQ(result->bytes_acked, 1002, "bytes_acked"); ASSERT_EQ(result->bytes_acked, 1002, "bytes_acked");
...@@ -56,18 +52,15 @@ static void run_test(struct tcpbpf_globals *result) ...@@ -56,18 +52,15 @@ static void run_test(struct tcpbpf_globals *result)
int i, rv; int i, rv;
listen_fd = start_server(AF_INET6, SOCK_STREAM, LO_ADDR6, 0, 0); listen_fd = start_server(AF_INET6, SOCK_STREAM, LO_ADDR6, 0, 0);
if (CHECK(listen_fd == -1, "start_server", "listen_fd:%d errno:%d\n", if (!ASSERT_NEQ(listen_fd, -1, "start_server"))
listen_fd, errno))
goto done; goto done;
cli_fd = connect_to_fd(listen_fd, 0); cli_fd = connect_to_fd(listen_fd, 0);
if (CHECK(cli_fd == -1, "connect_to_fd(listen_fd)", if (!ASSERT_NEQ(cli_fd, -1, "connect_to_fd(listen_fd)"))
"cli_fd:%d errno:%d\n", cli_fd, errno))
goto done; goto done;
accept_fd = accept(listen_fd, NULL, NULL); accept_fd = accept(listen_fd, NULL, NULL);
if (CHECK(accept_fd == -1, "accept(listen_fd)", if (!ASSERT_NEQ(accept_fd, -1, "accept(listen_fd)"))
"accept_fd:%d errno:%d\n", accept_fd, errno))
goto done; goto done;
/* Send 1000B of '+'s from cli_fd -> accept_fd */ /* Send 1000B of '+'s from cli_fd -> accept_fd */
...@@ -75,11 +68,11 @@ static void run_test(struct tcpbpf_globals *result) ...@@ -75,11 +68,11 @@ static void run_test(struct tcpbpf_globals *result)
buf[i] = '+'; buf[i] = '+';
rv = send(cli_fd, buf, 1000, 0); rv = send(cli_fd, buf, 1000, 0);
if (CHECK(rv != 1000, "send(cli_fd)", "rv:%d errno:%d\n", rv, errno)) if (!ASSERT_EQ(rv, 1000, "send(cli_fd)"))
goto done; goto done;
rv = recv(accept_fd, buf, 1000, 0); rv = recv(accept_fd, buf, 1000, 0);
if (CHECK(rv != 1000, "recv(accept_fd)", "rv:%d errno:%d\n", rv, errno)) if (!ASSERT_EQ(rv, 1000, "recv(accept_fd)"))
goto done; goto done;
/* Send 500B of '.'s from accept_fd ->cli_fd */ /* Send 500B of '.'s from accept_fd ->cli_fd */
...@@ -87,11 +80,11 @@ static void run_test(struct tcpbpf_globals *result) ...@@ -87,11 +80,11 @@ static void run_test(struct tcpbpf_globals *result)
buf[i] = '.'; buf[i] = '.';
rv = send(accept_fd, buf, 500, 0); rv = send(accept_fd, buf, 500, 0);
if (CHECK(rv != 500, "send(accept_fd)", "rv:%d errno:%d\n", rv, errno)) if (!ASSERT_EQ(rv, 500, "send(accept_fd)"))
goto done; goto done;
rv = recv(cli_fd, buf, 500, 0); rv = recv(cli_fd, buf, 500, 0);
if (CHECK(rv != 500, "recv(cli_fd)", "rv:%d errno:%d\n", rv, errno)) if (!ASSERT_EQ(rv, 500, "recv(cli_fd)"))
goto done; goto done;
/* /*
...@@ -100,12 +93,12 @@ static void run_test(struct tcpbpf_globals *result) ...@@ -100,12 +93,12 @@ static void run_test(struct tcpbpf_globals *result)
*/ */
shutdown(accept_fd, SHUT_WR); shutdown(accept_fd, SHUT_WR);
err = recv(cli_fd, buf, 1, 0); err = recv(cli_fd, buf, 1, 0);
if (CHECK(err, "recv(cli_fd) for fin", "err:%d errno:%d\n", err, errno)) if (!ASSERT_OK(err, "recv(cli_fd) for fin"))
goto done; goto done;
shutdown(cli_fd, SHUT_WR); shutdown(cli_fd, SHUT_WR);
err = recv(accept_fd, buf, 1, 0); err = recv(accept_fd, buf, 1, 0);
CHECK(err, "recv(accept_fd) for fin", "err:%d errno:%d\n", err, errno); ASSERT_OK(err, "recv(accept_fd) for fin");
done: done:
if (accept_fd != -1) if (accept_fd != -1)
close(accept_fd); close(accept_fd);
...@@ -124,12 +117,11 @@ void test_tcpbpf_user(void) ...@@ -124,12 +117,11 @@ void test_tcpbpf_user(void)
int cg_fd = -1; int cg_fd = -1;
skel = test_tcpbpf_kern__open_and_load(); skel = test_tcpbpf_kern__open_and_load();
if (CHECK(!skel, "open and load skel", "failed")) if (!ASSERT_OK_PTR(skel, "open and load skel"))
return; return;
cg_fd = test__join_cgroup(CG_NAME); cg_fd = test__join_cgroup(CG_NAME);
if (CHECK(cg_fd < 0, "test__join_cgroup(" CG_NAME ")", if (!ASSERT_GE(cg_fd, 0, "test__join_cgroup(" CG_NAME ")"))
"cg_fd:%d errno:%d", cg_fd, errno))
goto err; goto err;
skel->links.bpf_testcb = bpf_program__attach_cgroup(skel->progs.bpf_testcb, cg_fd); skel->links.bpf_testcb = bpf_program__attach_cgroup(skel->progs.bpf_testcb, cg_fd);
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
static int duration;
void test_udp_limit(void) void test_udp_limit(void)
{ {
struct udp_limit *skel; struct udp_limit *skel;
...@@ -14,11 +12,11 @@ void test_udp_limit(void) ...@@ -14,11 +12,11 @@ void test_udp_limit(void)
int cgroup_fd; int cgroup_fd;
cgroup_fd = test__join_cgroup("/udp_limit"); cgroup_fd = test__join_cgroup("/udp_limit");
if (CHECK(cgroup_fd < 0, "cg-join", "errno %d", errno)) if (!ASSERT_GE(cgroup_fd, 0, "cg-join"))
return; return;
skel = udp_limit__open_and_load(); skel = udp_limit__open_and_load();
if (CHECK(!skel, "skel-load", "errno %d", errno)) if (!ASSERT_OK_PTR(skel, "skel-load"))
goto close_cgroup_fd; goto close_cgroup_fd;
skel->links.sock = bpf_program__attach_cgroup(skel->progs.sock, cgroup_fd); skel->links.sock = bpf_program__attach_cgroup(skel->progs.sock, cgroup_fd);
...@@ -32,11 +30,11 @@ void test_udp_limit(void) ...@@ -32,11 +30,11 @@ void test_udp_limit(void)
* verify that. * verify that.
*/ */
fd1 = socket(AF_INET, SOCK_DGRAM, 0); fd1 = socket(AF_INET, SOCK_DGRAM, 0);
if (CHECK(fd1 < 0, "fd1", "errno %d", errno)) if (!ASSERT_GE(fd1, 0, "socket(fd1)"))
goto close_skeleton; goto close_skeleton;
fd2 = socket(AF_INET, SOCK_DGRAM, 0); fd2 = socket(AF_INET, SOCK_DGRAM, 0);
if (CHECK(fd2 >= 0, "fd2", "errno %d", errno)) if (!ASSERT_LT(fd2, 0, "socket(fd2)"))
goto close_skeleton; goto close_skeleton;
/* We can reopen again after close. */ /* We can reopen again after close. */
...@@ -44,7 +42,7 @@ void test_udp_limit(void) ...@@ -44,7 +42,7 @@ void test_udp_limit(void)
fd1 = -1; fd1 = -1;
fd1 = socket(AF_INET, SOCK_DGRAM, 0); fd1 = socket(AF_INET, SOCK_DGRAM, 0);
if (CHECK(fd1 < 0, "fd1-again", "errno %d", errno)) if (!ASSERT_GE(fd1, 0, "socket(fd1-again)"))
goto close_skeleton; goto close_skeleton;
/* Make sure the program was invoked the expected /* Make sure the program was invoked the expected
...@@ -54,13 +52,11 @@ void test_udp_limit(void) ...@@ -54,13 +52,11 @@ void test_udp_limit(void)
* - close fd1 - BPF_CGROUP_INET_SOCK_RELEASE * - close fd1 - BPF_CGROUP_INET_SOCK_RELEASE
* - open fd1 again - BPF_CGROUP_INET_SOCK_CREATE * - open fd1 again - BPF_CGROUP_INET_SOCK_CREATE
*/ */
if (CHECK(skel->bss->invocations != 4, "bss-invocations", if (!ASSERT_EQ(skel->bss->invocations, 4, "bss-invocations"))
"invocations=%d", skel->bss->invocations))
goto close_skeleton; goto close_skeleton;
/* We should still have a single socket in use */ /* We should still have a single socket in use */
if (CHECK(skel->bss->in_use != 1, "bss-in_use", if (!ASSERT_EQ(skel->bss->in_use, 1, "bss-in_use"))
"in_use=%d", skel->bss->in_use))
goto close_skeleton; goto close_skeleton;
close_skeleton: close_skeleton:
......
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