提交 b85cd2ea 编写于 作者: A Andrii Nakryiko 提交者: Zheng Zengkai

selftests/bpf: Switch to ".bss"/".rodata"/".data" lookups for internal maps

mainline inclusion
from mainline-5.16-rc1
commit 4f2511e1
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4f2511e1990985103929ab799fb3ebca81969b77

-------------------------------------------------

Utilize libbpf's feature of allowing to lookup internal maps by their
ELF section names. No need to guess or calculate the exact truncated
prefix taken from the object name.
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20211021014404.2635234-11-andrii@kernel.org
(cherry picked from commit 4f2511e1)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 3a18a3bc
...@@ -164,7 +164,7 @@ void test_core_autosize(void) ...@@ -164,7 +164,7 @@ void test_core_autosize(void)
usleep(1); usleep(1);
bss_map = bpf_object__find_map_by_name(skel->obj, "test_cor.bss"); bss_map = bpf_object__find_map_by_name(skel->obj, ".bss");
if (!ASSERT_OK_PTR(bss_map, "bss_map_find")) if (!ASSERT_OK_PTR(bss_map, "bss_map_find"))
goto cleanup; goto cleanup;
......
...@@ -877,7 +877,7 @@ void test_core_reloc(void) ...@@ -877,7 +877,7 @@ void test_core_reloc(void)
goto cleanup; goto cleanup;
} }
data_map = bpf_object__find_map_by_name(obj, "test_cor.bss"); data_map = bpf_object__find_map_by_name(obj, ".bss");
if (CHECK(!data_map, "find_data_map", "data map not found\n")) if (CHECK(!data_map, "find_data_map", "data map not found\n"))
goto cleanup; goto cleanup;
......
...@@ -103,11 +103,18 @@ static void test_global_data_struct(struct bpf_object *obj, __u32 duration) ...@@ -103,11 +103,18 @@ static void test_global_data_struct(struct bpf_object *obj, __u32 duration)
static void test_global_data_rdonly(struct bpf_object *obj, __u32 duration) static void test_global_data_rdonly(struct bpf_object *obj, __u32 duration)
{ {
int err = -ENOMEM, map_fd, zero = 0; int err = -ENOMEM, map_fd, zero = 0;
struct bpf_map *map; struct bpf_map *map, *map2;
__u8 *buff; __u8 *buff;
map = bpf_object__find_map_by_name(obj, "test_glo.rodata"); map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
if (CHECK_FAIL(!map || !bpf_map__is_internal(map))) if (!ASSERT_OK_PTR(map, "map"))
return;
if (!ASSERT_TRUE(bpf_map__is_internal(map), "is_internal"))
return;
/* ensure we can lookup internal maps by their ELF names */
map2 = bpf_object__find_map_by_name(obj, ".rodata");
if (!ASSERT_EQ(map, map2, "same_maps"))
return; return;
map_fd = bpf_map__fd(map); map_fd = bpf_map__fd(map);
......
...@@ -16,7 +16,7 @@ void test_global_data_init(void) ...@@ -16,7 +16,7 @@ void test_global_data_init(void)
if (CHECK_FAIL(err)) if (CHECK_FAIL(err))
return; return;
map = bpf_object__find_map_by_name(obj, "test_glo.rodata"); map = bpf_object__find_map_by_name(obj, ".rodata");
if (CHECK_FAIL(!map || !bpf_map__is_internal(map))) if (CHECK_FAIL(!map || !bpf_map__is_internal(map)))
goto out; goto out;
......
...@@ -92,7 +92,7 @@ void test_kfree_skb(void) ...@@ -92,7 +92,7 @@ void test_kfree_skb(void)
if (CHECK(!fexit, "find_prog", "prog eth_type_trans not found\n")) if (CHECK(!fexit, "find_prog", "prog eth_type_trans not found\n"))
goto close_prog; goto close_prog;
global_data = bpf_object__find_map_by_name(obj2, "kfree_sk.bss"); global_data = bpf_object__find_map_by_name(obj2, ".bss");
if (CHECK(!global_data, "find global data", "not found\n")) if (CHECK(!global_data, "find global data", "not found\n"))
goto close_prog; goto close_prog;
......
...@@ -37,7 +37,7 @@ void test_rdonly_maps(void) ...@@ -37,7 +37,7 @@ void test_rdonly_maps(void)
if (CHECK(err, "obj_load", "err %d errno %d\n", err, errno)) if (CHECK(err, "obj_load", "err %d errno %d\n", err, errno))
goto cleanup; goto cleanup;
bss_map = bpf_object__find_map_by_name(obj, "test_rdo.bss"); bss_map = bpf_object__find_map_by_name(obj, ".bss");
if (CHECK(!bss_map, "find_bss_map", "failed\n")) if (CHECK(!bss_map, "find_bss_map", "failed\n"))
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册