Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp859775pxw; Sat, 9 Apr 2022 03:03:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW9c8yBORhvkNRxPqQDD/19VQAtSiu6TC6PtKfxYUfWVrG8ws7AtS9eobavrx4qN/PtXJ5 X-Received: by 2002:a05:6402:430c:b0:419:4660:e261 with SMTP id m12-20020a056402430c00b004194660e261mr23267576edc.324.1649498609288; Sat, 09 Apr 2022 03:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649498609; cv=none; d=google.com; s=arc-20160816; b=L8NVFcohEnH6MNhpyY11ujvC+cPTLoiLG6cUpBu9E4iYnprSClSWHqA9ywuymyTds8 PQAc97Y+EtEPwo/hrA+UtObJNjKKQVLj4g/uqq0wzc8F5noEcE6aIncgmWjxD8TEFWpF gjWLmodfFq+utMwIubXmkKasTUaGRL6WWRtus+oOudiHSNw0q/vFlwhd4n+OVuExlXbb 7zUKmKFiONzIH41SHmwkgciu1z4kSZL+eRNLzSBhacEFMcy5QwmbsUzQS0yBnMN3wRou zwO1IkqxgqyKss5ZdlQSMVtnmDxVVba+KRhx2pZQxemOjpjbfqHc9hQxEcfTH3cJfIUd A+Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=n5q8/1C+/LCbS5CGbOTUmNklFZ3s8en/gT9RzZm5DDc=; b=O9HU630aBJv7fhFBGLJ+c8Pznl0N8kPdZqQ1U69zNbRi1WD2j/m243s+yWVXQvrZZM 8tDlMp8ynmFaeF1xcgVoQtXw/1QXPeQLE/uoO7T/b4I+zAHIwIZa6lp0+D4qlco6MUtt 8NzZ81WoVZdNCiqLVof6K3B+jHEg+DmQMYhI7Dn9oZv8us42Y7IzSfChBeZHYniZkVg+ SaeC9IH85iFzYkewg6ZAx/JLGCbPHyP7yRr9FRuqPOkdM+o4zIlgs5zAyAMgdrj1dhZH DDvSF5OIjedG6gs3QzAaUXaJkLXL6v2lnzj90a3saF/BOs0QOOM9Bugqj7CdsPI9+UMz 4iEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RkdT3bAf; 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 v15-20020a17090606cf00b006e871b03ff3si646061ejb.116.2022.04.09.03.03.02; Sat, 09 Apr 2022 03:03:29 -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=20210112 header.b=RkdT3bAf; 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 S238243AbiDHRgn (ORCPT + 99 others); Fri, 8 Apr 2022 13:36:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238213AbiDHRgf (ORCPT ); Fri, 8 Apr 2022 13:36:35 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4431EB647F for ; Fri, 8 Apr 2022 10:34:27 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id bg10so18735835ejb.4 for ; Fri, 08 Apr 2022 10:34:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=n5q8/1C+/LCbS5CGbOTUmNklFZ3s8en/gT9RzZm5DDc=; b=RkdT3bAfCsYXfpYn3lLDYi0cSQYw5M7wL2Dtjp+OeAWeABPG+zU7s1FrQqWG3rEgIH 2plHifG930QHOJt+6Db04vhR+Be4ww9DOKsmVfxE5mjk86shotqKwsriKGoJvX05nGFP 9GywnNWyFrNXlD8QyRq/CdJw0XY7GLSxy2WxbWmZgO3OXS78uDYp+hpTz8E410y2KwRW oMFG/FkNVnvd4nNQeKSf4wQJspfWrRDDQpV9suKKvyOvGDJATYr+vh3NyonqtEl177T9 g/wPvaSvxoG6SRXy8AxWT6uM3eJcIA8HAclf+ABYD54bJGBG/acxBZLDcwykZ33OOFsV hSxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=n5q8/1C+/LCbS5CGbOTUmNklFZ3s8en/gT9RzZm5DDc=; b=h74wV0tsgmPo36xbagL53q43llYgbleU2vvHZypCtm/Y2H380YucEUmg2NNwmpJdWJ gDY8PzXoUKl3fb6hTE3f1pmkmIqc7qmcswdUKsFytjibM4e+icP7I6k6MKvcnWvcMEIZ yb7qcGJSEnwGNZfz2u9VE541jLoEL46ATiSa9ewehUW6cAoOGM1VWBxlwOEvrPjJpLsr 8kUGodwIY05SRqMorPTZ/B1lyk+q7JiGF8TUhhGgz61fLlpWBQidRa4VCwa1uXEStOKw Bzet7H7bUGCF6DaFOrLz04ITPlijgqKeuG1daaHYl/lhp5NtsHwe+d5SfxmEz8bxCI/Z A/0A== X-Gm-Message-State: AOAM533DY0OWy5DBTovD5TQm/YvgC+gH5C2APOMl1oWuD9hF4nBPAqjd TzWqK9GXPTZE8Crhb8a4GuV4ZDHatvsylBA+U//HSg== X-Received: by 2002:a17:907:d06:b0:6e0:e2f5:4f55 with SMTP id gn6-20020a1709070d0600b006e0e2f54f55mr20243918ejc.618.1649439265440; Fri, 08 Apr 2022 10:34:25 -0700 (PDT) MIME-Version: 1.0 References: <20220311072859.2174624-1-brendanhiggins@google.com> <1e1472e8-1813-3903-f934-cb0ae7f09864@linuxfoundation.org> In-Reply-To: From: Brendan Higgins Date: Fri, 8 Apr 2022 13:34:12 -0400 Message-ID: Subject: Re: [PATCH v1] kunit: add support for kunit_suites that reference init code To: Martin Fernandez Cc: Shuah Khan , shuah@kernel.org, davidgow@google.com, dlatypov@google.com, daniel.gutson@eclypsium.com, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, keescook@chromium.org, jk@codeconstruct.com.au Content-Type: text/plain; charset="UTF-8" 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_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,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 Thu, Apr 7, 2022 at 5:34 PM Martin Fernandez wrote: > > On 4/4/22, Brendan Higgins wrote: > > On Mon, Apr 4, 2022 at 6:37 PM Shuah Khan > > wrote: > >> > >> Hi Brendan, > >> > >> On 3/11/22 12:28 AM, Brendan Higgins wrote: > >> > Add support for a new kind of kunit_suite registration macro called > >> > kunit_test_init_suite(); this new registration macro allows the > >> > registration of kunit_suites that reference functions marked __init and > >> > data marked __initdata. > >> > > >> > Signed-off-by: Brendan Higgins > >> > Tested-by: Martin Fernandez > >> > Reviewed-by: Kees Cook > >> > Reviewed-by: David Gow > >> > --- > >> > > >> > >> I almost applied it ... > >> > >> > This is a follow-up to the RFC here[1]. > >> > > >> > This patch is in response to a KUnit user issue[2] in which the user > >> > was > >> > attempting to test some init functions; although this is a functional > >> > solution as long as KUnit tests only run during the init phase, we will > >> > need to do more work if we ever allow tests to run after the init phase > >> > is over; it is for this reason that this patch adds a new registration > >> > macro rather than simply modifying the existing macros. > >> > > >> > Changes since last version: > >> > - I added more to the kunit_test_init_suites() kernel-doc comment > >> > detailing "how" the modpost warnings are suppressed in addition to > >> > the existing information regarding "why" it is OK for the modpost > >> > warnings to be suppressed. > >> > > >> > [1] > >> > https://lore.kernel.org/linux-kselftest/20220310210210.2124637-1-brendanhiggins@google.com/ > >> > [2] https://groups.google.com/g/kunit-dev/c/XDjieRHEneg/m/D0rFCwVABgAJ > >> > > >> > --- > >> > include/kunit/test.h | 26 ++++++++++++++++++++++++++ > >> > 1 file changed, 26 insertions(+) > >> > > >> > diff --git a/include/kunit/test.h b/include/kunit/test.h > >> > index b26400731c02..7f303a06bc97 100644 > >> > --- a/include/kunit/test.h > >> > +++ b/include/kunit/test.h > >> > @@ -379,6 +379,32 @@ static inline int kunit_run_all_tests(void) > >> > > >> > #define kunit_test_suite(suite) kunit_test_suites(&suite) > >> > > >> > +/** > >> > + * kunit_test_init_suites() - used to register one or more &struct > >> > kunit_suite > >> > + * containing init functions or init data. > >> > + * > >> > + * @__suites: a statically allocated list of &struct kunit_suite. > >> > + * > >> > + * This functions identically as &kunit_test_suites() except that it > >> > suppresses > >> > + * modpost warnings for referencing functions marked __init or data > >> > marked > >> > + * __initdata; this is OK because currently KUnit only runs tests upon > >> > boot > >> > + * during the init phase or upon loading a module during the init > >> > phase. > >> > + * > >> > + * NOTE TO KUNIT DEVS: If we ever allow KUnit tests to be run after > >> > boot, these > >> > + * tests must be excluded. > >> > + * > >> > + * The only thing this macro does that's different from > >> > kunit_test_suites is > >> > + * that it suffixes the array and suite declarations it makes with > >> > _probe; > >> > + * modpost suppresses warnings about referencing init data for symbols > >> > named in > >> > + * this manner. > >> > + */ > >> > +#define kunit_test_init_suites(__suites...) \ > >> > + __kunit_test_suites(CONCATENATE(__UNIQUE_ID(array), _probe), \ > >> > + CONCATENATE(__UNIQUE_ID(suites), _probe), \ > >> > + ##__suites) > >> > + > >> > +#define kunit_test_init_suite(suite) kunit_test_init_suites(&suite) > >> > + > >> > #define kunit_suite_for_each_test_case(suite, test_case) \ > >> > for (test_case = suite->test_cases; test_case->run_case; > >> > test_case++) > >> > > >> > > >> > >> The naming of the function and macro are rather confusing and can become > >> error prone. Let's find better naming scheme. > > > > Yeah, I wasn't sure about the name. I didn't have any better ideas > > initially though. Any suggestions? > > > > What about kunit_test_init_section_suite? Sounds fine to me. Shuah, does that sound OK to you? > >> > base-commit: 330f4c53d3c2d8b11d86ec03a964b86dc81452f5 > >> > > >> > >> thanks, > >> -- Shuah > >