From patchwork Wed Oct 11 14:17:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417493 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 214FACD6E7A for ; Wed, 11 Oct 2023 14:31:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7B15910E8BA; Wed, 11 Oct 2023 14:31:45 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4761810E8BA; Wed, 11 Oct 2023 14:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034704; x=1728570704; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KXcU60l+B2Pe8oGTg/ujLfCTJLWW5czT2nkdjrjHMAY=; b=Vc06z0ZYncQ1sgAAzJ9NzCRZ/gvTN6M3inkEcPA9EiLCDiEqJGer/+oU N1Mq+y5lG7O2ipBSiLzxQvkTZOZKWaTdRBi82QbShvR4E/uJ2SVCsO4nR 0J1RcWoMjh+LMUtwGkyM/FUTlSnc0/I07hcnY7lj7sE8kfriKJQVan480 a/YfXdbWceKFR7Wf5nexsk/Q+2XifnVLUsho2QH4OVA8d9XFev2n9Jjfk wYlNzuXNJa4cDGC2iFYUWiY9Ty0sHCUOMyi43dlkVR2SB5ZArXDzo5g/5 Ceps9xJ0FLG/4RADCubf4dqb680a8LgxCDei72PJKMh/g6UQwuYl1QT7f A==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042015" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042015" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:31:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641531" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641531" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:29:56 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:36 +0200 Message-ID: <20231011141734.590321-14-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 01/11] lib/ktap: Improve TODO workaround description 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" A workaround was implemented in IGT KTAP parser so it could accepted KTAP reports with missing top level KTAP version and test suite plan headers. While the issue has been fixed by a kernel side commit c95e7c05c139 ("kunit: Report the count of test suites in a module"), included in the mainline kernel since v6.6-rc1, we still need to keep that workaround in place to preserve IGT compatibility with LTS kernel version 6.1 as long as it is used by major Linux distributions. Update the comment with a reference to the kernel side fix and a clarification on why we need to keep the workaround in place. Signed-off-by: Janusz Krzysztofik Reviewed-by: Kamil Konieczny Reviewed-by: Mauro Carvaho Chehab --- lib/igt_ktap.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/igt_ktap.c b/lib/igt_ktap.c index 5eac102417..3df4d6950d 100644 --- a/lib/igt_ktap.c +++ b/lib/igt_ktap.c @@ -91,9 +91,16 @@ int igt_ktap_parse(const char *buf, struct igt_ktap_results *ktap) "%*1[ ]%*1[ ]%*1[ ]%*1[ ]KTAP%*[ ]version%*[ ]%u %n", &n, &len) == 1 && len == strlen(buf))) { /* - * TODO: drop the following workaround as soon as - * kernel side issue of missing lines with top level - * KTAP version and test suite plan is fixed. + * TODO: drop the following workaround, which addresses a kernel + * side issue of missing lines that provide top level KTAP + * version and test suite plan, as soon as no longer needed. + * + * The issue has been fixed in v6.6-rc1, commit c95e7c05c139 + * ("kunit: Report the count of test suites in a module"), + * but we still need this workaround for as long as LTS kernel + * version 6.1, with DRM selftests already converted to Kunit, + * but without that missing Kunit headers issue fixed, is used + * by major Linux distributions. */ if (ktap->expect == KTAP_START) { ktap->suite_count = 1; From patchwork Wed Oct 11 14:17:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417495 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 15F53CD6E77 for ; Wed, 11 Oct 2023 14:31:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E937510E8C2; Wed, 11 Oct 2023 14:31:47 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4B32910E8BF; Wed, 11 Oct 2023 14:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034706; x=1728570706; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/RIDSrKU9FdqsdvZzlKw77yW3mncuRgCUOVcczpa/w8=; b=nbBNDekwJhJ/bNx/UVBNiJK8KN3VbUaFj86tRxIhjK0byTyv7NBi3ICr R9NzZiSVnltrwrvmyl+t3FbNwdU1Zt4+7EVJrvm8XZUUNEMYgrOADVzvR AXr35SPQ/KxAzeamwe+4bH3Yey0be04r0hdZMWbbVNX6c/7XKNs04R/nI c7j312HWq6+DgId3uYDIm0WhT7nU5hESFW7+B3eKxh75gbCEUkp3FNf6u 8IGnd6CrssAvP/vfbCc2ydHHMEgVwWAhCPJ8A3mRcXX8/BmLksNkD069f an80VCi4OJM1HIqhDMAfCCR8nxBsDXMsg/9TTP8hvUYgPkCAZFPEL8b6i w==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042023" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042023" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:31:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641538" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641538" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:29:58 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:37 +0200 Message-ID: <20231011141734.590321-15-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 02/11] lib/kunit: Fix handling of potential errors from F_GETFL 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Function fcntl(..., F_GETFL, ...) that returns file status flags may also return a negative error code. Handle that error instead of blindly using the returned value as flags. Signed-off-by: Janusz Krzysztofik Reviewed-by: Kamil Konieczny Reviewed-by: Mauro Carvaho Chehab --- lib/igt_kmod.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index d98e6c5f9e..05ff178b27 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -783,8 +783,8 @@ static void __igt_kunit(struct igt_ktest *tst, const char *opts) igt_skip_on_f(tst->kmsg < 0, "Could not open /dev/kmsg\n"); - flags = fcntl(tst->kmsg, F_GETFL, 0) & ~O_NONBLOCK; - igt_skip_on_f(fcntl(tst->kmsg, F_SETFL, flags) == -1, + 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); From patchwork Wed Oct 11 14:17:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417496 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 205DCCD6E7C for ; Wed, 11 Oct 2023 14:31:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C62010E8CB; Wed, 11 Oct 2023 14:31:53 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 852CE10E8C6; Wed, 11 Oct 2023 14:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034708; x=1728570708; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/mtCjtYhA0W3JjBJCJht7t0OvWu85GqnVjjWvhSZz+s=; b=RM5uwG5smkOkJ8uNak/d3LcTrQH2Kl6NNyfR63t38dmeCaB3ayK4oGdq p7xOz3uYZNm6Qk9BZ2ankpk//3h4jRy4NUwIHT0bg2UGC6/m5MJ+kmqPE sJLZO6wgmGW8awUeQvEhqVAtxFZrmpUYikRc31oMsCpKmfZKAfmk3iXlq mzvK+Vnq6vaPot/9ZmLPDBiQCyDtDrgUR8f928LsMAFV97BdW48nbTGPR 4+OYzNfFqbiDNhmK2RCtZciU6CpWBKxTyCKazRe5aCntsXcnGh7NF7BXg Iq3qL3ZCZYs2SYMQTlAR7EsIj++jucoQTgtj8zOo0jRMBCPwoT6wBybZ/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042030" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042030" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:31:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641552" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641552" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:30:00 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:38 +0200 Message-ID: <20231011141734.590321-16-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 03/11] lib/kunit: Be more verbose on errors 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Use a more verbose variant of igt_fail() when failing a dynamic sub- subtest on kernel taint. Also, print a debug message on string duplication failure. Signed-off-by: Janusz Krzysztofik Reviewed-by: Kamil Konieczny --- lib/igt_kmod.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 05ff178b27..df0e650d49 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -834,7 +834,7 @@ static void __igt_kunit(struct igt_ktest *tst, const char *opts) if (!pthread_tryjoin_np(modprobe_thread, NULL)) igt_assert_eq(modprobe.err, 0); - igt_fail_on(igt_kernel_tainted(&taints)); + igt_assert_eq(igt_kernel_tainted(&taints), 0); } free(result); @@ -861,7 +861,7 @@ void igt_kunit(const char *module_name, const char *name, const char *opts) */ if (!name) { name = strdup(module_name); - if (name) { + if (!igt_debug_on(!name)) { char *suffix = strstr(name, "_test"); if (!suffix) From patchwork Wed Oct 11 14:17:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417497 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 C54AFCD6E77 for ; Wed, 11 Oct 2023 14:31:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8FB8110E8CD; Wed, 11 Oct 2023 14:31:53 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6172C10E8C5; Wed, 11 Oct 2023 14:31:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034710; x=1728570710; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CyKAUbGGIKwZ5RjMwj4Kul+jKwaY+pwtiD7vroI0fjA=; b=nBAe2QM0WcIA7FPDXHPZIzfIXT/ZJ3vdIWDJFZ3qKlKVVtI9rJBYsLLi YhdhAPH1v9jtLAIGJw+OP/BbMfqbgFLWdIf1BrS2iINF7AKy4CP8jXJPM jdQ0qe6X6Gvg3u5HSBqJ2JkeMvhywVRldBcs95SOYj9kCoC4qEsfKLbuH esBEINDm/BmlP8i5H9yFsNklFdHeyGYO0Sq0A6boFsDw31IK9prGjPVzJ oNitEK/4+yOit6o+JIxRtMjEtPCfl8ZyS7+lm9XMIEsjdajH1R5UKlliP FlMhC6qtHZ9JmtEU8YfZygKkBaUU8lnyUMm+k5tFsUyRJz5tfmmnfDeun g==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042033" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042033" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:31:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641559" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641559" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:30:03 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:39 +0200 Message-ID: <20231011141734.590321-17-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 04/11] lib/kunit: Fix misplaced igt_kunit() doc 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" When igt_kunit() was converted to a helper and wrapped with a new function promoted to take the name and role of the library API, related documentation was left unchanged and still placed in front the demoted function. Update that documentation and move it to where it now belongs. Signed-off-by: Janusz Krzysztofik Reviewed-by: Kamil Konieczny Reviewed-by: Mauro Carvaho Chehab --- lib/igt_kmod.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index df0e650d49..426ae5b26f 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -762,15 +762,6 @@ static void *modprobe_task(void *arg) return NULL; } -/** - * igt_kunit: - * @module_name: the name of the module - * @opts: options to load the module - * - * Loads the test module, parses its (k)tap dmesg output, then unloads it - * - * Returns: IGT default codes - */ static void __igt_kunit(struct igt_ktest *tst, const char *opts) { struct modprobe_data modprobe = { tst->kmod, opts, 0, }; @@ -849,6 +840,14 @@ static void __igt_kunit(struct igt_ktest *tst, const char *opts) igt_skip_on_f(ret, "KTAP parser failed\n"); } +/** + * igt_kunit: + * @module_name: the name of the module + * @name: the name of subtest, if different from that derived from module name + * @opts: options to load the module + * + * Loads the test module, parses its (k)tap dmesg output, then unloads it + */ void igt_kunit(const char *module_name, const char *name, const char *opts) { struct igt_ktest tst = { .kmsg = -1, }; From patchwork Wed Oct 11 14:17:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417499 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 D2AF3CD6E7D for ; Wed, 11 Oct 2023 14:32:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 91C5510E8D1; Wed, 11 Oct 2023 14:31:56 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 34D2510E8CE; Wed, 11 Oct 2023 14:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034714; x=1728570714; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CHl2TnZ4drkQgBfQAc7vGUPqggUgBtm9J7n++ozBqgA=; b=F4j2rTv3lfO7cIY54sNbyw8v/uQC+rWjGibrX5VZeopFvNzHNq0dbykc pi3i876VUWS9VCN3Ya0pwt8gxoYtNFPyoF2ZWXU3f1vLEULMIIlbymMgh e0b1QGs8ynX5Il42wEu9b2OhAiLRVIUmhKMnGMXzYYXgit9j1GvEBO9Wh 5D0++hqDzZsIAM+nmbCTnf3guzats/Sh+/YI2wslOeDEd7D2J2JFNgWKx aX98gWA/z4wUrT46TR7DMtJMOZYqvyw+sibvT/2WDFsEtLYoC7butzYWN A2yJLwwuHT/ZyZrOWSFcgI6/NQfL1xUjDgofDt8x2Out8AgQVOCJ0AlZo A==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042046" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042046" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:31:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641572" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641572" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:30:05 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:40 +0200 Message-ID: <20231011141734.590321-18-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 05/11] lib/kunit: Parse KTAP report from the main process thread 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" There was an attempt to parse KTAP reports in the background while a kunit test module is loading. However, since dynamic sub-subtests can be executed only from the main thread, that attempt was not quite successful, as IGT results from all executed kunit test cases were generated only after loading of kunit test module completed. Now that the parser maintains its state and we can call it separately for each input line of a KTAP report, it is perfectly possible to call the parser from the main thread while the module is loading in the background, and convert results from kunit test cases immediately to results of IGT dynamic sub-subtests by running an igt_dynamic() section for each result as soon as returned by the parser. Drop igt_ktap_parser() thread and execute igt_dynamic() for each kunit result obtained from igt_ktap_parse() called from the main thread. Also, drop no longer needed functions from igt_ktap soruces. v4: Print debug message on pthread_kill() error once per loop (Mauro), - move "parent" field of the structure near other pthread_* type fields (Kamil), - drop unneeded explicit return from noop void function (Kamil), - if (!err) looks strange, add a comment (Kamil), - preserve a link to KTAP standard in a comment above the winning implementation of KTAP parser (Kamil). v3: Fix ktap structure not freed on lseek error, - fix initial SIGCHLD handler not restored, - fix missing handling of potential errors returned by sigaction, - fix potential race of read() vs. ptherad_kill(), use robust mutex for synchronization with modprobe thread, - fix potentially illegal use of igt_assert() called outside of dynamic sub-subtest section, - fix unsupported exit code potentially passed to igt_fail(), - no need to fail a dynamic sub-subtest on potential KTAP parser error after a valid result from the parser has been processed, - fix trailing newlines missing from error messages, - add more debug statements, - integrate common code around kunit_result_free() into it. v2: Interrupt blocking read() on modprobe failure. Signed-off-by: Janusz Krzysztofik Acked-by: Mauro Carvalho Chehab # v2 Reviewed-by: Kamil Konieczny --- lib/igt_kmod.c | 264 +++++++++++++++++++---- lib/igt_ktap.c | 569 +------------------------------------------------ lib/igt_ktap.h | 22 -- 3 files changed, 226 insertions(+), 629 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 426ae5b26f..93d9479219 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -1,5 +1,5 @@ /* - * Copyright © 2016 Intel Corporation + * Copyright © 2016-2023 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -26,7 +26,12 @@ #include #include #include +#include +#include #include +#include + +#include "assembler/brw_compat.h" /* [un]likely() */ #include "igt_aux.h" #include "igt_core.h" @@ -751,6 +756,9 @@ struct modprobe_data { struct kmod_module *kmod; const char *opts; int err; + pthread_t parent; + pthread_mutex_t lock; + pthread_t thread; }; static void *modprobe_task(void *arg) @@ -759,16 +767,135 @@ static void *modprobe_task(void *arg) data->err = modprobe(data->kmod, data->opts); + if (igt_debug_on(data->err)) { + bool once = false; + int err; + + while (err = pthread_mutex_trylock(&data->lock), + err && !igt_debug_on(err != EBUSY)) { + igt_debug_on(pthread_kill(data->parent, SIGCHLD) && + !once); + once = true; + } + } else { + /* let main thread use mutex to detect modprobe completion */ + igt_debug_on(pthread_mutex_lock(&data->lock)); + } + return NULL; } +static void kunit_sigchld_handler(int signal) +{ +} + +static int kunit_kmsg_result_get(struct igt_list_head *results, + struct modprobe_data *modprobe, + int fd, struct igt_ktap_results *ktap) +{ + struct sigaction sigchld = { .sa_handler = kunit_sigchld_handler, }, + *saved; + char record[BUF_LEN + 1], *buf; + unsigned long taints; + int ret; + + do { + int err; + + if (igt_debug_on(igt_kernel_tainted(&taints))) + return -ENOTRECOVERABLE; + + err = igt_debug_on(sigaction(SIGCHLD, &sigchld, saved)); + if (err == -1) + return -errno; + else if (unlikely(err)) + return err; + + err = pthread_mutex_lock(&modprobe->lock); + switch (err) { + case EOWNERDEAD: + /* leave the mutex unrecoverable */ + igt_debug_on(pthread_mutex_unlock(&modprobe->lock)); + __attribute__ ((fallthrough)); + case ENOTRECOVERABLE: + igt_debug_on(sigaction(SIGCHLD, saved, NULL)); + if (igt_debug_on(modprobe->err)) + return modprobe->err; + break; + case 0: + break; + default: + igt_debug("pthread_mutex_lock() error: %d\n", err); + igt_debug_on(sigaction(SIGCHLD, saved, NULL)); + return -err; + } + + ret = read(fd, record, BUF_LEN); + + if (!err) { /* pthread_mutex_lock() succeeded */ + igt_debug_on(pthread_mutex_unlock(&modprobe->lock)); + igt_debug_on(sigaction(SIGCHLD, saved, NULL)); + } + + if (igt_debug_on(!ret)) + return -ENODATA; + if (igt_debug_on(ret == -1)) + return -errno; + if (unlikely(igt_debug_on(ret < 0))) + break; + + /* skip kmsg continuation lines */ + if (igt_debug_on(*record == ' ')) + continue; + + /* NULL-terminate the record */ + record[ret] = '\0'; + + /* detect start of log message, continue if not found */ + buf = strchrnul(record, ';'); + if (igt_debug_on(*buf == '\0')) + continue; + buf++; + + ret = igt_ktap_parse(buf, ktap); + if (!ret || igt_debug_on(ret != -EINPROGRESS)) + break; + } while (igt_list_empty(results)); + + return ret; +} + +static void kunit_result_free(struct igt_ktap_result **r, + char **suite_name, char **case_name) +{ + if (!*r) + return; + + igt_list_del(&(*r)->link); + + if ((*r)->suite_name != *suite_name) { + free(*suite_name); + *suite_name = (*r)->suite_name; + } + + if ((*r)->case_name != *case_name) { + free(*case_name); + *case_name = (*r)->case_name; + } + + free((*r)->msg); + free(*r); + *r = NULL; +} + static void __igt_kunit(struct igt_ktest *tst, const char *opts) { - struct modprobe_data modprobe = { tst->kmod, opts, 0, }; - struct kmod_module *kunit_kmod; - bool is_builtin; - struct ktap_test_results *results; - pthread_t modprobe_thread; + struct modprobe_data modprobe = { tst->kmod, opts, 0, pthread_self(), }; + char *suite_name = NULL, *case_name = NULL; + struct igt_ktap_result *r, *rn; + struct igt_ktap_results *ktap; + pthread_mutexattr_t attr; + IGT_LIST_HEAD(results); unsigned long taints; int flags, ret; @@ -780,60 +907,119 @@ static void __igt_kunit(struct igt_ktest *tst, const char *opts) igt_skip_on(lseek(tst->kmsg, 0, SEEK_END) < 0); - igt_skip_on(kmod_module_new_from_name(kmod_ctx(), "kunit", &kunit_kmod)); - is_builtin = kmod_module_get_initstate(kunit_kmod) == KMOD_MODULE_BUILTIN; - kmod_module_unref(kunit_kmod); + igt_skip_on(pthread_mutexattr_init(&attr)); + igt_skip_on(pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST)); + igt_skip_on(pthread_mutex_init(&modprobe.lock, &attr)); - results = ktap_parser_start(tst->kmsg, is_builtin); + ktap = igt_ktap_alloc(&results); + igt_require(ktap); - if (igt_debug_on(pthread_create(&modprobe_thread, NULL, + if (igt_debug_on(pthread_create(&modprobe.thread, NULL, modprobe_task, &modprobe))) { - ktap_parser_cancel(); - igt_ignore_warn(ktap_parser_stop()); + igt_ktap_free(ktap); igt_skip("Failed to create a modprobe thread\n"); } - while (READ_ONCE(results->still_running) || !igt_list_empty(&results->list)) - { - struct ktap_test_results_element *result; - - if (!pthread_tryjoin_np(modprobe_thread, NULL) && modprobe.err) { - ktap_parser_cancel(); + do { + ret = kunit_kmsg_result_get(&results, &modprobe, + tst->kmsg, ktap); + if (igt_debug_on(ret && ret != -EINPROGRESS)) break; - } - if (igt_kernel_tainted(&taints)) { - ktap_parser_cancel(); - pthread_cancel(modprobe_thread); + if (igt_debug_on(igt_list_empty(&results))) break; - } - pthread_mutex_lock(&results->mutex); - if (igt_list_empty(&results->list)) { - pthread_mutex_unlock(&results->mutex); - continue; - } + r = igt_list_first_entry(&results, r, link); - result = igt_list_first_entry(&results->list, result, link); + igt_dynamic_f("%s-%s", r->suite_name, r->case_name) { + if (r->code == IGT_EXIT_INVALID) { + /* parametrized test case, get actual result */ + kunit_result_free(&r, &suite_name, &case_name); - igt_list_del(&result->link); - pthread_mutex_unlock(&results->mutex); + igt_assert(igt_list_empty(&results)); - igt_dynamic(result->test_name) { - igt_assert(READ_ONCE(result->passed)); + ret = kunit_kmsg_result_get(&results, &modprobe, + tst->kmsg, ktap); + if (ret != -EINPROGRESS) + igt_fail_on(ret); + + igt_fail_on(igt_list_empty(&results)); + + r = igt_list_first_entry(&results, r, link); + + 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); + } - if (!pthread_tryjoin_np(modprobe_thread, NULL)) + igt_assert_neq(r->code, IGT_EXIT_INVALID); + + if (r->msg && *r->msg) { + igt_skip_on_f(r->code == IGT_EXIT_SKIP, + "%s\n", r->msg); + igt_fail_on_f(r->code == IGT_EXIT_FAILURE, + "%s\n", r->msg); + igt_abort_on_f(r->code == IGT_EXIT_ABORT, + "%s\n", r->msg); + } else { + igt_skip_on(r->code == IGT_EXIT_SKIP); + igt_fail_on(r->code == IGT_EXIT_FAILURE); + if (r->code == IGT_EXIT_ABORT) + 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); } - free(result); + kunit_result_free(&r, &suite_name, &case_name); + + } while (ret == -EINPROGRESS); + + igt_list_for_each_entry_safe(r, rn, &results, link) + kunit_result_free(&r, &suite_name, &case_name); + + free(case_name); + free(suite_name); + + 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)); + break; + case ENOTRECOVERABLE: + break; + default: + igt_debug("pthread_mutex_lock() failed\n"); + igt_debug_on(pthread_join(modprobe.thread, NULL)); + break; } - pthread_join(modprobe_thread, NULL); - - ret = ktap_parser_stop(); + igt_ktap_free(ktap); igt_skip_on(modprobe.err); igt_skip_on(igt_kernel_tainted(&taints)); diff --git a/lib/igt_ktap.c b/lib/igt_ktap.c index 3df4d6950d..aa7ea84476 100644 --- a/lib/igt_ktap.c +++ b/lib/igt_ktap.c @@ -4,17 +4,11 @@ * Copyright © 2023 Intel Corporation */ -#include -#include -#include -#include #include #include #include #include -#include -#include "igt_aux.h" #include "igt_core.h" #include "igt_ktap.h" #include "igt_list.h" @@ -48,6 +42,7 @@ struct igt_ktap_results { * * This function parses a line of text for KTAP report data * and passes results back to IGT kunit layer. + * https://kernel.org/doc/html/latest/dev-tools/ktap.html */ int igt_ktap_parse(const char *buf, struct igt_ktap_results *ktap) { @@ -319,565 +314,3 @@ void igt_ktap_free(struct igt_ktap_results *ktap) { free(ktap); } - -#define DELIMITER "-" - -struct ktap_parser_args { - int fd; - bool is_builtin; - int ret; -} ktap_args; - -static struct ktap_test_results results; - -static int log_to_end(enum igt_log_level level, int fd, - char *record, const char *format, ...) __attribute__((format(printf, 4, 5))); - -/** - * log_to_end: - * @level: #igt_log_level - * @record: record to store the read data - * @format: format string - * @...: optional arguments used in the format string - * - * This is an altered version of the generic structured logging helper function - * igt_log capable of reading to the end of a given line. - * - * Returns: 0 for success, or -2 if there's an error reading from the file - */ -static int log_to_end(enum igt_log_level level, int fd, - char *record, const char *format, ...) -{ - va_list args; - const char *lend; - - /* Cutoff after newline character, in order to not display garbage */ - char *cutoff = strchr(record, '\n'); - if (cutoff) { - if (cutoff - record < BUF_LEN) - cutoff[1] = '\0'; - } - - va_start(args, format); - igt_vlog(IGT_LOG_DOMAIN, level, format, args); - va_end(args); - - lend = strchrnul(record, '\n'); - while (*lend == '\0') { - igt_log(IGT_LOG_DOMAIN, level, "%s", record); - - if (read(fd, record, BUF_LEN) < 0) { - if (errno == EPIPE) - igt_warn("kmsg truncated: too many messages. You may want to increase log_buf_len in kmcdline\n"); - else - igt_warn("an error occurred while reading kmsg: %m\n"); - - return -2; - } - - lend = strchrnul(record, '\n'); - } - return 0; -} - -/** - * lookup_value: - * @haystack: the string to search in - * @needle: the string to search for - * - * Returns: the value of the needle in the haystack, or -1 if not found. - */ -static long lookup_value(const char *haystack, const char *needle) -{ - const char *needle_rptr; - char *needle_end; - long num; - - needle_rptr = strcasestr(haystack, needle); - - if (needle_rptr == NULL) - return -1; - - /* Skip search string and whitespaces after it */ - needle_rptr += strlen(needle); - - num = strtol(needle_rptr, &needle_end, 10); - - if (needle_rptr == needle_end) - return -1; - - if (num == LONG_MIN || num == LONG_MAX) - return 0; - - return num > 0 ? num : 0; -} - -/** - * tap_version_present: - * @record: buffer with tap data - * @print_info: whether tap version should be printed or not - * - * Returns: - * 0 if not found - * 1 if found - */ -static int tap_version_present(char* record, bool print_info) -{ - /* - * "(K)TAP version XX" should be the first line on all (sub)tests as per - * https://kernel.org/doc/html/latest/dev-tools/ktap.html#version-lines - * - * but actually isn't, as it currently depends on the KUnit module - * being built-in, so we can't rely on it every time - */ - const char *version_rptr = strcasestr(record, "TAP version "); - char *cutoff; - - if (version_rptr == NULL) - return 0; - - /* Cutoff after newline character, in order to not display garbage */ - cutoff = strchr(version_rptr, '\n'); - if (cutoff) - cutoff[0] = '\0'; - - if (print_info) - igt_info("%s\n", version_rptr); - - return 1; -} - -/** - * find_next_tap_subtest: - * @fd: file descriptor - * @record: buffer used to read fd - * @is_builtin: whether KUnit is built-in or not - * - * Returns: - * 0 if there's missing information - * -1 if not found - * -2 if there are problems while reading the file. - * any other value corresponds to the amount of cases of the next (sub)test - */ -static int find_next_tap_subtest(int fd, char *record, char *test_name, bool is_builtin) -{ - const char *test_lookup_str, *subtest_lookup_str, *name_rptr; - long test_count; - char *cutoff; - - test_name[0] = '\0'; - test_name[BUF_LEN] = '\0'; - - test_lookup_str = " subtest: "; - subtest_lookup_str = " test: "; - - if (!tap_version_present(record, true)) - return -1; - - if (is_builtin) { - if (read(fd, record, BUF_LEN) < 0) { - if (errno == EPIPE) - igt_warn("kmsg truncated: too many messages. You may want to increase log_buf_len in kmcdline\n"); - else - igt_warn("an error occurred while reading kmsg: %m\n"); - - return -2; - } - } - - name_rptr = strcasestr(record, test_lookup_str); - if (name_rptr != NULL) { - name_rptr += strlen(test_lookup_str); - } else { - name_rptr = strcasestr(record, subtest_lookup_str); - if (name_rptr != NULL) - name_rptr += strlen(subtest_lookup_str); - } - - if (name_rptr == NULL) { - if (!is_builtin) - /* We've probably found nothing */ - return -1; - igt_info("Missing test name\n"); - } else { - strncpy(test_name, name_rptr, BUF_LEN); - /* Cutoff after newline character, in order to not display garbage */ - cutoff = strchr(test_name, '\n'); - if (cutoff) - cutoff[0] = '\0'; - - if (read(fd, record, BUF_LEN) < 0) { - if (errno == EPIPE) - igt_warn("kmsg truncated: too many messages. You may want to increase log_buf_len in kmcdline\n"); - else - igt_warn("unknown error reading kmsg (%m)\n"); - - return -2; - } - - /* Now we can be sure we found tests */ - if (!is_builtin) - igt_info("KUnit is not built-in, skipping version check...\n"); - } - - /* - * Total test count will almost always appear as 0..N at the beginning - * of a run, so we use it to reliably identify a new run - */ - test_count = lookup_value(record, ".."); - - if (test_count <= 0) { - igt_info("Missing test count\n"); - if (test_name[0] == '\0') - return 0; - if (log_to_end(IGT_LOG_INFO, fd, record, - "Running some tests in: %s\n", - test_name) < 0) - return -2; - return 0; - } else if (test_name[0] == '\0') { - igt_info("Running %ld tests...\n", test_count); - return 0; - } - - if (log_to_end(IGT_LOG_INFO, fd, record, - "Executing %ld tests in: %s\n", - test_count, test_name) < 0) - return -2; - - return test_count; -} - -/** - * parse_kmsg_for_tap: - * @fd: file descriptor - * @record: buffer used to read fd - * @test_name: buffer to store the test name - * - * Returns: - * 1 if no results were found - * 0 if a test succeded - * -1 if a test failed - * -2 if there are problems reading the file - */ -static int parse_kmsg_for_tap(int fd, char *record, char *test_name) -{ - const char *lstart, *ok_lookup_str, *nok_lookup_str, - *ok_rptr, *nok_rptr, *comment_start, *value_parse_start; - char *test_name_end; - - ok_lookup_str = "ok "; - nok_lookup_str = "not ok "; - - lstart = strchrnul(record, ';'); - - if (*lstart == '\0') { - igt_warn("kmsg truncated: output malformed (%m)\n"); - return -2; - } - - lstart++; - while (isspace(*lstart)) - lstart++; - - nok_rptr = strstr(lstart, nok_lookup_str); - if (nok_rptr != NULL) { - nok_rptr += strlen(nok_lookup_str); - while (isdigit(*nok_rptr) || isspace(*nok_rptr) || *nok_rptr == '-') - nok_rptr++; - test_name_end = strncpy(test_name, nok_rptr, BUF_LEN); - while (!isspace(*test_name_end)) - test_name_end++; - *test_name_end = '\0'; - if (log_to_end(IGT_LOG_WARN, fd, record, - "%s", lstart) < 0) - return -2; - return -1; - } - - comment_start = strchrnul(lstart, '#'); - - /* Check if we're still in a subtest */ - if (*comment_start != '\0') { - comment_start++; - value_parse_start = comment_start; - - if (lookup_value(value_parse_start, "fail: ") > 0) { - if (log_to_end(IGT_LOG_WARN, fd, record, - "%s", lstart) < 0) - return -2; - return -1; - } - } - - ok_rptr = strstr(lstart, ok_lookup_str); - if (ok_rptr != NULL) { - ok_rptr += strlen(ok_lookup_str); - while (isdigit(*ok_rptr) || isspace(*ok_rptr) || *ok_rptr == '-') - ok_rptr++; - test_name_end = strncpy(test_name, ok_rptr, BUF_LEN); - while (!isspace(*test_name_end)) - test_name_end++; - *test_name_end = '\0'; - return 0; - } - - return 1; -} - -/** - * parse_tap_level: - * @fd: file descriptor - * @base_test_name: test_name from upper recursion level - * @test_count: test_count of this level - * @failed_tests: top level failed_tests pointer - * @found_tests: top level found_tests pointer - * @is_builtin: whether the KUnit module is built-in or not - * - * Returns: - * 0 if succeded - * -1 if error occurred - */ -__maybe_unused -static int parse_tap_level(int fd, char *base_test_name, int test_count, bool *failed_tests, - bool *found_tests, bool is_builtin) -{ - char record[BUF_LEN + 1]; - struct ktap_test_results_element *r; - int internal_test_count; - char test_name[BUF_LEN + 1]; - char base_test_name_for_next_level[BUF_LEN + 1]; - - for (int i = 0; i < test_count; i++) { - if (read(fd, record, BUF_LEN) < 0) { - if (errno == EPIPE) - igt_warn("kmsg truncated: too many messages. You may want to increase log_buf_len in kmcdline\n"); - else - igt_warn("error reading kmsg (%m)\n"); - - return -1; - } - - /* Sublevel found */ - if (tap_version_present(record, false)) - { - internal_test_count = find_next_tap_subtest(fd, record, test_name, - is_builtin); - switch (internal_test_count) { - case -2: - /* No more data to read */ - return -1; - case -1: - /* No test found */ - return -1; - case 0: - /* Tests found, but they're missing info */ - *found_tests = true; - return -1; - default: - *found_tests = true; - - memcpy(base_test_name_for_next_level, base_test_name, BUF_LEN); - if (strlen(base_test_name_for_next_level) < BUF_LEN - 1 && - base_test_name_for_next_level[0]) - strncat(base_test_name_for_next_level, DELIMITER, - BUF_LEN - strlen(base_test_name_for_next_level)); - memcpy(base_test_name_for_next_level + strlen(base_test_name_for_next_level), - test_name, BUF_LEN - strlen(base_test_name_for_next_level)); - - if (parse_tap_level(fd, base_test_name_for_next_level, - internal_test_count, failed_tests, found_tests, - is_builtin) == -1) - return -1; - break; - } - } - - switch (parse_kmsg_for_tap(fd, record, test_name)) { - case -2: - return -1; - case -1: - *failed_tests = true; - - r = malloc(sizeof(*r)); - - memcpy(r->test_name, base_test_name, BUF_LEN); - if (strlen(r->test_name) < BUF_LEN - 1) - if (r->test_name[0]) - strncat(r->test_name, DELIMITER, - BUF_LEN - strlen(r->test_name)); - memcpy(r->test_name + strlen(r->test_name), test_name, - BUF_LEN - strlen(r->test_name)); - r->test_name[BUF_LEN] = '\0'; - - r->passed = false; - - pthread_mutex_lock(&results.mutex); - igt_list_add_tail(&r->link, &results.list); - pthread_mutex_unlock(&results.mutex); - - test_name[0] = '\0'; - break; - case 0: - r = malloc(sizeof(*r)); - - memcpy(r->test_name, base_test_name, BUF_LEN); - if (strlen(r->test_name) < BUF_LEN - 1) - if (r->test_name[0]) - strncat(r->test_name, DELIMITER, - BUF_LEN - strlen(r->test_name)); - memcpy(r->test_name + strlen(r->test_name), test_name, - BUF_LEN - strlen(r->test_name)); - r->test_name[BUF_LEN] = '\0'; - - r->passed = true; - - pthread_mutex_lock(&results.mutex); - igt_list_add_tail(&r->link, &results.list); - pthread_mutex_unlock(&results.mutex); - - test_name[0] = '\0'; - break; - default: - break; - } - } - return 0; -} - -/** - * igt_ktap_parser: - * - * This function parses the output of a ktap script and passes it to main thread. - */ -void *igt_ktap_parser(void *unused) -{ - char record[BUF_LEN + 1], *buf, *suite_name = NULL, *case_name = NULL; - struct igt_ktap_results *ktap = NULL; - int fd = ktap_args.fd; - IGT_LIST_HEAD(list); - int err; - - ktap = igt_ktap_alloc(&list); - if (igt_debug_on(!ktap)) - goto igt_ktap_parser_end; - - while (err = read(fd, record, BUF_LEN), err > 0) { - struct igt_ktap_result *r, *rn; - - /* skip kmsg continuation lines */ - if (igt_debug_on(*record == ' ')) - continue; - - /* NULL-terminate the record */ - record[err] = '\0'; - - /* detect start of log message, continue if not found */ - buf = strchrnul(record, ';'); - if (igt_debug_on(*buf == '\0')) - continue; - buf++; - - err = igt_ktap_parse(buf, ktap); - - /* parsing error */ - if (err && err != -EINPROGRESS) - goto igt_ktap_parser_end; - - igt_list_for_each_entry_safe(r, rn, &list, link) { - struct ktap_test_results_element *result = NULL; - int code = r->code; - - if (code != IGT_EXIT_INVALID) - result = calloc(1, sizeof(*result)); - - if (result) { - snprintf(result->test_name, sizeof(result->test_name), - "%s-%s", r->suite_name, r->case_name); - - if (code == IGT_EXIT_SUCCESS) - result->passed = true; - } - - igt_list_del(&r->link); - if (r->suite_name != suite_name) { - free(suite_name); - suite_name = r->suite_name; - } - if (r->case_name != case_name) { - free(case_name); - case_name = r->case_name; - } - free(r->msg); - free(r); - - /* - * no extra result record expected on start - * of parametrized test case -- skip it - */ - if (code == IGT_EXIT_INVALID) - continue; - - if (!result) { - err = -ENOMEM; - goto igt_ktap_parser_end; - } - - pthread_mutex_lock(&results.mutex); - igt_list_add_tail(&result->link, &results.list); - pthread_mutex_unlock(&results.mutex); - } - - /* end of KTAP report */ - if (!err) - goto igt_ktap_parser_end; - } - - if (err < 0) { - if (errno == EPIPE) - igt_warn("kmsg truncated: too many messages. You may want to increase log_buf_len in kmcdline\n"); - else - igt_warn("error reading kmsg (%m)\n"); - } - -igt_ktap_parser_end: - free(suite_name); - free(case_name); - - if (!err) - ktap_args.ret = IGT_EXIT_SUCCESS; - - results.still_running = false; - - if (ktap) - igt_ktap_free(ktap); - - return NULL; -} - -static pthread_t ktap_parser_thread; - -struct ktap_test_results *ktap_parser_start(int fd, bool is_builtin) -{ - IGT_INIT_LIST_HEAD(&results.list); - pthread_mutex_init(&results.mutex, NULL); - results.still_running = true; - - ktap_args.fd = fd; - ktap_args.is_builtin = is_builtin; - ktap_args.ret = IGT_EXIT_FAILURE; - pthread_create(&ktap_parser_thread, NULL, igt_ktap_parser, NULL); - - return &results; -} - -void ktap_parser_cancel(void) -{ - pthread_cancel(ktap_parser_thread); -} - -int ktap_parser_stop(void) -{ - pthread_join(ktap_parser_thread, NULL); - return ktap_args.ret; -} diff --git a/lib/igt_ktap.h b/lib/igt_ktap.h index 6f8da3eab6..c422636bfc 100644 --- a/lib/igt_ktap.h +++ b/lib/igt_ktap.h @@ -27,8 +27,6 @@ #define BUF_LEN 4096 -#include - #include "igt_list.h" struct igt_ktap_result { @@ -45,24 +43,4 @@ 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_parser(void *unused); - -typedef struct ktap_test_results_element { - char test_name[BUF_LEN + 1]; - bool passed; - struct igt_list_head link; -} ktap_test_results_element; - -struct ktap_test_results { - struct igt_list_head list; - pthread_mutex_t mutex; - bool still_running; -}; - - - -struct ktap_test_results *ktap_parser_start(int fd, bool is_builtin); -void ktap_parser_cancel(void); -int ktap_parser_stop(void); - #endif /* IGT_KTAP_H */ From patchwork Wed Oct 11 14:17:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417498 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 A89C0CD6E7C for ; Wed, 11 Oct 2023 14:31:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7A89D10E8CE; Wed, 11 Oct 2023 14:31:56 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id D9C7210E8CE; Wed, 11 Oct 2023 14:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034714; x=1728570714; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PSId6gndnIooBnzlxNKz4dURwHJwM1TWgrGDqRCuK6Q=; b=JrE2/MRLOZb/pFx4DwJhA9Vub1X/DHgH+Y7Pm8tAtrQCuXSTrtAvlj5z DghRsicgzFERU5Netd/ZWlM/5X5O1ULzZEuwiY5lhWW18VEzAxmPGRHnP 5fkDckDKyJj1tyn9BumMFjRFsNwYzAZqiA+ifwsfCT158oefjWRgYAhXA +bTwxs33D8bRxxB4RMr5OZ9rEW7EArvl0OYKWbqYW5xLCFP6fKNv2pAPK i/3FXifxs9CY3vWXVP+uNjlzpCUUD2D/z1oRm5oqUpUXfbMU5ASxFpYx+ gEMeLzY6b3LNKfHbeyDjN/0S8BDi4t0D/9WQi5jLr3Ri76kwIiD+LGUHl g==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042053" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042053" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:31:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641574" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641574" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:30:07 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:41 +0200 Message-ID: <20231011141734.590321-19-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 06/11] lib/kunit: Omit suite name prefix if the same as subtest name 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Kunit test modules usually contain one test suite, named after the module name with the trailing "_test" or "_kunit" suffix omitted. Since we follow the same convention when we derive subtest names from module names, there is a great chance that those two names match. Take this into account when composing names for IGT dynamic sub-subtest names and drop the leading test suite name component when it is the same as subtest name. Signed-off-by: Janusz Krzysztofik Reviewed-by: Mauro Carvalho Chehab --- lib/igt_kmod.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 93d9479219..d014644fb4 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -888,7 +888,8 @@ static void kunit_result_free(struct igt_ktap_result **r, *r = NULL; } -static void __igt_kunit(struct igt_ktest *tst, const char *opts) +static void +__igt_kunit(struct igt_ktest *tst, const char *name, const char *opts) { struct modprobe_data modprobe = { tst->kmod, opts, 0, pthread_self(), }; char *suite_name = NULL, *case_name = NULL; @@ -931,7 +932,11 @@ static void __igt_kunit(struct igt_ktest *tst, const char *opts) r = igt_list_first_entry(&results, r, link); - igt_dynamic_f("%s-%s", r->suite_name, r->case_name) { + igt_dynamic_f("%s%s%s", + strcmp(r->suite_name, name) ? r->suite_name : "", + strcmp(r->suite_name, name) ? "-" : "", + r->case_name) { + if (r->code == IGT_EXIT_INVALID) { /* parametrized test case, get actual result */ kunit_result_free(&r, &suite_name, &case_name); @@ -1072,7 +1077,7 @@ void igt_kunit(const char *module_name, const char *name, const char *opts) * and for documentation. */ igt_subtest_with_dynamic(name) - __igt_kunit(&tst, opts); + __igt_kunit(&tst, name, opts); igt_fixture igt_ktest_end(&tst); From patchwork Wed Oct 11 14:17:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417502 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 BE7FBCD6E7C for ; Wed, 11 Oct 2023 14:32:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 63FCC10E8E3; Wed, 11 Oct 2023 14:32:06 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id CCD2A10E8D2; Wed, 11 Oct 2023 14:31:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034716; x=1728570716; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NvkhB9YPPTbIkzAmxQZTPm9D9AfHPrS3aL9QG0wiQ2o=; b=HjCKe/a9tCbd/zokiDI2wo7gW/L4AU8uDwvDF8AL4TTqzOXCztI1XXJ7 O+Mu13V+lQUK8R4h6yvHanThYY/kQm+hNtDq8EW+J/M26wyWh4NMWj+vb SsjXz8Z5W7qhjH4Q4QcSjsIWSkknin1kQFVkOuJbbsM4zOZlRltmTMjh9 DC3XgtcfuD1Yv062mDuOJIG+RYhHEBWoB0v4uUwYXQGjvrRNcFbRUBgl+ I0KPrHvY/mLswTW6/eiGluLuDFPylTpo7hUFjhpoYrGdMLw+0Z4D5f5hc OqsSbeJ2zQjlHFqTYbr1ZHhg4NEk2USSwh2WRRZuxcBAT3EQTbGZxx0H4 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042058" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042058" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:31:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641586" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641586" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:30:09 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:42 +0200 Message-ID: <20231011141734.590321-20-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 07/11] tests/kms_selftest: Let subtest names match suite names 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" There is a rule specified in Kunit Test Style and Nomenclature guidelines [1] that states modules should be named after the test suite, followed by _test. Of course, that rule applies only to modules that provide one test suite per module. As long as that rule is obeyed by authors of Kunit test modules, there is no need to hardcode related IGT subtest names in IGT source code. We are already able to derive subtest names from module names, with their _test or _kunit suffixes stripped. We may expect those names will match Kunit suite names provided by the modules. Drop custom subtest names from IGT Kunit tests that still use them. However, keep the mechanism that allows us to provide a name that differs from that derived from module name. That will be required if we ever need to support a kunit test module that provides multiple test suites (think of i915 selftests code converted to kunit and the i915 module potentially providing three test suites: mock, live and perf). [1] https://docs.kernel.org/dev-tools/kunit/style.html Signed-off-by: Janusz Krzysztofik Reviewed-by: Kamil Konieczny --- tests/kms_selftest.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/tests/kms_selftest.c b/tests/kms_selftest.c index 080ffdf2c0..6618dbe50b 100644 --- a/tests/kms_selftest.c +++ b/tests/kms_selftest.c @@ -37,35 +37,30 @@ * * arg[1]: * - * @drm_cmdline: drm cmdline - * @drm_damage: drm damage - * @drm_dp_mst: drm dp mst + * @drm_cmdline_parser: drm cmdline parser + * @drm_damage_helper: drm damage helper + * @drm_dp_mst_helper: drm dp mst helper * @drm_format_helper: drm format helper * @drm_format: drm format - * @drm_plane: drm plane - * @framebuffer: framebuffer + * @drm_plane_helper: drm plane helper + * @drm_framebuffer: drm framebuffer */ IGT_TEST_DESCRIPTION("Basic sanity check of KMS selftests."); -struct kms_kunittests { - const char *kunit; - const char *name; -}; - igt_main { - static const struct kms_kunittests kunit_subtests[] = { - { "drm_cmdline_parser_test", "drm_cmdline" }, - { "drm_damage_helper_test", "drm_damage" }, - { "drm_dp_mst_helper_test", "drm_dp_mst" }, - { "drm_format_helper_test", "drm_format_helper" }, - { "drm_format_test", "drm_format" }, - { "drm_framebuffer_test", "framebuffer" }, - { "drm_plane_helper_test", "drm_plane" }, - { NULL, NULL} + static const char *kunit_subtests[] = { + "drm_cmdline_parser_test", + "drm_damage_helper_test", + "drm_dp_mst_helper_test", + "drm_format_helper_test", + "drm_format_test", + "drm_framebuffer_test", + "drm_plane_helper_test", + NULL, }; - for (int i = 0; kunit_subtests[i].kunit != NULL; i++) - igt_kunit(kunit_subtests[i].kunit, kunit_subtests[i].name, NULL); + for (int i = 0; kunit_subtests[i] != NULL; i++) + igt_kunit(kunit_subtests[i], NULL, NULL); } From patchwork Wed Oct 11 14:17:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417501 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 E42A4CD6E7A for ; Wed, 11 Oct 2023 14:32:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DD8E10E8DC; Wed, 11 Oct 2023 14:32:05 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id C34BC10E8DB; Wed, 11 Oct 2023 14:31:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034718; x=1728570718; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F2r4gA67wREUpFTFt6demyQUbKEHwHhQXaRMzkkq3HY=; b=GMQOH5ZAkPu221XaCoiwQjzWxKwjBn18um6HbNimgGI7qkAlqsERt3Cv MRO4KI/2dJEffMdh2pKRNV5TF8ATG13zG26GHSBhFORGghRePLME6IXDD a8jyiyb9spjtRAy62uiQErc150vGsr9qml2JlX66MGRjH61Ml5fQmFHOd hj8loFQU3QsdPN/xB8NFjNcb7Au09GnpUld4tpTESXlzL6x6f6GWMeN9z dJkMN3QvZp8ILPvjHBZ7I9OKXnfbbwYvdKEiy5XxySEUXvdq9Rz82pRgO ILXwD6arJc94NP5V3LjnIRoe8nL2ZQxi/rpGUfWh1xDe16X+bbqfXIkQD g==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042076" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042076" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:31:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641593" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641593" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:30:11 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:43 +0200 Message-ID: <20231011141734.590321-21-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 08/11] lib/kunit: Provide all results cleanup helper 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Planned changes require a couple of loops around kunit_result_free(). Since we already have such loop, move it into a helper in preparation for future uses. Signed-off-by: Janusz Krzysztofik Reviewed-by: Kamil Konieczny --- lib/igt_kmod.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index d014644fb4..21c547bf42 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -888,13 +888,25 @@ static void kunit_result_free(struct igt_ktap_result **r, *r = NULL; } +static void kunit_results_free(struct igt_list_head *results, + char **suite_name, char **case_name) +{ + struct igt_ktap_result *r, *rn; + + igt_list_for_each_entry_safe(r, rn, results, link) + kunit_result_free(&r, suite_name, case_name); + + free(*case_name); + free(*suite_name); +} + static void __igt_kunit(struct igt_ktest *tst, const char *name, const char *opts) { struct modprobe_data modprobe = { tst->kmod, opts, 0, pthread_self(), }; char *suite_name = NULL, *case_name = NULL; - struct igt_ktap_result *r, *rn; struct igt_ktap_results *ktap; + struct igt_ktap_result *r; pthread_mutexattr_t attr; IGT_LIST_HEAD(results); unsigned long taints; @@ -1000,11 +1012,7 @@ __igt_kunit(struct igt_ktest *tst, const char *name, const char *opts) } while (ret == -EINPROGRESS); - igt_list_for_each_entry_safe(r, rn, &results, link) - kunit_result_free(&r, &suite_name, &case_name); - - free(case_name); - free(suite_name); + kunit_results_free(&results, &suite_name, &case_name); switch (pthread_mutex_lock(&modprobe.lock)) { case 0: From patchwork Wed Oct 11 14:17:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417500 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 786BDCD6E77 for ; Wed, 11 Oct 2023 14:32:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C57BE10E8E2; Wed, 11 Oct 2023 14:32:04 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id B1DB510E8DC; Wed, 11 Oct 2023 14:32:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034720; x=1728570720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XHC9GXm2gLX6YSeqpYZlcanA5zA7yJYDCbqVM3PN9j4=; b=WxYt6OnDxbLBE5NSNFGvp+whwhzDiIKpsS/X7tzH5+xoTc9K4On/XnBK Lqm6DUNG9nhK5NfV4SEryHLa6JfMzOhFp0643Cy9gBauAPbWHtdU2bexI z9LL9fp8AhBvS6WhhYoePwnnWrAow3aSYtEaAsQphevEDoelUFgi3KGdA QjWxhN5v4fJQA3O6v/zrZyvwlPjfY6iwOvF2O51D0L+BgqDOd7OvqmNO8 Cfv4X0MvfxJZZ5wTH2uKo1AAIDl2Zyywx8R7VKpZWsFQSE60b9yJxzcYO z7X47La8bZT6CS3rxfrCthPha1GHEs/a49FON5RSWpLtvMkIr/zkCavor w==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042088" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042088" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:32:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641598" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641598" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:30:13 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:44 +0200 Message-ID: <20231011141734.590321-22-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 09/11] lib/kunit: Prepare for KTAP parsing after modprobe completed 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" We are going to add support for reading a list of kunit test cases provided by a kunit test module prior to executing those test cases. That will be done by first loading kunit modules in list only mode, then reading the list from /dev/kmsg with our KTAP parser. Since that parsing will be performed after the kunit test module is successfully loaded and there will be no concurrently running modprobe thread, we need to make synchronization of reads from /dev/kmsg with potential errors modprobe thread optional. Signed-off-by: Janusz Krzysztofik Reviewed-by: Kamil Konieczny --- lib/igt_kmod.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 21c547bf42..5d85732b08 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -805,34 +805,36 @@ static int kunit_kmsg_result_get(struct igt_list_head *results, if (igt_debug_on(igt_kernel_tainted(&taints))) return -ENOTRECOVERABLE; - err = igt_debug_on(sigaction(SIGCHLD, &sigchld, saved)); - if (err == -1) - return -errno; - else if (unlikely(err)) - return err; - - err = pthread_mutex_lock(&modprobe->lock); - switch (err) { - case EOWNERDEAD: - /* leave the mutex unrecoverable */ - igt_debug_on(pthread_mutex_unlock(&modprobe->lock)); - __attribute__ ((fallthrough)); - case ENOTRECOVERABLE: - igt_debug_on(sigaction(SIGCHLD, saved, NULL)); - if (igt_debug_on(modprobe->err)) - return modprobe->err; - break; - case 0: - break; - default: - igt_debug("pthread_mutex_lock() error: %d\n", err); - igt_debug_on(sigaction(SIGCHLD, saved, NULL)); - return -err; + if (modprobe) { + err = igt_debug_on(sigaction(SIGCHLD, &sigchld, saved)); + if (err == -1) + return -errno; + else if (unlikely(err)) + return err; + + err = pthread_mutex_lock(&modprobe->lock); + switch (err) { + case EOWNERDEAD: + /* leave the mutex unrecoverable */ + igt_debug_on(pthread_mutex_unlock(&modprobe->lock)); + __attribute__ ((fallthrough)); + case ENOTRECOVERABLE: + igt_debug_on(sigaction(SIGCHLD, saved, NULL)); + if (igt_debug_on(modprobe->err)) + return modprobe->err; + break; + case 0: + break; + default: + igt_debug("pthread_mutex_lock() error: %d\n", err); + igt_debug_on(sigaction(SIGCHLD, saved, NULL)); + return -err; + } } ret = read(fd, record, BUF_LEN); - if (!err) { /* pthread_mutex_lock() succeeded */ + if (modprobe && !err) { /* pthread_mutex_lock() succeeded */ igt_debug_on(pthread_mutex_unlock(&modprobe->lock)); igt_debug_on(sigaction(SIGCHLD, saved, NULL)); } From patchwork Wed Oct 11 14:17:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417504 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 09118CD6E7B for ; Wed, 11 Oct 2023 14:32:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E5A1710E8EC; Wed, 11 Oct 2023 14:32:10 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6D9E310E8E1; Wed, 11 Oct 2023 14:32:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034724; x=1728570724; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jn+DJ6h3ZddJvSC+i83qZY5yV7RLmzO+wuA0TSsMvAA=; b=VcCcebknDJvgEuit8dqJpIHrxeLERGpPjl31gLfQjNe/ecTAG3J0lFpq ysyWTeb9QSHT3XmZ6vuv48VoofDNXByBqmecCo8MQGu5YKbWnBOPvkwlW N6gguMZp1jFi6J/y6LssiuKXdBQA0M9Dea4INo+1FmRcMSXYgTKt9ozqF v1kfbRAeOC0u/3Yx/dd2LSGIalXaJ8t9Wxal9Beo4MsBAkO8ZLMqCQb46 g6SgLWifk8TSECTBTUP6lXbACVWYxGs7PdZfHTECpJJO+s1QL8oRde/tB b0CiU+JjJJXJJc9byea2/ojwPUFRPVM4YxWvQGe2zvpyMy+0yWtLQV8VE g==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042107" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042107" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:32:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641624" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641624" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:30:15 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:45 +0200 Message-ID: <20231011141734.590321-23-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 10/11] lib/kunit: Fetch a list of test cases in advance 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Recent improvements to the kernel kunit framework allow us to obtain a list of test cases provided by a kunit test module without actually running them. Use that feature to get a list of expected test cases before we enter a loop around igt_dynamic(). Once done, enter the igt_dynamic() section for each consecutive test case immediately, even before first line of a related KTAP report appears, then look for a result from that test case. That should make our IGT results output still better synchronized with related kernel messages. The list of test cases provided by a kunit test module can be obtained by loading the kunit base module with specific options, then loading the test module. For that to be possible, take care of unloading the kunit base module before each kunit subtest (I was wrong when in one of my previous commit messages I suggested that on final unload of a kunit test module the kunit base module is unloaded automatically as its dependency, however, that didn't matter before, then no separate fix was required). Since that module can then be left loaded with non-default options if an error occurs, unload it explicitly before returning from igt_kunit(). There are two possible ways of getting a list of test cases: by loading the base kunit module with action=list module option, or by filtering out all test cases from being executed while asking for SKIP results from those filtered out. Since the latter provides regular KTAP report that we can already parse perfectly, use it instead of trying to identify an unstructured list of test cases of unknown length submitted by the former. If an IGT test that calls igt_kunit() provides a subtest name then use that name to filter out potential test cases that don't belong to the named test suite from the list. To avoid loading any modules if no subtest is going to be executed (e.g., if a nonexistent subtest has been requested), load the kunit modules in list mode from inside the igt_subtest_with_dynamic() section. In order to be free to skip the whole subtest on unmet requirements that need to be verified after that list has been already populated, clean it up from a follow up igt_fixture section. Since we may now finish processing of all test cases / dynamic sub- subtests before KTAP parsing completes, don't fail if we exit the loop of dynamic sub-subtests with -EINPROGRESS error code returned by the parser. v3: Preserve backward compatibility with kernels that can't provide listings of kunit test cases when kunit core is built as a module. v2: Split out changes in handling of modprobe errors and kernel taints to separate patches (Kamil), - fix some string duplicates referenced from filtered out test cases not freed, - don't check if next result is needed before fetching one, obviously true in first dynamic sub-subtest, and we always free last result before looping to next sub-subtest, - still break the loop of test cases on unexpected return codes from kunit_kmsg_get_result(), - use kunit_results_free() helper, - fix typos (Kamil), - update commit description. Signed-off-by: Janusz Krzysztofik Acked-by: Kamil Konieczny # v2 Reviewed-by: Kamil Konieczny --- lib/igt_kmod.c | 277 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 264 insertions(+), 13 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 5d85732b08..c20c52d372 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -902,8 +902,9 @@ static void kunit_results_free(struct igt_list_head *results, free(*suite_name); } -static void -__igt_kunit(struct igt_ktest *tst, const char *name, const char *opts) +static void __igt_kunit_legacy(struct igt_ktest *tst, + const char *name, + const char *opts) { struct modprobe_data modprobe = { tst->kmod, opts, 0, pthread_self(), }; char *suite_name = NULL, *case_name = NULL; @@ -912,13 +913,7 @@ __igt_kunit(struct igt_ktest *tst, const char *name, const char *opts) pthread_mutexattr_t attr; IGT_LIST_HEAD(results); unsigned long taints; - int flags, ret; - - 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"); + int ret; igt_skip_on(lseek(tst->kmsg, 0, SEEK_END) < 0); @@ -1041,6 +1036,232 @@ __igt_kunit(struct igt_ktest *tst, const char *name, const char *opts) igt_skip_on_f(ret, "KTAP parser failed\n"); } +static void kunit_get_tests(struct igt_list_head *tests, + struct igt_ktest *tst, + const char *filter, + const char *opts) +{ + 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); + + /* + * To get a list of test cases provided by a kunit test module, ask the + * generic kunit module to respond with SKIP result for each test found. + * We could also use action=list kunit parameter to get the listing, + * 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)); + + 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; + } + + if (!filter) + continue; + + if (strcmp(r->suite_name, filter)) + kunit_result_free(&r, &case_name, &suite_name); + } + + if (err) { + kunit_results_free(tests, &case_name, &suite_name); + } else { + free(suite_name); + 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"); +} + +static void __igt_kunit(struct igt_ktest *tst, + const char *name, + const char *opts, + struct igt_list_head *tests) +{ + 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; + unsigned long taints; + + igt_skip_on(lseek(tst->kmsg, 0, SEEK_END) < 0); + + igt_skip_on(pthread_mutexattr_init(&attr)); + igt_skip_on(pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST)); + igt_skip_on(pthread_mutex_init(&modprobe.lock, &attr)); + + ktap = igt_ktap_alloc(&results); + igt_require(ktap); + + if (igt_debug_on(pthread_create(&modprobe.thread, NULL, + modprobe_task, &modprobe))) { + igt_ktap_free(ktap); + igt_skip("Failed to create a modprobe thread\n"); + } + + igt_list_for_each_entry(t, tests, link) { + igt_dynamic_f("%s%s%s", + strcmp(t->suite_name, name) ? t->suite_name : "", + strcmp(t->suite_name, name) ? "-" : "", + t->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); + + while (igt_debug_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), + "case_name expected: %s, got: %s\n", + t->case_name, r->case_name) || + r->code == IGT_EXIT_INVALID) { + + 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; + + /* 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); + + if (r->msg && *r->msg) { + igt_skip_on_f(r->code == IGT_EXIT_SKIP, + "%s\n", r->msg); + igt_fail_on_f(r->code == IGT_EXIT_FAILURE, + "%s\n", r->msg); + igt_abort_on_f(r->code == IGT_EXIT_ABORT, + "%s\n", r->msg); + } else { + igt_skip_on(r->code == IGT_EXIT_SKIP); + igt_fail_on(r->code == IGT_EXIT_FAILURE); + if (r->code == IGT_EXIT_ABORT) + 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); + } + + kunit_result_free(&r, &suite_name, &case_name); + + if (igt_debug_on(ret != -EINPROGRESS)) + break; + } + + kunit_results_free(&results, &suite_name, &case_name); + + 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)); + break; + case ENOTRECOVERABLE: + break; + default: + igt_debug("pthread_mutex_lock() failed\n"); + igt_debug_on(pthread_join(modprobe.thread, NULL)); + 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"); +} + /** * igt_kunit: * @module_name: the name of the module @@ -1052,7 +1273,8 @@ __igt_kunit(struct igt_ktest *tst, const char *name, const char *opts) void igt_kunit(const char *module_name, const char *name, const char *opts) { struct igt_ktest tst = { .kmsg = -1, }; - + const char *filter = name; + IGT_LIST_HEAD(tests); /* * If the caller (an IGT test) provides no subtest name then we @@ -1077,6 +1299,17 @@ void igt_kunit(const char *module_name, const char *name, const char *opts) igt_skip_on(igt_ktest_init(&tst, module_name)); igt_skip_on(igt_ktest_begin(&tst)); + + /* + * Since we need to load kunit base module with specific + * options in order to get a list of test cases, make + * sure that the module is not loaded. However, since + * unload may fail if kunit base module is not loaded, + * ignore any failures, we'll fail later if still loaded. + */ + igt_ignore_warn(igt_kmod_unload("kunit", KMOD_REMOVE_FORCE)); + + igt_assert(igt_list_empty(&tests)); } /* @@ -1086,11 +1319,29 @@ void igt_kunit(const char *module_name, const char *name, const char *opts) * proper namespace for dynamic subtests, with is required for CI * and for documentation. */ - igt_subtest_with_dynamic(name) - __igt_kunit(&tst, name, opts); + igt_subtest_with_dynamic(name) { + kunit_get_tests(&tests, &tst, filter, opts); + /* + * TODO: drop the __igt_kunit() legacy processing path, required + * by kernels v6.1-v6.5 with DRM Kunit support but not + * capable of listing test cases when built as a module, + * as soon as no longer required by major Linux + * distributions, now usually based on LTS kernel v6.1. + */ + if (igt_debug_on(igt_list_empty(&tests))) + __igt_kunit_legacy(&tst, name, opts); + else + __igt_kunit(&tst, name, opts, &tests); + } + + igt_fixture { + char *suite_name = NULL, *case_name = NULL; + + kunit_results_free(&tests, &suite_name, &case_name); - igt_fixture igt_ktest_end(&tst); + igt_debug_on(igt_kmod_unload("kunit", KMOD_REMOVE_FORCE)); + } igt_ktest_fini(&tst); } From patchwork Wed Oct 11 14:17:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13417503 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 06911CD6E7A for ; Wed, 11 Oct 2023 14:32:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BDE2210E8E6; Wed, 11 Oct 2023 14:32:09 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 62BC810E8E1; Wed, 11 Oct 2023 14:32:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697034726; x=1728570726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NpPnxQOXrWSur2mpE1KtouvuaAj1ZZYah0+FY1HvPRU=; b=Z3t+PhgI1jY9Pr+aH6mjbT9UmYfp7XFK17GZi+jJ4XrDeQy6RECDF14v aUewyCKw6vqhKZfBifdI+AhOKSCD8UUMXF2RP9dd5psRbGpfm0s/DxdwU M5I+Q/hNproduiYyC5tSHjkUUEMlY5wJlb55nSTHEfFJDJZSbvdTL4PVu wXIugmIRpO8ifgRVtn4KhBi7EMnYRqWG1vb5/1UvhEosAm6xgqoezL7vP nf9yIauQy6ZLVWU+HGv3fmjhIf/USA9cAJZyl2HY2pe1xjp+6HTpjkFLS jneapo/c9hemVFGPNNXRvjUpp9XEc5cyuLIvlkvwFharDMUadg4wEt0Ry Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="364042135" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="364042135" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:32:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="897641650" X-IronPort-AV: E=Sophos;i="6.03,216,1694761200"; d="scan'208";a="897641650" Received: from jkrzyszt-mobl2.ger.corp.intel.com (HELO jkrzyszt-mobl2.intranet) ([10.213.15.228]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 07:30:18 -0700 From: Janusz Krzysztofik To: igt-dev@lists.freedesktop.org Date: Wed, 11 Oct 2023 16:17:46 +0200 Message-ID: <20231011141734.590321-24-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> References: <20231011141734.590321-13-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v3 11/11] lib/kunit: Execute kunit test cases only when needed 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: , Cc: intel-gfx@lists.freedesktop.org, Mauro Carvalho Chehab , intel-xe@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" IGT user interface allows to request execution of only those dynamic sub- subtests that match a user provided name pattern. If the user pattern doesn't match any names of test cases provided by a kunit test module used with the subtest to be run then no results from any dynamic sub-subtests will be reported. Since we already know the list of test cases provided by the kunit test module, there is no need to load that module to execute them unless the user pattern matches at least one of those test cases. Don't load the kunit test module in execute mode before entering the loop of dynamic sub-subtests, and do that only from the first actually executed dynamic sub-subtest. v2: Always pass last result to next dynamic sub-subtest, fetch first result right after loading the kunit test module for execution. Signed-off-by: Janusz Krzysztofik Reviewed-by: Kamil Konieczny --- lib/igt_kmod.c | 66 ++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index c20c52d372..ca0356b1ca 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -1130,33 +1130,37 @@ static void __igt_kunit(struct igt_ktest *tst, igt_skip_on(lseek(tst->kmsg, 0, SEEK_END) < 0); - igt_skip_on(pthread_mutexattr_init(&attr)); - igt_skip_on(pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST)); - igt_skip_on(pthread_mutex_init(&modprobe.lock, &attr)); - ktap = igt_ktap_alloc(&results); igt_require(ktap); - if (igt_debug_on(pthread_create(&modprobe.thread, NULL, - modprobe_task, &modprobe))) { - igt_ktap_free(ktap); - igt_skip("Failed to create a modprobe thread\n"); - } - igt_list_for_each_entry(t, tests, link) { igt_dynamic_f("%s%s%s", strcmp(t->suite_name, name) ? t->suite_name : "", strcmp(t->suite_name, name) ? "-" : "", t->case_name) { - if (igt_list_empty(&results)) { + if (!modprobe.thread) { + 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); + + modprobe.err = pthread_create(&modprobe.thread, + NULL, + modprobe_task, + &modprobe); + igt_assert_eq(modprobe.err, 0); + + igt_assert(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); + r = igt_list_first_entry(&results, r, link); + } while (igt_debug_on_f(strcmp(r->suite_name, t->suite_name), "suite_name expected: %s, got: %s\n", @@ -1228,30 +1232,30 @@ static void __igt_kunit(struct igt_ktest *tst, igt_assert_eq(igt_kernel_tainted(&taints), 0); } - kunit_result_free(&r, &suite_name, &case_name); - if (igt_debug_on(ret != -EINPROGRESS)) break; } kunit_results_free(&results, &suite_name, &case_name); - 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)); - break; - case ENOTRECOVERABLE: - break; - default: - igt_debug("pthread_mutex_lock() failed\n"); - igt_debug_on(pthread_join(modprobe.thread, NULL)); - break; + 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)); + break; + case ENOTRECOVERABLE: + break; + default: + igt_debug("pthread_mutex_lock() failed\n"); + igt_debug_on(pthread_join(modprobe.thread, NULL)); + break; + } } igt_ktap_free(ktap);