diff mbox series

[bpf-next,v1] selftests/bpf: correct the check of join cgroup

Message ID 20250204051154.57655-1-kerneljasonxing@gmail.com (mailing list archive)
State New
Headers show
Series [bpf-next,v1] selftests/bpf: correct the check of join cgroup | expand

Commit Message

Jason Xing Feb. 4, 2025, 5:11 a.m. UTC
Use ASSERT_OK_FD to check the return value of join cgroup,
or else this test will pass even if the fd < 0. ASSERT_OK_FD
can print the error message to the console.

Link: https://lore.kernel.org/all/6d62bd77-6733-40c7-b240-a1aeff55566c@linux.dev/
Suggested-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
---
 tools/testing/selftests/bpf/prog_tests/setget_sockopt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Hou Tao Feb. 5, 2025, 2:42 a.m. UTC | #1
On 2/4/2025 1:11 PM, Jason Xing wrote:
> Use ASSERT_OK_FD to check the return value of join cgroup,
> or else this test will pass even if the fd < 0. ASSERT_OK_FD
> can print the error message to the console.
>
> Link: https://lore.kernel.org/all/6d62bd77-6733-40c7-b240-a1aeff55566c@linux.dev/
> Suggested-by: Martin KaFai Lau <martin.lau@kernel.org>
> Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>

Acked-by: Hou Tao <houtao1@huawei.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/setget_sockopt.c b/tools/testing/selftests/bpf/prog_tests/setget_sockopt.c
index e12255121c15..e4dac529d424 100644
--- a/tools/testing/selftests/bpf/prog_tests/setget_sockopt.c
+++ b/tools/testing/selftests/bpf/prog_tests/setget_sockopt.c
@@ -202,7 +202,7 @@  static void test_nonstandard_opt(int family)
 void test_setget_sockopt(void)
 {
 	cg_fd = test__join_cgroup(CG_NAME);
-	if (cg_fd < 0)
+	if (!ASSERT_OK_FD(cg_fd, "join cgroup"))
 		return;
 
 	if (create_netns())