diff mbox series

libtracefs: Do not segfault in tests if synthetic events are not configured

Message ID 20230530002313.4094ef33@rorschach.local.home (mailing list archive)
State Accepted
Commit e97c311389c4b91e2044cddd0c33417b969329d7
Headers show
Series libtracefs: Do not segfault in tests if synthetic events are not configured | expand

Commit Message

Steven Rostedt May 30, 2023, 4:23 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If synthetic events are not configured in the kernel, the unit tests will
segfault and crash. Check if synthetic events exist and fail out nicely. The
tests will still fail if synthetic events are not configured, but they at least
will not crash.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 utest/tracefs-utest.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 17fcac722fbc..9cfafdbd039c 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -994,7 +994,9 @@  static void test_synth_compare(struct test_synth *synth, struct tracefs_dynevent
 		stype = tracefs_dynevent_info(devents[i], NULL,
 					      &event, NULL, NULL, &format);
 		CU_TEST(stype == TRACEFS_DYNEVENT_SYNTH);
-		CU_TEST(strcmp(event, synth[i].name) == 0);
+		if (stype != TRACEFS_DYNEVENT_SYNTH)
+			continue;
+		CU_TEST(event && synth[i].name && strcmp(event, synth[i].name) == 0);
 		if (synth[i].match_name) {
 			CU_TEST(strstr(format, synth[i].match_name) != NULL);
 		}