Re: [PATCH bpf-next v5 4/4] selftests/bpf: Add libbpf_probe_bpf_kfunc API selftests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Feb 10, 2025 at 01:59:45PM +0800, Tao Chen wrote:
> Add selftests for prog_kfunc feature probing.
> 
>  ./test_progs -t libbpf_probe_kfuncs
>  #153     libbpf_probe_kfuncs:OK
>  Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
> 
> Signed-off-by: Tao Chen <chen.dylane@xxxxxxxxx>
> ---
>  .../selftests/bpf/prog_tests/libbpf_probes.c  | 118 ++++++++++++++++++
>  1 file changed, 118 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> index 4ed46ed58a7b..fc4c9dc2cbed 100644
> --- a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> +++ b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> @@ -126,3 +126,121 @@ void test_libbpf_probe_helpers(void)
>  		ASSERT_EQ(res, d->supported, buf);
>  	}
>  }
> +
> +static int module_btf_fd(char *module)
> +{
> +	int fd, err;
> +	__u32 id = 0, len;
> +	struct bpf_btf_info info;
> +	char name[64];
> +
> +	while (true) {
> +		err = bpf_btf_get_next_id(id, &id);
> +		if (err && (errno == ENOENT || errno == EPERM))
> +			return 0;
> +		if (err) {
> +			err = -errno;
> +			return err;
> +		}
> +		fd = bpf_btf_get_fd_by_id(id);
> +		if (fd < 0) {
> +			if (errno == ENOENT)
> +				continue;
> +			err = -errno;
> +			return err;

nit, return -errno ?

jirka

> +		}
> +		len = sizeof(info);
> +		memset(&info, 0, sizeof(info));
> +		info.name = ptr_to_u64(name);
> +		info.name_len = sizeof(name);
> +		err = bpf_btf_get_info_by_fd(fd, &info, &len);
> +		if (err) {
> +			err = -errno;
> +			goto err_out;
> +		}
> +		/* find target module btf */
> +		if (!strcmp(name, module))
> +			break;
> +
> +		close(fd);
> +	}
> +
> +	return fd;
> +err_out:
> +	close(fd);
> +	return err;
> +}

SNIP




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux