Skip to content

Commit 9c65112

Browse files
anakryikoborkmann
authored andcommitted
selftests/btf: add initial BTF dedup tests
This patch sets up a new kind of tests (BTF dedup tests) and tests few aspects of BTF dedup algorithm. More complete set of tests will come in follow up patches. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent d5caef5 commit 9c65112

File tree

4 files changed

+537
-15
lines changed

4 files changed

+537
-15
lines changed

tools/lib/bpf/btf.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ static int btf_parse_type_sec(struct btf *btf)
237237
return 0;
238238
}
239239

240+
__u32 btf__get_nr_types(const struct btf *btf)
241+
{
242+
return btf->nr_types;
243+
}
244+
240245
const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 type_id)
241246
{
242247
if (type_id > btf->nr_types)
@@ -427,6 +432,13 @@ int btf__fd(const struct btf *btf)
427432
return btf->fd;
428433
}
429434

435+
void btf__get_strings(const struct btf *btf, const char **strings,
436+
__u32 *str_len)
437+
{
438+
*strings = btf->strings;
439+
*str_len = btf->hdr->str_len;
440+
}
441+
430442
const char *btf__name_by_offset(const struct btf *btf, __u32 offset)
431443
{
432444
if (offset < btf->hdr->str_len)

tools/lib/bpf/btf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ LIBBPF_API void btf__free(struct btf *btf);
5959
LIBBPF_API struct btf *btf__new(__u8 *data, __u32 size);
6060
LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
6161
const char *type_name);
62+
LIBBPF_API __u32 btf__get_nr_types(const struct btf *btf);
6263
LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
6364
__u32 id);
6465
LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
6566
LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id);
6667
LIBBPF_API int btf__fd(const struct btf *btf);
68+
LIBBPF_API void btf__get_strings(const struct btf *btf, const char **strings,
69+
__u32 *str_len);
6770
LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
6871
LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf);
6972
LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, char *map_name,

tools/lib/bpf/libbpf.map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ LIBBPF_0.0.2 {
135135
bpf_get_link_xdp_id;
136136
btf__dedup;
137137
btf__get_map_kv_tids;
138+
btf__get_nr_types;
139+
btf__get_strings;
138140
btf_ext__free;
139141
btf_ext__func_info_rec_size;
140142
btf_ext__line_info_rec_size;

0 commit comments

Comments
 (0)