From patchwork Mon Aug 29 00:09:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isabella Basso X-Patchwork-Id: 12957352 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28781ECAAD5 for ; Mon, 29 Aug 2022 00:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229446AbiH2AJu (ORCPT ); Sun, 28 Aug 2022 20:09:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbiH2AJt (ORCPT ); Sun, 28 Aug 2022 20:09:49 -0400 Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99A4E2734; Sun, 28 Aug 2022 17:09:48 -0700 (PDT) Received: from mx0.riseup.net (mx0-pn.riseup.net [10.0.1.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mx0.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4MG9mX1DtHzDr8x; Mon, 29 Aug 2022 00:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1661731788; bh=ThcwD+/ARB/097HCNk/WNN4lmuiNd29bmbeq+JVzaCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h5tUqD2ZwNaJzFNdPNOm/AWpG+I3jFVLHriqritRMoIf/WVAKnrZN6U7hIN+UE8gd C0qNJA8Y/jtfzZG2Z7ykTjnjUzI5C+yT4VJhUG1bcwiw4x9zyS9ZTJVYQjThvjt0OS 8hwgQyzed8NVDotjysWRmhHoRDX2INC1EUNlPwFc= Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx0.riseup.net (Postfix) with ESMTPS id 4MG9mV3Bksz9sNj; Mon, 29 Aug 2022 00:09:46 +0000 (UTC) X-Riseup-User-ID: 1F040BCC012FFF67A8C1706CE96F24ADEEA8BC2421AAF385962892E6DB1139C9 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4MG9mP0Z0Tz5vTc; Mon, 29 Aug 2022 00:09:40 +0000 (UTC) From: Isabella Basso To: igt-dev@lists.freedesktop.org Cc: magalilemes00@gmail.com, maira.canal@usp.br, tales.aparecida@gmail.com, rodrigo.siqueira@amd.com, mwen@igalia.com, andrealmeid@riseup.net, twoerner@gmail.com, leandro.ribeiro@collabora.com, n@nfraprado.net, kunit-dev@googlegroups.com, davidgow@google.com, dlatypov@google.com, brendanhiggins@google.com, daniel@ffwll.ch, skhan@linuxfoundation.org, linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org, daniel@fooishbar.org, linux-kernel@vger.kernel.org, Isabella Basso Subject: [PATCH i-g-t v2 1/4] lib/igt_kmod: rename kselftest functions to ktest Date: Sun, 28 Aug 2022 21:09:17 -0300 Message-Id: <20220829000920.38185-2-isabbasso@riseup.net> In-Reply-To: <20220829000920.38185-1-isabbasso@riseup.net> References: <20220829000920.38185-1-isabbasso@riseup.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This aims at making IGT's structure more general to different kernel testing frameworks such as KUnit, as they use a lot of the same functionality. Signed-off-by: Isabella Basso Reviewed-by: Janusz Krzysztofik --- lib/igt_kmod.c | 22 +++++++++++----------- lib/igt_kmod.h | 12 ++++++------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index bcf7dfeb..bb6cb7bb 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -718,8 +718,8 @@ static int open_parameters(const char *module_name) return open(path, O_RDONLY); } -int igt_kselftest_init(struct igt_kselftest *tst, - const char *module_name) +int igt_ktest_init(struct igt_ktest *tst, + const char *module_name) { int err; @@ -738,7 +738,7 @@ int igt_kselftest_init(struct igt_kselftest *tst, return 0; } -int igt_kselftest_begin(struct igt_kselftest *tst) +int igt_ktest_begin(struct igt_ktest *tst) { int err; @@ -753,7 +753,7 @@ int igt_kselftest_begin(struct igt_kselftest *tst) return 0; } -int igt_kselftest_execute(struct igt_kselftest *tst, +int igt_kselftest_execute(struct igt_ktest *tst, struct igt_kselftest_list *tl, const char *options, const char *result) @@ -791,13 +791,13 @@ int igt_kselftest_execute(struct igt_kselftest *tst, return err; } -void igt_kselftest_end(struct igt_kselftest *tst) +void igt_ktest_end(struct igt_ktest *tst) { kmod_module_remove_module(tst->kmod, KMOD_REMOVE_FORCE); close(tst->kmsg); } -void igt_kselftest_fini(struct igt_kselftest *tst) +void igt_ktest_fini(struct igt_ktest *tst) { free(tst->module_name); kmod_module_unref(tst->kmod); @@ -820,15 +820,15 @@ void igt_kselftests(const char *module_name, const char *result, const char *filter) { - struct igt_kselftest tst; + struct igt_ktest tst; IGT_LIST_HEAD(tests); struct igt_kselftest_list *tl, *tn; - if (igt_kselftest_init(&tst, module_name) != 0) + if (igt_ktest_init(&tst, module_name) != 0) return; igt_fixture - igt_require(igt_kselftest_begin(&tst) == 0); + igt_require(igt_ktest_begin(&tst) == 0); igt_kselftest_get_tests(tst.kmod, filter, &tests); igt_subtest_with_dynamic(filter ?: "all") { @@ -847,9 +847,9 @@ void igt_kselftests(const char *module_name, } igt_fixture { - igt_kselftest_end(&tst); + igt_ktest_end(&tst); igt_require(!igt_list_empty(&tests)); } - igt_kselftest_fini(&tst); + igt_ktest_fini(&tst); } diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h index f98dd29f..ceb10cd0 100644 --- a/lib/igt_kmod.h +++ b/lib/igt_kmod.h @@ -50,7 +50,7 @@ void igt_kselftests(const char *module_name, const char *result_option, const char *filter); -struct igt_kselftest { +struct igt_ktest { struct kmod_module *kmod; char *module_name; int kmsg; @@ -63,19 +63,19 @@ struct igt_kselftest_list { char param[]; }; -int igt_kselftest_init(struct igt_kselftest *tst, +int igt_ktest_init(struct igt_ktest *tst, const char *module_name); -int igt_kselftest_begin(struct igt_kselftest *tst); +int igt_ktest_begin(struct igt_ktest *tst); void igt_kselftest_get_tests(struct kmod_module *kmod, const char *filter, struct igt_list_head *tests); -int igt_kselftest_execute(struct igt_kselftest *tst, +int igt_kselftest_execute(struct igt_ktest *tst, struct igt_kselftest_list *tl, const char *module_options, const char *result); -void igt_kselftest_end(struct igt_kselftest *tst); -void igt_kselftest_fini(struct igt_kselftest *tst); +void igt_ktest_end(struct igt_ktest *tst); +void igt_ktest_fini(struct igt_ktest *tst); #endif /* IGT_KMOD_H */ From patchwork Mon Aug 29 00:09:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isabella Basso X-Patchwork-Id: 12957353 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3333ECAAA2 for ; Mon, 29 Aug 2022 00:10:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229520AbiH2AJ6 (ORCPT ); Sun, 28 Aug 2022 20:09:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbiH2AJ4 (ORCPT ); Sun, 28 Aug 2022 20:09:56 -0400 Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3CFE13F3F; Sun, 28 Aug 2022 17:09:53 -0700 (PDT) Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4MG9mc3tjkzDq8c; Mon, 29 Aug 2022 00:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1661731793; bh=nw1YRmqcdBzZBVcFj0rpWQgfxBxuosXOsCCFJ9smdJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P4+1NdJrI/tzqJERKOBbSfbtER0u2uaKNniyGZh+pWeMHagb2SitqDujW+B+e/Awx 1XF+qQpe5yl/hM336jCbX3MtBQQYEBcFgeSoGbPW3tEix+c++PWbfMkHfqJCrnQczS NO4tf0xZsMPqugacs7jGUkHO/N+a0BeBzmL2ZPJ4= X-Riseup-User-ID: 2860CEA6AFDDFE6C5BAA18060787332CF5114A24920F5EDA57C2A10ED7FDC7E1 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4MG9mV5cVfz5vkC; Mon, 29 Aug 2022 00:09:46 +0000 (UTC) From: Isabella Basso To: igt-dev@lists.freedesktop.org Cc: magalilemes00@gmail.com, maira.canal@usp.br, tales.aparecida@gmail.com, rodrigo.siqueira@amd.com, mwen@igalia.com, andrealmeid@riseup.net, twoerner@gmail.com, leandro.ribeiro@collabora.com, n@nfraprado.net, kunit-dev@googlegroups.com, davidgow@google.com, dlatypov@google.com, brendanhiggins@google.com, daniel@ffwll.ch, skhan@linuxfoundation.org, linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org, daniel@fooishbar.org, linux-kernel@vger.kernel.org, Isabella Basso Subject: [PATCH i-g-t v2 2/4] lib/igt_kmod.c: check if module is builtin before attempting to unload it Date: Sun, 28 Aug 2022 21:09:18 -0300 Message-Id: <20220829000920.38185-3-isabbasso@riseup.net> In-Reply-To: <20220829000920.38185-1-isabbasso@riseup.net> References: <20220829000920.38185-1-isabbasso@riseup.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This change makes `igt_module_unload_r` safer as it checks whether the module can be unloaded before attempting it. Signed-off-by: Isabella Basso Acked-by: Janusz Krzysztofik --- lib/igt_kmod.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index bb6cb7bb..97cac7f5 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -256,6 +256,9 @@ static int igt_kmod_unload_r(struct kmod_module *kmod, unsigned int flags) struct kmod_list *holders, *pos; int err = 0; + if (kmod_module_get_initstate(kmod) == KMOD_MODULE_BUILTIN) + return err; + holders = kmod_module_get_holders(kmod); kmod_list_foreach(pos, holders) { struct kmod_module *it = kmod_module_get_module(pos); From patchwork Mon Aug 29 00:09:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isabella Basso X-Patchwork-Id: 12957354 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E76FECAAD5 for ; Mon, 29 Aug 2022 00:10:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbiH2AKN (ORCPT ); Sun, 28 Aug 2022 20:10:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbiH2AKI (ORCPT ); Sun, 28 Aug 2022 20:10:08 -0400 Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E0AB1FCE2; Sun, 28 Aug 2022 17:10:03 -0700 (PDT) Received: from mx0.riseup.net (mx0-pn.riseup.net [10.0.1.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mx0.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4MG9mp4sF9zDrP4; Mon, 29 Aug 2022 00:10:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1661731802; bh=f4+prBiGFgdsfKSr1oPKSV/k0Dk38ybPDQ/q4E5A+E8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g+iXiOZO2DwIGR/PO2Cy5Y/sBvsQsOJqGdkc/XAR7LOARQ5YHf/AWCcuclpTBKuJ+ mWVhAhp9I5trtfyvGjwlMrTy9to+JLXo6vkZGCaZedyIHT9E9rQg9kgRfE5Q3KFkfR g6bjN+eQZ/G/182D3lj3EnWZNNQA7KmiO2KIahzk= Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx0.riseup.net (Postfix) with ESMTPS id 4MG9mj6h4Hz9st8; Mon, 29 Aug 2022 00:09:57 +0000 (UTC) X-Riseup-User-ID: 273D4EC73442C7EBCDD9757B70B29BC09C9B5794DDD05F577B1F011D24FD1BAF Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4MG9mc50g1z5vTc; Mon, 29 Aug 2022 00:09:52 +0000 (UTC) From: Isabella Basso To: igt-dev@lists.freedesktop.org Cc: magalilemes00@gmail.com, maira.canal@usp.br, tales.aparecida@gmail.com, rodrigo.siqueira@amd.com, mwen@igalia.com, andrealmeid@riseup.net, twoerner@gmail.com, leandro.ribeiro@collabora.com, n@nfraprado.net, kunit-dev@googlegroups.com, davidgow@google.com, dlatypov@google.com, brendanhiggins@google.com, daniel@ffwll.ch, skhan@linuxfoundation.org, linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org, daniel@fooishbar.org, linux-kernel@vger.kernel.org, Isabella Basso Subject: [PATCH i-g-t v2 3/4] lib/igt_kmod: add compatibility for KUnit Date: Sun, 28 Aug 2022 21:09:19 -0300 Message-Id: <20220829000920.38185-4-isabbasso@riseup.net> In-Reply-To: <20220829000920.38185-1-isabbasso@riseup.net> References: <20220829000920.38185-1-isabbasso@riseup.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org This adds functions for both executing the tests as well as parsing (K)TAP kmsg output, as per the KTAP spec [1]. [1] https://www.kernel.org/doc/html/latest/dev-tools/ktap.html Signed-off-by: Isabella Basso --- lib/igt_kmod.c | 290 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_kmod.h | 2 + 2 files changed, 292 insertions(+) diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 97cac7f5..93cdfcc5 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "igt_aux.h" #include "igt_core.h" @@ -32,6 +33,8 @@ #include "igt_sysfs.h" #include "igt_taints.h" +#define BUF_LEN 4096 + /** * SECTION:igt_kmod * @short_description: Wrappers around libkmod for module loading/unloading @@ -713,6 +716,293 @@ void igt_kselftest_get_tests(struct kmod_module *kmod, kmod_module_info_free_list(pre); } +/** + * 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; +} + +static int find_next_tap_subtest(char *record, char *test_name, + bool is_subtest) +{ + const char *name_lookup_str, + *lend, *version_rptr, *name_rptr; + long test_count; + + name_lookup_str = "test: "; + + version_rptr = strcasestr(record, "TAP version "); + name_rptr = strcasestr(record, name_lookup_str); + + /* + * total test count will almost always appear as 0..N at the beginning + * of a run, so we use it as indication of a run + */ + test_count = lookup_value(record, ".."); + + /* no count found, so this is probably not starting a (sub)test */ + if (test_count < 0) { + if (name_rptr != NULL) { + if (test_name[0] == '\0') + strncpy(test_name, + name_rptr + strlen(name_lookup_str), + BUF_LEN); + else if (strcmp(test_name, name_rptr + strlen(name_lookup_str)) == 0) + return 0; + else + test_name[0] = '\0'; + + } + return -1; + } + + /* + * "(K)TAP version XX" should be the first line on all (sub)tests as per + * https://www.kernel.org/doc/html/latest/dev-tools/ktap.html#version-lines + * but actually isn't, as it currently depends on whoever writes the + * test to print this info + */ + if (version_rptr == NULL) + igt_info("Missing test version string\n"); + + if (name_rptr == NULL) { + /* we have to keep track of the name string, as it might be + * contained in a line read previously */ + if (test_name[0] == '\0') { + igt_info("Missing test name string\n"); + + if (is_subtest) + igt_info("Running %ld subtests...\n", test_count); + else + igt_info("Running %ld tests...\n", test_count); + } else { + lend = strchrnul(test_name, '\n'); + + if (*lend == '\0') { + if (is_subtest) + igt_info("Executing %ld subtests in: %s\n", + test_count, test_name); + else + igt_info("Executing %ld tests in: %s\n", + test_count, test_name); + return test_count; + } + + if (is_subtest) + igt_info("Executing %ld subtests in: %.*s\n", + test_count, (int)(lend - test_name), + test_name); + else + igt_info("Executing %ld tests in: %.*s\n", + test_count, (int)(lend - test_name), + test_name); + test_name[0] = '\0'; + } + } else { + name_rptr += strlen(name_lookup_str); + lend = strchrnul(name_rptr, '\n'); + /* + * as the test count comes after the test name we need not check + * for a long line again + */ + if (is_subtest) + igt_info("Executing %ld subtests in: %.*s\n", + test_count, (int)(lend - name_rptr), + name_rptr); + else + igt_info("Executing %ld tests in: %.*s\n", + test_count, (int)(lend - name_rptr), + name_rptr); + } + + return test_count; +} + +static void parse_kmsg_for_tap(const char *lstart, char *lend, + int *sublevel, bool *failed_tests) +{ + const char *nok_rptr, *comment_start, *value_parse_start; + + nok_rptr = strstr(lstart, "not ok "); + if (nok_rptr != NULL) { + igt_warn("kmsg> %.*s\n", + (int)(lend - lstart), lstart); + *failed_tests = true; + return; + } + + 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) { + igt_warn("kmsg> %.*s\n", + (int)(lend - comment_start), comment_start); + *failed_tests = true; + (*sublevel)--; + return; + } + } + + igt_info("kmsg> %.*s\n", + (int)(lend - lstart), lstart); +} + +static void igt_kunit_subtests(int fd, char *record, + int *sublevel, bool *failed_tests) +{ + char test_name[BUF_LEN + 1], *lend; + + lend = NULL; + test_name[0] = '\0'; + test_name[BUF_LEN] = '\0'; + + while (*sublevel >= 0) { + const char *lstart; + ssize_t r; + + if (lend != NULL && *lend != '\0') + lseek(fd, (int) (lend - record), SEEK_CUR); + + r = read(fd, record, BUF_LEN); + + if (r <= 0) { + switch (errno) { + case EINTR: + continue; + case EPIPE: + igt_warn("kmsg truncated: too many messages. \ + You may want to increase log_buf_len \ + in your boot options\n"); + continue; + case !EAGAIN: + igt_warn("kmsg truncated: unknown error (%m)\n"); + *sublevel = -1; + default: + break; + } + break; + } + + lend = strchrnul(record, '\n'); + + /* in case line > 4096 */ + if (*lend == '\0') + continue; + + if (find_next_tap_subtest(record, test_name, *sublevel > 0) != -1) + (*sublevel)++; + + if (*sublevel > 0) { + lstart = strchrnul(record, ';'); + + if (*lstart == '\0') { + igt_warn("kmsg truncated: output malformed (%m)\n"); + igt_fail(IGT_EXIT_FAILURE); + } + + lstart++; + while (isspace(*lstart)) + lstart++; + + parse_kmsg_for_tap(lstart, lend, sublevel, failed_tests); + } + } + + if (*failed_tests || *sublevel < 0) + igt_fail(IGT_EXIT_FAILURE); + else + igt_success(); +} + +/** + * igt_kunit: + * @module_name: the name of the module + * @opts: options to load the module + * + * Loads the kunit module, parses its dmesg output, then unloads it + */ +void igt_kunit(const char *module_name, const char *opts) +{ + struct igt_ktest tst; + char record[BUF_LEN + 1]; + bool failed_tests = false; + int sublevel = 0; + + record[BUF_LEN] = '\0'; + + /* get normalized module name */ + if (igt_ktest_init(&tst, module_name) != 0) { + igt_warn("Unable to initialize ktest for %s\n", module_name); + return; + } + + if (igt_ktest_begin(&tst) != 0) { + igt_warn("Unable to begin ktest for %s\n", module_name); + + igt_ktest_fini(&tst); + return; + } + + if (tst.kmsg < 0) { + igt_warn("Could not open /dev/kmsg"); + goto unload; + } + + if (lseek(tst.kmsg, 0, SEEK_END)) { + igt_warn("Could not seek the end of /dev/kmsg"); + goto unload; + } + + /* The kunit module is required for running any kunit tests */ + if (igt_kmod_load("kunit", NULL) != 0) { + igt_warn("Unable to load kunit module\n"); + goto unload; + } + + if (igt_kmod_load(module_name, opts) != 0) { + igt_warn("Unable to load %s module\n", module_name); + goto unload; + } + + igt_kunit_subtests(tst.kmsg, record, &sublevel, &failed_tests); +unload: + igt_kmod_unload("kunit", 0); + + igt_ktest_end(&tst); + + igt_ktest_fini(&tst); +} + static int open_parameters(const char *module_name) { char path[256]; diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h index ceb10cd0..737143c1 100644 --- a/lib/igt_kmod.h +++ b/lib/igt_kmod.h @@ -45,6 +45,8 @@ int __igt_i915_driver_unload(char **whom); int igt_amdgpu_driver_load(const char *opts); int igt_amdgpu_driver_unload(void); +void igt_kunit(const char *module_name, const char *opts); + void igt_kselftests(const char *module_name, const char *module_options, const char *result_option, From patchwork Mon Aug 29 00:09:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isabella Basso X-Patchwork-Id: 12957355 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C79EECAAD5 for ; Mon, 29 Aug 2022 00:10:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229504AbiH2AKQ (ORCPT ); Sun, 28 Aug 2022 20:10:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbiH2AKL (ORCPT ); Sun, 28 Aug 2022 20:10:11 -0400 Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 946B222BE2; Sun, 28 Aug 2022 17:10:04 -0700 (PDT) Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4MG9mq0vbVzDrgM; Mon, 29 Aug 2022 00:10:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1661731803; bh=GqYqpPbeOc3SjjOOqv4u8JdDVfsfn7HITY3mPh8GK74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XQrhd3DI9Tkvfi8b9btJi+1qblNzmjU/J90LnnOjNkYHIVcFC9YLimZRj2spMurmT SWv7xUcXsozflAa6GubJQmFUWdPk8erbKrzKsjoyvrqGrgyxv5wHCH4OE4BUE3FSr2 ZFYs5u7UAwMZ8CzDzs+yfJBeQLqmG5VvxwdJiE+M= X-Riseup-User-ID: 917F8FFE9CD523F10637D9A466C228627F64C6493909752F6C5CE9D789C5504D Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4MG9mk0Nkdz5vkC; Mon, 29 Aug 2022 00:09:57 +0000 (UTC) From: Isabella Basso To: igt-dev@lists.freedesktop.org Cc: magalilemes00@gmail.com, maira.canal@usp.br, tales.aparecida@gmail.com, rodrigo.siqueira@amd.com, mwen@igalia.com, andrealmeid@riseup.net, twoerner@gmail.com, leandro.ribeiro@collabora.com, n@nfraprado.net, kunit-dev@googlegroups.com, davidgow@google.com, dlatypov@google.com, brendanhiggins@google.com, daniel@ffwll.ch, skhan@linuxfoundation.org, linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org, daniel@fooishbar.org, linux-kernel@vger.kernel.org, Isabella Basso Subject: [PATCH i-g-t v2 4/4] tests: DRM selftests: switch to KUnit Date: Sun, 28 Aug 2022 21:09:20 -0300 Message-Id: <20220829000920.38185-5-isabbasso@riseup.net> In-Reply-To: <20220829000920.38185-1-isabbasso@riseup.net> References: <20220829000920.38185-1-isabbasso@riseup.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org As the DRM selftests are now using KUnit [1], update IGT tests as well. [1] - https://lore.kernel.org/all/20220708203052.236290-1-maira.canal@usp.br/ Signed-off-by: Isabella Basso --- tests/drm_buddy.c | 7 ++++--- tests/drm_mm.c | 7 ++++--- tests/kms_selftest.c | 12 +++++++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/drm_buddy.c b/tests/drm_buddy.c index 06876e0c..74c06dce 100644 --- a/tests/drm_buddy.c +++ b/tests/drm_buddy.c @@ -6,9 +6,10 @@ #include "igt.h" #include "igt_kmod.h" -IGT_TEST_DESCRIPTION("Basic sanity check of DRM's buddy allocator (struct drm_buddy)"); +IGT_TEST_DESCRIPTION("Basic sanity check of DRM's buddy allocator (struct \ + drm_buddy) using KUnit"); -igt_main +igt_simple_main { - igt_kselftests("test-drm_buddy", NULL, NULL, NULL); + igt_kunit("drm_buddy_test", NULL); } diff --git a/tests/drm_mm.c b/tests/drm_mm.c index 2052b115..75fc6682 100644 --- a/tests/drm_mm.c +++ b/tests/drm_mm.c @@ -24,9 +24,10 @@ #include "igt.h" #include "igt_kmod.h" -IGT_TEST_DESCRIPTION("Basic sanity check of DRM's range manager (struct drm_mm)"); +IGT_TEST_DESCRIPTION("Basic sanity check of DRM's range manager (struct drm_mm)\ + using KUnit"); -igt_main +igt_simple_main { - igt_kselftests("test-drm_mm", NULL, NULL, NULL); + igt_kunit("drm_mm_test", NULL); } diff --git a/tests/kms_selftest.c b/tests/kms_selftest.c index abc4bfe9..bbf24c2b 100644 --- a/tests/kms_selftest.c +++ b/tests/kms_selftest.c @@ -24,9 +24,15 @@ #include "igt.h" #include "igt_kmod.h" -IGT_TEST_DESCRIPTION("Basic sanity check of KMS selftests."); +IGT_TEST_DESCRIPTION("Basic sanity check of KMS selftests using KUnit"); -igt_main +igt_simple_main { - igt_kselftests("test-drm_modeset", NULL, NULL, NULL); + igt_kunit("drm_cmdline_parser_test", NULL); + igt_kunit("drm_damage_helper_test", NULL); + igt_kunit("drm_dp_mst_helper_test", NULL); + igt_kunit("drm_format_helper_test", NULL); + igt_kunit("drm_format_test", NULL); + igt_kunit("drm_framebuffer_test", NULL); + igt_kunit("drm_plane_helper_test", NULL); }