Skip to content

Commit cd04b04

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
selftests/bpf: Add set test to resolve_btfids
Adding test to for sets resolve_btfids. We're checking that testing set gets properly resolved and sorted. Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent e4d1af4 commit cd04b04

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

tools/testing/selftests/bpf/prog_tests/resolve_btfids.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ BTF_ID(struct, S)
4747
BTF_ID(union, U)
4848
BTF_ID(func, func)
4949

50+
BTF_SET_START(test_set)
51+
BTF_ID(typedef, S)
52+
BTF_ID(typedef, T)
53+
BTF_ID(typedef, U)
54+
BTF_ID(struct, S)
55+
BTF_ID(union, U)
56+
BTF_ID(func, func)
57+
BTF_SET_END(test_set)
58+
5059
static int
5160
__resolve_symbol(struct btf *btf, int type_id)
5261
{
@@ -116,12 +125,40 @@ int test_resolve_btfids(void)
116125
*/
117126
for (j = 0; j < ARRAY_SIZE(test_lists); j++) {
118127
test_list = test_lists[j];
119-
for (i = 0; i < ARRAY_SIZE(test_symbols) && !ret; i++) {
128+
for (i = 0; i < ARRAY_SIZE(test_symbols); i++) {
120129
ret = CHECK(test_list[i] != test_symbols[i].id,
121130
"id_check",
122131
"wrong ID for %s (%d != %d)\n",
123132
test_symbols[i].name,
124133
test_list[i], test_symbols[i].id);
134+
if (ret)
135+
return ret;
136+
}
137+
}
138+
139+
/* Check BTF_SET_START(test_set) IDs */
140+
for (i = 0; i < test_set.cnt; i++) {
141+
bool found = false;
142+
143+
for (j = 0; j < ARRAY_SIZE(test_symbols); j++) {
144+
if (test_symbols[j].id != test_set.ids[i])
145+
continue;
146+
found = true;
147+
break;
148+
}
149+
150+
ret = CHECK(!found, "id_check",
151+
"ID %d not found in test_symbols\n",
152+
test_set.ids[i]);
153+
if (ret)
154+
break;
155+
156+
if (i > 0) {
157+
ret = CHECK(test_set.ids[i - 1] > test_set.ids[i],
158+
"sort_check",
159+
"test_set is not sorted\n");
160+
if (ret)
161+
break;
125162
}
126163
}
127164

0 commit comments

Comments
 (0)