aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2022-08-05 11:40:34 -0400
committerSteven Rostedt (Google) <rostedt@goodmis.org>2022-08-05 11:45:10 -0400
commitd83b6628927326d158ccd5766dea42cb5925b051 (patch)
treefe8f9a291b783587e70b82dea92bb2ab218b6478
parent2cb6cc2f4e556a9c7a011a5932720b2832324ee7 (diff)
downloadtrace-cmd-d83b6628927326d158ccd5766dea42cb5925b051.tar.gz
tracecmd utest: Add test to test using the libraries to read
Add a test that uses tracecmd_open() and tracecmd_iterate_events() to read a trace.dat file. Link: https://lore.kernel.org/linux-trace-devel/20220805154040.2014381-4-rostedt@goodmis.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--utest/Makefile4
-rw-r--r--utest/tracecmd-utest.c53
2 files changed, 55 insertions, 2 deletions
diff --git a/utest/Makefile b/utest/Makefile
index 2b8f85f2..d475bad5 100644
--- a/utest/Makefile
+++ b/utest/Makefile
@@ -10,7 +10,9 @@ OBJS =
OBJS += trace-utest.o
OBJS += tracecmd-utest.o
-LIBS += -lcunit $(LIBTRACEEVENT_LDLAGS) $(LIBTRACEFS_LDLAGS)
+LIBS += $(LIBTRACECMD_STATIC) -lcunit $(LIBTRACEEVENT_LDLAGS) $(LIBTRACEFS_LDLAGS)
+
+LIBS += $(ZLIB_LDLAGS) $(LIBZSTD_LDLAGS)
OBJS := $(OBJS:%.o=$(bdir)/%.o)
DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d)
diff --git a/utest/tracecmd-utest.c b/utest/tracecmd-utest.c
index 7db5999e..e45b3537 100644
--- a/utest/tracecmd-utest.c
+++ b/utest/tracecmd-utest.c
@@ -17,7 +17,7 @@
#include <CUnit/CUnit.h>
#include <CUnit/Basic.h>
-#include <tracefs.h>
+#include <trace-cmd.h>
#include "trace-utest.h"
@@ -244,6 +244,55 @@ static void test_trace_convert6(void)
CU_TEST(ret == 0);
}
+struct callback_data {
+ long counter;
+ struct trace_seq seq;
+};
+
+static int read_events(struct tracecmd_input *handle, struct tep_record *record,
+ int cpu, void *data)
+{
+ struct tep_handle *tep = tracecmd_get_tep(handle);
+ struct callback_data *cd = data;
+ struct trace_seq *seq = &cd->seq;
+
+ cd->counter++;
+
+ trace_seq_reset(seq);
+ tep_print_event(tep, seq, record, "%6.1000d", TEP_PRINT_TIME);
+ trace_seq_printf(seq, " [%03d] ", cpu);
+ tep_print_event(tep, seq, record, "%s-%d %s %s\n",
+ TEP_PRINT_COMM, TEP_PRINT_PID,
+ TEP_PRINT_NAME, TEP_PRINT_INFO);
+ trace_seq_do_printf(seq);
+ return 0;
+}
+
+static void test_trace_library_read(void)
+{
+ struct tracecmd_input *handle;
+ struct callback_data data;
+ struct stat st;
+ int ret;
+
+ data.counter = 0;
+ trace_seq_init(&data.seq);
+
+ /* If the trace data is already created, just use it, otherwise make it again */
+ if (stat(TRACECMD_FILE, &st) < 0) {
+ ret = run_trace("record", TRACECMD_OUT, "-e", "sched", "sleep", "1", NULL);
+ CU_TEST(ret == 0);
+ }
+
+ handle = tracecmd_open(TRACECMD_FILE, 0);
+ CU_TEST(handle != NULL);
+ ret = tracecmd_iterate_events(handle, NULL, 0, read_events, &data);
+ CU_TEST(ret == 0);
+
+ CU_TEST(data.counter > 0);
+ trace_seq_destroy(&data.seq);
+}
+
static int test_suite_destroy(void)
{
unlink(TRACECMD_FILE);
@@ -292,4 +341,6 @@ void test_tracecmd_lib(void)
test_trace_record_report);
CU_add_test(suite, "Test convert from v7 to v6",
test_trace_convert6);
+ CU_add_test(suite, "Use libraries to read file",
+ test_trace_library_read);
}