All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libtraceevent utest: exit test if mmap fails
@ 2026-05-26 18:42 Sudip Mukherjee
  2026-05-29 18:41 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Sudip Mukherjee @ 2026-05-26 18:42 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Sudip Mukherjee

CU_TEST() continues execution even if the test fails. It just records
that the test has failed and moves on.
So, when libtraceevent is built in a chroot, it can open
/sys/kernel/btf/vmlinux but fails in mmap stage and since CU_TEST()
does not stop so we get a segfault when tep_load_btf() tries to use
the mapped buffer.

Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
 utest/traceevent-utest.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/utest/traceevent-utest.c b/utest/traceevent-utest.c
index b62411c..547619d 100644
--- a/utest/traceevent-utest.c
+++ b/utest/traceevent-utest.c
@@ -397,6 +397,12 @@ static void test_btf_read(void)
 	CU_TEST(fstat(fd, &st) == 0);
 
 	buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+	if (buf == MAP_FAILED) {
+		printf("kernel has btf, but it might be a chroot and mmap has failed\n");
+		close(fd);
+		return;
+	}
+
 	CU_TEST(buf != MAP_FAILED);
 
 	CU_TEST(tep_load_btf(test_tep, buf, st.st_size) == 0);
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-29 18:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-26 18:42 [PATCH] libtraceevent utest: exit test if mmap fails Sudip Mukherjee
2026-05-29 18:41 ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.