@@ -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);
}
Use a lock to avoid exposing the counters, and any other global data, to potential races. Signed-off-by: Andrew Jones <drjones@redhat.com> --- lib/report.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)