From patchwork Fri Apr 21 00:49:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Matlack X-Patchwork-Id: 9691515 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 2BD6C6038D for ; Fri, 21 Apr 2017 00:50:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D7722847B for ; Fri, 21 Apr 2017 00:50:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11FD42848D; Fri, 21 Apr 2017 00:50:37 +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 A81762847B for ; Fri, 21 Apr 2017 00:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033749AbdDUAuY (ORCPT ); Thu, 20 Apr 2017 20:50:24 -0400 Received: from mail-oi0-f43.google.com ([209.85.218.43]:33934 "EHLO mail-oi0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033687AbdDUAuS (ORCPT ); Thu, 20 Apr 2017 20:50:18 -0400 Received: by mail-oi0-f43.google.com with SMTP id x184so74072045oia.1 for ; Thu, 20 Apr 2017 17:50:18 -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=OTpRvCDn65QO0kY9KBig2u7PNK/HjQJ3t4f8HoKax9o=; b=eGl8r4KM4k/qhlqeithZ06RsinAJ32S8vDZvAsPwYgg8K/Bj7+vhB0gqJHCNuOutlk z03yN7kV+qUlqdm92sG0Iix3D0/Zl7aEP41Thji5V6vDYGsHkztHt0ED+6zn1j1VqxRN geSW2bnwFFrrPyvKj9eAaqNtsKbXz9P/vc9sWwYcH4iqIYgeUz6oouuSOczr1waoetgY fXV7Y9BYnh/S8cKDZ9VDQp8sFV7eRR9+/2Df8jLh/lkg7IJZ7kqK/DdVOT+crLay0PSr mIKQ5j49MGv96pAU+r8ab6hF5pBRNRL30rwxMAPZjCF75Rc+P36pDv7CYsRB841yJHDp d24w== 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=OTpRvCDn65QO0kY9KBig2u7PNK/HjQJ3t4f8HoKax9o=; b=KRSJYAv2b8K0Gv2Lvr1blyeBhYnr3kJGSUwZE3jEbtvE+de0CAx9VBbQaM0BQGCb8I hFLzxxnttOE/9LWMtDBLMWzTKE0iAak16BtYCUNlAqXq4lyt0bzISoNmjF/I32xQmvqz CklRQDZHXPXFWZSSZkzpiPAlM8NERy5m+dl7L8h99s6iOd9bVsLZKk1+2SiVrbNAtSPl 7Z67/XNMF4hIiEokCK5iycRBw9+rjOIy+iaVkFnZZeXPsMA2Vw0L0uzB1QzCB9FR6xGX q+RcO95nRNYMlewD/8+Tr2LNpxCZGmzYhV/DekXSXue4aac551cYzv9InDDQOo1ixZbI eUPA== X-Gm-Message-State: AN3rC/4e9zPh4S8E7R3EqO+YB6qkPSUZzKUL1eYOdYngyodgusPwVnyX TPjiVQX7ePPNamTh X-Received: by 10.84.232.13 with SMTP id h13mr13012942plk.42.1492735812929; Thu, 20 Apr 2017 17:50:12 -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.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Apr 2017 17:50:12 -0700 (PDT) From: David Matlack To: kvm@vger.kernel.org Cc: Peter Feiner , David Matlack Subject: [kvm-unit-tests PATCH 05/32] lib: better test name filtering Date: Thu, 20 Apr 2017 17:49:37 -0700 Message-Id: <20170421005004.137260-6-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 Limited glob matching with leading or trailing '*'. Tests (and globs of tests) can be excluded by prepending with a '-'. Signed-off-by: Peter Feiner Signed-off-by: David Matlack --- lib/libcflat.h | 2 ++ lib/string.c | 41 +++++++++++++++++++++++++++++++++++++++++ x86/vmx.c | 52 +++++++++++++++++++++++++++------------------------- 3 files changed, 70 insertions(+), 25 deletions(-) diff --git a/lib/libcflat.h b/lib/libcflat.h index 96a37926f302..248fd023626e 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -105,6 +105,8 @@ extern void report_skip(const char *msg_fmt, ...); extern void report_info(const char *msg_fmt, ...); extern int report_summary(void); +bool simple_glob(const char *text, const char *pattern); + extern void dump_stack(void); extern void dump_frame_stack(const void *instruction, const void *frame); diff --git a/lib/string.c b/lib/string.c index 833f22be48c5..bc52d5c2695f 100644 --- a/lib/string.c +++ b/lib/string.c @@ -173,3 +173,44 @@ char *getenv(const char *name) } return NULL; } + +/* Very simple glob matching. Allows '*' at beginning and end of pattern. */ +bool simple_glob(const char *text, const char *pattern) +{ + bool star_start = false; + bool star_end = false; + size_t n = strlen(pattern); + char copy[n + 1]; + + if (pattern[0] == '*') { + pattern += 1; + n -= 1; + star_start = true; + } + + strcpy(copy, pattern); + + if (n > 0 && pattern[n - 1] == '*') { + n -= 1; + copy[n] = '\0'; + star_end = true; + } + + if (star_start && star_end) + return strstr(text, copy); + + if (star_end) + return strstr(text, copy) == text; + + if (star_start) { + size_t text_len = strlen(text); + const char *suffix; + + if (n > text_len) + return false; + suffix = text + text_len - n; + return !strcmp(suffix, copy); + } + + return !strcmp(text, copy); +} diff --git a/x86/vmx.c b/x86/vmx.c index 0590b69ec1d2..651807a76a1e 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -1159,41 +1159,43 @@ out: extern struct vmx_test vmx_tests[]; -/* Match name with wanted allowing underscores in place of spaces. */ -static bool test_name_wanted(const char *name, const char *wanted) +static bool +test_wanted(const char *name, const char *filters[], int filter_count) { + int i; + bool positive = false; + bool match = false; + char clean_name[strlen(name) + 1]; + char *c; const char *n; - const char *w; - for (n = name, w = wanted; *n != '\0' && *w != '\0'; n++, w++) { - if (*n != *w && !(*n == ' ' && *w == '_')) - return false; - } - return *n == '\0' && *w == '\0'; -} + /* Replace spaces with underscores. */ + n = name; + c = &clean_name[0]; + do *c++ = (*n == ' ') ? '_' : *n; + while (*n++); -static bool test_wanted(const char *name, char *wanted[], int nwanted) -{ - bool is_wanted = true; - int i; - - if (!nwanted) - goto out; + for (i = 0; i < filter_count; i++) { + const char *filter = filters[i]; - for (i = 0; i < nwanted; ++i) { - if (test_name_wanted(name, wanted[i])) - goto out; + if (filter[0] == '-') { + if (simple_glob(clean_name, filter + 1)) + return false; + } else { + positive = true; + match |= simple_glob(clean_name, filter); + } } - is_wanted = false; - -out: - if (is_wanted) + if (!positive || match) { matched++; - return is_wanted; + return true; + } else { + return false; + } } -int main(int argc, char *argv[]) +int main(int argc, const char *argv[]) { int i = 0;