Commit 675bc8ab authored by Wang Yufen's avatar Wang Yufen Committed by Andrii Nakryiko

selftests/bpf: Convert sockopt_inherit test to ASSERT_* macros

Convert the selftest to use the preferred ASSERT_* macros instead of the
deprecated CHECK().
Signed-off-by: default avatarWang Yufen <wangyufen@huawei.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/1664169131-32405-5-git-send-email-wangyufen@huawei.com
parent 099763e7
...@@ -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);
......
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