From patchwork Fri Apr 29 18:12:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12832581 X-Patchwork-Delegate: brendanhiggins@google.com 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 96C74C433F5 for ; Fri, 29 Apr 2022 18:13:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355638AbiD2SQ0 (ORCPT ); Fri, 29 Apr 2022 14:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229935AbiD2SQ0 (ORCPT ); Fri, 29 Apr 2022 14:16:26 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F9BEA6E37 for ; Fri, 29 Apr 2022 11:13:07 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2f4dee8688cso80455907b3.16 for ; Fri, 29 Apr 2022 11:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=2kiTLLWMzE1fRaVFv2RZTJ9b23xbStkawa5kRyjYyA8=; b=keqK+zylXN4pY8llCOBPg1Er0xKEg1omQb4Cj4I7sP2jLPCAJxPCRtn2RdUNZGfWA2 FGOCY8T7aXIKF8uj4+c8dGhHnigGnxQu9g3akFu5WpTlvCwa0owfS9ei/ZrL6lUrF9pJ RLbPdQpht3OpwGjuhaMLs5UkOEAg7ZOnXSE6whUlBoUhl9PKXtjNdBJfDZia/A0YKEt4 sruyz8Uv6xOLeo4z/CO+19HT2Ld/0qcE92J+5JwquXW3cXxP7qguCR5+9qM8rO71vw6Q 9yGtVMTNpd6Y7h0MlWSEH1mJNIkJNicH2NJRugMUaQv79RX/Dhru8UyxOol5dieNeLd0 4XuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=2kiTLLWMzE1fRaVFv2RZTJ9b23xbStkawa5kRyjYyA8=; b=lP8R5aBSUEiS+W9lJKM/A+dR2QEktOj3UYs5oUB7WBXmgitwmSnyHPS/H2AOBy88/3 VgCaWUNG49VrsCgpx2TLWUYd+bfGEdrYmZiVtfK1e9fvVs/14BtGmz+UJuYHhNDhqTYt mxZGSiGtV26Wbswy/9XbXuPQrVg2fC+MQmiRFz7si+s+c3Oaph6rDvuFtDYcjZy3WJY0 0HeEsVG1Ie+4NC99ZJ7XKVQrq0H/jewDTwFtad4UK6BR8TjlRBEBLpQI8x2vzmeskL8G Fh59aA8eOCgZetV1AgTLv02BTtgX+SfW+WTZdrONMIIstyzOSN4JiyNDfukAbulMcNyN S3vg== X-Gm-Message-State: AOAM531Ws4sb2bKhKmO9pMYhv7toPDZpD3zkkePVftrJpVHUkCbzyZFr KpssPgrCNv3NGEz7mLBLm1vjzchlXdIWRg== X-Google-Smtp-Source: ABdhPJww5bRnHtr8wc3vsPj0eMHvAcjEqA+BTTAGRMBxrErBjDajT2Sbx0bHXuuQSEFvAbFSto7zqzARc3pVjw== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:183a:36d7:2dcb:1773]) (user=dlatypov job=sendgmr) by 2002:a25:d354:0:b0:645:d617:560a with SMTP id e81-20020a25d354000000b00645d617560amr682256ybf.247.1651255986725; Fri, 29 Apr 2022 11:13:06 -0700 (PDT) Date: Fri, 29 Apr 2022 11:12:56 -0700 Message-Id: <20220429181259.622060-1-dlatypov@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v2 1/4] kunit: rename print_subtest_{start,end} for clarity (s/subtest/suite) From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, Daniel Latypov Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org These names sound more general than they are. The _end() function increments a `static int kunit_suite_counter`, so it can only safely be called on suites, aka top-level subtests. It would need to have a separate counter for each level of subtest to be generic enough. So rename it to make it clear it's only appropriate for suites. Signed-off-by: Daniel Latypov Reviewed-by: David Gow Reviewed-by: Brendan Higgins --- v1 -> v2: no change (see patch 2 and 4) --- lib/kunit/test.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) base-commit: 59729170afcd4900e08997a482467ffda8d88c7f diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 0f66c13d126e..64ee6a9d8003 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -134,7 +134,7 @@ size_t kunit_suite_num_test_cases(struct kunit_suite *suite) } EXPORT_SYMBOL_GPL(kunit_suite_num_test_cases); -static void kunit_print_subtest_start(struct kunit_suite *suite) +static void kunit_print_suite_start(struct kunit_suite *suite) { kunit_log(KERN_INFO, suite, KUNIT_SUBTEST_INDENT "# Subtest: %s", suite->name); @@ -192,7 +192,7 @@ EXPORT_SYMBOL_GPL(kunit_suite_has_succeeded); static size_t kunit_suite_counter = 1; -static void kunit_print_subtest_end(struct kunit_suite *suite) +static void kunit_print_suite_end(struct kunit_suite *suite) { kunit_print_ok_not_ok((void *)suite, false, kunit_suite_has_succeeded(suite), @@ -498,7 +498,7 @@ int kunit_run_tests(struct kunit_suite *suite) struct kunit_result_stats suite_stats = { 0 }; struct kunit_result_stats total_stats = { 0 }; - kunit_print_subtest_start(suite); + kunit_print_suite_start(suite); kunit_suite_for_each_test_case(suite, test_case) { struct kunit test = { .param_value = NULL, .param_index = 0 }; @@ -552,7 +552,7 @@ int kunit_run_tests(struct kunit_suite *suite) } kunit_print_suite_stats(suite, suite_stats, total_stats); - kunit_print_subtest_end(suite); + kunit_print_suite_end(suite); return 0; } From patchwork Fri Apr 29 18:12:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12832582 X-Patchwork-Delegate: brendanhiggins@google.com 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 8DCE7C433F5 for ; Fri, 29 Apr 2022 18:13:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379925AbiD2SQf (ORCPT ); Fri, 29 Apr 2022 14:16:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379716AbiD2SQ3 (ORCPT ); Fri, 29 Apr 2022 14:16:29 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0705B1AB3 for ; Fri, 29 Apr 2022 11:13:09 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 9-20020a250909000000b006484b89c979so7976845ybj.21 for ; Fri, 29 Apr 2022 11:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=tmbVGyHWnlJ8gG/+aK542d489GBFQrAnhxibyOD20PI=; b=oJkYYWfPlFNxpWPKmes11c1uNsw36Qs4NyVSb4xnhl0owZ1v4+hgfLggkUVwqsJ3OG kuBHGef7/XMigHi8T41U9jwE1Ws6eDYQTpp064jpFj4chi+Cg9Vrj+JUYaYCBJLHUuAg N+0gyLbeNlL0JMYVyMP/saHiHBqZjscUPKB3hGTRSQVtxqCZlVYD5GBn1I5+InfsnzzG ndMuGEOmgbI+lLCbNJEmnEwNZI8J5NtwSvkvbUq4VmKSz5qmfArHKGpQmdMB6vmSnltF ttYRr5qnEeiYSsjRqWwSvkyGbYxXQMZn3MyFjUThDidxkUwLlZlwIpEmPReoE0LsOH27 SBLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=tmbVGyHWnlJ8gG/+aK542d489GBFQrAnhxibyOD20PI=; b=HtNDIPkgV9OIM0QGJeeTHKBUIceUTRG6eswuDeYg1r8SmPkkj1cRViJm/GrfPIRkS9 fdiJL7LIqnMAkbemwfubbgTN4BOhls+aJYVYUmi9PJBl0ABAA5TamTIm61usIcTWGJay zC1f//KlHwz7Aynzus6BpkEcLo9lvCgkse4mdCMCGaMRkvSbhW/lTyxsUP+h3Xl5F+cM 8mtI+/o4pNfNAwMpvyIDwkTm8EOhwUC0rFvlz8mgVruKuAKZr7pdog1czitTQEMeVbe5 CTIwEp9HXRevORap2iw18LpVzzEDEWULvgXJPvsD067kF1n2ATA8dCghYUcWwkCOARl5 0mLg== X-Gm-Message-State: AOAM531mTJ+YhOPzMgATTqEUaEB33EM8t8NROU8i7XdyqO0G/G2WCXoF zzPVISsLgKM1gpYzyZQZbrG4bd7mbDg4WA== X-Google-Smtp-Source: ABdhPJwfn6H3jkDfOm0T0xVJq/twaeRoLLoSnqOpELQeWQzr18SW0bB8RsYlvRfz3T/MANKfSOVv2GQsfAeXqA== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:183a:36d7:2dcb:1773]) (user=dlatypov job=sendgmr) by 2002:a81:6a46:0:b0:2f4:dc3f:e8f8 with SMTP id f67-20020a816a46000000b002f4dc3fe8f8mr579331ywc.292.1651255988924; Fri, 29 Apr 2022 11:13:08 -0700 (PDT) Date: Fri, 29 Apr 2022 11:12:57 -0700 In-Reply-To: <20220429181259.622060-1-dlatypov@google.com> Message-Id: <20220429181259.622060-2-dlatypov@google.com> Mime-Version: 1.0 References: <20220429181259.622060-1-dlatypov@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v2 2/4] kunit: add ability to specify suite-level init and exit functions From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, Daniel Latypov Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org KUnit has support for setup/cleanup logic for each test case in a suite. But it lacks the ability to specify setup/cleanup for the entire suite itself. This can be used to do setup that is too expensive or cumbersome to do for each test. Or it can be used to do simpler things like log debug information after the suite completes. It's a fairly common feature, so the lack of it is noticeable. Some examples in other frameworks and languages: * https://docs.python.org/3/library/unittest.html#setupclass-and-teardownclass * https://google.github.io/googletest/reference/testing.html#Test::SetUpTestSuite Meta: This is very similar to this patch here: https://lore.kernel.org/linux-kselftest/20210805043503.20252-3-bvanassche@acm.org/ The changes from that patch: * pass in `struct kunit *` so users can do stuff like `kunit_info(suite, "debug message")` * makes sure the init failure is bubbled up as a failure * updates kunit-example-test.c to use a suite init * Updates kunit/usage.rst to mention the new support * some minor cosmetic things * use `suite_{init,exit}` instead of `{init/exit}_suite` * make suite init error message more consistent w/ test init * etc. Signed-off-by: Daniel Latypov Reviewed-by: David Gow Reviewed-by: Brendan Higgins --- v1 -> v2: add suite_init_err to struct kunit_suite so kunit_suite_has_succeeded() still works for CONFIG_KUNIT_DEBUGFS=y. --- Documentation/dev-tools/kunit/usage.rst | 19 +++++++++++-------- include/kunit/test.h | 5 +++++ lib/kunit/kunit-example-test.c | 14 ++++++++++++++ lib/kunit/test.c | 17 +++++++++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst index 1c83e7d60a8a..d62a04255c2e 100644 --- a/Documentation/dev-tools/kunit/usage.rst +++ b/Documentation/dev-tools/kunit/usage.rst @@ -125,8 +125,8 @@ We need many test cases covering all the unit's behaviors. It is common to have many similar tests. In order to reduce duplication in these closely related tests, most unit testing frameworks (including KUnit) provide the concept of a *test suite*. A test suite is a collection of test cases for a unit of code -with a setup function that gets invoked before every test case and then a tear -down function that gets invoked after every test case completes. For example: +with optional setup and teardown functions that run before/after the whole +suite and/or every test case. For example: .. code-block:: c @@ -141,16 +141,19 @@ down function that gets invoked after every test case completes. For example: .name = "example", .init = example_test_init, .exit = example_test_exit, + .suite_init = example_suite_init, + .suite_exit = example_suite_exit, .test_cases = example_test_cases, }; kunit_test_suite(example_test_suite); -In the above example, the test suite ``example_test_suite`` would run the test -cases ``example_test_foo``, ``example_test_bar``, and ``example_test_baz``. Each -would have ``example_test_init`` called immediately before it and -``example_test_exit`` called immediately after it. -``kunit_test_suite(example_test_suite)`` registers the test suite with the -KUnit test framework. +In the above example, the test suite ``example_test_suite`` would first run +``example_suite_init``, then run the test cases ``example_test_foo``, +``example_test_bar``, and ``example_test_baz``. Each would have +``example_test_init`` called immediately before it and ``example_test_exit`` +called immediately after it. Finally, ``example_suite_exit`` would be called +after everything else. ``kunit_test_suite(example_test_suite)`` registers the +test suite with the KUnit test framework. .. note:: A test case will only run if it is associated with a test suite. diff --git a/include/kunit/test.h b/include/kunit/test.h index 97cd76461886..604eb5263b6b 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -153,6 +153,8 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status) * struct kunit_suite - describes a related collection of &struct kunit_case * * @name: the name of the test. Purely informational. + * @suite_init: called once per test suite before the test cases. + * @suite_exit: called once per test suite after all test cases. * @init: called before every test case. * @exit: called after every test case. * @test_cases: a null terminated array of test cases. @@ -167,6 +169,8 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status) */ struct kunit_suite { const char name[256]; + int (*suite_init)(struct kunit_suite *suite); + void (*suite_exit)(struct kunit_suite *suite); int (*init)(struct kunit *test); void (*exit)(struct kunit *test); struct kunit_case *test_cases; @@ -175,6 +179,7 @@ struct kunit_suite { char status_comment[KUNIT_STATUS_COMMENT_SIZE]; struct dentry *debugfs; char *log; + int suite_init_err; }; /** diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c index 91b1df7f59ed..f8fe582c9e36 100644 --- a/lib/kunit/kunit-example-test.c +++ b/lib/kunit/kunit-example-test.c @@ -40,6 +40,17 @@ static int example_test_init(struct kunit *test) return 0; } +/* + * This is run once before all test cases in the suite. + * See the comment on example_test_suite for more information. + */ +static int example_test_init_suite(struct kunit_suite *suite) +{ + kunit_info(suite, "initializing suite\n"); + + return 0; +} + /* * This test should always be skipped. */ @@ -142,17 +153,20 @@ static struct kunit_case example_test_cases[] = { * may be specified which runs after every test case and can be used to for * cleanup. For clarity, running tests in a test suite would behave as follows: * + * suite.suite_init(suite); * suite.init(test); * suite.test_case[0](test); * suite.exit(test); * suite.init(test); * suite.test_case[1](test); * suite.exit(test); + * suite.suite_exit(suite); * ...; */ static struct kunit_suite example_test_suite = { .name = "example", .init = example_test_init, + .suite_init = example_test_init_suite, .test_cases = example_test_cases, }; diff --git a/lib/kunit/test.c b/lib/kunit/test.c index 64ee6a9d8003..65c56bd0545d 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -179,6 +179,9 @@ enum kunit_status kunit_suite_has_succeeded(struct kunit_suite *suite) const struct kunit_case *test_case; enum kunit_status status = KUNIT_SKIPPED; + if (suite->suite_init_err) + return KUNIT_FAILURE; + kunit_suite_for_each_test_case(suite, test_case) { if (test_case->status == KUNIT_FAILURE) return KUNIT_FAILURE; @@ -498,6 +501,15 @@ int kunit_run_tests(struct kunit_suite *suite) struct kunit_result_stats suite_stats = { 0 }; struct kunit_result_stats total_stats = { 0 }; + if (suite->suite_init) { + suite->suite_init_err = suite->suite_init(suite); + if (suite->suite_init_err) { + kunit_err(suite, KUNIT_SUBTEST_INDENT + "# failed to initialize (%d)", suite->suite_init_err); + goto suite_end; + } + } + kunit_print_suite_start(suite); kunit_suite_for_each_test_case(suite, test_case) { @@ -551,7 +563,11 @@ int kunit_run_tests(struct kunit_suite *suite) kunit_accumulate_stats(&total_stats, param_stats); } + if (suite->suite_exit) + suite->suite_exit(suite); + kunit_print_suite_stats(suite, suite_stats, total_stats); +suite_end: kunit_print_suite_end(suite); return 0; @@ -562,6 +578,7 @@ static void kunit_init_suite(struct kunit_suite *suite) { kunit_debugfs_create_suite(suite); suite->status_comment[0] = '\0'; + suite->suite_init_err = 0; } int __kunit_test_suites_init(struct kunit_suite * const * const suites) From patchwork Fri Apr 29 18:12:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12832583 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 51241C433EF for ; Fri, 29 Apr 2022 18:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379934AbiD2SQg (ORCPT ); Fri, 29 Apr 2022 14:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379915AbiD2SQb (ORCPT ); Fri, 29 Apr 2022 14:16:31 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3362BF95F for ; Fri, 29 Apr 2022 11:13:11 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id d22-20020a25add6000000b00645d796034fso8073268ybe.2 for ; Fri, 29 Apr 2022 11:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Ia9AduyfzsduaRDy65QoQpMuuQ/nrqWkXPaBfG45mh8=; b=Wt625QvyBcBL8KwQdT/OqYIuN6WELk7AmEtxSFDkrsxQWe93lNWtci0RSG8XuQgGNw stQ3eVOou8GHMbJQ7IxWccaQElk26bPmuPWFMrJVuI9gzk4z1xBndXIM5M4R4Q0s+GT6 mM1jfllZBVFHfYgwRYgKS/C1HwwH8Bc8pwM46AZJZehzoehCOmEbOv6OJJE1p/lsnv+V R1+SAsBx6RLGfweJ+eSKDwEQE2HF1zLZrF1HjAuAG19ZsafYy9dPVUceteE15HWzqvLi Csq2cC+tFI0GtGOuG3ErqSTBkULrx713sE0Ok71hcBGivKKPepo0v7ZKMwxSgRO/4VqS aLFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Ia9AduyfzsduaRDy65QoQpMuuQ/nrqWkXPaBfG45mh8=; b=MPw6yoT7grje901UaiOvyhk7Z7qxeWNtQo6ZlaU4TO9zM8iFNm3dMPwF0CUkUMv8ej 5E1GAVbp4sURI9exgT3gNyxeNvsR423RekrBzjwJKNlUP4rrbdseBeDzJ+NqoUARKMeW K4Ixd/DLdPe48EJF+QMfHeCNd3g2XVuOy32cjyNzrzQgTPG8WLeO7f3cvNnoD7ybP7nA jqdetixJO+jwjZmia5t4bG7xTG/7/ClYj7ySNfgGtLT7zXHkrUOO29r6QAmh0LibKRnO ns3HNVnNXTgVQHY5AsPf0l8oYqF+sfBpukTSE+/q3KyoGS/2Yph4W9QkRwFmcQeYXDo0 C9RA== X-Gm-Message-State: AOAM531bF1bQYP4N64c+2zqfMgZnLQbfBM+NyCHlHYwQldHrpGJijEvq oTPNPzF2XMshXuSKZo1FxflbEONv6iJ85w== X-Google-Smtp-Source: ABdhPJwApmwGXTnrXiumQYuKuHpAL+YQOd50zL1va4pYM42T2MZQ0Bxgw+pG6hAP+xLf3Nv0DgJJluVZN+lK6g== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:183a:36d7:2dcb:1773]) (user=dlatypov job=sendgmr) by 2002:a81:2c3:0:b0:2f7:c26e:5790 with SMTP id 186-20020a8102c3000000b002f7c26e5790mr599582ywc.84.1651255991186; Fri, 29 Apr 2022 11:13:11 -0700 (PDT) Date: Fri, 29 Apr 2022 11:12:58 -0700 In-Reply-To: <20220429181259.622060-1-dlatypov@google.com> Message-Id: <20220429181259.622060-3-dlatypov@google.com> Mime-Version: 1.0 References: <20220429181259.622060-1-dlatypov@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v2 3/4] kfence: test: use new suite_{init/exit} support, add .kunitconfig From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, Daniel Latypov , kasan-dev@googlegroups.com, Marco Elver Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently, the kfence test suite could not run via "normal" means since KUnit didn't support per-suite setup/teardown. So it manually called internal kunit functions to run itself. This has some downsides, like missing TAP headers => can't use kunit.py to run or even parse the test results (w/o tweaks). Use the newly added support and convert it over, adding a .kunitconfig so it's even easier to run from kunit.py. People can now run the test via $ ./tools/testing/kunit/kunit.py run --kunitconfig=mm/kfence --arch=x86_64 ... [11:02:32] Testing complete. Passed: 23, Failed: 0, Crashed: 0, Skipped: 2, Errors: 0 [11:02:32] Elapsed time: 43.562s total, 0.003s configuring, 9.268s building, 34.281s running Cc: kasan-dev@googlegroups.com Signed-off-by: Daniel Latypov Tested-by: David Gow Reviewed-by: Marco Elver Reviewed-by: Brendan Higgins --- v1 -> v2: no change (see patch 2 and 4) --- mm/kfence/.kunitconfig | 6 ++++++ mm/kfence/kfence_test.c | 31 +++++++++++++------------------ 2 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 mm/kfence/.kunitconfig diff --git a/mm/kfence/.kunitconfig b/mm/kfence/.kunitconfig new file mode 100644 index 000000000000..f3d65e939bfa --- /dev/null +++ b/mm/kfence/.kunitconfig @@ -0,0 +1,6 @@ +CONFIG_KUNIT=y +CONFIG_KFENCE=y +CONFIG_KFENCE_KUNIT_TEST=y + +# Additional dependencies. +CONFIG_FTRACE=y diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c index 1b50f70a4c0f..96206a4ee9ab 100644 --- a/mm/kfence/kfence_test.c +++ b/mm/kfence/kfence_test.c @@ -826,14 +826,6 @@ static void test_exit(struct kunit *test) test_cache_destroy(); } -static struct kunit_suite kfence_test_suite = { - .name = "kfence", - .test_cases = kfence_test_cases, - .init = test_init, - .exit = test_exit, -}; -static struct kunit_suite *kfence_test_suites[] = { &kfence_test_suite, NULL }; - static void register_tracepoints(struct tracepoint *tp, void *ignore) { check_trace_callback_type_console(probe_console); @@ -847,11 +839,7 @@ static void unregister_tracepoints(struct tracepoint *tp, void *ignore) tracepoint_probe_unregister(tp, probe_console, NULL); } -/* - * We only want to do tracepoints setup and teardown once, therefore we have to - * customize the init and exit functions and cannot rely on kunit_test_suite(). - */ -static int __init kfence_test_init(void) +static int kfence_suite_init(struct kunit_suite *suite) { /* * Because we want to be able to build the test as a module, we need to @@ -859,18 +847,25 @@ static int __init kfence_test_init(void) * won't work here. */ for_each_kernel_tracepoint(register_tracepoints, NULL); - return __kunit_test_suites_init(kfence_test_suites); + return 0; } -static void kfence_test_exit(void) +static void kfence_suite_exit(struct kunit_suite *suite) { - __kunit_test_suites_exit(kfence_test_suites); for_each_kernel_tracepoint(unregister_tracepoints, NULL); tracepoint_synchronize_unregister(); } -late_initcall_sync(kfence_test_init); -module_exit(kfence_test_exit); +static struct kunit_suite kfence_test_suite = { + .name = "kfence", + .test_cases = kfence_test_cases, + .init = test_init, + .exit = test_exit, + .suite_init = kfence_suite_init, + .suite_exit = kfence_suite_exit, +}; + +kunit_test_suites(&kfence_test_suite); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Alexander Potapenko , Marco Elver "); From patchwork Fri Apr 29 18:12:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Latypov X-Patchwork-Id: 12832584 X-Patchwork-Delegate: brendanhiggins@google.com 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 32F6AC433FE for ; Fri, 29 Apr 2022 18:13:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233327AbiD2SQg (ORCPT ); Fri, 29 Apr 2022 14:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379919AbiD2SQe (ORCPT ); Fri, 29 Apr 2022 14:16:34 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28F19C7497 for ; Fri, 29 Apr 2022 11:13:14 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id j11-20020a05690212cb00b006454988d225so7998827ybu.10 for ; Fri, 29 Apr 2022 11:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sL4XXKW/JkXSCKlfCPPNQVCwhZjkWTkPQxVqGebWlkY=; b=J8I5/PjQmTyc7WXDivtsNpPPj3oCtvBdvBNDRZ016t+T537sEc6xywczIJjMi05DZh OT1tpJeA7Ys1Oalyk/Q7g8bQO3eNce6w6ztjAyvQGEW7zmxJZvQO6ZCtW+9Tie8pys5Q tgMFfSRBeh79U+MlvjO7SwoBhWU6fipFTqmjGEvrjTzjp51iImfSo4bPnFMHPC37HuzK +NUVBBR0ZgofOK61hfA1YC99wfQ0UpDi75zqTeBk2mysDTntcVYfxeM3lHA9iDwjCVmn DRjB0Xwxj7EMaeICNXQPuX77pluy0vvMfEFcJ1AgmId2Qgl9lIpd1K+HYiz68u2ZCc2F FLFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sL4XXKW/JkXSCKlfCPPNQVCwhZjkWTkPQxVqGebWlkY=; b=T8O7QLpcTN+puOVJkCc+9AqjXK8ZNdx38eZjrP0jCoAwcsaheofzc1bvpUjQwudQUO 0e7xJgCcA57gunFXF4BGQlIXkQioL0qLdg9H12c1PAGI2B5oGdSEgCEqMUqTZoGrZmyA 0eOj4UGRXT8ySsUyaOD3+9bY3C+bRrfOfmPe0jqG0cv4iMLPqarPkGY0pFZdJqo70URS Lc8lrKM5AcdGtqbrY6wo2PmwaYYUkKwfnT0TnTSSFyaaf4QyHhRSMwl2st+DFTH+Gn9w uUIDAqAAwZab405+mSy88uS87d6XTR58HC88mDBvPA7m3TRb1thAzurc2NfDzKAnF1oF KE9g== X-Gm-Message-State: AOAM532K6BxDFfk0jj318XV+xIAP+zMlb+yc9pIygDqy2TP7VfZgu9+n x50sd2NpNEAAVlX/4hBsQe+YAhAcCdegoQ== X-Google-Smtp-Source: ABdhPJyyVRFTKlRDuFIct0JNB1b+NegMWENKiEyuTk/7a5uhOrU993QYfuCRnGk4qCfG6URZ47v+Y5zg7zypzw== X-Received: from dlatypov.svl.corp.google.com ([2620:15c:2cd:202:183a:36d7:2dcb:1773]) (user=dlatypov job=sendgmr) by 2002:a25:9383:0:b0:648:458e:423e with SMTP id a3-20020a259383000000b00648458e423emr669169ybm.583.1651255993442; Fri, 29 Apr 2022 11:13:13 -0700 (PDT) Date: Fri, 29 Apr 2022 11:12:59 -0700 In-Reply-To: <20220429181259.622060-1-dlatypov@google.com> Message-Id: <20220429181259.622060-4-dlatypov@google.com> Mime-Version: 1.0 References: <20220429181259.622060-1-dlatypov@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v2 4/4] kunit: fix debugfs code to use enum kunit_status, not bool From: Daniel Latypov To: brendanhiggins@google.com, davidgow@google.com Cc: linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, Daniel Latypov Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Commit 6d2426b2f258 ("kunit: Support skipped tests") switched to using `enum kunit_status` to track the result of running a test/suite since we now have more than just pass/fail. This callsite wasn't updated, silently converting to enum to a bool and then back. Fixes: 6d2426b2f258 ("kunit: Support skipped tests") Signed-off-by: Daniel Latypov Reviewed-by: Brendan Higgins --- v1 -> v2: added this patch. --- lib/kunit/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kunit/debugfs.c b/lib/kunit/debugfs.c index b71db0abc12b..1048ef1b8d6e 100644 --- a/lib/kunit/debugfs.c +++ b/lib/kunit/debugfs.c @@ -52,7 +52,7 @@ static void debugfs_print_result(struct seq_file *seq, static int debugfs_print_results(struct seq_file *seq, void *v) { struct kunit_suite *suite = (struct kunit_suite *)seq->private; - bool success = kunit_suite_has_succeeded(suite); + enum kunit_status success = kunit_suite_has_succeeded(suite); struct kunit_case *test_case; if (!suite || !suite->log)