]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
selftests/bpf: Add set test to resolve_btfids
authorJiri Olsa <jolsa@kernel.org>
Tue, 25 Aug 2020 19:21:24 +0000 (21:21 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 25 Aug 2020 22:41:15 +0000 (15:41 -0700)
Adding test to for sets resolve_btfids. We're checking that
testing set gets properly resolved and sorted.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200825192124.710397-15-jolsa@kernel.org
tools/testing/selftests/bpf/prog_tests/resolve_btfids.c

index 3b127cab4864c1c22d1af81f6ae3021d09c6528b..8826c652adad2728290b13383c5a2f7fc2bb16e5 100644 (file)
@@ -47,6 +47,15 @@ BTF_ID(struct,  S)
 BTF_ID(union,   U)
 BTF_ID(func,    func)
 
+BTF_SET_START(test_set)
+BTF_ID(typedef, S)
+BTF_ID(typedef, T)
+BTF_ID(typedef, U)
+BTF_ID(struct,  S)
+BTF_ID(union,   U)
+BTF_ID(func,    func)
+BTF_SET_END(test_set)
+
 static int
 __resolve_symbol(struct btf *btf, int type_id)
 {
@@ -116,12 +125,40 @@ int test_resolve_btfids(void)
         */
        for (j = 0; j < ARRAY_SIZE(test_lists); j++) {
                test_list = test_lists[j];
-               for (i = 0; i < ARRAY_SIZE(test_symbols) && !ret; i++) {
+               for (i = 0; i < ARRAY_SIZE(test_symbols); i++) {
                        ret = CHECK(test_list[i] != test_symbols[i].id,
                                    "id_check",
                                    "wrong ID for %s (%d != %d)\n",
                                    test_symbols[i].name,
                                    test_list[i], test_symbols[i].id);
+                       if (ret)
+                               return ret;
+               }
+       }
+
+       /* Check BTF_SET_START(test_set) IDs */
+       for (i = 0; i < test_set.cnt; i++) {
+               bool found = false;
+
+               for (j = 0; j < ARRAY_SIZE(test_symbols); j++) {
+                       if (test_symbols[j].id != test_set.ids[i])
+                               continue;
+                       found = true;
+                       break;
+               }
+
+               ret = CHECK(!found, "id_check",
+                           "ID %d not found in test_symbols\n",
+                           test_set.ids[i]);
+               if (ret)
+                       break;
+
+               if (i > 0) {
+                       ret = CHECK(test_set.ids[i - 1] > test_set.ids[i],
+                                   "sort_check",
+                                   "test_set is not sorted\n");
+                       if (ret)
+                               break;
                }
        }