From patchwork Sun Feb 1 18:34:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 5757491 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 527929F269 for ; Sun, 1 Feb 2015 18:35:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8EEEC2026F for ; Sun, 1 Feb 2015 18:35:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A084A20260 for ; Sun, 1 Feb 2015 18:35:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753818AbbBASfA (ORCPT ); Sun, 1 Feb 2015 13:35:00 -0500 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 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t11IYseu025543 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 1 Feb 2015 13:34:55 -0500 Received: from hawk.usersys.redhat.com ([10.34.1.145]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t11IYnLS003050; Sun, 1 Feb 2015 13:34:53 -0500 From: Andrew Jones To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: christoffer.dall@linaro.org, pbonzini@redhat.com 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> In-Reply-To: <1422815686-24591-1-git-send-email-drjones@redhat.com> References: <1422815686-24591-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); }