Skip to contentSkip to conversation

libtracefs utest: Limit trace cpu read test to available sub-buffers

PATCH New Jamie Dolan 1 participant 1 message Dec 4

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtracefs utest: Limit trace cpu read test to available sub-buffers

Commit 65f629e ("libtracefs utest: Do not test more events than what the ring buffer can hold") added a check to limit the number of events generated during the "trace cpu read" test.

However, on architectures with larger page sizes, such as ppc64el with a 64K PAGE_SIZE, the ring buffer may contain fewer than 50 sub-buffers. This can cause the buffer to overflow and the test to read fewer events than expected.

Use data.nr_subbufs to limit the number of events generated when 50 or fewer sub-buffers are available.

This follows the approach suggested by Adrien Nader and Steven Rostedt in the upstream Bugzilla discussion, which was subsequently tested successfully on arm64 and ppc64el.

Fixes 65f629e0933b ("libtracefs utest: Do not test more events than what the ring buffer can hold")

Bug-Ubuntu: https://launchpad.net/bugs/2062119

---
 utest/tracefs-utest.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
utest/tracefs-utest.c +1 -10
index e48232c..2eb4897 100644
@@ -1271,8 +1271,6 @@ static void test_cpu_read(struct test_cpu_data *data, int expect)
 static void test_instance_trace_cpu_read(struct tracefs_instance *instance, bool map)
 {
 	struct test_cpu_data data;
-	size_t buffer_size;
-	int big_num = 50;
 
 	if (setup_trace_cpu(instance, &data, true, map))
 		return;
@@ -1281,14 +1279,7 @@ static void test_instance_trace_cpu_read(struct tracefs_instance *instance, bool
 	test_cpu_read(&data, data.events_per_buf / 2);
 	test_cpu_read(&data, data.events_per_buf);
 	test_cpu_read(&data, data.events_per_buf + 1);
-
-	buffer_size = tracefs_instance_get_buffer_size(instance, 0) * 1024;
-	if (data.events_per_buf * big_num > (buffer_size - data.events_per_buf)) {
-		big_num = (buffer_size / data.events_per_buf);
-		big_num -= data.events_per_buf * 2;
-		CU_TEST(big_num > 0);
-	}
-	test_cpu_read(&data, data.events_per_buf * big_num);
+	test_cpu_read(&data, data.events_per_buf * (50 < data.nr_subbufs ? 50 : data.nr_subbufs - 1));
 
 	shutdown_trace_cpu(&data);
 }
Signature · 1 line
2.43.0