From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Jones Subject: [PATCH 02/18] lib/report: guard access to counters Date: Sun, 1 Feb 2015 19:34:30 +0100 Message-ID: <1422815686-24591-3-git-send-email-drjones@redhat.com> References: <1422815686-24591-1-git-send-email-drjones@redhat.com> Cc: christoffer.dall@linaro.org, pbonzini@redhat.com To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:37045 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753681AbbBASe6 (ORCPT ); Sun, 1 Feb 2015 13:34:58 -0500 In-Reply-To: <1422815686-24591-1-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Use a lock to avoid exposing the counters, and any other global data, to potential races. Signed-off-by: Andrew Jones --- 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