From patchwork Thu Jan 29 16:53:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 434608 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 428D21402E1; Fri, 30 Jan 2015 03:54:58 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YGsMn-0007tc-5k; Thu, 29 Jan 2015 16:54:53 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1YGsMh-0007tF-GD for fwts-devel@lists.ubuntu.com; Thu, 29 Jan 2015 16:54:47 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginm.net ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1YGsMh-0004em-C7 for fwts-devel@lists.ubuntu.com; Thu, 29 Jan 2015 16:54:47 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] lib: fwts_framework: add --show-tests-categories option (LP: #1415953) Date: Thu, 29 Jan 2015 16:53:41 +0000 Message-Id: <1422550421-26486-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 2.1.4 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King I would be useful to list all the tests with the categories that they are associated with. This can then be parsed for automated test scripts that need to determine the kinds of tests that are available. Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Ivan Hu --- doc/fwts.1 | 3 ++ src/lib/include/fwts_framework.h | 3 +- src/lib/src/fwts_framework.c | 88 ++++++++++++++++++++++++++++++++-------- 3 files changed, 75 insertions(+), 19 deletions(-) diff --git a/doc/fwts.1 b/doc/fwts.1 index f9737a7..904d2d6 100644 --- a/doc/fwts.1 +++ b/doc/fwts.1 @@ -303,6 +303,9 @@ options to show these specific tests. show all the available tests listed by minor test description. By default will show all tests. Use the \-\-batch, \-\-interactive, \-\-batch\-experimental, \-\-interactive\-experimental options to show these specific tests. .TP +.B \-\-show\-tests\-categories +show all the available tests and the categories they belong to. +.TP .B \-\-skip\-test=test[,test..] specify tests to skip over and not run. List must be comma separated. .TP diff --git a/src/lib/include/fwts_framework.h b/src/lib/include/fwts_framework.h index 02fc931..52df68a 100644 --- a/src/lib/include/fwts_framework.h +++ b/src/lib/include/fwts_framework.h @@ -51,7 +51,8 @@ typedef enum { FWTS_FLAG_TEST_ACPI = 0x04000000, FWTS_FLAG_UTILS = 0x08000000, FWTS_FLAG_QUIET = 0x10000000, - FWTS_FLAG_SHOW_TESTS_FULL = 0x20000000 + FWTS_FLAG_SHOW_TESTS_FULL = 0x20000000, + FWTS_FLAG_SHOW_TESTS_CATEGORIES = 0x40000000 } fwts_framework_flags; #define FWTS_FLAG_TEST_MASK \ diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c index ec5d19d..6c5598d 100644 --- a/src/lib/src/fwts_framework.c +++ b/src/lib/src/fwts_framework.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,11 @@ #include "fwts.h" #include "fwts_pm_method.h" +typedef struct { + const char *title; /* Test category */ + fwts_framework_flags flag; /* Mask of category */ +} fwts_categories; + /* Suffix ".log", ".xml", etc gets automatically appended */ #define RESULTS_LOG "results" @@ -43,6 +49,18 @@ FWTS_FLAG_UNSAFE | \ FWTS_FLAG_TEST_UEFI) +static fwts_categories categories[] = { + { "Batch", FWTS_FLAG_BATCH }, + { "Interactive", FWTS_FLAG_INTERACTIVE }, + { "Batch Experimental", FWTS_FLAG_BATCH_EXPERIMENTAL }, + { "Interactive Experimental", FWTS_FLAG_INTERACTIVE_EXPERIMENTAL }, + { "Power States", FWTS_FLAG_POWER_STATES }, + { "Utilities", FWTS_FLAG_UTILS }, + { "Unsafe", FWTS_FLAG_UNSAFE }, + { "UEFI", FWTS_FLAG_TEST_UEFI }, + { NULL, 0 }, +}; + static fwts_list tests_to_skip; static fwts_option fwts_framework_options[] = { @@ -85,6 +103,7 @@ static fwts_option fwts_framework_options[] = { { "uefi", "", 0, "Run UEFI tests." }, { "rsdp", "R:", 1, "Specify the physical address of the ACPI RSDP." }, { "pm-method", "", 1, "Select the power method to use. Accepted values are \"logind\", \"pm-utils\", \"sysfs\""}, + { "show-tests-categories","", 0, "Show tests and associated categories." }, { NULL, NULL, 0, NULL } }; @@ -173,7 +192,7 @@ int fwts_framework_compare_test_name(void *data1, void *data2) } /* - * fwts_framework_show_tests() + * fwts_framework_show_tests_brief() * dump out registered tests in brief form */ static void fwts_framework_show_tests_brief(void) @@ -207,6 +226,49 @@ static void fwts_framework_show_tests_brief(void) } /* + * fwts_framework_show_tests_categories() + * dump out registered tests in brief form with categories + */ +static void fwts_framework_show_tests_categories(void) +{ + fwts_list sorted; + fwts_list_link *item; + + fwts_list_init(&sorted); + + fwts_list_foreach(item, &fwts_framework_test_list) { + fwts_list_add_ordered(&sorted, + fwts_list_data(fwts_framework_test *, item), + fwts_framework_compare_test_name); + } + + fwts_list_foreach(item, &sorted) { + fwts_framework_test *test = fwts_list_data(fwts_framework_test*, item); + int i, n = 0; + + printf("%-17.17s", test->name); + + for (i = 0; categories[i].title != NULL; i++) { + if (categories[i].flag & test->flags) { + char *src = (char *)categories[i].title, *dst; + size_t len = strlen(src) + 1; + char buf[len]; + + for (dst = buf; *src; src++, dst++) + *dst = tolower(*src); + *dst = '\0'; + + printf("%s%s", + n == 0 ? " " : ", ", buf); + n++; + } + } + putchar('\n'); + } + fwts_list_free_items(&sorted, NULL); +} + +/* * fwts_framework_show_tests() * dump out registered tests. */ @@ -218,23 +280,6 @@ static void fwts_framework_show_tests(fwts_framework *fw, const bool full) bool need_nl = false; int total = 0; - typedef struct { - const char *title; /* Test category */ - fwts_framework_flags flag; /* Mask of category */ - } fwts_categories; - - static fwts_categories categories[] = { - { "Batch", FWTS_FLAG_BATCH }, - { "Interactive", FWTS_FLAG_INTERACTIVE }, - { "Batch Experimental", FWTS_FLAG_BATCH_EXPERIMENTAL }, - { "Interactive Experimental", FWTS_FLAG_INTERACTIVE_EXPERIMENTAL }, - { "Power States", FWTS_FLAG_POWER_STATES }, - { "Utilities", FWTS_FLAG_UTILS }, - { "Unsafe", FWTS_FLAG_UNSAFE }, - { "UEFI", FWTS_FLAG_TEST_UEFI }, - { NULL, 0 }, - }; - /* Dump out tests registered under all categories */ for (i = 0; categories[i].title != NULL; i++) { @@ -1170,6 +1215,9 @@ int fwts_framework_options_handler(fwts_framework *fw, int argc, char * const ar if (fwts_framework_pm_method_parse(fw, optarg) != FWTS_OK) return FWTS_ERROR; break; + case 39: /* --show-tests-categories */ + fw->flags |= FWTS_FLAG_SHOW_TESTS_CATEGORIES; + break; } break; case 'a': /* --all */ @@ -1322,6 +1370,10 @@ int fwts_framework_args(const int argc, char **argv) fwts_framework_show_tests(fw, true); goto tidy_close; } + if (fw->flags & FWTS_FLAG_SHOW_TESTS_CATEGORIES) { + fwts_framework_show_tests_categories(); + goto tidy_close; + } if ((fw->flags & FWTS_FLAG_RUN_ALL) == 0) fw->flags |= FWTS_FLAG_BATCH; if ((fw->lspci == NULL) || (fw->results_logname == NULL)) {