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

selftests/bpf: add test of __weak unknown virtual __kconfig extern

Exercise libbpf's logic for unknown __weak virtual __kconfig externs.
USDT selftests are already excercising non-weak known virtual extern
already (LINUX_HAS_BPF_COOKIE), so no need to add explicit tests for it.

Tested-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20220714070755.3235561-3-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
ce6dc74a 55d00c37

+10 -10
+7 -10
tools/testing/selftests/bpf/prog_tests/core_extern.c
··· 39 39 "CONFIG_STR=\"abracad\"\n" 40 40 "CONFIG_MISSING=0", 41 41 .data = { 42 + .unkn_virt_val = 0, 42 43 .bpf_syscall = false, 43 44 .tristate_val = TRI_MODULE, 44 45 .bool_val = true, ··· 122 121 void test_core_extern(void) 123 122 { 124 123 const uint32_t kern_ver = get_kernel_version(); 125 - int err, duration = 0, i, j; 124 + int err, i, j; 126 125 struct test_core_extern *skel = NULL; 127 126 uint64_t *got, *exp; 128 127 int n = sizeof(*skel->data) / sizeof(uint64_t); ··· 137 136 continue; 138 137 139 138 skel = test_core_extern__open_opts(&opts); 140 - if (CHECK(!skel, "skel_open", "skeleton open failed\n")) 139 + if (!ASSERT_OK_PTR(skel, "skel_open")) 141 140 goto cleanup; 142 141 err = test_core_extern__load(skel); 143 142 if (t->fails) { 144 - CHECK(!err, "skel_load", 145 - "shouldn't succeed open/load of skeleton\n"); 143 + ASSERT_ERR(err, "skel_load_should_fail"); 146 144 goto cleanup; 147 - } else if (CHECK(err, "skel_load", 148 - "failed to open/load skeleton\n")) { 145 + } else if (!ASSERT_OK(err, "skel_load")) { 149 146 goto cleanup; 150 147 } 151 148 err = test_core_extern__attach(skel); 152 - if (CHECK(err, "attach_raw_tp", "failed attach: %d\n", err)) 149 + if (!ASSERT_OK(err, "attach_raw_tp")) 153 150 goto cleanup; 154 151 155 152 usleep(1); ··· 157 158 got = (uint64_t *)skel->data; 158 159 exp = (uint64_t *)&t->data; 159 160 for (j = 0; j < n; j++) { 160 - CHECK(got[j] != exp[j], "check_res", 161 - "result #%d: expected %llx, but got %llx\n", 162 - j, (__u64)exp[j], (__u64)got[j]); 161 + ASSERT_EQ(got[j], exp[j], "result"); 163 162 } 164 163 cleanup: 165 164 test_core_extern__destroy(skel);
+3
tools/testing/selftests/bpf/progs/test_core_extern.c
··· 11 11 static int (*bpf_missing_helper)(const void *arg1, int arg2) = (void *) 999; 12 12 13 13 extern int LINUX_KERNEL_VERSION __kconfig; 14 + extern int LINUX_UNKNOWN_VIRTUAL_EXTERN __kconfig __weak; 14 15 extern bool CONFIG_BPF_SYSCALL __kconfig; /* strong */ 15 16 extern enum libbpf_tristate CONFIG_TRISTATE __kconfig __weak; 16 17 extern bool CONFIG_BOOL __kconfig __weak; ··· 23 22 extern uint64_t CONFIG_MISSING __kconfig __weak; 24 23 25 24 uint64_t kern_ver = -1; 25 + uint64_t unkn_virt_val = -1; 26 26 uint64_t bpf_syscall = -1; 27 27 uint64_t tristate_val = -1; 28 28 uint64_t bool_val = -1; ··· 40 38 int i; 41 39 42 40 kern_ver = LINUX_KERNEL_VERSION; 41 + unkn_virt_val = LINUX_UNKNOWN_VIRTUAL_EXTERN; 43 42 bpf_syscall = CONFIG_BPF_SYSCALL; 44 43 tristate_val = CONFIG_TRISTATE; 45 44 bool_val = CONFIG_BOOL;