Commit d155fcb3 authored by Wang Yufen's avatar Wang Yufen Committed by Andrii Nakryiko

selftests/bpf: Convert sockmap_ktls 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-3-git-send-email-wangyufen@huawei.com
parent 38e35e1d
...@@ -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);
......
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