diff mbox series

[2/3] libtracefs utest: Fix min percent test

Message ID 20241017200609.932728-3-rostedt@goodmis.org (mailing list archive)
State New
Headers show
Series libtracefs utest: Fixes and new tests | expand

Commit Message

Steven Rostedt Oct. 17, 2024, 8:03 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

On PowerPC 64 which has 64K pages, it screws up the accounting of some
calculations used for tests. For instance, 1% of the ring buffer may not
be more than a page. So testing 1% and then subtracting the number of
events per page is going to lead to a negative number. This will obviously
fail.

Take into account that the subbuffer may be very large, and to make a
minimum percent to use in case a subbuffer size is greater than 1%.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=219358
Reported-by: Adrien Nader <adrien@notk.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 utest/tracefs-utest.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 742f4546bef0..b5095a18bb16 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -1340,6 +1340,17 @@  static void test_cpu_read_buf_percent(struct test_cpu_data *data, int percent)
 
 	/* For percent == 0, just test for any data */
 	if (percent) {
+		int min_percent;
+
+		/*
+		 * For architectures like PowerPC with 64K PAGE_SIZE and thus
+		 * large sub buffers, where we will not have over 100 sub buffers
+		 * percent must at least cover more than 1 sub buffer.
+		 */
+		min_percent = (100 + (data->nr_subbufs - 1)) / data->nr_subbufs;
+		if (percent < min_percent)
+			percent = min_percent;
+
 		expect = data->nr_subbufs * data->events_per_buf * percent / 100;
 
 		/* Add just under the percent */