From: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 1/2] lib/kunit: Split out reusable part of test case list gathering
Date: Mon, 6 Nov 2023 10:59:37 +0100 [thread overview]
Message-ID: <20231106095935.7031-5-janusz.krzysztofik@linux.intel.com> (raw)
In-Reply-To: <20231106095935.7031-4-janusz.krzysztofik@linux.intel.com>
We are going to make use of kunit test case filtering feature, now also
available to modular builds. That means we will no longer need to load
a kunit test module in background and parse its all test cases KTAP output
in parallel, only wait for the module to load with a filter for a specific
test case, then parse its KTAP output containing only result of that
single test case.
We already have a piece of code that just collects all results from KTAP
report, used for fetching the list of test cases from the module. Move
that code to a separate function, ready for reuse as a parser of complete
results of a single test case.
Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
---
lib/igt_kmod.c | 127 +++++++++++++++++++++++++++++++------------------
1 file changed, 80 insertions(+), 47 deletions(-)
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index e967c9bcdc..37591b7389 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -953,6 +953,73 @@ static void kunit_results_free(struct igt_list_head *results,
free(*suite_name);
}
+static int kunit_kmsg_get_results(struct igt_list_head *results,
+ struct igt_ktest *tst,
+ const char *filter,
+ const char *opts)
+{
+ char *suite_name = NULL, *case_name = NULL;
+ struct igt_ktap_results *ktap;
+ int flags, err;
+
+ if (igt_debug_on(tst->kmsg < 0))
+ return tst->kmsg;
+
+ if (igt_debug_on((flags = fcntl(tst->kmsg, F_GETFL, 0), flags < 0)))
+ return flags;
+
+ if (flags & O_NONBLOCK &&
+ igt_debug_on((err = fcntl(tst->kmsg, F_SETFL, flags & ~O_NONBLOCK),
+ err == -1)))
+ return -errno;
+
+ errno = 0;
+ if (igt_debug_on(lseek(tst->kmsg, 0, SEEK_END) == -1 && errno))
+ return -errno;
+
+ err = igt_debug_on(igt_kmod_load("kunit", filter));
+ if (err) {
+ /*
+ * TODO: drop the following workaround, which is required by LTS
+ * kernel v6.1 not capable of listing nor filtering test
+ * cases when built as a module.
+ * If loading the kunit module with required parameters fails
+ * then assume that we are running on a kernel with missing test
+ * case listing and filtering capabilities. Don't fail but just
+ * return with empty list of test cases, that should tell the
+ * caller to use a legacy method of iterating over KTAP results
+ * collected from blind execution of all Kunit test cases
+ * provided by a Kunit test module.
+ */
+ return 0;
+ }
+
+ err = igt_debug_on(modprobe(tst->kmod, opts));
+ if (err)
+ goto out_kmod_unload;
+
+ ktap = igt_ktap_alloc(results);
+ if (igt_debug_on(!ktap)) {
+ err = -ENOMEM;
+ goto out_remove_module;
+ }
+
+ do
+ igt_debug_on((err = kunit_kmsg_result_get(results, NULL, tst->kmsg, ktap),
+ err && err != -EINPROGRESS));
+ while (err == -EINPROGRESS);
+
+ igt_ktap_free(ktap);
+
+ if (err)
+ kunit_results_free(results, &case_name, &suite_name);
+
+out_remove_module:
+ igt_debug_on(kmod_module_remove_module(tst->kmod, KMOD_REMOVE_FORCE));
+out_kmod_unload:
+ return igt_debug_on(igt_kmod_unload("kunit", KMOD_REMOVE_FORCE)) ?: err;
+}
+
static void __igt_kunit_legacy(struct igt_ktest *tst,
const char *name,
const char *opts)
@@ -1094,16 +1161,7 @@ static void kunit_get_tests(struct igt_list_head *tests,
{
char *suite_name = NULL, *case_name = NULL;
struct igt_ktap_result *r, *rn;
- struct igt_ktap_results *ktap;
- int flags, err;
-
- igt_skip_on_f(tst->kmsg < 0, "Could not open /dev/kmsg\n");
-
- igt_skip_on((flags = fcntl(tst->kmsg, F_GETFL, 0), flags < 0));
- igt_skip_on_f(fcntl(tst->kmsg, F_SETFL, flags & ~O_NONBLOCK) == -1,
- "Could not set /dev/kmsg to blocking mode\n");
-
- igt_skip_on(lseek(tst->kmsg, 0, SEEK_END) < 0);
+ int err = 0;
/*
* To get a list of test cases provided by a kunit test module, ask the
@@ -1112,44 +1170,22 @@ static void kunit_get_tests(struct igt_list_head *tests,
* however, parsing a KTAP report -- something that we already can do
* perfectly -- seems to be more safe than extracting a test case list
* of unknown length from /dev/kmsg.
- *
- * TODO: drop the following workaround, which is required by LTS kernel
- * v6.1 not capable of listing test cases when built as a module.
- * If loading the kunit module with required parameters fails then
- * assume that we are running on a kernel with missing test case listing
- * capabilities. Dont's skip but just return with empty list of test
- * cases, that should tell the caller to use a legacy method of
- * iterating over KTAP results collected from blind execution of all
- * Kunit test cases provided by a Kunit test module.
*/
- if (igt_debug_on(igt_kmod_load("kunit",
- "filter=module=none filter_action=skip")))
- return;
-
- igt_skip_on(modprobe(tst->kmod, opts));
+ igt_skip_on(kunit_kmsg_get_results(tests, tst,
+ "filter=module=none filter_action=skip", opts));
- ktap = igt_ktap_alloc(tests);
- igt_require(ktap);
-
- do
- err = kunit_kmsg_result_get(tests, NULL, tst->kmsg, ktap);
- while (err == -EINPROGRESS);
-
- igt_ktap_free(ktap);
-
- if (!err)
- igt_list_for_each_entry_safe(r, rn, tests, link) {
- if (igt_debug_on(r->code != IGT_EXIT_SKIP)) {
- err = r->code ?: -EPROTO;
- break;
- }
+ igt_list_for_each_entry_safe(r, rn, tests, link) {
+ if (igt_debug_on(r->code != IGT_EXIT_SKIP)) {
+ err = r->code ?: -EPROTO;
+ break;
+ }
- if (!filter)
- continue;
+ if (!filter)
+ continue;
- if (strcmp(r->suite_name, filter))
- kunit_result_free(&r, &case_name, &suite_name);
- }
+ if (strcmp(r->suite_name, filter))
+ kunit_result_free(&r, &case_name, &suite_name);
+ }
if (err) {
kunit_results_free(tests, &case_name, &suite_name);
@@ -1158,9 +1194,6 @@ static void kunit_get_tests(struct igt_list_head *tests,
free(case_name);
}
- igt_skip_on(kmod_module_remove_module(tst->kmod, KMOD_REMOVE_FORCE));
- igt_skip_on(igt_kmod_unload("kunit", KMOD_REMOVE_FORCE));
-
igt_skip_on_f(err,
"KTAP parser failed while getting a list of test cases\n");
}
--
2.42.0
next prev parent reply other threads:[~2023-11-06 9:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-06 9:59 [igt-dev] [PATCH i-g-t 0/2] lib/kunit: Execute test cases synchronously Janusz Krzysztofik
2023-11-06 9:59 ` Janusz Krzysztofik [this message]
2023-11-06 9:59 ` [igt-dev] [PATCH i-g-t 2/2] " Janusz Krzysztofik
2023-11-10 7:52 ` Mauro Carvalho Chehab
2023-11-14 18:33 ` [Intel-xe] " Janusz Krzysztofik
2023-11-06 13:31 ` [igt-dev] ✓ CI.xeBAT: success for " Patchwork
2023-11-06 13:41 ` [igt-dev] ✗ Fi.CI.BAT: failure " Patchwork
2023-11-07 8:14 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2023-11-07 16:24 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2023-11-08 8:43 ` Janusz Krzysztofik
2023-11-10 4:53 ` Illipilli, TejasreeX
2023-11-09 16:06 ` [igt-dev] ✓ Fi.CI.IGT: success " Patchwork
2023-11-09 16:32 ` Patchwork
2023-11-09 17:07 ` Patchwork
2023-11-09 17:13 ` Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231106095935.7031-5-janusz.krzysztofik@linux.intel.com \
--to=janusz.krzysztofik@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=igt-dev@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox