Skip to contentSkip to conversation

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

PATCH New Steven Rostedt 1 participant 1 message May 30, 2023

lore
Share & tools
lore
#0 lore raw

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

From: "Steven Rostedt (Google)" <[email protected]>

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.

---
 utest/tracefs-utest.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
utest/tracefs-utest.c +3 -1
index 17fcac722fbc..9cfafdbd039c 100644
@@ -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);
 		}
Signature · 1 line
2.39.2