From patchwork Mon Mar 18 10:13:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13595197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91E53C54E58 for ; Mon, 18 Mar 2024 10:36:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F09C510F540; Mon, 18 Mar 2024 10:36:17 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="WRvnxljd"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4069710F536; Mon, 18 Mar 2024 10:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710758176; x=1742294176; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3P5hQfQN7Uws/eF+C5TJCMuuwqvRzqSc+rRbu6Xxz2w=; b=WRvnxljd+9cGDH/4noPTsYhZdr5/zgQoUN9Q9FeBhHTRbfmaWm5d5mzD FggVrwQ1V7wlPeI6bEjNnGUmKShOSXTofbNjT6jDc+BocEaYYs1TNdAAb p3VLnYb+COPaw3YgK0njRjxkBuoP168PYFLJS2pvaaRKc4hl1/dkg5luM Z5cHkDkUB+OjKyuM2v8NthIudnUqKHby4iUCWHQFuaGFonm403IS+56wn 0Cjwci811XaHeH5F/WOWx8PuXy0F2PsmK+n70Lf2zNlBwgB+xjVRMNgOU FNMn6NCYMVsLVFLdj2LbzAeBFn7CuSX3grDmbOFSgddeHXvxr7XmViXZg g==; X-IronPort-AV: E=McAfee;i="6600,9927,11016"; a="6168191" X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="6168191" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 03:36:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="18015792" Received: from jkrzyszt-mobl2.ger.corp.intel.com ([10.213.26.105]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 03:36:14 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Kamil Konieczny , Mauro Carvalho Chehab , Jonathan Cavitt , Lucas De Marchi 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 Message-ID: <20240318103534.701693-8-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com> References: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 Reviewed-by: Kamil Konieczny --- 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); From patchwork Mon Mar 18 10:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13595200 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA0A3C54E72 for ; Mon, 18 Mar 2024 10:36:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 27E3010F54E; Mon, 18 Mar 2024 10:36:25 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="JWTiNvbe"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8BCA210F542; Mon, 18 Mar 2024 10:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710758178; x=1742294178; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vme7zger9lqPwSdS7rFdcLSQgdsKYwLEmpibVFiJ/qc=; b=JWTiNvbePNpZNZog5h/7Mt0+E8Ul1IJeoAqCiHTv6p6kT0cO9R52wxEL xe2SuCYcJiecN5CcNwweRojPSONXxvzJWFS2Urw0ca3x/JUrKypcBv0IJ KsTF0ZdWjrAeoCt+v7tzNpPDelSgNRMcvypSW7RgOqS1KMMWp2TSXzE7w PHLb1jK4YtutSR/KB+6rf3Cx64bdl6eOo+zhzcw0+h8IH8bq7QyONmdJu GoeEMczdgej6TDCNhoAn4HTrw6jVpzUVIADED+cvnMIHrqSPOuBtP1nw6 qiXJupr6Ih7pMBEdvwGqZZdXabEdbjMJrN1xK0WLSZZ3OhV93ks5lEyJy A==; X-IronPort-AV: E=McAfee;i="6600,9927,11016"; a="6168196" X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="6168196" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 03:36:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="18015804" Received: from jkrzyszt-mobl2.ger.corp.intel.com ([10.213.26.105]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 03:36:16 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Kamil Konieczny , Mauro Carvalho Chehab , Jonathan Cavitt , Lucas De Marchi Subject: [PATCH i-g-t v3 2/5] lib/kunit: Let igt_ktap_free() take care of pointer reset Date: Mon, 18 Mar 2024 11:13:28 +0100 Message-ID: <20240318103534.701693-9-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com> References: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Users who store a pointer to struct igt_ktap_results, obtained from igt_ktap_alloc(), in a central location and then call igt_ktap_free() when no longer needed, now have to reset that pointer to NULL to avoid double free on final cleanup. For their convenience, teach igt_ktap_free() to accept that location as an argument and reset the pointer after freeing the structure. Signed-off-by: Janusz Krzysztofik Reviewed-by: Kamil Konieczny --- lib/igt_kmod.c | 12 +++++------- lib/igt_ktap.c | 5 +++-- lib/igt_ktap.h | 2 +- lib/tests/igt_ktap_parser.c | 24 ++++++++++++------------ 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index ca20012a97..8a6824ea7e 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -1094,7 +1094,7 @@ static void __igt_kunit_legacy(struct igt_ktest *tst, if (igt_debug_on(pthread_create(&modprobe.thread, NULL, modprobe_task, &modprobe))) { - igt_ktap_free(ktap); + igt_ktap_free(&ktap); igt_skip("Failed to create a modprobe thread\n"); } @@ -1197,7 +1197,7 @@ static void __igt_kunit_legacy(struct igt_ktest *tst, break; } - igt_ktap_free(ktap); + igt_ktap_free(&ktap); igt_skip_on(modprobe.err); igt_skip_on(igt_kernel_tainted(&taints)); @@ -1243,8 +1243,7 @@ static bool kunit_get_tests(struct igt_list_head *tests, err = kunit_kmsg_result_get(tests, NULL, tst->kmsg, *ktap); while (err == -EINPROGRESS); - igt_ktap_free(*ktap); - *ktap = NULL; + igt_ktap_free(ktap); igt_skip_on_f(err, "KTAP parser failed while getting a list of test cases\n"); @@ -1405,8 +1404,7 @@ static void __igt_kunit(struct igt_ktest *tst, } } - igt_ktap_free(*ktap); - *ktap = NULL; + igt_ktap_free(ktap); igt_skip_on(modprobe.err); igt_skip_on(igt_kernel_tainted(&taints)); @@ -1487,7 +1485,7 @@ void igt_kunit(const char *module_name, const char *suite, const char *opts) igt_fixture { char *suite_name = NULL, *case_name = NULL; - igt_ktap_free(ktap); + igt_ktap_free(&ktap); kunit_results_free(&tests, &suite_name, &case_name); diff --git a/lib/igt_ktap.c b/lib/igt_ktap.c index aa7ea84476..300fb2bb5a 100644 --- a/lib/igt_ktap.c +++ b/lib/igt_ktap.c @@ -310,7 +310,8 @@ struct igt_ktap_results *igt_ktap_alloc(struct igt_list_head *results) return ktap; } -void igt_ktap_free(struct igt_ktap_results *ktap) +void igt_ktap_free(struct igt_ktap_results **ktap) { - free(ktap); + free(*ktap); + *ktap = NULL; } diff --git a/lib/igt_ktap.h b/lib/igt_ktap.h index c422636bfc..7684e859b3 100644 --- a/lib/igt_ktap.h +++ b/lib/igt_ktap.h @@ -41,6 +41,6 @@ struct igt_ktap_results; struct igt_ktap_results *igt_ktap_alloc(struct igt_list_head *results); int igt_ktap_parse(const char *buf, struct igt_ktap_results *ktap); -void igt_ktap_free(struct igt_ktap_results *ktap); +void igt_ktap_free(struct igt_ktap_results **ktap); #endif /* IGT_KTAP_H */ diff --git a/lib/tests/igt_ktap_parser.c b/lib/tests/igt_ktap_parser.c index 6357bdf6a5..8c2d16080d 100644 --- a/lib/tests/igt_ktap_parser.c +++ b/lib/tests/igt_ktap_parser.c @@ -45,7 +45,7 @@ static void ktap_list(void) igt_assert_eq(igt_ktap_parse(" ok 4 test_case_4 # SKIP\n", ktap), -EINPROGRESS); igt_assert_eq(igt_ktap_parse("ok 3 test_suite_3\n", ktap), 0); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); igt_assert_eq(igt_list_length(&results), 8); @@ -107,7 +107,7 @@ static void ktap_results(void) igt_assert_eq(igt_ktap_parse(" ok 1 test_case\n", ktap), -EINPROGRESS); igt_assert_eq(igt_ktap_parse("not ok 1 test_suite\n", ktap), 0); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); igt_assert_eq(igt_list_length(&results), 2); @@ -162,7 +162,7 @@ static void ktap_success(void) igt_assert_eq(igt_ktap_parse("not ok 1 test_suite\n", ktap), 0); igt_assert_eq(igt_list_length(&results), 2); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); result = igt_list_last_entry(&results, result, link); igt_list_del(&result->link); @@ -186,48 +186,48 @@ static void ktap_top_version(void) ktap = igt_ktap_alloc(&results); igt_require(ktap); igt_assert_eq(igt_ktap_parse("1..1\n", ktap), -EPROTO); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); ktap = igt_ktap_alloc(&results); igt_require(ktap); /* TODO: change to -EPROTO as soon as related workaround is dropped */ igt_assert_eq(igt_ktap_parse(" KTAP version 1\n", ktap), -EINPROGRESS); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); ktap = igt_ktap_alloc(&results); igt_require(ktap); igt_assert_eq(igt_ktap_parse(" # Subtest: test_suite\n", ktap), -EPROTO); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); ktap = igt_ktap_alloc(&results); igt_require(ktap); igt_assert_eq(igt_ktap_parse(" 1..1\n", ktap), -EPROTO); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); ktap = igt_ktap_alloc(&results); igt_require(ktap); igt_assert_eq(igt_ktap_parse(" KTAP version 1\n", ktap), -EPROTO); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); ktap = igt_ktap_alloc(&results); igt_require(ktap); igt_assert_eq(igt_ktap_parse(" # Subtest: test_case\n", ktap), -EPROTO); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); ktap = igt_ktap_alloc(&results); igt_require(ktap); igt_assert_eq(igt_ktap_parse(" ok 1 parameter 1\n", ktap), -EPROTO); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); ktap = igt_ktap_alloc(&results); igt_require(ktap); igt_assert_eq(igt_ktap_parse(" ok 1 test_case\n", ktap), -EPROTO); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); ktap = igt_ktap_alloc(&results); igt_require(ktap); igt_assert_eq(igt_ktap_parse("ok 1 test_suite\n", ktap), -EPROTO); - igt_ktap_free(ktap); + igt_ktap_free(&ktap); } igt_main From patchwork Mon Mar 18 10:13:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13595198 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E03BC54E73 for ; Mon, 18 Mar 2024 10:36:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5FBEC10F54D; Mon, 18 Mar 2024 10:36:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="DSv67osK"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id C440C10F54D; Mon, 18 Mar 2024 10:36:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710758181; x=1742294181; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i2DNOxfCS127zn8QYpRJ1U9s+DlTDWfbWXS5vyx7TVk=; b=DSv67osKSgyCSRIca0Y1Ur0b2ANwrZOE0JtYTI9mMv4biPBuGCP2gWt2 yRdwmTi6phDOa4EbWZDFlkj/+xhx0o7gxzeB6L+FaRZ/Xplvi3yhX3ZQW bqufwoPMiBMR5V+KzJ6WdqUEwBSwyGFWnVk3WhVrzcDZPeLMn1HdPXyOz 8bv/BPOi4f3qKWS9deS9K8qbVhhmYN6+gqRFzZCWJG58NsPYrOHDexNeM TbHPlYoEb3O3UfGjNx5vjNftzWASCggzdHC2k6m7eu2VV3DOLi2wbF/hM 1mDYf9KPgynZQWLjbL7R8f/wyw5rOEAFzZVg53zeu62ztJCVoCgmSiGf0 A==; X-IronPort-AV: E=McAfee;i="6600,9927,11016"; a="6168201" X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="6168201" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 03:36:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="18015809" Received: from jkrzyszt-mobl2.ger.corp.intel.com ([10.213.26.105]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 03:36:19 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Kamil Konieczny , Mauro Carvalho Chehab , Jonathan Cavitt , Lucas De Marchi Subject: [PATCH i-g-t v3 3/5] lib/kunit: Time out promptly on missing KTAP report Date: Mon, 18 Mar 2024 11:13:29 +0100 Message-ID: <20240318103534.701693-10-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com> References: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" If a test provides a subtest name that doesn't match any test suites provided by the requested KUnit test module then no KTAP report appears in dmesg, not even an empty one as one may expect. As a consequence, we now loop endlessly around reading potential lines of the missing report from /dev/kmsg, until killed by IGT runner on timeout. When trying to collect names of test cases from a KTAP report generated in all skip mode, set an alarm that fires up 10 seconds after we start waiting for the report, interrupts blocking read() if pending, and terminates the subtest with SKIP result. As soon as we have collected a non-empty list of test cases, we may as well expect a non-empty KTAP report from actual execution of those test cases, assuming successful load of the KUnit test module in execution mode. Then, there is no need to set up a similar timeout before we start to extract and parse that report. Suggested-by: Kamil Konieczny Signed-off-by: Janusz Krzysztofik Reviewed-by: Kamil Konieczny --- lib/igt_kmod.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 8a6824ea7e..f0e4d5ec76 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -1204,12 +1204,19 @@ static void __igt_kunit_legacy(struct igt_ktest *tst, igt_skip_on_f(ret, "KTAP parser failed\n"); } +static void kunit_get_tests_timeout(int signal) +{ + igt_skip("Timed out while trying to extract a list of KUnit test cases from /dev/kmsg\n"); +} + static bool kunit_get_tests(struct igt_list_head *tests, struct igt_ktest *tst, const char *suite, const char *opts, struct igt_ktap_results **ktap) { + struct sigaction sigalrm = { .sa_handler = kunit_get_tests_timeout, }, + *saved; struct igt_ktap_result *r, *rn; unsigned long taints; int flags, err; @@ -1239,10 +1246,16 @@ static bool kunit_get_tests(struct igt_list_head *tests, *ktap = igt_ktap_alloc(tests); igt_require(*ktap); + igt_skip_on(sigaction(SIGALRM, &sigalrm, saved)); + alarm(10); + do err = kunit_kmsg_result_get(tests, NULL, tst->kmsg, *ktap); while (err == -EINPROGRESS); + alarm(0); + igt_debug_on(sigaction(SIGALRM, saved, NULL)); + igt_ktap_free(ktap); igt_skip_on_f(err, From patchwork Mon Mar 18 10:13:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13595199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B098C54E71 for ; Mon, 18 Mar 2024 10:36:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A7E5710F54A; Mon, 18 Mar 2024 10:36:24 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="WYlj2/gc"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E5B610F54A; Mon, 18 Mar 2024 10:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710758183; x=1742294183; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bAdW1IZHk6MOr/TR6Oar5fVbqRJv0DNEcjg8iLNyHnM=; b=WYlj2/gcS3WKNQN+pFT0G5mkLGtFdn3+sFGQt2fmbny1nZXGPudogNY+ U5FdmxvwghvRxHCCX0IVcwSN3nOdIzVkO9m7Zw3skVLDaYamk2pnkHCAy hd4gAzN2zaQvLLe6Gg+Iu8VZ2rYMiriHUgxbmIFAKwINyGdTvf8uhdQqv FoapJOlUeJdhA7vew9kJY+OWWN7C57dEmK8NN/+iRTH/dXO3jNjutbC5I gLUhhsSmC/9MNDHeHDBi/N9z/6x/WpwUwbtLDh8yT4InvlzgJxE2O5Kzs ho3AlATs5viu0XANOsoY3W5hQKasw9LKR5mLSLyDZdNhNP525f5qZE/G3 A==; X-IronPort-AV: E=McAfee;i="6600,9927,11016"; a="6168205" X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="6168205" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 03:36:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="18015814" Received: from jkrzyszt-mobl2.ger.corp.intel.com ([10.213.26.105]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 03:36:21 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Kamil Konieczny , Mauro Carvalho Chehab , Jonathan Cavitt , Lucas De Marchi Subject: [PATCH i-g-t v3 4/5] lib/kunit: Execute test cases synchronously Date: Mon, 18 Mar 2024 11:13:30 +0100 Message-ID: <20240318103534.701693-11-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com> References: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Up to now we were loading a KUnit test module in test execution mode only once per subtest, in background, and then, in parallel with execution of test cases while the module was loading, we were looking through dmesg for KTAP results from each expected test case. As a consequence, our IGT messages were more or less delayed, never in full sync with kernel messages. Moreover, parsing of KTAP results from already completed test cases could be abandoned on a failure from loading the test module or kernel taint caused by a subsequent test case. Also, parsing of KTAP results from all subsequent test cases could be abandoned on a failure of the parser caused by any test case. Other than that, if a user requested a single dynamic sub-subtest, all test cases were executed anyway while results from only one of them that corresponded to the selected dynamic sub-subtest were reported. That way, kernel messages from unrelated test cases, not only the selected one, could contribute to dmesg-fail or dmesg- warn CI results from that sub-subtest. Since recent KUnit implementation is capable of executing only those test cases that match a user filter, stop executing all of them asynchronously and parsing their KTAP results as they appear. Instead, reload the test module once per each dynamic sub-subtest with a filter that selects a specific test case and wait for its completion. If successful and no kernel taint has occurred then parse the whole KTAP report from a single test case it has produced and translate it to IGT result of that single corresponding sub-subtest. With that in place, we no longer need to skip the whole subtest on a failure from module loading or KTAP reading or parsing. Since such event is now local to execution of an individual test case, only fail its corresponding dynamic sub-subtests and continue with subsequent ones. However, still omit execution of subsequent test cases once the kernel gets tainted. v3: Refresh on top of changes to struct igt_ktap_results pointer handling, - use "for(;;) {}" instead of "do {} while();" when processing results from parametrized test cases (Kamil). v2: Refresh on top of changes to KUnit filters handling, - include the code of a new helper from a previously separate patch, - actually limit the scope of the helper to fetching a KTAP report from a file descriptor, and let the caller decide on how other steps, like setting up filters or loading a test module, and errors they return are handled, - similar to kernel taint handling, just omit any remaining dynamic sub- subtests if unloading the test module fails, - update commit description with a more detailed justification of why we need these changes. Signed-off-by: Janusz Krzysztofik Cc: Mauro Carvalho Chehab Cc: Jonathan Cavitt Cc: Kamil Konieczny Reviewed-by: Kamil Konieczny --- lib/igt_kmod.c | 156 +++++++++++++++++-------------------------------- 1 file changed, 54 insertions(+), 102 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index f0e4d5ec76..c495d11b16 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -1070,6 +1070,25 @@ static void kunit_results_free(struct igt_list_head *results, free(*suite_name); } +static int kunit_get_results(struct igt_list_head *results, int kmsg_fd, + struct igt_ktap_results **ktap) +{ + int err; + + *ktap = igt_ktap_alloc(results); + if (igt_debug_on(!*ktap)) + return -ENOMEM; + + do + igt_debug_on((err = kunit_kmsg_result_get(results, NULL, kmsg_fd, *ktap), + err && err != -EINPROGRESS)); + while (err == -EINPROGRESS); + + igt_ktap_free(ktap); + + return err; +} + static void __igt_kunit_legacy(struct igt_ktest *tst, const char *subtest, const char *opts) @@ -1277,82 +1296,52 @@ static void __igt_kunit(struct igt_ktest *tst, 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; - pthread_mutexattr_t attr; - IGT_LIST_HEAD(results); - int ret = -EINPROGRESS; - unsigned long taints; - - igt_skip_on(lseek(tst->kmsg, 0, SEEK_END) < 0); - - *ktap = igt_ktap_alloc(&results); - igt_require(*ktap); + struct igt_ktap_result *t; igt_list_for_each_entry(t, tests, link) { + char *suite_name = NULL, *case_name = NULL; + IGT_LIST_HEAD(results); + unsigned long taints; + igt_dynamic_f("%s%s%s", strcmp(t->suite_name, subtest) ? t->suite_name : "", strcmp(t->suite_name, subtest) ? "-" : "", t->case_name) { + struct igt_ktap_result *r = NULL; + char glob[1024]; + int i; - if (!modprobe.thread) { - igt_require(kunit_set_filtering(suite, NULL, NULL)); + igt_skip_on(igt_kernel_tainted(&taints)); - igt_assert_eq(pthread_mutexattr_init(&attr), 0); - igt_assert_eq(pthread_mutexattr_setrobust(&attr, - PTHREAD_MUTEX_ROBUST), - 0); - igt_assert_eq(pthread_mutex_init(&modprobe.lock, - &attr), 0); + igt_fail_on(lseek(tst->kmsg, 0, SEEK_END) == -1 && errno); - modprobe.err = pthread_create(&modprobe.thread, - NULL, - modprobe_task, - &modprobe); - igt_assert_eq(modprobe.err, 0); + igt_assert_lt(snprintf(glob, sizeof(glob), "%s.%s", + t->suite_name, t->case_name), + sizeof(glob)); + igt_assert(kunit_set_filtering(glob, NULL, NULL)); - igt_assert(igt_list_empty(&results)); - igt_assert_eq(ret, -EINPROGRESS); - ret = kunit_kmsg_result_get(&results, &modprobe, - tst->kmsg, *ktap); + igt_assert_eq(modprobe(tst->kmod, opts), 0); + igt_assert_eq(igt_kernel_tainted(&taints), 0); + + igt_assert_eq(kunit_get_results(&results, tst->kmsg, ktap), 0); + + for (i = 0; i < 2; i++) { + kunit_result_free(&r, &suite_name, &case_name); igt_fail_on(igt_list_empty(&results)); r = igt_list_first_entry(&results, r, link); - } - while (igt_debug_on_f(strcmp(r->suite_name, t->suite_name), + igt_fail_on_f(strcmp(r->suite_name, t->suite_name), "suite_name expected: %s, got: %s\n", - t->suite_name, r->suite_name) || - igt_debug_on_f(strcmp(r->case_name, t->case_name), + t->suite_name, r->suite_name); + igt_fail_on_f(strcmp(r->case_name, t->case_name), "case_name expected: %s, got: %s\n", - t->case_name, r->case_name) || - r->code == IGT_EXIT_INVALID) { + t->case_name, r->case_name); - int code = r->code; - - kunit_result_free(&r, &suite_name, &case_name); - if (igt_list_empty(&results)) { - igt_assert_eq(ret, -EINPROGRESS); - ret = kunit_kmsg_result_get(&results, - &modprobe, - tst->kmsg, - *ktap); - igt_fail_on(igt_list_empty(&results)); - } - - r = igt_list_first_entry(&results, r, link); - - if (code != IGT_EXIT_INVALID) - continue; + if (r->code != IGT_EXIT_INVALID) + break; /* result from parametrized test case */ - igt_fail_on_f(strcmp(r->suite_name, suite_name), - "suite_name expected: %s, got: %s\n", - suite_name, r->suite_name); - igt_fail_on_f(strcmp(r->case_name, case_name), - "case_name expected: %s, got: %s\n", - case_name, r->case_name); } igt_assert_neq(r->code, IGT_EXIT_INVALID); @@ -1371,58 +1360,21 @@ static void __igt_kunit(struct igt_ktest *tst, igt_fail(r->code); } igt_assert_eq(r->code, IGT_EXIT_SUCCESS); - - switch (pthread_mutex_lock(&modprobe.lock)) { - case 0: - igt_debug_on(pthread_mutex_unlock(&modprobe.lock)); - break; - case EOWNERDEAD: - /* leave the mutex unrecoverable */ - igt_debug_on(pthread_mutex_unlock(&modprobe.lock)); - __attribute__ ((fallthrough)); - case ENOTRECOVERABLE: - igt_assert_eq(modprobe.err, 0); - break; - default: - igt_debug("pthread_mutex_lock() failed\n"); - break; - } - - igt_assert_eq(igt_kernel_tainted(&taints), 0); } - if (igt_debug_on(ret != -EINPROGRESS)) - break; - } - - kunit_results_free(&results, &suite_name, &case_name); + kunit_results_free(&results, &suite_name, &case_name); - if (modprobe.thread) { - switch (pthread_mutex_lock(&modprobe.lock)) { - case 0: - igt_debug_on(pthread_cancel(modprobe.thread)); - igt_debug_on(pthread_mutex_unlock(&modprobe.lock)); - igt_debug_on(pthread_join(modprobe.thread, NULL)); - break; - case EOWNERDEAD: - /* leave the mutex unrecoverable */ - igt_debug_on(pthread_mutex_unlock(&modprobe.lock)); + if (igt_debug_on(igt_kernel_tainted(&taints))) { + igt_info("Kernel tainted, not executing more selftests.\n"); break; - case ENOTRECOVERABLE: - break; - default: - igt_debug("pthread_mutex_lock() failed\n"); - igt_debug_on(pthread_join(modprobe.thread, NULL)); + } + + if (igt_debug_on(kmod_module_remove_module(tst->kmod, + KMOD_REMOVE_FORCE))) { + igt_info("Unloading test module failed, not executing more selftests.\n"); break; } } - - igt_ktap_free(ktap); - - igt_skip_on(modprobe.err); - igt_skip_on(igt_kernel_tainted(&taints)); - if (ret != -EINPROGRESS) - igt_skip_on_f(ret, "KTAP parser failed\n"); } /** From patchwork Mon Mar 18 10:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13595201 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8CBAC54E58 for ; Mon, 18 Mar 2024 10:36:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 34F0A10F552; Mon, 18 Mar 2024 10:36:26 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="F5rSZIgc"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8099B10F552; Mon, 18 Mar 2024 10:36:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710758185; x=1742294185; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=a0v1nVFvLUOLk0DnUPtRMAhsBxCXgFxaJBgTDsEAuOI=; b=F5rSZIgc/I/DKwyNDDtHB140Qhx/JZ7AfKwBA9quR2YYkGmz5lok4PyS uN80R6Ir20iOPTG1rjz+G+C3BIou54wfaenIB5Z+FzsFfJECMbjJZ2C/M nMoeDZ89Uv1BQZNLdL5bxK2tqWMzWvFczDuAj9zx/tMXWVPMkewSIc1zA H8+dYE6cnC+C6fIWyI5mdE+OaXU4Sah237+i6pNTgEsIwNTetf09TMCcM GBGg8QJcUvddOyHM9eVPn6mCzstVCrFkX5dTocDyGcXanFU9/HbUCFGo7 lzPo8yY2pan8XAL4dNwdX+vzJRCdvYdyNY3enegIWoU2vC0/Rhu607len g==; X-IronPort-AV: E=McAfee;i="6600,9927,11016"; a="6168208" X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="6168208" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 03:36:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,134,1708416000"; d="scan'208";a="18015818" Received: from jkrzyszt-mobl2.ger.corp.intel.com ([10.213.26.105]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2024 03:36:23 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Kamil Konieczny , Mauro Carvalho Chehab , Jonathan Cavitt , Lucas De Marchi Subject: [PATCH i-g-t v3 5/5] lib/kunit: Minimize code duplication Date: Mon, 18 Mar 2024 11:13:31 +0100 Message-ID: <20240318103534.701693-12-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com> References: <20240318103534.701693-7-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" A new helper has been introduced recently, used for fetching KTAP results of a single test case. Since that helper is called for that purpose only after the test module is loaded with all other test cases filtered out, its actual implementation is as simple as collecting all results from a single KTAP report, no matter how many test suites and test cases it covers. Then, it's a good candidate for reuse in other scenarios when a single KTAP report is handled, e.g., when we collect a list of test cases from a single test suite or test module. Go for it. v3: Rebased on top of changes to struct igt_ktap_results pointer handling. v2: Rebased on invalid test suite name workaround. Signed-off-by: Janusz Krzysztofik Cc: Jonathan Cavitt Reviewed-by: Kamil Konieczny --- lib/igt_kmod.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index c495d11b16..8979a5928b 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -1262,21 +1262,14 @@ 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); - igt_skip_on(sigaction(SIGALRM, &sigalrm, saved)); alarm(10); - do - err = kunit_kmsg_result_get(tests, NULL, tst->kmsg, *ktap); - while (err == -EINPROGRESS); + err = kunit_get_results(tests, tst->kmsg, ktap); alarm(0); igt_debug_on(sigaction(SIGALRM, saved, NULL)); - igt_ktap_free(ktap); - igt_skip_on_f(err, "KTAP parser failed while getting a list of test cases\n");