Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7354572rwp; Tue, 18 Jul 2023 14:07:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlENY9RsHkhnpL9mziCue4CdOfg0F/whslFH7J9nqcBh1NlYZpNsyiPQYFU9PMkA7L9hghCu X-Received: by 2002:a17:903:32c4:b0:1b5:5162:53bd with SMTP id i4-20020a17090332c400b001b5516253bdmr197665plr.33.1689714435043; Tue, 18 Jul 2023 14:07:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689714435; cv=none; d=google.com; s=arc-20160816; b=wMy9YWjJ0d0fjk2aZVU/qqGSD4wNEOuCJqfcKCjNfuVX429qaxATD80IwYcGtyczT8 +s3hRXtUJgKBI5dg/3NzmWYEhMYjEO2INRl5N9dscOQdHrG+uRzMFe0lXpeqgsc75brC PqwDhJ+61tp0sZe4sKVVeUy069eJ/hsKbqUi3Vm2deOqpiN0PjZF9x018b0dzT7h9uej QO5UAYkS4Y8GpIrK003S8n5aj9vo1zTX2pmdhfZSpQJGTlgLuum3LT6t2yoNrfwIn3fW WoIojQip/4VTEMc/HbNnYx604Kqpu3JBZQkWvIHmhWEvXWuAAhA7bKRlcxlYYPKhqSAF euww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=BgQcqwhLTNI8qX6knCzj+hGMtjn0S20ah/hoUWW0q2U=; fh=VMQfd9eF8jn7uhntv/42vh2I4oIh+FZo+DRjFCMxhHI=; b=cDedBdf1mnQ03brULqyPAIgZdoExJ8r7mKaX2aAQQE58I6cocTIZaMVCJxIr1D7WBS e7iXxdz9SBujSmVaJjJfK9hkAkFndrOe+UQfuttaNYoUWcQ+hox6SJycNszUnZl9Cis1 6E2/LcpL3/hz6dGrO0l33R+8b5UNiwS98ffk0fqc/w4veEjNVLOVUgephOq3v3OTf1dz lG70SJol8mU/u6m/beRc3o4mX7QipspSXI1JGNI8H/mgnE3dzBjWX0EsfoD0V6B1RU1A AJWOzvOqXzT1w4oHdpJLBDpBfen2WbteusDi+BxnwJJUpe2D/ms++YI+hpK9CBh5cnPy 0KJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=hVKdbNRu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s18-20020a17090330d200b001b9e29e5866si2079671plc.352.2023.07.18.14.07.01; Tue, 18 Jul 2023 14:07:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=hVKdbNRu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbjGRUtx (ORCPT + 99 others); Tue, 18 Jul 2023 16:49:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbjGRUtv (ORCPT ); Tue, 18 Jul 2023 16:49:51 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C96FBD for ; Tue, 18 Jul 2023 13:49:50 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fbb07e7155so139765e9.0 for ; Tue, 18 Jul 2023 13:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689713389; x=1692305389; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BgQcqwhLTNI8qX6knCzj+hGMtjn0S20ah/hoUWW0q2U=; b=hVKdbNRuovsCs+y0Lf2bjXemqvVB1qeWfMqk5yyraYwCcDvNKtONwM+9XfpFN1W2NA tjgJrVAb3dsXBTNQ49SmM3AwnYOhUE/vqp/wEYLOf83X2W+tDVEXTHfYPKQ2tUo9NPaT dw5ZrZz/j56/coQr2r1iopReeZ+mBe+jfH/39c/vzxbEe4h2YJfXd+fcTPAwN0H0T4cV MBqZJQwb6H1hrxwxIbfv56yZ0fo9pEyNfm1ssTyQdVI+F44curhBWxXdMIR7a+769jzY mh2JTM5D3dwczbjf4t4s/+GLzOEMKj457HnZ9/URUATtGgVJn5v2gsUDhUBv+VENOOLr PzNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689713389; x=1692305389; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BgQcqwhLTNI8qX6knCzj+hGMtjn0S20ah/hoUWW0q2U=; b=Gl5ppH6PX10ZYdAdJ8Q5mH6+dSro0SZZMYUk0fTOwxvhhKtgjaOQyhGhzbGbbfTU7U Tcy0I1+z79ApoJBDBel7eCxAJJ1cXpILMHTjg3oIvmauqiOk/Pyi8pRpgB5umTp+gref 0XJ7XnY0ntl5faHmiZ6V+km8oM+Mb84h6u5PAkLv3g/ytScp9Dx0x3BnzK2CPxCnU1PW ZBGVeEcU+5mXFZJbP8//aZbeHbVr7X6/XxHVMjBvlKrewCXDS9M9kRIgMdQ3VMm9S9vY nN3ilNIKZIriXcZNTGTzmwlIqa9AaUWjXVsz0bcllC5AAPbcwvKmNBKIaeHT10SZ8cor /LXw== X-Gm-Message-State: ABy/qLZHlZrwUMjQ7uCM2htPNPH1PXQI8cJELYnFmn3A78yKC0NmJZDT qG6fmQbuUhgKxUi6RgHnl1ToJ2hKfPgtwPWrc+8Esg== X-Received: by 2002:a05:600c:3ca0:b0:3f7:7bd4:3b9d with SMTP id bg32-20020a05600c3ca000b003f77bd43b9dmr162464wmb.6.1689713388786; Tue, 18 Jul 2023 13:49:48 -0700 (PDT) MIME-Version: 1.0 References: <20230707210947.1208717-1-rmoar@google.com> <20230707210947.1208717-10-rmoar@google.com> In-Reply-To: From: Rae Moar Date: Tue, 18 Jul 2023 16:49:35 -0400 Message-ID: Subject: Re: [RFC v2 9/9] kunit: Add documentation of KUnit test attributes To: David Gow Cc: shuah@kernel.org, dlatypov@google.com, brendan.higgins@linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, keescook@chromium.org, linux-hardening@vger.kernel.org, jstultz@google.com, tglx@linutronix.de, sboyd@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 18, 2023 at 3:39=E2=80=AFAM David Gow wro= te: > > On Sat, 8 Jul 2023 at 05:10, Rae Moar wrote: > > > > Add documentation on the use of test attributes under the section "Tips= for > > Running KUnit Tests" in the KUnit docs. > > > > Documentation includes three sections on how to mark tests with attribu= tes, > > how attributes are reported, and how the user can filter tests using te= st > > attributes. > > > > Signed-off-by: Rae Moar > > --- > > Looks good overall. Some nitpicks below. > > Reviewed-by: David Gow > > > > > Changes since v1: > > - This is a new patch > > > > .../dev-tools/kunit/running_tips.rst | 163 ++++++++++++++++++ > > 1 file changed, 163 insertions(+) > > > > diff --git a/Documentation/dev-tools/kunit/running_tips.rst b/Documenta= tion/dev-tools/kunit/running_tips.rst > > index 8e8c493f17d1..c9bc5a6595d3 100644 > > --- a/Documentation/dev-tools/kunit/running_tips.rst > > +++ b/Documentation/dev-tools/kunit/running_tips.rst > > @@ -262,3 +262,166 @@ other code executed during boot, e.g. > > # Reset coverage counters before running the test. > > $ echo 0 > /sys/kernel/debug/gcov/reset > > $ modprobe kunit-example-test > > + > > + > > +Test Attributes and Filtering > > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D > > + > > +Test suites and cases can be marked with test attributes, such as spee= d of > > +test. These attributes will later be printed in test output and can be= used to > > +filter test execution. > > + > > +Marking Test Attributes > > +----------------------- > > + > > +Tests are marked with an attribute by including a ``kunit_attributes``= object > > +in the test definition. > > + > > +Test cases can be marked using the ``KUNIT_CASE_ATTR(test_name, attrib= utes)`` > > +macro to define the test case instead of ``KUNIT_CASE(test_name)``. > > + > > +.. code-block:: c > > + > > + static const struct kunit_attributes example_attr =3D { > > + .speed =3D KUNIT_VERY_SLOW, > > + }; > > + > > + static struct kunit_case example_test_cases[] =3D { > > + KUNIT_CASE_ATTR(example_test, example_attr), > > + }; > > + > > +.. note:: > > + To mark a test case as slow, you can also use ``KUNIT_CASE_SLOW= (test_name)``. > > + This is a helpful macro as the slow attribute is the most commo= nly used. > > + > > +Test suites can be marked with an attribute by setting the "attr" fiel= d in the > > +suite definition. > > + > > +.. code-block:: c > > + > > + static const struct kunit_attributes example_attr =3D { > > + .speed =3D KUNIT_VERY_SLOW, > > + }; > > + > > + static struct kunit_suite example_test_suite =3D { > > + ..., > > + .attr =3D example_attr, > > + }; > > + > > +.. note:: > > + Not all attributes need to be set in a ``kunit_attributes`` obj= ect. Unset > > + attributes will remain uninitialized and act as though the attr= ibute is set > > + to 0 or NULL. Thus, if an attribute is set to 0, it is treated = as unset. > > + These unset attributes will not be reported and may act as a de= fault value > > + for filtering purposes. > > + > > +Reporting Attributes > > +-------------------- > > + > > +When a user runs tests, attributes will be present in kernel output (i= n KTAP > > +format). This is an example of how test attributes for test cases will= be formatted > > +in Kernel output: > > + > > +.. code-block:: none > > + > > + # example_test.speed: slow > > + ok 1 example_test > > + > > +This is an example of how test attributes for test suites will be form= atted in > > +Kernel output: > > + > > +.. code-block:: none > > + > > + KTAP version 2 > > + # Subtest: example_suite > > + # module: kunit_example_test > > + 1..3 > > + ... > > + ok 1 example_suite > > + > > Maybe worth noting that kunit.py will hide these for passing tests by > default, and --raw_output is needed to see them? > I will definitely add this in. If attributes are popular in the future, I could create a future patch to show attributes in the parser output as well. > > +Additionally, users can output a full attribute report of tests with t= heir > > +attributes, using the command line flag ``--list_tests_attr``: > > + > > +.. code-block:: bash > > + > > + kunit.py run "example" --list_tests_attr > > + > > +.. note:: > > + This report can be accessed when running KUnit manually by pass= ing in the > > + module_param ``kunit.action=3Dlist_attr``. > > + > > +Filtering > > +--------- > > + > > +Users can filter tests using the ``--filter`` command line flag when r= unning > > +tests. As an example: > > + > > +.. code-block:: bash > > + > > + kunit.py run --filter speed=3Dslow > > + > > + > > +You can also use the following operations on filters: "<", ">", "<=3D"= , ">=3D", > > +"!=3D", and "=3D". Example: > > + > > +.. code-block:: bash > > + > > + kunit.py run --filter "speed>slow" > > + > > +This example will run all tests with speeds faster than slow. Note tha= t the > > +characters < and > are often interpreted by the shell, so they may nee= d to be > > +quoted or escaped, as above. > > + > > +Additionally, you can use multiple filters at once. Simply separate fi= lters > > +using commas. Example: > > + > > +.. code-block:: bash > > + > > + kunit.py run --filter "speed>slow, module=3Dkunit_example_test" > > + > > +.. note:: > > + You can use this filtering feature when running KUnit manually = by passing > > + the filter as a module param: ``kunit.filter=3D"speed>slow, spe= ed<=3Dnormal"``. > > + > > +Filtered tests will not run or show up in the test output. You can use= the > > +``--filter_skip`` flag to skip filtered tests instead. These tests wil= l be > > +shown in the test output in the test but will not run. To use this fea= ture when > > +running KUnit manually, use the ``kunit.filter`` module param with > > +``kunit.filter_action=3Dskip``. > > + > > +Rules of Filtering Procedure > > +---------------------------- > > + > > +Since both suites and test cases can have attributes, there may be con= flicts > > +between attributes during filtering. The process of filtering follows = these > > +rules: > > + > > +- Filtering always operates at a per-test level. > > + > > +- If a test has an attribute set, then the test's value is filtered on= . > > + > > +- Otherwise, the value falls back to the suite's value. > > + > > +- If neither are set, the attribute has a global "default" value, whic= h is used. > > + > > +List of Current Attributes > > +-------------------------- > > I wonder whether this should end up part of the KTAP spec (or as an > appendix/supplement to it). Or even as a separate page within the > KUnit documentation to avoid running_tips.rst from getting too huge. I am a bit hesitant to move this as part of the KTAP spec in case there will exist KTAP attributes/data that are not supported by the KUnit test attributes framework (could be runtime specific attributes that use a different framework?). However, I do worry about the size of this page. Do you think that I should move all of the attributes to a new documentation page? > > > + > > +``speed`` > > + > > +This attribute indicates the speed of a test's execution (how slow or = fast the > > +test is). > > + > > +This attribute is saved as an enum with the following categories: "nor= mal", > > +"slow", or "very_slow". The assumed default speed for tests is "normal= ". This > > +indicates that the test takes a relatively trivial amount of time (les= s than > > +1 second), regardless of the machine it is running on. Any test slower= than > > +this could be marked as "slow" or "very_slow". > > Is it worth noting that "KUNIT_CASE_SLOW()" can be used to easily set > this to slow? This definitely seems important to add. I will add this to the documentatio= n. > > > > + > > +``module`` > > + > > +This attribute indicates the name of the module associated with the te= st. > > + > > +This attribute is automatically saved as a string and is printed for e= ach suite. > > +Tests can also be filtered using this attribute. > > + > > -- > > 2.41.0.255.g8b1d071c50-goog > > > > > Error: new blank line at EOF. Oops. I will change this.