[kvm-unit-tests PATCH 1/2] lib/report: Add helper method to clear multiple prefixes

James Raphael Tiovalen jamestiotio at gmail.com
Tue Sep 10 08:08:41 PDT 2024


Add a method to pop a specified number of prefixes. This method is
useful when tests want to clear multiple prefixes at once.

Suggested-by: Andrew Jones <andrew.jones at linux.dev>
Signed-off-by: James Raphael Tiovalen <jamestiotio at gmail.com>
---
 lib/libcflat.h |  1 +
 lib/report.c   | 21 +++++++++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/lib/libcflat.h b/lib/libcflat.h
index 16a83880..eec34c3f 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -96,6 +96,7 @@ void report_prefix_pushf(const char *prefix_fmt, ...)
 					__attribute__((format(printf, 1, 2)));
 extern void report_prefix_push(const char *prefix);
 extern void report_prefix_pop(void);
+extern void report_prefix_popn(int n);
 extern void report(bool pass, const char *msg_fmt, ...)
 		__attribute__((format(printf, 2, 3), nonnull(2)));
 extern void report_xfail(bool xfail, bool pass, const char *msg_fmt, ...)
diff --git a/lib/report.c b/lib/report.c
index 7f3c4f05..0756e64e 100644
--- a/lib/report.c
+++ b/lib/report.c
@@ -60,23 +60,32 @@ void report_prefix_push(const char *prefix)
 	report_prefix_pushf("%s", prefix);
 }
 
-void report_prefix_pop(void)
+static void __report_prefix_pop(void)
 {
 	char *p, *q;
 
-	spin_lock(&lock);
-
-	if (!*prefixes) {
-		spin_unlock(&lock);
+	if (!*prefixes)
 		return;
-	}
 
 	for (p = prefixes, q = strstr(p, PREFIX_DELIMITER) + 2;
 			*q;
 			p = q, q = strstr(p, PREFIX_DELIMITER) + 2)
 		;
 	*p = '\0';
+}
 
+void report_prefix_pop(void)
+{
+	spin_lock(&lock);
+	__report_prefix_pop();
+	spin_unlock(&lock);
+}
+
+void report_prefix_popn(int n)
+{
+	spin_lock(&lock);
+	while (n--)
+		__report_prefix_pop();
 	spin_unlock(&lock);
 }
 
-- 
2.43.0




More information about the kvm-riscv mailing list