Message ID | 1422550421-26486-1-git-send-email-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
On Thu, Jan 29, 2015 at 11:53 AM, Colin King <colin.king@canonical.com> wrote: > From: Colin Ian King <colin.king@canonical.com> > > 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 <colin.king@canonical.com> > --- > 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 <string.h> > #include <stdarg.h> > #include <stdbool.h> > +#include <ctype.h> > #include <time.h> > #include <getopt.h> > #include <sys/utsname.h> > @@ -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)) { > -- > 2.1.4 > > Thanks Colin, definitely Acked-by: Keng-Yu Lin <kengyu@canonical.com>
On 2015年01月30日 00:53, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > 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 <colin.king@canonical.com> > --- > 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 <string.h> > #include <stdarg.h> > #include <stdbool.h> > +#include <ctype.h> > #include <time.h> > #include <getopt.h> > #include <sys/utsname.h> > @@ -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)) { Acked-by: Ivan Hu <ivan.hu@canonical.com>
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 <string.h> #include <stdarg.h> #include <stdbool.h> +#include <ctype.h> #include <time.h> #include <getopt.h> #include <sys/utsname.h> @@ -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)) {