Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3533634pxb; Mon, 4 Apr 2022 20:14:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgxMmfDfKMc8/ktoGF6Xg5cdkbYH1Vj+c3/x9zLL0yg4+nAnRTLbRfsVPhTh0B1rzMBw+b X-Received: by 2002:a17:90b:164f:b0:1c7:8d20:ff6d with SMTP id il15-20020a17090b164f00b001c78d20ff6dmr1685922pjb.64.1649128439802; Mon, 04 Apr 2022 20:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649128439; cv=none; d=google.com; s=arc-20160816; b=wlmsA0UkEDRtcNpdR4KvPVmLguMjsm2BqKvh0t3c9kM0Js0LKGR1OMtq7n9+wamaWp ATA4An3pX+oXkul/JSs4AHeAv93/YoQZtwlyVZobwnZum+mxQSmvtGIYKeA6PQagZipI o6WVfkcaFX3PhE0e543r2xkgxp+VboE3NWb4O+bN7PGJ0lBYoDbaORPSz4WbubAjLIu4 T4Upno+5SClhTPAkrqO5fZbzf5lQeVSdH/NyRH7m56je2kLEIEWk8QSTChas1c0LUG6E h6Nuo9eu8lsUsQ6id9TXoGhXeaAwfx0yRI5Snst0MlBddmIXQvJFnfJOs4MNJ53VdNLP U+Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=8RkDTj+tVN/WuUnfdI9iKChyCQMganXuCI7qsE2bz9c=; b=RV0wTGrXnQEYTmsNIG61k6D23GqYWaCOFYgP5fzTCUKoEbbvQB+jheeZwaiw/M4esy fbpJmjaKYO1jOV1/xc8leT9hjEe9w+1hdlXBsEf6dbSWZeWb1PbCEhjX+leXk5jHKZjh SYdAsMYTz622vP/WAlc71Bed3MEVWivl1zxevLRKPAu+QUJ63L2ZN6gCdfpiCIZaXuAs TKUSlyoWSjCvDWq5V81y7D7reYC6UuzdlkC+5za+iC7DV3vB5koBFkt1JL3HXZjyj4ON N0Ciz4wsTylC8iSeJkQxo1CnsK8Z6USCNtfh4OU7nOKr0j77Cn6e/wIGjRcK5n7r9sAA XsZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=fl075IfJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b15-20020a056a000a8f00b004fa3a8dff9csi12677574pfl.83.2022.04.04.20.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 20:13:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=fl075IfJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2CD5B468262; Mon, 4 Apr 2022 18:14:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbiDDXIv (ORCPT + 99 others); Mon, 4 Apr 2022 19:08:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236768AbiDDXIU (ORCPT ); Mon, 4 Apr 2022 19:08:20 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27CBF55740 for ; Mon, 4 Apr 2022 15:37:18 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id x4so13128706iop.7 for ; Mon, 04 Apr 2022 15:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=8RkDTj+tVN/WuUnfdI9iKChyCQMganXuCI7qsE2bz9c=; b=fl075IfJf1jFfYAqt/jIkBDHdk2V+ognrp14WSdgOENUk0zwZkldU73FG4kjEG89nQ AC2rm+mA8uK7mf+rlpMteKCHFgukgBdjtbeeGfDHXFWJhphX1/uWlqMSjzSwaDkucHs1 8MV8GXFEyLyB4ljN2AUCdsxJgPXhamItAKzxs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8RkDTj+tVN/WuUnfdI9iKChyCQMganXuCI7qsE2bz9c=; b=qaC0tXM4smMpGgEG5DYmGpmjJI/6Z+sQcf6CUrfOEePSUjRk9LStnSy71XkKG3Jjoh DnvmIa26Zm67rtr2n3Yp+09XgrKigZqJodqUTHZP0UkvLU4AFfC6bJNlXMojJM/vnEV1 EA7ExhBQsSa6JleGtW9cQNh2TlYynatCY92U7j3krykXgDWtj5GlSl/WuAFKJXPBfwmr C5El27rAiHJ3V/SrEby6oevjYBkCmNDMCOyfm2OdtLJT8JxswgzlGLH6m5B4duoO92B3 9r1RSOWsQ57S+1pDz6qWorFVUq1+Rpa29yMAetAgj6amlsh2RA21YpN7IkpPvmmFrmlq V4gA== X-Gm-Message-State: AOAM531/SlGCvP5NqN9kQdr+WFzCuoYE38WSlm+XwG67ER2KEwk4lOP+ hbTAuk7mIsBfV2x23K6oMStR+A== X-Received: by 2002:a05:6602:122a:b0:649:5df1:36f0 with SMTP id z10-20020a056602122a00b006495df136f0mr268677iot.214.1649111837395; Mon, 04 Apr 2022 15:37:17 -0700 (PDT) Received: from [192.168.1.128] ([71.205.29.0]) by smtp.gmail.com with ESMTPSA id x3-20020a056e021ca300b002ca049c9530sm6663151ill.7.2022.04.04.15.37.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Apr 2022 15:37:17 -0700 (PDT) Subject: Re: [PATCH v1] kunit: add support for kunit_suites that reference init code To: Brendan Higgins , shuah@kernel.org, davidgow@google.com, dlatypov@google.com, martin.fernandez@eclypsium.com, daniel.gutson@eclypsium.com Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, keescook@chromium.org, jk@codeconstruct.com.au, Shuah Khan References: <20220311072859.2174624-1-brendanhiggins@google.com> From: Shuah Khan Message-ID: <1e1472e8-1813-3903-f934-cb0ae7f09864@linuxfoundation.org> Date: Mon, 4 Apr 2022 16:37:15 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20220311072859.2174624-1-brendanhiggins@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE 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 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. > base-commit: 330f4c53d3c2d8b11d86ec03a964b86dc81452f5 > thanks, -- Shuah