From: David Matlack Subject: [kvm-unit-tests PATCH 01/32] x86: add test filter to vmx.flat. Date: Thu, 20 Apr 2017 17:49:33 -0700 Message-ID: <20170421005004.137260-2-dmatlack@google.com> References: <20170421005004.137260-1-dmatlack@google.com> Cc: Peter Feiner , David Matlack To: kvm@vger.kernel.org Return-path: Received: from mail-io0-f175.google.com ([209.85.223.175]:36171 "EHLO mail-io0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S946602AbdDUAuK (ORCPT ); Thu, 20 Apr 2017 20:50:10 -0400 Received: by mail-io0-f175.google.com with SMTP id o22so104063570iod.3 for ; Thu, 20 Apr 2017 17:50:09 -0700 (PDT) In-Reply-To: <20170421005004.137260-1-dmatlack@google.com> Sender: kvm-owner@vger.kernel.org List-ID: From: Peter Feiner The VMX nesting test has lots of test cases. Now a specific test case can be run by appending its name to the multiboot command line (i.e., under Qemu's: -append ) Signed-off-by: Peter Feiner Signed-off-by: David Matlack --- x86/vmx.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index b0b69602bdae..202cfaaa822e 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -1158,9 +1158,37 @@ out: extern struct vmx_test vmx_tests[]; -int main(void) +/* Match name with wanted allowing underscores in place of spaces. */ +static bool test_name_wanted(const char *name, const char *wanted) +{ + 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'; +} + +static bool test_wanted(struct vmx_test *test, char *wanted[], int nwanted) +{ + int i; + + if (!nwanted) + return true; + + for (i = 0; i < nwanted; ++i) { + if (test_name_wanted(test->name, wanted[i])) + return true; + } + return false; +} + +int main(int argc, char *argv[]) { int i = 0; + int matched = 0; setup_vm(); setup_idt(); @@ -1188,9 +1216,16 @@ int main(void) test_vmxoff(); test_vmx_caps(); - while (vmx_tests[++i].name != NULL) + while (vmx_tests[++i].name != NULL) { + if (!test_wanted(&vmx_tests[i], argv + 1, argc - 1)) + continue; + matched++; if (test_run(&vmx_tests[i])) goto exit; + } + + if (!matched) + report("command line didn't match any tests!", matched); exit: return report_summary(); -- 2.12.2.816.g2cccc81164-goog