diff mbox series

[2/3] libtracefs: Add tests for the new methods for writing

Message ID 20210415121311.59787-3-y.karadz@gmail.com (mailing list archive)
State Accepted
Commit 749283b51adcbfd664137b330938439351102405
Headers show
Series New methods for writing to file | expand

Commit Message

Yordan Karadzhov April 15, 2021, 12:13 p.m. UTC
We add testing for "int tracefs_instance_file_append()" and
"int tracefs_instance_file_clear()".
The test case performs registration and deregistration of kprobes.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 utest/tracefs-utest.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
diff mbox series

Patch

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index d675c16..edb3a3d 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -28,6 +28,11 @@ 
 #define TRACE_ON	"tracing_on"
 #define TRACE_CLOCK	"trace_clock"
 
+#define KPROB_EVTS	"kprobe_events"
+#define KPROBE_1	"p:mkdir do_mkdirat path=+u0($arg2):ustring"
+#define KPROBE_1_RM	"-:mkdir"
+#define KPROBE_2	"p:open do_sys_openat2 file=+u0($arg2):ustring flags=+0($arg3):x64"
+
 static struct tracefs_instance *test_instance;
 static struct tep_handle *test_tep;
 struct test_sample {
@@ -375,6 +380,7 @@  static void test_instance_file(void)
 	char *inst_file;
 	char *inst_dir;
 	struct stat st;
+	char *kprobes;
 	char *fname;
 	char *file1;
 	char *file2;
@@ -443,6 +449,32 @@  static void test_instance_file(void)
 	free(file1);
 	free(file2);
 
+	ret = tracefs_instance_file_write(NULL, KPROB_EVTS, KPROBE_1);
+	CU_TEST(ret == strlen(KPROBE_1));
+	kprobes = tracefs_instance_file_read(NULL, KPROB_EVTS, &size);
+	CU_TEST(kprobes != NULL);
+	CU_TEST(strstr(kprobes, KPROBE_1 + 2) != NULL);
+	free(kprobes);
+
+	ret = tracefs_instance_file_append(NULL, KPROB_EVTS, KPROBE_2);
+	CU_TEST(ret == strlen(KPROBE_2));
+	kprobes = tracefs_instance_file_read(NULL, KPROB_EVTS, &size);
+	CU_TEST(kprobes != NULL);
+	CU_TEST(strstr(kprobes, KPROBE_2 + 2) != NULL);
+	free(kprobes);
+
+	ret = tracefs_instance_file_append(NULL, KPROB_EVTS, KPROBE_1_RM);
+	CU_TEST(ret == strlen(KPROBE_1_RM));
+	kprobes = tracefs_instance_file_read(NULL, KPROB_EVTS, &size);
+	CU_TEST(kprobes != NULL);
+	CU_TEST(strstr(kprobes, KPROBE_1 + 2) == NULL);
+	free(kprobes);
+
+	ret = tracefs_instance_file_clear(NULL, KPROB_EVTS);
+	CU_TEST(ret == 0);
+	kprobes = tracefs_instance_file_read(NULL, KPROB_EVTS, &size);
+	CU_TEST(kprobes == NULL);
+
 	tracefs_put_tracing_file(inst_file);
 	free(fname);