All of lore.kernel.org
 help / color / mirror / Atom feed
From: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	Kamil Konieczny <kamil.konieczny@linux.intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Jonathan Cavitt <jonathan.cavitt@intel.com>,
	Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [PATCH i-g-t v3 1/5] lib/kunit: Store igt_ktap_results pointer in a central location
Date: Mon, 18 Mar 2024 11:13:27 +0100	[thread overview]
Message-ID: <20240318103534.701693-8-janusz.krzysztofik@linux.intel.com> (raw)
In-Reply-To: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com>

To give more freedom to future enhancements of KUnit library (legacy path
excluded) in using IGT fails and skips, maintain a pointer to struct
igt_ktap_results, allocated by several functions, in a single central
location, and free it from a closing igt_fixture section before return.

Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
---
 lib/igt_kmod.c | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index b4b8848983..ca20012a97 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -1207,10 +1207,10 @@ static void __igt_kunit_legacy(struct igt_ktest *tst,
 static bool kunit_get_tests(struct igt_list_head *tests,
 			    struct igt_ktest *tst,
 			    const char *suite,
-			    const char *opts)
+			    const char *opts,
+			    struct igt_ktap_results **ktap)
 {
 	struct igt_ktap_result *r, *rn;
-	struct igt_ktap_results *ktap;
 	unsigned long taints;
 	int flags, err;
 
@@ -1236,14 +1236,15 @@ static bool kunit_get_tests(struct igt_list_head *tests,
 	igt_skip_on(modprobe(tst->kmod, opts));
 	igt_skip_on(igt_kernel_tainted(&taints));
 
-	ktap = igt_ktap_alloc(tests);
-	igt_require(ktap);
+	*ktap = igt_ktap_alloc(tests);
+	igt_require(*ktap);
 
 	do
-		err = kunit_kmsg_result_get(tests, NULL, tst->kmsg, ktap);
+		err = kunit_kmsg_result_get(tests, NULL, tst->kmsg, *ktap);
 	while (err == -EINPROGRESS);
 
-	igt_ktap_free(ktap);
+	igt_ktap_free(*ktap);
+	*ktap = NULL;
 
 	igt_skip_on_f(err,
 		      "KTAP parser failed while getting a list of test cases\n");
@@ -1261,12 +1262,12 @@ static void __igt_kunit(struct igt_ktest *tst,
 			const char *subtest,
 			const char *suite,
 			const char *opts,
-			struct igt_list_head *tests)
+			struct igt_list_head *tests,
+			struct igt_ktap_results **ktap)
 {
 	struct modprobe_data modprobe = { tst->kmod, opts, 0, pthread_self(), };
 	char *suite_name = NULL, *case_name = NULL;
 	struct igt_ktap_result *t, *r = NULL;
-	struct igt_ktap_results *ktap;
 	pthread_mutexattr_t attr;
 	IGT_LIST_HEAD(results);
 	int ret = -EINPROGRESS;
@@ -1274,8 +1275,8 @@ static void __igt_kunit(struct igt_ktest *tst,
 
 	igt_skip_on(lseek(tst->kmsg, 0, SEEK_END) < 0);
 
-	ktap = igt_ktap_alloc(&results);
-	igt_require(ktap);
+	*ktap = igt_ktap_alloc(&results);
+	igt_require(*ktap);
 
 	igt_list_for_each_entry(t, tests, link) {
 		igt_dynamic_f("%s%s%s",
@@ -1302,7 +1303,7 @@ static void __igt_kunit(struct igt_ktest *tst,
 				igt_assert(igt_list_empty(&results));
 				igt_assert_eq(ret, -EINPROGRESS);
 				ret = kunit_kmsg_result_get(&results, &modprobe,
-							    tst->kmsg, ktap);
+							    tst->kmsg, *ktap);
 				igt_fail_on(igt_list_empty(&results));
 
 				r = igt_list_first_entry(&results, r, link);
@@ -1324,7 +1325,7 @@ static void __igt_kunit(struct igt_ktest *tst,
 					ret = kunit_kmsg_result_get(&results,
 								    &modprobe,
 								    tst->kmsg,
-								    ktap);
+								    *ktap);
 					igt_fail_on(igt_list_empty(&results));
 				}
 
@@ -1404,7 +1405,8 @@ static void __igt_kunit(struct igt_ktest *tst,
 		}
 	}
 
-	igt_ktap_free(ktap);
+	igt_ktap_free(*ktap);
+	*ktap = NULL;
 
 	igt_skip_on(modprobe.err);
 	igt_skip_on(igt_kernel_tainted(&taints));
@@ -1427,6 +1429,7 @@ static void __igt_kunit(struct igt_ktest *tst,
 void igt_kunit(const char *module_name, const char *suite, const char *opts)
 {
 	struct igt_ktest tst = { .kmsg = -1, };
+	struct igt_ktap_results *ktap = NULL;
 	const char *subtest = suite;
 	IGT_LIST_HEAD(tests);
 
@@ -1475,15 +1478,17 @@ void igt_kunit(const char *module_name, const char *suite, const char *opts)
 		 *	 LTS kernels not capable of using KUnit filters for
 		 *	 listing test cases in KTAP format, with igt_require.
 		 */
-		if (!kunit_get_tests(&tests, &tst, suite, opts))
+		if (!kunit_get_tests(&tests, &tst, suite, opts, &ktap))
 			__igt_kunit_legacy(&tst, subtest, opts);
 		else
-			__igt_kunit(&tst, subtest, suite, opts, &tests);
+			__igt_kunit(&tst, subtest, suite, opts, &tests, &ktap);
 	}
 
 	igt_fixture {
 		char *suite_name = NULL, *case_name = NULL;
 
+		igt_ktap_free(ktap);
+
 		kunit_results_free(&tests, &suite_name, &case_name);
 
 		igt_ktest_end(&tst);
-- 
2.43.0


  reply	other threads:[~2024-03-18 10:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 10:13 [PATCH i-g-t v3 0/5] lib/kunit: Execute test cases synchronously Janusz Krzysztofik
2024-03-18 10:13 ` Janusz Krzysztofik [this message]
2024-03-19 18:25   ` [PATCH i-g-t v3 1/5] lib/kunit: Store igt_ktap_results pointer in a central location Kamil Konieczny
2024-03-18 10:13 ` [PATCH i-g-t v3 2/5] lib/kunit: Let igt_ktap_free() take care of pointer reset Janusz Krzysztofik
2024-03-19 18:30   ` Kamil Konieczny
2024-03-18 10:13 ` [PATCH i-g-t v3 3/5] lib/kunit: Time out promptly on missing KTAP report Janusz Krzysztofik
2024-03-19 18:33   ` Kamil Konieczny
2024-03-18 10:13 ` [PATCH i-g-t v3 4/5] lib/kunit: Execute test cases synchronously Janusz Krzysztofik
2024-03-25 17:04   ` Kamil Konieczny
2024-03-18 10:13 ` [PATCH i-g-t v3 5/5] lib/kunit: Minimize code duplication Janusz Krzysztofik
2024-03-25 17:12   ` Kamil Konieczny
2024-03-18 17:21 ` ✗ CI.Patch_applied: failure for lib/kunit: Execute test cases synchronously (rev3) Patchwork
2024-03-18 17:59 ` ✓ CI.xeBAT: success for lib/kunit: Execute test cases synchronously (rev6) Patchwork
2024-03-18 18:10 ` ✓ Fi.CI.BAT: " Patchwork
2024-03-18 23:28 ` ✗ Fi.CI.IGT: failure " Patchwork
2024-03-19 18:39 ` [PATCH i-g-t v3 0/5] lib/kunit: Execute test cases synchronously Cavitt, Jonathan

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=20240318103534.701693-8-janusz.krzysztofik@linux.intel.com \
    --to=janusz.krzysztofik@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jonathan.cavitt@intel.com \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=lucas.demarchi@intel.com \
    --cc=mchehab@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.