All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: Vincent Donnefort <vdonnefort@google.com>,
	"Steven Rostedt (Google)" <rostedt@goodmis.org>
Subject: [PATCH 7/7] libtracefs utest: Add tests to use mapping if supported
Date: Tue,  9 Jan 2024 21:51:51 -0500	[thread overview]
Message-ID: <20240110030116.81837-8-rostedt@goodmis.org> (raw)
In-Reply-To: <20240110030116.81837-1-rostedt@goodmis.org>

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If the memory mapping of the ring buffer is supported, run the tests that do
tracefs_cpu_open() also with tracefs_cpu_open_mapped().

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 utest/tracefs-utest.c | 69 ++++++++++++++++++++++++++++++-------------
 1 file changed, 49 insertions(+), 20 deletions(-)

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index f5afec0e338a..963fac70846d 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -122,6 +122,8 @@ static struct test_sample test_array[TEST_ARRAY_SIZE];
 static int test_found;
 static unsigned long long last_ts;
 
+static bool mapping_is_supported;
+
 static void msleep(int ms)
 {
 	struct timespec tspec;
@@ -1098,7 +1100,7 @@ static int make_trace_temp_file(void)
 	return fd;
 }
 
-static int setup_trace_cpu(struct tracefs_instance *instance, struct test_cpu_data *data, bool nonblock)
+static int setup_trace_cpu(struct tracefs_instance *instance, struct test_cpu_data *data, bool nonblock, bool map)
 {
 	struct tep_format_field **fields;
 	struct tep_event *event;
@@ -1121,7 +1123,11 @@ static int setup_trace_cpu(struct tracefs_instance *instance, struct test_cpu_da
 
 	data->tep = test_tep;
 
-	data->tcpu = tracefs_cpu_open(instance, 0, nonblock);
+	if (map)
+		data->tcpu = tracefs_cpu_open_mapped(instance, 0, nonblock);
+	else
+		data->tcpu = tracefs_cpu_open(instance, 0, nonblock);
+
 	CU_TEST(data->tcpu != NULL);
 	if (!data->tcpu)
 		goto fail;
@@ -1205,14 +1211,17 @@ static void shutdown_trace_cpu(struct test_cpu_data *data)
 	cleanup_trace_cpu(data);
 }
 
-static void reset_trace_cpu(struct test_cpu_data *data, bool nonblock)
+static void reset_trace_cpu(struct test_cpu_data *data, bool nonblock, bool map)
 {
 	close(data->fd);
 	tracefs_cpu_close(data->tcpu);
 
 	data->fd = make_trace_temp_file();
 	CU_TEST(data->fd >= 0);
-	data->tcpu = tracefs_cpu_open(data->instance, 0, nonblock);
+	if (map)
+		data->tcpu = tracefs_cpu_open_mapped(data->instance, 0, nonblock);
+	else
+		data->tcpu = tracefs_cpu_open(data->instance, 0, nonblock);
 	CU_TEST(data->tcpu != NULL);
 }
 
@@ -1252,11 +1261,11 @@ static void test_cpu_read(struct test_cpu_data *data, int expect)
 	CU_TEST(cnt == expect);
 }
 
