Re: libtraceevent: bail out of utest if mmap fails

Steven Rostedt <[email protected]> Wed, 6 May 2026 09:27:35 -0400
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <20260506092735.2a4b07f0@fedora>
On Tue, 5 May 2026 23:22:44 +0300
Emil Thorsoe <[email protected]> wrote:

> Just like, when failing to open the BTF file, failing to
> mmap the BTF is testing the test environment, not the code.
> 
> This mmap fails with ENODEV on i686 nix build on nixos-unstable.
> 
> Just bail out without failing the test, when mmap fails.
> 
> Signed-off-by: Emil Thorsoe <[email protected]>
> ---
>  utest/traceevent-utest.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/utest/traceevent-utest.c b/utest/traceevent-utest.c
> index b62411c..df98fa1 100644
> --- a/utest/traceevent-utest.c
> +++ b/utest/traceevent-utest.c
> @@ -397,8 +397,11 @@ static void test_btf_read(void)
>  	CU_TEST(fstat(fd, &st) == 0);
>  
>  	buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
> -	CU_TEST(buf != MAP_FAILED);
> -
> +	if (buf == MAP_FAILED) {
> +		printf("[KERNEL DOES NOT ALLOW MMAP OF BTF FILE] ...");

Hmm. Instead of failing, let's instead allocate memory and read it, and
use that instead.

	char *btf_buf = NULL;
	[..]

	if (buf == MAP_FAILED) {
		btf_buf = malloc(st.size);
		/* error check here */
		CU_TEST(read(fd, btf_buf, st.st_size) == st.st_size);
	}
	[..]
	if (btf_buf)
		free(btf_buf);
	else
		munmap(btf, st.st_size); 

or something like that.

Thanks,

-- Steve




> +		close(fd);
> +		return;
> +	}
>  	CU_TEST(tep_load_btf(test_tep, buf, st.st_size) == 0);
>  
>  	munmap(buf, st.st_size);