Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7355514rwp; Tue, 18 Jul 2023 14:08:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlGKgk5WIxSLkka2hnnVDtDmHhyu2FEoVXJeerH+txto+lr7KXF5zZtEd3XR3XDAbK5k1zsQ X-Received: by 2002:a05:6a20:3c8c:b0:137:30db:bc1e with SMTP id b12-20020a056a203c8c00b0013730dbbc1emr197588pzj.3.1689714492277; Tue, 18 Jul 2023 14:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689714492; cv=none; d=google.com; s=arc-20160816; b=WC+sl7BsWdEBrbqxC0xFg70YsrtyOAKuPW4d3lMLpMnb7ihkUZGrxSkzWj/EkgK62R ur3omd5YzorV5b1SZIP06/9FrxrQ5LyjJ23Clh6b8xIDIxz+MLeHR6mZJ+s2wRpCA1iW 6SJtXqSo9aLtpGs8/R3eD6HLEU3D863QH2j164PiYYMI4AZAsqEZc9R35QuK1xqeSocW 0ldVj66rjjYD8zMz7NyhzucDPwxM8r+hnk2FeSvLzInrHY/otC1RtCuMXtSqsf099D50 xDWXNYnlxIEa6hiruvQb2qaK5U7SNHPq2T/YYdgn3uwp8IdENvFBtYlRk4Et5LNXobZ1 d/IA== 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=GqVfsPSqh0LbeBvoORwyyBidJKmm58T1GcZQwn4bT3I=; fh=VMQfd9eF8jn7uhntv/42vh2I4oIh+FZo+DRjFCMxhHI=; b=lUlP6Ht5iXuxw9HCmIh7CQS4fA39R4lZ+cVyMe4gtqOXU7kpO7INrwkblbhbOqi1e7 motMGdlU2/F1G6rw0HHl9rXKRUJGQz+YeEZZ92hHsXcRHH4d5fP7bunPWOqmSg9/TKSN o8SbNB3FtYxovtALr3nYnD0lks/ddqX9zFNPsTfUCs/WCt4Gsj+MxxfSYBFyNtt09aA2 r9OG5ecCkg8NQ0K9djWpmOccVYZJEXOf8pY8U4CYn1dPI8DOsbCSVRT+g5wJqCar+pm/ Utt8Mm+buG4iZoxVp16Bc6AuVh0A766w8ECuhWxWVgxQhapt2Wtk7fW9idXSIArLvnCG HO2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=fmdNRvXS; 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 fh30-20020a056a00391e00b0067bc790ce11si2039960pfb.161.2023.07.18.14.08.00; Tue, 18 Jul 2023 14:08:12 -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=fmdNRvXS; 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 S230475AbjGRUki (ORCPT + 99 others); Tue, 18 Jul 2023 16:40:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230466AbjGRUkh (ORCPT ); Tue, 18 Jul 2023 16:40:37 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41C64EC for ; Tue, 18 Jul 2023 13:40:35 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-521ac15e333so12200a12.0 for ; Tue, 18 Jul 2023 13:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689712834; x=1692304834; 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=GqVfsPSqh0LbeBvoORwyyBidJKmm58T1GcZQwn4bT3I=; b=fmdNRvXS3fpla427GqCxknVcPn9s5GjEteFKVdiXaD9jKMdiysLLQTIF4PEJG+HTf0 x0hc1Do7yqnxVEGeaxl7Y8qKeL23eRc7dY+Z/wO5EBE6mb94jPTinu9sUdhzZ8Clif5K jZeFhcixJbbBo8v9KO5gpnyfUFUfkltyHEru089t0eFdsPHQlAX65IT6187OSoAsd8Tn 84jUFel0vkCD620mq3Y4MLuznQOS02XXLSzfJUaLw0ygrPctOOa2rckXtYHfMjbNfbuY Wny7J606C/nRs3m/9wbDT7tlLQChJBcYn2tpVpdfqpOA5cL8T7mkppVgJeneCaC2bzl5 MOPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689712834; x=1692304834; 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=GqVfsPSqh0LbeBvoORwyyBidJKmm58T1GcZQwn4bT3I=; b=IUp0IwhNTk9i0gB62TYVxvSuZupUIUdftKksPCPzl/1+k+RDJGyu7y+Obuv3XEcEPs cyt1KWucektP80zGNNuevXflxWZHbz/a9x878jEcBDBDHDFyHLk1bZSN7WMpSIDInPNV Ddn9kniWrUb+rP/uYXawaP5eiBMa+HPAI92OIo7d6ZAFud1qNtnbdQxp2gnhgWqa/FFF Q4FXLyvlTqIyCFj4P2dhWQ2T2wtY39d3kwK+NP7az4rhgzYgrvGEFPelRz38o0BkBYkd 3D1w8YFpFyD+Zjhl87oFdq3iZWhuZ0hUKSX76VyUEIM3jcHUpx48hUGhqgqhwPdVUpJT UOJw== X-Gm-Message-State: ABy/qLaaLr7FCSZ6pbt6w1XoJ3hM6daAOmKwVXD83yfcBmQxFrCEN/WN 9sJwrBKaXKajrmX+iKlOSf2TCqPOCi6BDxGvHSgRrw== X-Received: by 2002:a50:9fae:0:b0:51e:295f:4ef0 with SMTP id c43-20020a509fae000000b0051e295f4ef0mr160300edf.5.1689712833559; Tue, 18 Jul 2023 13:40:33 -0700 (PDT) MIME-Version: 1.0 References: <20230707210947.1208717-1-rmoar@google.com> <20230707210947.1208717-5-rmoar@google.com> In-Reply-To: From: Rae Moar Date: Tue, 18 Jul 2023 16:40:19 -0400 Message-ID: Subject: Re: [RFC v2 4/9] kunit: Add ability to filter 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=unavailable 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 filtering of test attributes. Users can filter tests using the > > module_param called "filter". > > > > Filters are imputed in the format: > > > > Example: kunit.filter=3D"speed>slow" > > > > Operations include: >, <, >=3D, <=3D, !=3D, and =3D. These operations w= ill act the > > same for attributes of the same type but may not between types. > > > > Note multiple filters can be inputted by separating them with a comma. > > Example: kunit.filter=3D"speed=3Dslow, module!=3Dexample" > > > > Since both suites and test cases can have attributes, there may be > > conflicts. 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, which > > is used. > > > > Filtered tests will not be run or show in output. The tests can instead= be > > skipped using the configurable option "kunit.filter_action=3Dskip". > > > > Note the default settings for running tests remains unfiltered. > > > > Finally, add "filter" methods for the speed and module attributes to pa= rse > > and compare attribute values. > > > > Note this filtering functionality will be added to kunit.py in the next > > patch. > > > > Signed-off-by: Rae Moar > > --- > > > > Changes since v1: > > - Change method for inputting filters to allow for spaces in filtering > > values > > - Add option to skip filtered tests instead of not run or show them wit= h > > the --filter_skip flag > > > > include/kunit/attributes.h | 31 +++++ > > lib/kunit/attributes.c | 256 +++++++++++++++++++++++++++++++++++++ > > lib/kunit/executor.c | 94 +++++++++++--- > > lib/kunit/executor_test.c | 12 +- > > lib/kunit/test.c | 10 +- > > 5 files changed, 375 insertions(+), 28 deletions(-) > > > > diff --git a/include/kunit/attributes.h b/include/kunit/attributes.h > > index 9fcd184cce36..bc76a0b786d2 100644 > > --- a/include/kunit/attributes.h > > +++ b/include/kunit/attributes.h > > @@ -9,6 +9,20 @@ > > #ifndef _KUNIT_ATTRIBUTES_H > > #define _KUNIT_ATTRIBUTES_H > > > > +/* > > + * struct kunit_attr_filter - representation of attributes filter with= the > > + * attribute object and string input > > + */ > > +struct kunit_attr_filter { > > + struct kunit_attr *attr; > > + char *input; > > +}; > > + > > +/* > > + * Returns the name of the filter's attribute. > > + */ > > +const char *kunit_attr_filter_name(struct kunit_attr_filter filter); > > + > > /* > > * Print all test attributes for a test case or suite. > > * Output format for test cases: "# .: " > > @@ -16,4 +30,21 @@ > > */ > > void kunit_print_attr(void *test_or_suite, bool is_test, unsigned int = test_level); > > > > +/* > > + * Returns the number of fitlers in input. > > + */ > > +int kunit_get_filter_count(char *input); > > + > > +/* > > + * Parse attributes filter input and return an objects containing the > > + * attribute object and the string input of the next filter. > > + */ > > +struct kunit_attr_filter kunit_next_attr_filter(char **filters, int *e= rr); > > + > > +/* > > + * Returns a copy of the suite containing only tests that pass the fil= ter. > > + */ > > +struct kunit_suite *kunit_filter_attr_tests(const struct kunit_suite *= const suite, > > + struct kunit_attr_filter filter, char *action, int *err= ); > > + > > #endif /* _KUNIT_ATTRIBUTES_H */ > > diff --git a/lib/kunit/attributes.c b/lib/kunit/attributes.c > > index 43dcb5de8b8f..91cbcacafba9 100644 > > --- a/lib/kunit/attributes.c > > +++ b/lib/kunit/attributes.c > > @@ -67,6 +67,104 @@ static const char *attr_string_to_string(void *attr= , bool *to_free) > > return (char *) attr; > > } > > > > +/* Filter Methods */ > > + > > +static const char op_list[] =3D "<>!=3D"; > > + > > +/* > > + * Returns whether the inputted integer value matches the filter given > > + * by the operation string and inputted integer. > > + */ > > +static int int_filter(long val, const char *op, int input, int *err) > > +{ > > + if (!strncmp(op, "<=3D", 2)) > > + return (val <=3D input); > > + else if (!strncmp(op, ">=3D", 2)) > > + return (val >=3D input); > > + else if (!strncmp(op, "!=3D", 2)) > > + return (val !=3D input); > > + else if (!strncmp(op, ">", 1)) > > + return (val > input); > > + else if (!strncmp(op, "<", 1)) > > + return (val < input); > > + else if (!strncmp(op, "=3D", 1)) > > + return (val =3D=3D input); > > + *err =3D -EINVAL; > > + pr_err("kunit executor: invalid filter operation: %s\n", op); > > More a nitpick for the kunit.py patch, but I'd love to have this shown > to the user as an error when run under kunit.py. It's very annoying to > miss this and only get a "no tests run" error (or worse, unfiltered > results) back. > I agree. I would love to change this. I am currently looking into how easy this is to change. It would be nice to at least see a general KUnit executor error in the output instead of the "no tests run!" error. > > > + return false; > > +}