|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +/* Copyright (c) 2025 Meta Platforms Inc. */ |
| 3 | +#include <test_progs.h> |
| 4 | +#include "test_btf_ext.skel.h" |
| 5 | +#include "btf_helpers.h" |
| 6 | + |
| 7 | +static void subtest_line_func_info(void) |
| 8 | +{ |
| 9 | + struct test_btf_ext *skel; |
| 10 | + struct bpf_prog_info info; |
| 11 | + struct bpf_line_info line_info[128], *libbpf_line_info; |
| 12 | + struct bpf_func_info func_info[128], *libbpf_func_info; |
| 13 | + __u32 info_len = sizeof(info), libbbpf_line_info_cnt, libbbpf_func_info_cnt; |
| 14 | + int err, fd; |
| 15 | + |
| 16 | + skel = test_btf_ext__open_and_load(); |
| 17 | + if (!ASSERT_OK_PTR(skel, "skel_open_and_load")) |
| 18 | + return; |
| 19 | + |
| 20 | + fd = bpf_program__fd(skel->progs.global_func); |
| 21 | + |
| 22 | + memset(&info, 0, sizeof(info)); |
| 23 | + info.line_info = ptr_to_u64(&line_info); |
| 24 | + info.nr_line_info = sizeof(line_info); |
| 25 | + info.line_info_rec_size = sizeof(*line_info); |
| 26 | + err = bpf_prog_get_info_by_fd(fd, &info, &info_len); |
| 27 | + if (!ASSERT_OK(err, "prog_line_info")) |
| 28 | + goto out; |
| 29 | + |
| 30 | + libbpf_line_info = bpf_program__line_info(skel->progs.global_func); |
| 31 | + libbbpf_line_info_cnt = bpf_program__line_info_cnt(skel->progs.global_func); |
| 32 | + |
| 33 | + memset(&info, 0, sizeof(info)); |
| 34 | + info.func_info = ptr_to_u64(&func_info); |
| 35 | + info.nr_func_info = sizeof(func_info); |
| 36 | + info.func_info_rec_size = sizeof(*func_info); |
| 37 | + err = bpf_prog_get_info_by_fd(fd, &info, &info_len); |
| 38 | + if (!ASSERT_OK(err, "prog_func_info")) |
| 39 | + goto out; |
| 40 | + |
| 41 | + libbpf_func_info = bpf_program__func_info(skel->progs.global_func); |
| 42 | + libbbpf_func_info_cnt = bpf_program__func_info_cnt(skel->progs.global_func); |
| 43 | + |
| 44 | + if (!ASSERT_OK_PTR(libbpf_line_info, "bpf_program__line_info")) |
| 45 | + goto out; |
| 46 | + if (!ASSERT_EQ(libbbpf_line_info_cnt, info.nr_line_info, "line_info_cnt")) |
| 47 | + goto out; |
| 48 | + if (!ASSERT_OK_PTR(libbpf_func_info, "bpf_program__func_info")) |
| 49 | + goto out; |
| 50 | + if (!ASSERT_EQ(libbbpf_func_info_cnt, info.nr_func_info, "func_info_cnt")) |
| 51 | + goto out; |
| 52 | + ASSERT_MEMEQ(libbpf_line_info, line_info, libbbpf_line_info_cnt * sizeof(*line_info), |
| 53 | + "line_info"); |
| 54 | + ASSERT_MEMEQ(libbpf_func_info, func_info, libbbpf_func_info_cnt * sizeof(*func_info), |
| 55 | + "func_info"); |
| 56 | +out: |
| 57 | + test_btf_ext__destroy(skel); |
| 58 | +} |
| 59 | + |
| 60 | +void test_btf_ext(void) |
| 61 | +{ |
| 62 | + if (test__start_subtest("line_func_info")) |
| 63 | + subtest_line_func_info(); |
| 64 | +} |
0 commit comments