Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp107630pxh; Thu, 7 Apr 2022 15:30:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBI5TW0o+GdF5CmGU9iz1u/d0U16M+WcNLI1rS1NMLECbP27FSRzWj5jhEhxZ3U+mLozku X-Received: by 2002:a17:902:d2cb:b0:157:6ad:e4bf with SMTP id n11-20020a170902d2cb00b0015706ade4bfmr5520690plc.5.1649370650443; Thu, 07 Apr 2022 15:30:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649370650; cv=none; d=google.com; s=arc-20160816; b=BMrVXS75HO5DtZClqXXiExniY4aMzzwEc0piMZuwO9qE/K30NpzeRz7v9IyXGz4FUf qCLXIQ4QAeM+vktqD4EIvZh4vKXaKpcEDPZRBtfWZep/1DK6cDInm1EtcP/ldjEaK3AX NwiDoYrqI0EJmY1ohPccGt+dBWrEerk0AaqKBamqAsGDGVf7pqLvVM+MWVqQ3kycxmW/ MBQru5nrx8oVSdcE8/nhRaYkK8FMYnrqpSp3QzXEfUh3X3EbFrv5AsQ7eovJdrW2MAB2 1VSSjpZECIenoKGs8QmWfbtht6TVUcJuimRFRUHUuvd7FHTFGcZvNZrLPj8nqGt+tWOR Wd6Q== 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:references :in-reply-to:mime-version:dkim-signature; bh=yaGos3SERrC2jdiQiJ/85vABo3kZeiwvqRtqI7sWR/o=; b=RQmrDYG9NA2cS47zlgYqTsLzs1bVl04l9J8TsrfvOgHEbTDIhsAqAHvN1bxr63EeuS e7igkCREdKoTXrPnznUCeABoZNQS/1AcveHFlnj2Haaj4MpQzQS2hW8+oBPjMGiovNwc SPs3ThBqEapvLpTdkjRYMuiYzg7XZYjsZ1Jc6LK/JokwttpYgzcRApNIObPWzv/izzC1 gaHALPv+eFzfasyv2jQGHEbHHYKvjSjfakoGZDg+clu1PoghIsNUqaMIjyhuQw9ZXsyE 7ON5OiI0kL7msojj5yfd+PxeVJBgODUw2JXY39+j77rRcWPo6ujdwU9TlG5Wz0bSMSQ9 Fk4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=UnoHu1EK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m12-20020a056a00080c00b004fa7ebac146si21779126pfk.28.2022.04.07.15.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 15:30:50 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=UnoHu1EK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AFA9B1A4D73; Thu, 7 Apr 2022 14:35:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231701AbiDGVhB (ORCPT + 99 others); Thu, 7 Apr 2022 17:37:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbiDGVhA (ORCPT ); Thu, 7 Apr 2022 17:37:00 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B5AB19FF7E for ; Thu, 7 Apr 2022 14:34:59 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id x131so11834692ybe.11 for ; Thu, 07 Apr 2022 14:34:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eclypsium.com; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=yaGos3SERrC2jdiQiJ/85vABo3kZeiwvqRtqI7sWR/o=; b=UnoHu1EK+12NpKKA6uHxlvH9RUZbPSgYKriZSpsoZk125w5ipGaiJ7sTtSTGJbeMdp Di350AKk06PeKhYE+MJWSKTJDYk4A7TfEFWKJ92lqYXLXG0/bkkDCtMSY4ru7ns8Cs30 0NIEgnHab0r5/k/hTOZPAKpTGMTGQGQyTK33Uukp8gs2IzZlnPz6LrjMGmCnCqLwUZ25 18itwsp3ELXHwK29xjTTLEMg8uzfg7NH4o8JLk0FisLvmB12XKsQ7g2lpr3Ncu5s+INw N+bbiivMFNquAbOtNEkdbNn0yw4WP/NnDLWLnUCQIm4OAwysRaQ56esx+QbJW1tI3C1l 7+hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=yaGos3SERrC2jdiQiJ/85vABo3kZeiwvqRtqI7sWR/o=; b=ntjt7vzjFNjVxX7xMxLl5Lj5F0hAdHLHO+JQdNKcaP1G3AxhZboEcrzQyn4Dw+WIbr CLmmUeyVjGDdsk7z/3UFwmZyKnduKmAcZobZk45Xs0MC9zYqSN4uyaOEAu6NPwOeKtEv oY4391Sqx8bgoU9tjQIjUaYPQ3Bg7iQhgdz6xvxXlFneV3hE1hMLE/NmM2CZ+1v0g1xb pg529Rorpc2uSRuIInbdM6AyCObM/xhkUjlxHIFpv64hMtp5q6DWgIzU/MyQZbd8xNW/ +t7SgxUUBJF2OBo3p4HtJztj/Utsb5g9XK7AELEvU5f4OHZ2RYMiVNb29czQt7lXf2d5 YZXw== X-Gm-Message-State: AOAM532B1VKh1gg2rJT05euS7Aq74X0gUYxnmIl5WTjV+ssp6fKk7ibG xin0bcWpUmO86nyKd3jLCx80iBBHEzPXyDNfE6/w2Q== X-Received: by 2002:a25:e689:0:b0:63e:4f58:d27 with SMTP id d131-20020a25e689000000b0063e4f580d27mr4753250ybh.341.1649367298317; Thu, 07 Apr 2022 14:34:58 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a81:10a:0:0:0:0:0 with HTTP; Thu, 7 Apr 2022 14:34:57 -0700 (PDT) In-Reply-To: References: <20220311072859.2174624-1-brendanhiggins@google.com> <1e1472e8-1813-3903-f934-cb0ae7f09864@linuxfoundation.org> From: Martin Fernandez Date: Thu, 7 Apr 2022 18:34:57 -0300 Message-ID: Subject: Re: [PATCH v1] kunit: add support for kunit_suites that reference init code To: Brendan Higgins 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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=no 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 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? >> > base-commit: 330f4c53d3c2d8b11d86ec03a964b86dc81452f5 >> > >> >> thanks, >> -- Shuah >