-static void test_instance_trace_cpu_read(struct tracefs_instance *instance)
+static void test_instance_trace_cpu_read(struct tracefs_instance *instance, bool map)
 {
 	struct test_cpu_data data;
 
-	if (setup_trace_cpu(instance, &data, true))
+	if (setup_trace_cpu(instance, &data, true, map))
 		return;
 
 	test_cpu_read(&data, 1);
@@ -1270,8 +1279,13 @@ static void test_instance_trace_cpu_read(struct tracefs_instance *instance)
 
 static void test_trace_cpu_read(void)
 {
-	test_instance_trace_cpu_read(NULL);
-	test_instance_trace_cpu_read(test_instance);
+	test_instance_trace_cpu_read(NULL, false);
+	if (mapping_is_supported)
+		test_instance_trace_cpu_read(NULL, true);
+
+	test_instance_trace_cpu_read(test_instance, false);
+	if (mapping_is_supported)
+		test_instance_trace_cpu_read(test_instance, true);
 }
 
 static void *trace_cpu_read_thread(void *arg)
@@ -1292,6 +1306,7 @@ static void *trace_cpu_read_thread(void *arg)
 
 static void test_cpu_read_buf_percent(struct test_cpu_data *data, int percent)
 {
+	char buffer[tracefs_cpu_read_size(data->tcpu)];
 	pthread_t thread;
 	int save_percent;
 	ssize_t expect;
@@ -1343,7 +1358,7 @@ static void test_cpu_read_buf_percent(struct test_cpu_data *data, int percent)
 
 	CU_TEST(data->done == true);
 
-	while (tracefs_cpu_flush_buf(data->tcpu))
+	while (tracefs_cpu_flush(data->tcpu, buffer))
 		;
 
 	tracefs_cpu_stop(data->tcpu);
@@ -1353,24 +1368,24 @@ static void test_cpu_read_buf_percent(struct test_cpu_data *data, int percent)
 	CU_TEST(ret == 0);
 }
 
-static void test_instance_trace_cpu_read_buf_percent(struct tracefs_instance *instance)
+static void test_instance_trace_cpu_read_buf_percent(struct tracefs_instance *instance, bool map)
 {
 	struct test_cpu_data data;
 
-	if (setup_trace_cpu(instance, &data, false))
+	if (setup_trace_cpu(instance, &data, false, map))
 		return;
 
 	test_cpu_read_buf_percent(&data, 0);
 
-	reset_trace_cpu(&data, false);
+	reset_trace_cpu(&data, false, map);
 
 	test_cpu_read_buf_percent(&data, 1);
 
-	reset_trace_cpu(&data, false);
+	reset_trace_cpu(&data, false, map);
 
 	test_cpu_read_buf_percent(&data, 50);
 
-	reset_trace_cpu(&data, false);
+	reset_trace_cpu(&data, false, map);
 
 	test_cpu_read_buf_percent(&data, 100);
 
@@ -1379,8 +1394,12 @@ static void test_instance_trace_cpu_read_buf_percent(struct tracefs_instance *in
 
 static void test_trace_cpu_read_buf_percent(void)
 {
-	test_instance_trace_cpu_read_buf_percent(NULL);
-	test_instance_trace_cpu_read_buf_percent(test_instance);
+	test_instance_trace_cpu_read_buf_percent(NULL, false);
+	if (mapping_is_supported)
+		test_instance_trace_cpu_read_buf_percent(NULL, true);
+	test_instance_trace_cpu_read_buf_percent(test_instance, false);
+	if (mapping_is_supported)
+		test_instance_trace_cpu_read_buf_percent(test_instance, true);
 }
 
 struct follow_data {
@@ -1916,11 +1935,11 @@ static void test_cpu_pipe(struct test_cpu_data *data, int expect)
 	CU_TEST(cnt == expect);
 }
 
-static void test_instance_trace_cpu_pipe(struct tracefs_instance *instance)
+static void test_instance_trace_cpu_pipe(struct tracefs_instance *instance, bool map)
 {
 	struct test_cpu_data data;
 
-	if (setup_trace_cpu(instance, &data, true))
+	if (setup_trace_cpu(instance, &data, true, map))
 		return;
 
 	test_cpu_pipe(&data, 1);
@@ -1934,8 +1953,12 @@ static void test_instance_trace_cpu_pipe(struct tracefs_instance *instance)
 
 static void test_trace_cpu_pipe(void)
 {
-	test_instance_trace_cpu_pipe(NULL);
-	test_instance_trace_cpu_pipe(test_instance);
+	test_instance_trace_cpu_pipe(NULL, false);
+	if (mapping_is_supported)
+		test_instance_trace_cpu_pipe(NULL, true);
+	test_instance_trace_cpu_pipe(test_instance, false);
+	if (mapping_is_supported)
+		test_instance_trace_cpu_pipe(test_instance, true);
 }
 
 static struct tracefs_dynevent **get_dynevents_check(enum tracefs_dynevent_type types, int count)
@@ -3557,6 +3580,12 @@ static int test_suite_init(void)
 	if (!test_instance)
 		return 1;
 
+	mapping_is_supported = tracefs_mapped_is_supported();
+	if (mapping_is_supported)
+		printf("Testing mmapped buffers too\n");
+	else
+		printf("Memory mapped buffers not supported\n");
+
 	/* Start with a new slate */
 	tracefs_instance_reset(NULL);
 
-- 
2.43.0


      parent reply	other threads:[~2024-01-10  3:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10  2:51 [PATCH 0/7] libtracefs: More fixes for memory mapping ring buffer API Steven Rostedt
2024-01-10  2:51 ` [PATCH 1/7] libtracefs: Have mapping work with the other tracefs_cpu* functions Steven Rostedt
2024-01-10  2:51 ` [PATCH 2/7] libtracefs: Have tracefs_mmap_read() include subbuf meta data Steven Rostedt
2024-01-10  2:51 ` [PATCH 3/7] libtracefs: Have nonblock tracefs_cpu reads set errno EAGAIN Steven Rostedt
2024-01-10  2:51 ` [PATCH 4/7] libtracefs: Fix tracefs_mmap() kbuf usage Steven Rostedt
2024-01-10  2:51 ` [PATCH 5/7] libtracefs: Call mmap ioctl if a refresh happens Steven Rostedt
2024-01-10  2:51 ` [PATCH 6/7] libtracefs: Add tracefs_mapped_is_supported() API Steven Rostedt
2024-01-10  2:51 ` Steven Rostedt [this message]

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=20240110030116.81837-8-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=vdonnefort@google.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 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.