All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libtracefs: Unit test for the tracing filter API
@ 2021-04-03  2:01 Sameeruddin shaik
  2021-04-02 14:56 ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Sameeruddin shaik @ 2021-04-03  2:01 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, tz.stoyanov, Sameeruddin shaik

tracefs_function_filter();

Signed-off-by: Sameeruddin shaik <sameeruddin.shaik8@gmail.com>

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index ed2693b..09e564f 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -11,6 +11,7 @@
 #include <time.h>
 #include <dirent.h>
 #include <ftw.h>
+#include <errno.h>
 
 #include <CUnit/CUnit.h>
 #include <CUnit/Basic.h>
@@ -1020,6 +1021,80 @@ static void test_custom_trace_dir(void)
 	free(dname);
 }
 
+static int test_instance_filter(struct tracefs_instance *instance,
+				const char **filters, const char *module,
+				int flags)
+{
+	int ret;
+	int i;
+
+	if (filters) {
+		for (i = 0; filters[i]; i++) {
+			ret = tracefs_function_filter(instance, filters[i],
+						      module, flags);
+			if (ret) {
+				if (errno == EINVAL)
+					printf("Filter %s did not match\n",
+					       filters[i]);
+				else
+					printf("Failed writing %s\n",
+					       filters[i]);
+			}
+		}
+	} else {
+		ret = tracefs_function_filter(instance, NULL, module, flags);
+	}
+	return ret;
+}
+
+static void test_tracefs_function_filter(void)
+{
+	const char *filter[] = {"run_init_process", "ufs*", "^ext4.*$", NULL};
+	const char *future_filter[] = {"write_dummy", "read_dummy", NULL};
+	const char *future_module = "dummy";
+	struct tracefs_instance *instance;
+	const char *module = "btrtl";
+	int ret;
+
+	instance = tracefs_instance_create(TEST_INSTANCE_NAME);
+	CU_TEST(instance != NULL);
+
+	ret = tracefs_function_filter(instance, NULL, NULL,
+				      TRACEFS_FL_RESET | TRACEFS_FL_CONTINUE);
+	if (ret) {
+		printf("Failed to reset the filter\n");
+		if (ret < 0)
+			tracefs_function_filter(instance, NULL, NULL, 0);
+	}
+	/* Test string, kernel glob and regex for specific_instance*/
+	ret = test_instance_filter(instance, filter, NULL, TRACEFS_FL_CONTINUE);
+	CU_ASSERT(ret == 0);
+	/* Test Module only with no filters*/
+	ret = test_instance_filter(instance, NULL, module, TRACEFS_FL_CONTINUE);
+	CU_ASSERT(ret == 0);
+	ret = test_instance_filter(instance, future_filter, future_module,
+				   TRACEFS_FL_CONTINUE | TRACEFS_FL_FUTURE);
+	CU_ASSERT(ret == 0);
+	tracefs_function_filter(instance, NULL, NULL, 0);
+
+	ret = tracefs_function_filter(NULL, NULL, NULL,
+				      TRACEFS_FL_RESET | TRACEFS_FL_CONTINUE);
+	if (ret) {
+		printf("Failed to reset the filter\n");
+		if (ret < 0)
+			tracefs_function_filter(instance, NULL, NULL, 0);
+	}
+	/* Test top instance*/
+	ret = test_instance_filter(NULL, filter, NULL, TRACEFS_FL_CONTINUE);
+	CU_ASSERT(ret == 0);
+	ret = test_instance_filter(NULL, NULL, module, TRACEFS_FL_CONTINUE);
+	CU_ASSERT(ret == 0);
+	ret = test_instance_filter(NULL, future_filter, future_module,
+				   TRACEFS_FL_CONTINUE | TRACEFS_FL_FUTURE);
+	CU_ASSERT(ret == 0);
+	tracefs_function_filter(NULL, NULL, NULL, 0);
+}
+
 static int test_suite_destroy(void)
 {
 	tracefs_instance_destroy(test_instance);
@@ -1075,4 +1150,6 @@ void test_tracefs_lib(void)
 		    test_tracing_options);
 	CU_add_test(suite, "custom system directory",
 		    test_custom_trace_dir);
+	CU_add_test(suite, "Set Filter API",
+		    test_tracefs_function_filter);
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-06  0:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-03  2:01 [PATCH] libtracefs: Unit test for the tracing filter API Sameeruddin shaik
2021-04-02 14:56 ` Steven Rostedt
2021-04-07  0:44   ` sameeruddin shaik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.