[PATCH 02/18] lib/report: guard access to counters

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

 



Use a lock to avoid exposing the counters, and any other
global data, to potential races.

Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 lib/report.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/report.c b/lib/report.c
index dc30250c676d3..35e664108a921 100644
--- a/lib/report.c
+++ b/lib/report.c
@@ -11,20 +11,26 @@
  */
 
 #include "libcflat.h"
+#include "asm/spinlock.h"
 
 static unsigned int tests, failures, xfailures;
 static char prefixes[256];
+static struct spinlock lock;
 
 void report_prefix_push(const char *prefix)
 {
+	spin_lock(&lock);
 	strcat(prefixes, prefix);
 	strcat(prefixes, ": ");
+	spin_unlock(&lock);
 }
 
 void report_prefix_pop(void)
 {
 	char *p, *q;
 
+	spin_lock(&lock);
+
 	if (!*prefixes)
 		return;
 
@@ -33,6 +39,8 @@ void report_prefix_pop(void)
 			p = q, q = strstr(p, ": ") + 2)
 		;
 	*p = '\0';
+
+	spin_unlock(&lock);
 }
 
 void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va)
@@ -41,6 +49,8 @@ void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va)
 	char *fail = xfail ? "XFAIL" : "FAIL";
 	char buf[2000];
 
+	spin_lock(&lock);
+
 	tests++;
 	printf("%s: ", cond ? pass : fail);
 	puts(prefixes);
@@ -53,6 +63,8 @@ void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va)
 		xfailures++;
 	else if (!cond)
 		failures++;
+
+	spin_unlock(&lock);
 }
 
 void report(const char *msg_fmt, bool pass, ...)
@@ -73,10 +85,14 @@ void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...)
 
 int report_summary(void)
 {
+	spin_lock(&lock);
+
 	printf("\nSUMMARY: %d tests, %d unexpected failures", tests, failures);
 	if (xfailures)
 		printf(", %d expected failures\n", xfailures);
 	else
 		printf("\n");
 	return failures > 0 ? 1 : 0;
+
+	spin_unlock(&lock);
 }
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[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