linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: tz.stoyanov@gmail.com, linux-trace-devel@vger.kernel.org,
	"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 2/3] libtracefs: Add tests for the new methods for writing
Date: Thu, 15 Apr 2021 15:13:10 +0300	[thread overview]
Message-ID: <20210415121311.59787-3-y.karadz@gmail.com> (raw)
In-Reply-To: <20210415121311.59787-1-y.karadz@gmail.com>

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 --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);
 
-- 
2.25.1


  parent reply	other threads:[~2021-04-15 12:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-15 12:13 [PATCH 0/3] New methods for writing to file Yordan Karadzhov (VMware)
2021-04-15 12:13 ` [PATCH 1/3] libtracefs: Add more methods for writing to files Yordan Karadzhov (VMware)
2021-04-15 12:13 ` Yordan Karadzhov (VMware) [this message]
2021-04-15 12:13 ` [PATCH 3/3] libtracefs: Document the new methods for writing to file Yordan Karadzhov (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=20210415121311.59787-3-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tz.stoyanov@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).