]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests/bpf: Switch to ".bss"/".rodata"/".data" lookups for internal maps
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 21 Oct 2021 01:44:04 +0000 (18:44 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 22 Oct 2021 00:10:11 +0000 (17:10 -0700)
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: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20211021014404.2635234-11-andrii@kernel.org
tools/testing/selftests/bpf/prog_tests/core_autosize.c
tools/testing/selftests/bpf/prog_tests/core_reloc.c
tools/testing/selftests/bpf/prog_tests/global_data.c
tools/testing/selftests/bpf/prog_tests/global_data_init.c
tools/testing/selftests/bpf/prog_tests/kfree_skb.c
tools/testing/selftests/bpf/prog_tests/rdonly_maps.c

index 3d4b2a358d476d997cd54748f88640ab58cd8daf..2a0dac6394ef42c31a7ad34ebf2630087564eca1 100644 (file)
@@ -163,7 +163,7 @@ void test_core_autosize(void)
 
        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"))
                goto cleanup;
 
index 763302e63a29485941d87fdb03ef71cb78d6a719..cc50f8feeca3d90bab6e29a3cfa5b92fb461894d 100644 (file)
@@ -867,7 +867,7 @@ void test_core_reloc(void)
                        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"))
                        goto cleanup;
 
index 9efa7e50eab27f7d11aa0dbddd9e86610522cc0c..afd8639f9a947d5d746d85084cc970339ba50b68 100644 (file)
@@ -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)
 {
        int err = -ENOMEM, map_fd, zero = 0;
-       struct bpf_map *map;
+       struct bpf_map *map, *map2;
        __u8 *buff;
 
        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;
 
        map_fd = bpf_map__fd(map);
index ee46b11f1f9a208a0d62c70a8e6900beb7f3cc66..1db86eab101b3018ce747f6750ce742dbad27113 100644 (file)
@@ -16,7 +16,7 @@ void test_global_data_init(void)
        if (CHECK_FAIL(err))
                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)))
                goto out;
 
index 032a322d51f2a2d227ce99dfea51e933c2c55903..01e51d16c8b8d144e8d9aef93956286de44bbf22 100644 (file)
@@ -93,7 +93,7 @@ void serial_test_kfree_skb(void)
        if (CHECK(!fexit, "find_prog", "prog eth_type_trans not found\n"))
                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"))
                goto close_prog;
 
index 5f9eaa3ab5847551c96a093c620f0189e6cc3da1..fd5d2ddfb06276337e64fa7a592b1d434d2787bf 100644 (file)
@@ -37,7 +37,7 @@ void test_rdonly_maps(void)
        if (CHECK(err, "obj_load", "err %d errno %d\n", err, errno))
                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"))
                goto cleanup;