diff mbox series

[3/3] libtracefs utest: Add better logic to cause missed events

Message ID 20240723220853.489058-4-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 310b7964c41fe9521ca6c6954d77e0b416c62912
Headers show
Series libtracefs: Enable ring buffer user space memory mapping | expand

Commit Message

Steven Rostedt July 23, 2024, 10:07 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

When the system is running without much debug, it is possible to run the
function tracer without triggering missed events. As the tests are expecting
to have missed events to test the missed events handler, it gfails the test
because no missed events happen, and the missed events handler is correctly
not called. But the tests expect it to be called.

Add more logic to force missed events.

 * Shrink the buffer to just 4 pages.
 * Run "ls -l /usr/bin > /dev/null" instead of sleep().

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

Patch

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 737e54a4f7fe..b29525335116 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -1576,6 +1576,8 @@  static void test_instance_follow_events_clear(struct tracefs_instance *instance)
 {
 	struct follow_data fdata;
 	struct tep_handle *tep;
+	unsigned long page_size;
+	size_t save_size;
 	char **list;
 	int ret;
 
@@ -1671,7 +1673,7 @@  static void test_instance_follow_events_clear(struct tracefs_instance *instance)
 
 	tracefs_trace_on(instance);
 	call_getppid(100);
-	msleep(100);
+	system("ls -l /usr/bin > /dev/null");
 	tracefs_trace_off(instance);
 
 	ret = tracefs_iterate_raw_events(tep, instance, NULL, 0, NULL, &fdata);
@@ -1695,17 +1697,26 @@  static void test_instance_follow_events_clear(struct tracefs_instance *instance)
 	if (!fdata.function)
 		return;
 
+	/* Shrink the buffer to make sure we have missed events */
+	page_size = getpagesize();
+	save_size = tracefs_instance_get_buffer_size(instance, 0);
+	ret = tracefs_instance_set_buffer_size(instance, page_size * 4, 0);
+	CU_TEST(ret == 0);
+
 	tracefs_trace_on(instance);
 	call_getppid(100);
 	/* Stir the kernel a bit */
 	list = tracefs_event_systems(NULL);
 	tracefs_list_free(list);
-	sleep(1);
+	system("ls -l /usr/bin > /dev/null");
 	tracefs_trace_off(instance);
 
 	ret = tracefs_iterate_raw_events(tep, instance, NULL, 0, NULL, &fdata);
 	CU_TEST(ret == 0);
 
+	ret = tracefs_instance_set_buffer_size(instance, save_size, 0);
+	CU_TEST(ret == 0);
+
 	/* Nothing should have been hit */
 	CU_TEST(fdata.switch_hit == 0);
 	CU_TEST(fdata.waking_hit == 0);