forked from Minki/linux
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: Wang Yufen <wangyufen@huawei.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/1664169131-32405-5-git-send-email-wangyufen@huawei.com
This commit is contained in:
parent
099763e7da
commit
675bc8abe1
@ -76,20 +76,16 @@ static void *server_thread(void *arg)
|
||||
pthread_cond_signal(&server_started);
|
||||
pthread_mutex_unlock(&server_started_mtx);
|
||||
|
||||
if (CHECK_FAIL(err < 0)) {
|
||||
perror("Failed to listed on socket");
|
||||
if (!ASSERT_GE(err, 0, "listed on socket"))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err += verify_sockopt(fd, CUSTOM_INHERIT1, "listen", 1);
|
||||
err += verify_sockopt(fd, CUSTOM_INHERIT2, "listen", 1);
|
||||
err += verify_sockopt(fd, CUSTOM_LISTENER, "listen", 1);
|
||||
|
||||
client_fd = accept(fd, (struct sockaddr *)&addr, &len);
|
||||
if (CHECK_FAIL(client_fd < 0)) {
|
||||
perror("Failed to accept client");
|
||||
if (!ASSERT_GE(client_fd, 0, "accept client"))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err += verify_sockopt(client_fd, CUSTOM_INHERIT1, "accept", 1);
|
||||
err += verify_sockopt(client_fd, CUSTOM_INHERIT2, "accept", 1);
|
||||
@ -183,20 +179,20 @@ static void run_test(int cgroup_fd)
|
||||
goto close_bpf_object;
|
||||
|
||||
err = prog_attach(obj, cgroup_fd, "cgroup/getsockopt", "_getsockopt");
|
||||
if (CHECK_FAIL(err))
|
||||
if (!ASSERT_OK(err, "prog_attach _getsockopt"))
|
||||
goto close_bpf_object;
|
||||
|
||||
err = prog_attach(obj, cgroup_fd, "cgroup/setsockopt", "_setsockopt");
|
||||
if (CHECK_FAIL(err))
|
||||
if (!ASSERT_OK(err, "prog_attach _setsockopt"))
|
||||
goto close_bpf_object;
|
||||
|
||||
server_fd = start_server();
|
||||
if (CHECK_FAIL(server_fd < 0))
|
||||
if (!ASSERT_GE(server_fd, 0, "start_server"))
|
||||
goto close_bpf_object;
|
||||
|
||||
pthread_mutex_lock(&server_started_mtx);
|
||||
if (CHECK_FAIL(pthread_create(&tid, NULL, server_thread,
|
||||
(void *)&server_fd))) {
|
||||
if (!ASSERT_OK(pthread_create(&tid, NULL, server_thread,
|
||||
(void *)&server_fd), "pthread_create")) {
|
||||
pthread_mutex_unlock(&server_started_mtx);
|
||||
goto close_server_fd;
|
||||
}
|
||||
@ -204,17 +200,17 @@ static void run_test(int cgroup_fd)
|
||||
pthread_mutex_unlock(&server_started_mtx);
|
||||
|
||||
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;
|
||||
|
||||
CHECK_FAIL(verify_sockopt(client_fd, CUSTOM_INHERIT1, "connect", 0));
|
||||
CHECK_FAIL(verify_sockopt(client_fd, CUSTOM_INHERIT2, "connect", 0));
|
||||
CHECK_FAIL(verify_sockopt(client_fd, CUSTOM_LISTENER, "connect", 0));
|
||||
ASSERT_OK(verify_sockopt(client_fd, CUSTOM_INHERIT1, "connect", 0), "verify_sockopt1");
|
||||
ASSERT_OK(verify_sockopt(client_fd, CUSTOM_INHERIT2, "connect", 0), "verify_sockopt2");
|
||||
ASSERT_OK(verify_sockopt(client_fd, CUSTOM_LISTENER, "connect", 0), "verify_sockopt ener");
|
||||
|
||||
pthread_join(tid, &server_err);
|
||||
|
||||
err = (int)(long)server_err;
|
||||
CHECK_FAIL(err);
|
||||
ASSERT_OK(err, "pthread_join retval");
|
||||
|
||||
close(client_fd);
|
||||
|
||||
@ -229,7 +225,7 @@ void test_sockopt_inherit(void)
|
||||
int cgroup_fd;
|
||||
|
||||
cgroup_fd = test__join_cgroup("/sockopt_inherit");
|
||||
if (CHECK_FAIL(cgroup_fd < 0))
|
||||
if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup"))
|
||||
return;
|
||||
|
||||
run_test(cgroup_fd);
|
||||
|
Loading…
Reference in New Issue
Block a user