Linux Trace Development
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Emil Thorsoe <ethorsoe@tuxera.com>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: libtraceevent: bail out of utest if mmap fails
Date: Wed, 6 May 2026 09:27:35 -0400	[thread overview]
Message-ID: <20260506092735.2a4b07f0@fedora> (raw)
In-Reply-To: <2677c065-b9c9-4fd1-a4a8-de4f027a0b58@tuxera.com>

On Tue, 5 May 2026 23:22:44 +0300
Emil Thorsoe <ethorsoe@tuxera.com> 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 <ethorsoe@tuxera.com>
> ---
>  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);


      reply	other threads:[~2026-05-06 13:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-05 20:22 libtraceevent: bail out of utest if mmap fails Emil Thorsoe
2026-05-06 13:27 ` Steven Rostedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260506092735.2a4b07f0@fedora \
    --to=rostedt@goodmis.org \
    --cc=ethorsoe@tuxera.com \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox