Commit b0e2a039 authored by Yuran Pereira's avatar Yuran Pereira Committed by Andrii Nakryiko

selftests/bpf: Replaces the usage of CHECK calls for ASSERTs in bpf_tcp_ca

bpf_tcp_ca uses the `CHECK` calls even though the use of
ASSERT_ series of macros is preferred in the bpf selftests.

This patch replaces all `CHECK` calls for equivalent `ASSERT_`
macro calls.
Signed-off-by: default avatarYuran Pereira <yuran.pereira@hotmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/GV1PR10MB6563F180C0F2BB4F6CFA5130E8BBA@GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM
parent 57b97ecb
...@@ -20,15 +20,14 @@ ...@@ -20,15 +20,14 @@
static const unsigned int total_bytes = 10 * 1024 * 1024; static const unsigned int total_bytes = 10 * 1024 * 1024;
static int expected_stg = 0xeB9F; static int expected_stg = 0xeB9F;
static int stop, duration; static int stop;
static int settcpca(int fd, const char *tcp_ca) static int settcpca(int fd, const char *tcp_ca)
{ {
int err; int err;
err = setsockopt(fd, IPPROTO_TCP, TCP_CONGESTION, tcp_ca, strlen(tcp_ca)); err = setsockopt(fd, IPPROTO_TCP, TCP_CONGESTION, tcp_ca, strlen(tcp_ca));
if (CHECK(err == -1, "setsockopt(fd, TCP_CONGESTION)", "errno:%d\n", if (!ASSERT_NEQ(err, -1, "setsockopt"))
errno))
return -1; return -1;
return 0; return 0;
...@@ -65,8 +64,7 @@ static void *server(void *arg) ...@@ -65,8 +64,7 @@ static void *server(void *arg)
bytes += nr_sent; bytes += nr_sent;
} }
CHECK(bytes != total_bytes, "send", "%zd != %u nr_sent:%zd errno:%d\n", ASSERT_EQ(bytes, total_bytes, "send");
bytes, total_bytes, nr_sent, errno);
done: done:
if (fd >= 0) if (fd >= 0)
...@@ -92,10 +90,11 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) ...@@ -92,10 +90,11 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
WRITE_ONCE(stop, 0); WRITE_ONCE(stop, 0);
lfd = socket(AF_INET6, SOCK_STREAM, 0); lfd = socket(AF_INET6, SOCK_STREAM, 0);
if (CHECK(lfd == -1, "socket", "errno:%d\n", errno)) if (!ASSERT_NEQ(lfd, -1, "socket"))
return; return;
fd = socket(AF_INET6, SOCK_STREAM, 0); fd = socket(AF_INET6, SOCK_STREAM, 0);
if (CHECK(fd == -1, "socket", "errno:%d\n", errno)) { if (!ASSERT_NEQ(fd, -1, "socket")) {
close(lfd); close(lfd);
return; return;
} }
...@@ -108,26 +107,27 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) ...@@ -108,26 +107,27 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
sa6.sin6_family = AF_INET6; sa6.sin6_family = AF_INET6;
sa6.sin6_addr = in6addr_loopback; sa6.sin6_addr = in6addr_loopback;
err = bind(lfd, (struct sockaddr *)&sa6, addrlen); err = bind(lfd, (struct sockaddr *)&sa6, addrlen);
if (CHECK(err == -1, "bind", "errno:%d\n", errno)) if (!ASSERT_NEQ(err, -1, "bind"))
goto done; goto done;
err = getsockname(lfd, (struct sockaddr *)&sa6, &addrlen); err = getsockname(lfd, (struct sockaddr *)&sa6, &addrlen);
if (CHECK(err == -1, "getsockname", "errno:%d\n", errno)) if (!ASSERT_NEQ(err, -1, "getsockname"))
goto done; goto done;
err = listen(lfd, 1); err = listen(lfd, 1);
if (CHECK(err == -1, "listen", "errno:%d\n", errno)) if (!ASSERT_NEQ(err, -1, "listen"))
goto done; goto done;
if (sk_stg_map) { if (sk_stg_map) {
err = bpf_map_update_elem(bpf_map__fd(sk_stg_map), &fd, err = bpf_map_update_elem(bpf_map__fd(sk_stg_map), &fd,
&expected_stg, BPF_NOEXIST); &expected_stg, BPF_NOEXIST);
if (CHECK(err, "bpf_map_update_elem(sk_stg_map)", if (!ASSERT_OK(err, "bpf_map_update_elem(sk_stg_map)"))
"err:%d errno:%d\n", err, errno))
goto done; goto done;
} }
/* connect to server */ /* connect to server */
err = connect(fd, (struct sockaddr *)&sa6, addrlen); err = connect(fd, (struct sockaddr *)&sa6, addrlen);
if (CHECK(err == -1, "connect", "errno:%d\n", errno)) if (!ASSERT_NEQ(err, -1, "connect"))
goto done; goto done;
if (sk_stg_map) { if (sk_stg_map) {
...@@ -135,14 +135,13 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) ...@@ -135,14 +135,13 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
err = bpf_map_lookup_elem(bpf_map__fd(sk_stg_map), &fd, err = bpf_map_lookup_elem(bpf_map__fd(sk_stg_map), &fd,
&tmp_stg); &tmp_stg);
if (CHECK(!err || errno != ENOENT, if (!ASSERT_ERR(err, "bpf_map_lookup_elem(sk_stg_map)") ||
"bpf_map_lookup_elem(sk_stg_map)", !ASSERT_EQ(errno, ENOENT, "bpf_map_lookup_elem(sk_stg_map)"))
"err:%d errno:%d\n", err, errno))
goto done; goto done;
} }
err = pthread_create(&srv_thread, NULL, server, (void *)(long)lfd); err = pthread_create(&srv_thread, NULL, server, (void *)(long)lfd);
if (CHECK(err != 0, "pthread_create", "err:%d errno:%d\n", err, errno)) if (!ASSERT_OK(err, "pthread_create"))
goto done; goto done;
/* recv total_bytes */ /* recv total_bytes */
...@@ -156,13 +155,12 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map) ...@@ -156,13 +155,12 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
bytes += nr_recv; bytes += nr_recv;
} }
CHECK(bytes != total_bytes, "recv", "%zd != %u nr_recv:%zd errno:%d\n", ASSERT_EQ(bytes, total_bytes, "recv");
bytes, total_bytes, nr_recv, errno);
WRITE_ONCE(stop, 1); WRITE_ONCE(stop, 1);
pthread_join(srv_thread, &thread_ret); pthread_join(srv_thread, &thread_ret);
CHECK(IS_ERR(thread_ret), "pthread_join", "thread_ret:%ld", ASSERT_OK(IS_ERR(thread_ret), "thread_ret");
PTR_ERR(thread_ret));
done: done:
close(lfd); close(lfd);
close(fd); close(fd);
...@@ -174,7 +172,7 @@ static void test_cubic(void) ...@@ -174,7 +172,7 @@ static void test_cubic(void)
struct bpf_link *link; struct bpf_link *link;
cubic_skel = bpf_cubic__open_and_load(); cubic_skel = bpf_cubic__open_and_load();
if (CHECK(!cubic_skel, "bpf_cubic__open_and_load", "failed\n")) if (!ASSERT_OK_PTR(cubic_skel, "bpf_cubic__open_and_load"))
return; return;
link = bpf_map__attach_struct_ops(cubic_skel->maps.cubic); link = bpf_map__attach_struct_ops(cubic_skel->maps.cubic);
...@@ -197,7 +195,7 @@ static void test_dctcp(void) ...@@ -197,7 +195,7 @@ static void test_dctcp(void)
struct bpf_link *link; struct bpf_link *link;
dctcp_skel = bpf_dctcp__open_and_load(); dctcp_skel = bpf_dctcp__open_and_load();
if (CHECK(!dctcp_skel, "bpf_dctcp__open_and_load", "failed\n")) if (!ASSERT_OK_PTR(dctcp_skel, "bpf_dctcp__open_and_load"))
return; return;
link = bpf_map__attach_struct_ops(dctcp_skel->maps.dctcp); link = bpf_map__attach_struct_ops(dctcp_skel->maps.dctcp);
...@@ -207,9 +205,7 @@ static void test_dctcp(void) ...@@ -207,9 +205,7 @@ static void test_dctcp(void)
} }
do_test("bpf_dctcp", dctcp_skel->maps.sk_stg_map); do_test("bpf_dctcp", dctcp_skel->maps.sk_stg_map);
CHECK(dctcp_skel->bss->stg_result != expected_stg, ASSERT_EQ(dctcp_skel->bss->stg_result, expected_stg, "stg_result");
"Unexpected stg_result", "stg_result (%x) != expected_stg (%x)\n",
dctcp_skel->bss->stg_result, expected_stg);
bpf_link__destroy(link); bpf_link__destroy(link);
bpf_dctcp__destroy(dctcp_skel); bpf_dctcp__destroy(dctcp_skel);
......
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