* [PATCH] libtracefs: Add unit tests for the follow functions
@ 2022-11-15 5:02 Steven Rostedt
0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2022-11-15 5:02 UTC (permalink / raw)
To: Linux Trace Devel
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Add unit tests for tracefs_follow_events() and
tracefs_follow_missed_events().
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
utest/tracefs-utest.c | 136 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 136 insertions(+)
diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 2c9b267ea427..805cc3b9f975 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -605,6 +605,141 @@ static void test_trace_cpu_read(void)
test_instance_trace_cpu_read(test_instance);
}
+struct follow_data {
+ struct tep_event *sched_switch;
+ struct tep_event *sched_waking;
+ struct tep_event *function;
+ int missed;
+};
+
+static int switch_callback(struct tep_event *event, struct tep_record *record,
+ int cpu, void *data)
+{
+ struct follow_data *fdata = data;
+
+ CU_TEST(cpu == record->cpu);
+ CU_TEST(event->id == fdata->sched_switch->id);
+ return 0;
+}
+
+static int waking_callback(struct tep_event *event, struct tep_record *record,
+ int cpu, void *data)
+{
+ struct follow_data *fdata = data;
+
+ CU_TEST(cpu == record->cpu);
+ CU_TEST(event->id == fdata->sched_waking->id);
+ return 0;
+}
+
+static int function_callback(struct tep_event *event, struct tep_record *record,
+ int cpu, void *data)
+{
+ struct follow_data *fdata = data;
+
+ CU_TEST(cpu == record->cpu);
+ CU_TEST(event->id == fdata->function->id);
+ return 0;
+}
+
+static int missed_callback(struct tep_event *event, struct tep_record *record,
+ int cpu, void *data)
+{
+ struct follow_data *fdata = data;
+
+ fdata->missed = record->missed_events;
+ return 0;
+}
+
+static int all_callback(struct tep_event *event, struct tep_record *record,
+ int cpu, void *data)
+{
+ struct follow_data *fdata = data;
+
+ CU_TEST(fdata->missed == record->missed_events);
+ fdata->missed = 0;
+ return 0;
+}
+
+static void *stop_thread(void *arg)
+{
+ struct tracefs_instance *instance = arg;
+
+ sleep(1);
+ tracefs_iterate_stop(instance);
+ return NULL;
+}
+
+static void test_instance_follow_events(struct tracefs_instance *instance)
+{
+ struct follow_data fdata;
+ struct tep_handle *tep;
+ pthread_t thread;
+ int ret;
+
+ memset(&fdata, 0, sizeof(fdata));
+
+ tep = tracefs_local_events(NULL);
+ CU_TEST(tep != NULL);
+ if (!tep)
+ return;
+
+ fdata.sched_switch = tep_find_event_by_name(tep, "sched", "sched_switch");
+ CU_TEST(fdata.sched_switch != NULL);
+ if (!fdata.sched_switch)
+ return;
+
+ fdata.sched_waking = tep_find_event_by_name(tep, "sched", "sched_waking");
+ CU_TEST(fdata.sched_waking != NULL);
+ if (!fdata.sched_waking)
+ return;
+
+ fdata.function = tep_find_event_by_name(tep, "ftrace", "function");
+ CU_TEST(fdata.function != NULL);
+ if (!fdata.function)
+ return;
+
+ ret = tracefs_follow_event(tep, instance, "sched", "sched_switch",
+ switch_callback, &fdata);
+ CU_TEST(ret == 0);
+
+ ret = tracefs_follow_event(tep, instance, "sched", "sched_waking",
+ waking_callback, &fdata);
+ CU_TEST(ret == 0);
+
+ ret = tracefs_follow_event(tep, instance, "ftrace", "function",
+ function_callback, &fdata);
+ CU_TEST(ret == 0);
+
+ ret = tracefs_follow_missed_events(instance, missed_callback, &fdata);
+ CU_TEST(ret == 0);
+
+ ret = tracefs_event_enable(instance, "sched", "sched_switch");
+ CU_TEST(ret == 0);
+
+ ret = tracefs_event_enable(instance, "sched", "sched_waking");
+ CU_TEST(ret == 0);
+
+ ret = tracefs_tracer_set(instance, TRACEFS_TRACER_FUNCTION);
+ CU_TEST(ret == 0);
+
+ pthread_create(&thread, NULL, stop_thread, instance);
+
+ ret = tracefs_iterate_raw_events(tep, instance, NULL, 0, all_callback, &fdata);
+ CU_TEST(ret == 0);
+
+ pthread_join(thread, NULL);
+
+ tracefs_tracer_clear(instance);
+ tracefs_event_disable(instance, NULL, NULL);
+}
+
+static void test_follow_events(void)
+{
+ test_instance_follow_events(NULL);
+ test_instance_follow_events(test_instance);
+}
+
static int read_trace_cpu_file(struct test_cpu_data *data)
{
unsigned long long ts;
@@ -2113,6 +2248,7 @@ void test_tracefs_lib(void)
fprintf(stderr, "Suite \"%s\" cannot be ceated\n", TRACEFS_SUITE);
return;
}
+ CU_add_test(suite, "Follow events", test_follow_events);
CU_add_test(suite, "trace cpu read",
test_trace_cpu_read);
CU_add_test(suite, "trace cpu pipe",
--
2.35.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-15 5:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-15 5:02 [PATCH] libtracefs: Add unit tests for the follow functions Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).