/* * These symbols point to the .kunit_test_suites section and are defined in * include/asm-generic/vmlinux.lds.h, and consequently must be extern.
*/ externstruct kunit_suite * const __kunit_suites_start[]; externstruct kunit_suite * const __kunit_suites_end[]; externstruct kunit_suite * const __kunit_init_suites_start[]; externstruct kunit_suite * const __kunit_init_suites_end[];
staticchar *action_param;
module_param_named(action, action_param, charp, 0400);
MODULE_PARM_DESC(action, "Changes KUnit executor behavior, valid values are:\n" ": run the tests like normal\n" "'list' to list test names instead of running them.\n" "'list_attr' to list test names and attributes instead of running them.\n");
module_param_named(filter_glob, filter_glob_param, charp, 0600);
MODULE_PARM_DESC(filter_glob, "Filter which KUnit test suites/tests run at boot-time, e.g. list* or list*.*del_test");
module_param_named(filter, filter_param, charp, 0600);
MODULE_PARM_DESC(filter, "Filter which KUnit test suites/tests run at boot-time using attributes, e.g. speed>slow");
module_param_named(filter_action, filter_action_param, charp, 0600);
MODULE_PARM_DESC(filter_action, "Changes behavior of filtered tests using attributes, valid values are:\n" ": do not run filtered tests as normal\n" "'skip': skip all filtered tests instead so tests will appear in output\n");
/* glob_match() needs NULL terminated strings, so we need a copy of filter_glob_param. */ struct kunit_glob_filter { char *suite_glob; char *test_glob;
};
/* Split "suite_glob.test_glob" into two. Assumes filter_glob is not empty. */ staticint kunit_parse_glob_filter(struct kunit_glob_filter *parsed, constchar *filter_glob)
{ constchar *period = strchr(filter_glob, '.');
if (!period) {
parsed->suite_glob = kstrdup(filter_glob, GFP_KERNEL); if (!parsed->suite_glob) return -ENOMEM;
parsed->test_glob = NULL; return 0;
}
parsed->suite_glob = kstrndup(filter_glob, period - filter_glob, GFP_KERNEL); if (!parsed->suite_glob) return -ENOMEM;
/* Create a copy of suite with only tests that match test_glob. */ staticstruct kunit_suite *
kunit_filter_glob_tests(conststruct kunit_suite *const suite, constchar *test_glob)
{ int n = 0; struct kunit_case *filtered, *test_case; struct kunit_suite *copy;
kunit_suite_for_each_test_case(suite, test_case) { if (!test_glob || glob_match(test_glob, test_case->name))
++n;
}
if (n == 0) return NULL;
copy = kmemdup(suite, sizeof(*copy), GFP_KERNEL); if (!copy) return ERR_PTR(-ENOMEM);
/* * Filter and reallocate test suites. Must return the filtered test suites set * allocated at a valid virtual address or NULL in case of error.
*/ struct kunit_suite_set
kunit_filter_suites(conststruct kunit_suite_set *suite_set, constchar *filter_glob, char *filters, char *filter_action, int *err)
{ int i, j, k; int filter_count = 0; struct kunit_suite **copy, **copy_start, *filtered_suite, *new_filtered_suite; struct kunit_suite_set filtered = {NULL, NULL}; struct kunit_glob_filter parsed_glob; struct kunit_attr_filter *parsed_filters = NULL; struct kunit_suite * const *suites;
const size_t max = suite_set->end - suite_set->start;
copy = kcalloc(max, sizeof(*copy), GFP_KERNEL); if (!copy) { /* won't be able to run anything, return an empty set */ return filtered;
}
copy_start = copy;
if (filter_glob) {
*err = kunit_parse_glob_filter(&parsed_glob, filter_glob); if (*err) goto free_copy;
}
/* Hack: print a ktap header so kunit.py can find the start of KUnit output. */
pr_info("KTAP version 1\n");
for (suites = suite_set->start; suites < suite_set->end; suites++) { /* Print suite name and suite attributes */
pr_info("%s\n", (*suites)->name); if (include_attr)
kunit_print_attr((void *)(*suites), false, 0);
/* Print test case name and attributes in suite */
kunit_suite_for_each_test_case((*suites), test_case) {
pr_info("%s.%s\n", (*suites)->name, test_case->name); if (include_attr)
kunit_print_attr((void *)test_case, true, 0);
}
}
}
/* Allocate memory for array of all kunit suites */
total_suite_start = kmalloc_array(init_num_suites + num_suites, suite_size, GFP_KERNEL); if (!total_suite_start) return total_suite_set;
/* Append and mark init suites and then append all other kunit suites */
memcpy(total_suite_start, init_suite_set.start, init_num_suites * suite_size); for (i = 0; i < init_num_suites; i++)
total_suite_start[i]->is_init = true;
/* Set kunit suite set start and end */
total_suite_set.start = total_suite_start;
total_suite_set.end = total_suite_start + (init_num_suites + num_suites);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.