From patchwork Fri Dec 12 16:06:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 5483661 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1111A9F30B for ; Fri, 12 Dec 2014 16:06:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 28D8920172 for ; Fri, 12 Dec 2014 16:06:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E0A23201D3 for ; Fri, 12 Dec 2014 16:06:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935051AbaLLQGa (ORCPT ); Fri, 12 Dec 2014 11:06:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47872 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933644AbaLLQG3 (ORCPT ); Fri, 12 Dec 2014 11:06:29 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBCG6TPZ008500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 12 Dec 2014 11:06:29 -0500 Received: from hawk.usersys.redhat.com (dhcp-1-108.brq.redhat.com [10.34.1.108]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBCG6Kmm007006; Fri, 12 Dec 2014 11:06:28 -0500 From: Andrew Jones To: kvm@vger.kernel.org Subject: [PATCH 08/10] report: add prefix support Date: Fri, 12 Dec 2014 17:06:15 +0100 Message-Id: <1418400377-17388-9-git-send-email-drjones@redhat.com> In-Reply-To: <1418400377-17388-1-git-send-email-drjones@redhat.com> References: <1418400377-17388-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 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 Add some methods to report in order to manage output prefixes. Also add strstr to string, as it was useful for implementing report_prefix_pop. Prefixes can be useful, as test code frequently has the following pattern main() { foreach(subtest) run(subtest) } But, if we want output lines to include 'subtest: ', then we need report("%s: ...", cond, subtest, ...) for each report line. With push/pop we can now just do subtest() { report_prefix_push(subtest); report(...); ... report(...); report_prefix_pop(); } Signed-off-by: Andrew Jones --- lib/libcflat.h | 2 ++ lib/report.c | 22 ++++++++++++++++++++++ lib/string.c | 17 +++++++++++++++++ lib/string.h | 1 + 4 files changed, 42 insertions(+) diff --git a/lib/libcflat.h b/lib/libcflat.h index 7db29a4f4f3cb..9747ccdbc9f1d 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -57,6 +57,8 @@ extern int snprintf(char *buf, int size, const char *fmt, ...); extern int vsnprintf(char *buf, int size, const char *fmt, va_list va); extern long atol(const char *ptr); +void report_prefix_push(const char *prefix); +void report_prefix_pop(void); void report(const char *msg_fmt, bool pass, ...); void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...); int report_summary(void); diff --git a/lib/report.c b/lib/report.c index 7a9f270b1fafb..dc30250c676d3 100644 --- a/lib/report.c +++ b/lib/report.c @@ -13,6 +13,27 @@ #include "libcflat.h" static unsigned int tests, failures, xfailures; +static char prefixes[256]; + +void report_prefix_push(const char *prefix) +{ + strcat(prefixes, prefix); + strcat(prefixes, ": "); +} + +void report_prefix_pop(void) +{ + char *p, *q; + + if (!*prefixes) + return; + + for (p = prefixes, q = strstr(p, ": ") + 2; + *q; + p = q, q = strstr(p, ": ") + 2) + ; + *p = '\0'; +} void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va) { @@ -22,6 +43,7 @@ void va_report_xfail(const char *msg_fmt, bool xfail, bool cond, va_list va) tests++; printf("%s: ", cond ? pass : fail); + puts(prefixes); vsnprintf(buf, sizeof(buf), msg_fmt, va); puts(buf); puts("\n"); diff --git a/lib/string.c b/lib/string.c index 026f50252287c..e7bcfe945fcfa 100644 --- a/lib/string.c +++ b/lib/string.c @@ -45,6 +45,23 @@ char *strchr(const char *s, int c) return (char *)s; } +char *strstr(const char *s1, const char *s2) +{ + size_t l1, l2; + + l2 = strlen(s2); + if (!l2) + return (char *)s1; + l1 = strlen(s1); + while (l1 >= l2) { + l1--; + if (!memcmp(s1, s2, l2)) + return (char *)s1; + s1++; + } + return NULL; +} + void *memset(void *s, int c, size_t n) { size_t i; diff --git a/lib/string.h b/lib/string.h index dbab368b1b9e4..7820db86ee4e0 100644 --- a/lib/string.h +++ b/lib/string.h @@ -6,6 +6,7 @@ extern char *strcat(char *dest, const char *src); extern char *strcpy(char *dest, const char *src); extern int strcmp(const char *a, const char *b); extern char *strchr(const char *s, int c); +char *strstr(const char *haystack, const char *needle); extern void *memset(void *s, int c, size_t n); extern void *memcpy(void *dest, const void *src, size_t n); extern int memcmp(const void *s1, const void *s2, size_t n);