linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org, y.karadz@gmail.com
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v5 08/12] libtracefs: Add unit test for synthetic events
Date: Fri,  5 Nov 2021 14:16:20 +0200	[thread overview]
Message-ID: <20211105121624.398717-9-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20211105121624.398717-1-tz.stoyanov@gmail.com>

All tracefs library APIs should be covered in the unit test. There is
unit test section for the tracefs_sql* set of APIs, which use synthetic
events internally, but no tests for the tracefs_synthetic* APIs.
An initial unit test section is added for tracefs_synthetic* APIs. Not
all APIs are covered, that section should be extended. Unit tests for
basic tracefs_synthetic* APIs are added, to test the changes related to
dynamic events code in the library, related to synthetic events.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 utest/tracefs-utest.c | 95 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 5b656d4..6287f31 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -403,6 +403,100 @@ static struct tracefs_dynevent **get_dynevents_check(enum tracefs_dynevent_type
 	return devents;
 }
 
+
+struct test_synth {
+	char *name;
+	char *start_system;
+	char *start_event;
+	char *end_system;
+	char *end_event;
+	char *start_match_field;
+	char *end_match_field;
+	char *match_name;
+};
+
+static void test_synth_compare(struct test_synth *synth, struct tracefs_dynevent **devents)
+{
+	enum tracefs_dynevent_type stype;
+	char *format;
+	char *event;
+	int i;
+
+	for (i = 0; devents && devents[i]; i++) {
+		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 (synth[i].match_name) {
+			CU_TEST(strstr(format, synth[i].match_name) != NULL);
+		}
+	}
+	CU_TEST(devents[i] == NULL);
+}
+
+static void test_instance_syntetic(struct tracefs_instance *instance)
+{
+	struct test_synth sevents[] = {
+		{"synth_1", "sched", "sched_waking", "sched", "sched_switch", "pid", "next_pid", "pid_match"},
+		{"synth_2", "syscalls", "sys_enter_openat2", "syscalls", "sys_exit_openat2", "__syscall_nr", "__syscall_nr", "nr_match"},
+	};
+	int sevents_count = sizeof(sevents) / sizeof((sevents)[0]);
+	struct tracefs_dynevent **devents;
+	struct tracefs_synth **synth;
+	struct tep_handle *tep;
+	int ret;
+	int i;
+
+	synth = calloc(sevents_count + 1, sizeof(*synth));
+
+	tep = tracefs_local_events(NULL);
+	CU_TEST(tep != NULL);
+
+	/* kprobes APIs */
+	ret = tracefs_dynevent_destroy_all(TRACEFS_DYNEVENT_SYNTH, true);
+	CU_TEST(ret == 0);
+	get_dynevents_check(TRACEFS_DYNEVENT_SYNTH, 0);
+
+	for (i = 0; i < sevents_count; i++) {
+		synth[i] = tracefs_synth_alloc(tep,  sevents[i].name,
+					       sevents[i].start_system, sevents[i].start_event,
+					       sevents[i].end_system, sevents[i].end_event,
+					       sevents[i].start_match_field, sevents[i].end_match_field,
+					       sevents[i].match_name);
+		CU_TEST(synth[i] != NULL);
+	}
+
+	get_dynevents_check(TRACEFS_DYNEVENT_SYNTH, 0);
+
+	for (i = 0; i < sevents_count; i++) {
+		ret = tracefs_synth_create(instance, synth[i]);
+		CU_TEST(ret == 0);
+	}
+
+	devents = get_dynevents_check(TRACEFS_DYNEVENT_SYNTH, sevents_count);
+	CU_TEST(devents != NULL);
+	test_synth_compare(sevents, devents);
+	tracefs_dynevent_list_free(devents);
+
+	for (i = 0; i < sevents_count; i++) {
+		ret = tracefs_synth_destroy(instance, synth[i]);
+		CU_TEST(ret == 0);
+	}
+
+	get_dynevents_check(TRACEFS_DYNEVENT_SYNTH, 0);
+
+	for (i = 0; i < sevents_count; i++)
+		tracefs_synth_free(synth[i]);
+
+	tep_free(tep);
+	free(synth);
+}
+
+static void test_synthetic(void)
+{
+	test_instance_syntetic(test_instance);
+}
+
 static void test_trace_file(void)
 {
 	const char *tmp = get_rand_str();
@@ -1525,4 +1619,5 @@ void test_tracefs_lib(void)
 	CU_add_test(suite, "ftrace marker",
 		    test_ftrace_marker);
 	CU_add_test(suite, "kprobes", test_kprobes);
+	CU_add_test(suite, "syntetic events", test_synthetic);
 }
-- 
2.31.1


  parent reply	other threads:[~2021-11-05 12:16 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05 12:16 [PATCH v5 00/12] libtracefs dynamic events support Tzvetomir Stoyanov (VMware)
2021-11-05 12:16 ` [PATCH v5 01/12] libtracefs: New APIs for dynamic events Tzvetomir Stoyanov (VMware)
2021-11-05 15:03   ` Steven Rostedt
2021-11-05 15:21     ` Tzvetomir Stoyanov
2021-11-05 15:27       ` Steven Rostedt
2021-11-05 15:08   ` Steven Rostedt
2021-11-05 15:12     ` Steven Rostedt
2021-11-05 12:16 ` [PATCH v5 02/12] libtracefs: New APIs for kprobe allocation Tzvetomir Stoyanov (VMware)
2021-11-05 12:16 ` [PATCH v5 03/12] libtracefs: Remove redundant kprobes APIs Tzvetomir Stoyanov (VMware)
2021-11-05 12:16 ` [PATCH v5 04/12] libtracefs: Reimplement kprobe raw APIs Tzvetomir Stoyanov (VMware)
2021-11-05 12:16 ` [PATCH v5 05/12] libtracefs: Extend kprobes unit test Tzvetomir Stoyanov (VMware)
2021-11-05 12:16 ` [PATCH v5 06/12] libtracefs: Rename tracefs_synth_init API Tzvetomir Stoyanov (VMware)
2021-11-05 12:16 ` [PATCH v5 07/12] libtracefs: Use the internal dynamic events API when creating synthetic events Tzvetomir Stoyanov (VMware)
2021-11-05 12:16 ` Tzvetomir Stoyanov (VMware) [this message]
2021-11-05 12:16 ` [PATCH v5 09/12] libtracefs: Update kprobes man pages Tzvetomir Stoyanov (VMware)
2021-11-05 12:16 ` [PATCH v5 10/12] libtracefs: Document dynamic events APIs Tzvetomir Stoyanov (VMware)
2021-11-05 12:16 ` [PATCH v5 11/12] libtracefs: Remove man page compile artifact Tzvetomir Stoyanov (VMware)
2021-11-05 14:24   ` Steven Rostedt
2021-11-05 14:34     ` Tzvetomir Stoyanov
2021-11-05 14:40       ` Tzvetomir Stoyanov
2021-11-05 14:45         ` Steven Rostedt
2021-11-05 14:44       ` Steven Rostedt
2021-11-05 12:16 ` [PATCH v5 12/12] libtracefs: Fix duplication in synthetic events man page Tzvetomir Stoyanov (VMware)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211105121624.398717-9-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=y.karadz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).