Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Convert udp_limit 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-12-git-send-email-wangyufen@huawei.com

authored by

Wang Yufen and committed by
Andrii Nakryiko
1fddca3d 9d0b05bd

+7 -11
+7 -11
tools/testing/selftests/bpf/prog_tests/udp_limit.c
··· 5 5 #include <sys/types.h> 6 6 #include <sys/socket.h> 7 7 8 - static int duration; 9 - 10 8 void test_udp_limit(void) 11 9 { 12 10 struct udp_limit *skel; ··· 12 14 int cgroup_fd; 13 15 14 16 cgroup_fd = test__join_cgroup("/udp_limit"); 15 - if (CHECK(cgroup_fd < 0, "cg-join", "errno %d", errno)) 17 + if (!ASSERT_GE(cgroup_fd, 0, "cg-join")) 16 18 return; 17 19 18 20 skel = udp_limit__open_and_load(); 19 - if (CHECK(!skel, "skel-load", "errno %d", errno)) 21 + if (!ASSERT_OK_PTR(skel, "skel-load")) 20 22 goto close_cgroup_fd; 21 23 22 24 skel->links.sock = bpf_program__attach_cgroup(skel->progs.sock, cgroup_fd); ··· 30 32 * verify that. 31 33 */ 32 34 fd1 = socket(AF_INET, SOCK_DGRAM, 0); 33 - if (CHECK(fd1 < 0, "fd1", "errno %d", errno)) 35 + if (!ASSERT_GE(fd1, 0, "socket(fd1)")) 34 36 goto close_skeleton; 35 37 36 38 fd2 = socket(AF_INET, SOCK_DGRAM, 0); 37 - if (CHECK(fd2 >= 0, "fd2", "errno %d", errno)) 39 + if (!ASSERT_LT(fd2, 0, "socket(fd2)")) 38 40 goto close_skeleton; 39 41 40 42 /* We can reopen again after close. */ ··· 42 44 fd1 = -1; 43 45 44 46 fd1 = socket(AF_INET, SOCK_DGRAM, 0); 45 - if (CHECK(fd1 < 0, "fd1-again", "errno %d", errno)) 47 + if (!ASSERT_GE(fd1, 0, "socket(fd1-again)")) 46 48 goto close_skeleton; 47 49 48 50 /* Make sure the program was invoked the expected ··· 52 54 * - close fd1 - BPF_CGROUP_INET_SOCK_RELEASE 53 55 * - open fd1 again - BPF_CGROUP_INET_SOCK_CREATE 54 56 */ 55 - if (CHECK(skel->bss->invocations != 4, "bss-invocations", 56 - "invocations=%d", skel->bss->invocations)) 57 + if (!ASSERT_EQ(skel->bss->invocations, 4, "bss-invocations")) 57 58 goto close_skeleton; 58 59 59 60 /* We should still have a single socket in use */ 60 - if (CHECK(skel->bss->in_use != 1, "bss-in_use", 61 - "in_use=%d", skel->bss->in_use)) 61 + if (!ASSERT_EQ(skel->bss->in_use, 1, "bss-in_use")) 62 62 goto close_skeleton; 63 63 64 64 close_skeleton: