From patchwork Fri Apr 21 00:49:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 9691559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 112C46038D for ; Fri, 21 Apr 2017 00:51:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02A0A2843F for ; Fri, 21 Apr 2017 00:51:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAA682847C; Fri, 21 Apr 2017 00:51:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12BDC2843F for ; Fri, 21 Apr 2017 00:51:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034323AbdDUAvY (ORCPT ); Thu, 20 Apr 2017 20:51:24 -0400 Received: from mail-oi0-f48.google.com ([209.85.218.48]:36385 "EHLO mail-oi0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033707AbdDUAu3 (ORCPT ); Thu, 20 Apr 2017 20:50:29 -0400 Received: by mail-oi0-f48.google.com with SMTP id r203so73049123oib.3 for ; Thu, 20 Apr 2017 17:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4ACAMuSbHQDfSXpWFHKGsrbQVxdDYz7X0RiJWL+1N3I=; b=ZBWo0Zdi8+EMu5TVM7D4QnTIrRONzQi/sM9uTVU56DNv//I3JINKGrQvigFZCPB3Yw WNgRFGXnHt7kGHyAd+01NtxoEvLgK4xyrJ3j8FoPARz/qIoJqZwvsgEeO+o7CCp69vuF 6u2D6WYbiE3hWUolyJIsI6jKjrIINojeWDeEr2feGFg61tlQbhpP4obDQzJuFUJTCHBq doJjy0iaKYw2Dy6t8bt8bX5RY18roVlUNTwKV0uuSlWkVCENH93ANdwIVHsF98SVXAiy pbEEZguL9Pm2C5ELig8mMA640OUzopinQX6H9hrbAkOXxC8TfhZN7+pkPzod/VY2db6v QiyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4ACAMuSbHQDfSXpWFHKGsrbQVxdDYz7X0RiJWL+1N3I=; b=Or+dH3DPmL833h2NWISs7PCWMytu9FIdyiOywhh/6ZViodhc23YH29NuKdnxYT6VFq 6yEbu+XIPajvZAnvvoEHIzWW+JEAyUPJdhRnGOiJM05otuegBbvYKlv0q9iVHiDc712U UO3DPm5SEhKjhBLUZuKPpJOhzAAp6+tNtPrEYoN2xYa8tMpmkra+F4677bDtoMwYjUCL IRAouHTfJiSs+5UvMuMD7m3hwI79ylhn4ifssunWcGwCC0o3EDF2YBLhFhda/iqoAThk jk77NJeM8DAsH8rHO+xDj55lYaqrKRF1Sz0do/0+gOs/Q9FQr5yrR4TREXHeUjDQRNxj rtZg== X-Gm-Message-State: AN3rC/6c57uU9EXoB6z2vR+DJoImTXX7ZAjEsaGM71We8yDWvLLdjGWo znto6NvyyCggLC9y X-Received: by 10.84.229.2 with SMTP id b2mr12991038plk.154.1492735828520; Thu, 20 Apr 2017 17:50:28 -0700 (PDT) Received: from dmatlack.sea.corp.google.com ([100.100.206.82]) by smtp.gmail.com with ESMTPSA id e13sm12466486pfb.30.2017.04.20.17.50.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Apr 2017 17:50:27 -0700 (PDT) From: David Matlack To: kvm@vger.kernel.org Cc: Peter Feiner , David Matlack Subject: [kvm-unit-tests PATCH 21/32] lib: printf-style report prefixes Date: Thu, 20 Apr 2017 17:49:53 -0700 Message-Id: <20170421005004.137260-22-dmatlack@google.com> X-Mailer: git-send-email 2.12.2.816.g2cccc81164-goog In-Reply-To: <20170421005004.137260-1-dmatlack@google.com> References: <20170421005004.137260-1-dmatlack@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Feiner Signed-off-by: Peter Feiner Signed-off-by: David Matlack Reviewed-by: Andrew Jones --- lib/libcflat.h | 1 + lib/report.c | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/libcflat.h b/lib/libcflat.h index 5d356df75f1f..05c18543dd72 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -96,6 +96,7 @@ extern int vsnprintf(char *buf, int size, const char *fmt, va_list va) extern int vprintf(const char *fmt, va_list va) __attribute__((format(printf, 1, 0))); +void report_prefix_pushf(const char *prefix_fmt, ...); extern void report_prefix_push(const char *prefix); extern void report_prefix_pop(void); extern void report(const char *msg_fmt, bool pass, ...); diff --git a/lib/report.c b/lib/report.c index e24e81382f9e..1033f1e44e99 100644 --- a/lib/report.c +++ b/lib/report.c @@ -17,14 +17,42 @@ static unsigned int tests, failures, xfailures, skipped; static char prefixes[256]; static struct spinlock lock; -void report_prefix_push(const char *prefix) +#define PREFIX_DELIMITER ": " + +void report_prefix_pushf(const char *prefix_fmt, ...) { + va_list va; + int len; + int start; + spin_lock(&lock); - strcat(prefixes, prefix); - strcat(prefixes, ": "); + + len = strlen(prefixes); + assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes)); + start = len; + + va_start(va, prefix_fmt); + len += vsnprintf(&prefixes[len], sizeof(prefixes) - len, prefix_fmt, + va); + va_end(va); + assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes)); + + assert_msg(!strstr(&prefixes[start], PREFIX_DELIMITER), + "Prefix \"%s\" contains delimiter \"" PREFIX_DELIMITER "\"", + &prefixes[start]); + + len += snprintf(&prefixes[len], sizeof(prefixes) - len, + PREFIX_DELIMITER); + assert_msg(len < sizeof(prefixes), "%d >= %lu", len, sizeof(prefixes)); + spin_unlock(&lock); } +void report_prefix_push(const char *prefix) +{ + report_prefix_pushf("%s", prefix); +} + void report_prefix_pop(void) { char *p, *q; @@ -34,9 +62,9 @@ void report_prefix_pop(void) if (!*prefixes) return; - for (p = prefixes, q = strstr(p, ": ") + 2; + for (p = prefixes, q = strstr(p, PREFIX_DELIMITER) + 2; *q; - p = q, q = strstr(p, ": ") + 2) + p = q, q = strstr(p, PREFIX_DELIMITER) + 2) ; *p = '\0';