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
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 7/9] trace-cmd: Unit tests for libtracefs APIs related to ftrace events and systems
Date: Wed, 29 Jan 2020 11:54:19 +0200	[thread overview]
Message-ID: <20200129095421.881786-8-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20200129095421.881786-1-tz.stoyanov@gmail.com>

Added unit tests for these APIs:
  tracefs_event_systems()
  tracefs_system_events()
  tracefs_list_free()

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

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 7930c64..e4ab64f 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -9,6 +9,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <time.h>
+#include <dirent.h>
 
 #include <CUnit/CUnit.h>
 #include <CUnit/Basic.h>
@@ -258,6 +259,69 @@ static void test_instance_file(void)
 	free(inst_dir);
 }
 
+static void exclude_string(char **strings, char *name)
+{
+	int i;
+
+	for (i = 0; strings[i]; i++) {
+		if (strcmp(strings[i], name) == 0) {
+			free(strings[i]);
+			strings[i] = strdup("/");
+			return;
+		}
+	}
+}
+
+static void test_check_files(const char *fdir, char **files)
+{
+	struct dirent *dent;
+	DIR *dir;
+	int i;
+
+	dir = opendir(fdir);
+	CU_TEST(dir != NULL);
+
+	while ((dent = readdir(dir)))
+		exclude_string(files, dent->d_name);
+
+	closedir(dir);
+
+	for (i = 0; files[i]; i++)
+		CU_TEST(files[i][0] == '/');
+}
+
+static void test_system_event(void)
+{
+	const char *tdir;
+	char **systems;
+	char **events;
+	char *sdir = NULL;
+
+	tdir  = tracefs_get_tracing_dir();
+	CU_TEST(tdir != NULL);
+
+	systems = tracefs_event_systems(tdir);
+	CU_TEST(systems != NULL);
+
+	events = tracefs_system_events(tdir, systems[0]);
+	CU_TEST(events != NULL);
+
+	asprintf(&sdir, "%s/events/%s", tdir, systems[0]);
+	CU_TEST(sdir != NULL);
+	test_check_files(sdir, events);
+	free(sdir);
+	sdir = NULL;
+
+	asprintf(&sdir, "%s/events", tdir);
+	CU_TEST(sdir != NULL);
+	test_check_files(sdir, systems);
+
+	tracefs_list_free(systems);
+	tracefs_list_free(events);
+
+	free(sdir);
+}
+
 static int test_suite_destroy(void)
 {
 	tracefs_instance_destroy(test_instance);
@@ -297,6 +361,8 @@ void test_tracefs_lib(void)
 		    test_trace_file);
 	CU_add_test(suite, "instance file / directory APIs",
 		    test_instance_file);
+	CU_add_test(suite, "systems and events APIs",
+		    test_system_event);
 	CU_add_test(suite, "tracefs_iterate_raw_events API",
 		    test_iter_raw_events);
 }
-- 
2.24.1


  parent reply	other threads:[~2020-01-29  9:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-29  9:54 [PATCH 0/9] libtracefs: few fixes and a lot of unit tests Tzvetomir Stoyanov (VMware)
2020-01-29  9:54 ` [PATCH 1/9] trace-cmd: fix description of tracefs_get_tracing_dir() API Tzvetomir Stoyanov (VMware)
2020-01-29  9:54 ` [PATCH 2/9] trace-cmd: Remove tracefs_read_page_record() API Tzvetomir Stoyanov (VMware)
2020-01-29  9:54 ` [PATCH 3/9] trace-cmd: Add sanity check of tracefs_get_tracing_file() input parameter Tzvetomir Stoyanov (VMware)
2020-01-29  9:54 ` [PATCH 4/9] trace-cmd: Unit test for libtracefs Tzvetomir Stoyanov (VMware)
2020-01-29  9:54 ` [PATCH 5/9] trace-cmd: Unit tests for libtracefs APIs related to tracing file / directory Tzvetomir Stoyanov (VMware)
2020-01-29  9:54 ` [PATCH 6/9] trace-cmd: Unit tests for libtracefs APIs related to ftrace instances Tzvetomir Stoyanov (VMware)
2020-01-29  9:54 ` Tzvetomir Stoyanov (VMware) [this message]
2020-01-29  9:54 ` [PATCH 8/9] trace-cmd: Unit test for tracefs_tracers() API Tzvetomir Stoyanov (VMware)
2020-01-29  9:54 ` [PATCH 9/9] trace-cmd: Unit tests for libtracefs APIs related to allocating a tep handler based on local events 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=20200129095421.881786-8-tz.stoyanov@gmail.com \
    --to=tz.stoyanov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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).