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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
Signed-off-by: James Raphael Tiovalen <jamestiotio@xxxxxxxxx>
---
 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





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux