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

selftests/bpf: Replace CHECK with ASSERT macros for ksyms test

Replace CHECK with ASSERT macros for ksyms tests.
This test failed earlier with clang lto kernel, but the
issue is gone with latest code base. But replacing
CHECK with ASSERT still improves code as ASSERT is
preferred in selftests.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20240326041448.1197812-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Yonghong Song and committed by
Alexei Starovoitov
cdfd9cc3 5da7fb04

+11 -19
+11 -19
tools/testing/selftests/bpf/prog_tests/ksyms.c
··· 5 5 #include "test_ksyms.skel.h" 6 6 #include <sys/stat.h> 7 7 8 - static int duration; 9 - 10 8 void test_ksyms(void) 11 9 { 12 10 const char *btf_path = "/sys/kernel/btf/vmlinux"; ··· 16 18 int err; 17 19 18 20 err = kallsyms_find("bpf_link_fops", &link_fops_addr); 19 - if (CHECK(err == -EINVAL, "kallsyms_fopen", "failed to open: %d\n", errno)) 21 + if (!ASSERT_NEQ(err, -EINVAL, "bpf_link_fops: kallsyms_fopen")) 20 22 return; 21 - if (CHECK(err == -ENOENT, "ksym_find", "symbol 'bpf_link_fops' not found\n")) 23 + if (!ASSERT_NEQ(err, -ENOENT, "bpf_link_fops: ksym_find")) 22 24 return; 23 25 24 26 err = kallsyms_find("__per_cpu_start", &per_cpu_start_addr); 25 - if (CHECK(err == -EINVAL, "kallsyms_fopen", "failed to open: %d\n", errno)) 27 + if (!ASSERT_NEQ(err, -EINVAL, "__per_cpu_start: kallsyms_fopen")) 26 28 return; 27 - if (CHECK(err == -ENOENT, "ksym_find", "symbol 'per_cpu_start' not found\n")) 29 + if (!ASSERT_NEQ(err, -ENOENT, "__per_cpu_start: ksym_find")) 28 30 return; 29 31 30 - if (CHECK(stat(btf_path, &st), "stat_btf", "err %d\n", errno)) 32 + if (!ASSERT_OK(stat(btf_path, &st), "stat_btf")) 31 33 return; 32 34 btf_size = st.st_size; 33 35 34 36 skel = test_ksyms__open_and_load(); 35 - if (CHECK(!skel, "skel_open", "failed to open and load skeleton\n")) 37 + if (!ASSERT_OK_PTR(skel, "test_ksyms__open_and_load")) 36 38 return; 37 39 38 40 err = test_ksyms__attach(skel); 39 - if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err)) 41 + if (!ASSERT_OK(err, "test_ksyms__attach")) 40 42 goto cleanup; 41 43 42 44 /* trigger tracepoint */ 43 45 usleep(1); 44 46 45 47 data = skel->data; 46 - CHECK(data->out__bpf_link_fops != link_fops_addr, "bpf_link_fops", 47 - "got 0x%llx, exp 0x%llx\n", 48 - data->out__bpf_link_fops, link_fops_addr); 49 - CHECK(data->out__bpf_link_fops1 != 0, "bpf_link_fops1", 50 - "got %llu, exp %llu\n", data->out__bpf_link_fops1, (__u64)0); 51 - CHECK(data->out__btf_size != btf_size, "btf_size", 52 - "got %llu, exp %llu\n", data->out__btf_size, btf_size); 53 - CHECK(data->out__per_cpu_start != per_cpu_start_addr, "__per_cpu_start", 54 - "got %llu, exp %llu\n", data->out__per_cpu_start, 55 - per_cpu_start_addr); 48 + ASSERT_EQ(data->out__bpf_link_fops, link_fops_addr, "bpf_link_fops"); 49 + ASSERT_EQ(data->out__bpf_link_fops1, 0, "bpf_link_fops1"); 50 + ASSERT_EQ(data->out__btf_size, btf_size, "btf_size"); 51 + ASSERT_EQ(data->out__per_cpu_start, per_cpu_start_addr, "__per_cpu_start"); 56 52 57 53 cleanup: 58 54 test_ksyms__destroy(skel);