aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2022-11-15 00:02:56 -0500
committerSteven Rostedt (Google) <rostedt@goodmis.org>2022-11-15 09:57:16 -0500
commit2221ce0ec1284bdc99476af547f8460a645fd120 (patch)
tree04f90a10a5a35202819dcb338049acb85d3089e1
parent445014301140e795bf451b739c33ac8514d38660 (diff)
downloadlibtracefs-2221ce0ec1284bdc99476af547f8460a645fd120.tar.gz
libtracefs: Add unit tests for the follow functions
Add unit tests for tracefs_follow_events() and tracefs_follow_missed_events(). Link: https://lore.kernel.org/linux-trace-devel/20221115000256.5a0c89d8@gandalf.local.home Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--utest/tracefs-utest.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 2c9b267..010ff1d 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",