From 2e2a7d0852abcdacacfb3ba18c38a09f746b20fe Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 13 Dec 2016 12:27:47 +0000 Subject: lib/kselftest: Parse embedded test number from parameter Order the tests by an embedded test number from the parameter string. Signed-off-by: Chris Wilson --- lib/igt_aux.h | 14 ++++++++++++-- lib/igt_kmod.c | 60 +++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 59 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/igt_aux.h b/lib/igt_aux.h index ca728c26..30f914b9 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -289,7 +289,7 @@ struct igt_list { }; #define __IGT_INIT_LIST(name) { &(name), &(name) } -#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name); +#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name) static inline void igt_list_init(struct igt_list *list) { @@ -352,14 +352,24 @@ static inline bool igt_list_empty(const struct igt_list *list) #define igt_list_first_entry(head, pos, member) \ container_of((head)->next, (pos), member) +#define igt_list_last_entry(head, pos, member) \ + container_of((head)->prev, (pos), member) + #define igt_list_next_entry(pos, member) \ container_of((pos)->member.next, (pos), member) +#define igt_list_prev_entry(pos, member) \ + container_of((pos)->member.prev, (pos), member) #define igt_list_for_each(pos, head, member) \ - for (pos = igt_list_first_entry(head, pos, member); \ + for (pos = igt_list_first_entry(head, pos, member); \ &pos->member != (head); \ pos = igt_list_next_entry(pos, member)) +#define igt_list_for_each_reverse(pos, head, member) \ + for (pos = igt_list_last_entry(head, pos, member); \ + &pos->member != (head); \ + pos = igt_list_prev_entry(pos, member)) + #define igt_list_for_each_safe(pos, tmp, head, member) \ for (pos = igt_list_first_entry(head, pos, member), \ tmp = igt_list_next_entry(pos, member); \ diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 388be30f..b2d8913a 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -341,17 +341,36 @@ static void kmsg_dump(int fd) } } +struct test_list { + struct igt_list link; + unsigned int number; + char *name; + char param[]; +}; + +static void tests_add(struct test_list *tl, struct igt_list *list) +{ + struct test_list *pos; + + igt_list_for_each(pos, list, link) + if (pos->number > tl->number) + break; + + igt_list_add_tail(&tl->link, &pos->link); +} + void igt_kselftests(const char *module_name, const char *module_options, const char *filter) { const char *param_prefix = "igt__"; - const int param_len = strlen(param_prefix); + const int prefix_len = strlen(param_prefix); + IGT_LIST(tests); char options[1024]; struct kmod_ctx *ctx = kmod_ctx(); struct kmod_module *kmod; struct kmod_list *d, *pre; - int module_subtest_count; + struct test_list *tl, *tn; int err, kmsg = -1; igt_require(kmod_module_new_from_name(ctx, module_name, &kmod) == 0); @@ -365,34 +384,50 @@ void igt_kselftests(const char *module_name, kmsg = open("/dev/kmsg", O_RDONLY | O_NONBLOCK); } - module_subtest_count = 0; pre = NULL; if (kmod_module_get_info(kmod, &pre)) { kmod_list_foreach(d, pre) { const char *key, *val; - char *subtest, *colon; + char *colon; + int offset; key = kmod_module_info_get_key(d); if (strcmp(key, "parmtype")) continue; val = kmod_module_info_get_value(d); - if (!val || strncmp(val, param_prefix, param_len)) + if (!val || strncmp(val, param_prefix, prefix_len)) continue; if (filter && - strncmp(val + param_len, filter, strlen(filter))) + strncmp(val + prefix_len, filter, strlen(filter))) continue; - subtest = strdup(val); - colon = strchr(subtest, ':'); + offset = strlen(val) + 1; + tl = malloc(sizeof(*tl) + offset); + if (!tl) + continue; + + memcpy(tl->param, val, offset); + colon = strchr(tl->param, ':'); *colon = '\0'; - igt_subtest_f("%s", subtest + param_len) { + tl->number = 0; + tl->name = tl->param + prefix_len; + if (sscanf(tl->name, "%u__%n", + &tl->number, &offset) == 1) + tl->name += offset; + + tests_add(tl, &tests); + } + kmod_module_info_free_list(pre); + + igt_list_for_each_safe(tl, tn, &tests, link) { + igt_subtest_f("%s", tl->name) { lseek(kmsg, 0, SEEK_END); snprintf(options, sizeof(options), "%s=1 %s", - subtest, module_options ?: ""); + tl->param, module_options ?: ""); err = 0; if (modprobe(kmod, options)) @@ -410,9 +445,8 @@ void igt_kselftests(const char *module_name, module_name, options, strerror(-err), -err); } - module_subtest_count++; + free(tl); } - kmod_module_info_free_list(pre); } igt_fixture { @@ -422,6 +456,6 @@ void igt_kselftests(const char *module_name, if (strcmp(module_name, "i915") == 0) igt_i915_driver_load(NULL); - igt_require(module_subtest_count); + igt_require(!igt_list_empty(&tests)); } } -- cgit v1.2.3