On 16/3/26 15:51, Jiri Olsa wrote:
> Adding tests for tracing_multi link attachment via all possible
> libbpf apis - skeleton, function pattern and btf ids.
>
> Signed-off-by: Jiri Olsa <[email protected]>
> ---
> tools/testing/selftests/bpf/Makefile | 3 +-
> .../selftests/bpf/prog_tests/tracing_multi.c | 245 ++++++++++++++++++
> .../bpf/progs/tracing_multi_attach.c | 40 +++
> .../selftests/bpf/progs/tracing_multi_check.c | 150 +++++++++++
> 4 files changed, 437 insertions(+), 1 deletion(-)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/tracing_multi.c
> create mode 100644 tools/testing/selftests/bpf/progs/tracing_multi_attach.c
> create mode 100644 tools/testing/selftests/bpf/progs/tracing_multi_check.c
>
> diff --git a/tools/testing/selftests/bpf/Makefile
> b/tools/testing/selftests/bpf/Makefile
> index 869b582b1d1f..e09beba5674e 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -485,7 +485,7 @@ SKEL_BLACKLIST := btf__% test_pinning_invalid.c
> test_sk_assign.c
> LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h
> \
> linked_vars.skel.h linked_maps.skel.h \
> test_subskeleton.skel.h test_subskeleton_lib.skel.h \
> - test_usdt.skel.h
> + test_usdt.skel.h tracing_multi.skel.h
>
> LSKELS := fexit_sleep.c trace_printk.c trace_vprintk.c map_ptr_kern.c
> \
> core_kern.c core_kern_overflow.c test_ringbuf.c \
> @@ -511,6 +511,7 @@ test_usdt.skel.h-deps := test_usdt.bpf.o
> test_usdt_multispec.bpf.o
> xsk_xdp_progs.skel.h-deps := xsk_xdp_progs.bpf.o
> xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o
> xdp_features.skel.h-deps := xdp_features.bpf.o
> +tracing_multi.skel.h-deps := tracing_multi_attach.bpf.o
> tracing_multi_check.bpf.o
>
> LINKED_BPF_OBJS := $(foreach skel,$(LINKED_SKELS),$($(skel)-deps))
> LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.c,$(LINKED_BPF_OBJS))
> diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
> b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
> new file mode 100644
> index 000000000000..cebf4eb68f18
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/tracing_multi.c
> @@ -0,0 +1,245 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <test_progs.h>
> +#include <bpf/btf.h>
> +#include <search.h>
> +#include "bpf/libbpf_internal.h"
> +#include "tracing_multi.skel.h"
> +#include "trace_helpers.h"
> +
> +static const char * const bpf_fentry_test[] = {
> + "bpf_fentry_test1",
> + "bpf_fentry_test2",
> + "bpf_fentry_test3",
> + "bpf_fentry_test4",
> + "bpf_fentry_test5",
> + "bpf_fentry_test6",
> + "bpf_fentry_test7",
> + "bpf_fentry_test8",
> + "bpf_fentry_test9",
> + "bpf_fentry_test10",
> +};
> +
> +#define FUNCS_CNT (ARRAY_SIZE(bpf_fentry_test))
> +
> +static int compare(const void *ppa, const void *ppb)
> +{
> + const char *pa = *(const char **) ppa;
> + const char *pb = *(const char **) ppb;
> +
> + return strcmp(pa, pb);
> +}
> +
> +static __u32 *get_ids(const char * const funcs[], int funcs_cnt, const char
> *mod)
> +{
> + struct btf *btf, *vmlinux_btf;
> + __u32 nr, type_id, cnt = 0;
> + void *root = NULL;
> + __u32 *ids = NULL;
> + int i, err = 0;
> +
> + btf = btf__load_vmlinux_btf();
> + if (!ASSERT_OK_PTR(btf, "btf__load_vmlinux_btf"))
> + return NULL;
> +
> + if (mod) {
> + vmlinux_btf = btf;
> + btf = btf__load_module_btf(mod, vmlinux_btf);
> + if (!ASSERT_OK_PTR(btf, "btf__load_module_btf"))
> + return NULL;
^ vmlinux_btf does not get released.
> + }
> +
> + ids = calloc(funcs_cnt, sizeof(ids[0]));
> + if (!ids)
> + goto out;
> +
> + /*
> + * We sort function names by name and search them
> + * below for each function.
> + */
> + for (i = 0; i < funcs_cnt; i++)
> + tsearch(&funcs[i], &root, compare);
^ tdestroy() is missing to free tree nodes?
Thanks,
Leon
[...]