Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3514415pxb; Mon, 4 Apr 2022 19:28:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfOkBcxr4WCUFKgVbWuQCdyqJZXJ2JpH8fp9ElED7CjbawAtCXo822B0PwFSWjb9IbzodM X-Received: by 2002:a17:90b:4a01:b0:1c9:a552:f487 with SMTP id kk1-20020a17090b4a0100b001c9a552f487mr1530350pjb.68.1649125734093; Mon, 04 Apr 2022 19:28:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649125734; cv=none; d=google.com; s=arc-20160816; b=PVuhytVNo0wcPhSgaCLIJAw04e2BzF+rsWZ9N8c+oVQA+/kQRv7lK9jCaa38i461UN AaHygwSYlKxu5hsD2IJUI3XxWYgWjGvNDhs8BYeJCqlOnioIeofNaeyJullsg9FgUhoW 7ry4jRlu7lBlCA/JCcgL25aOysCJp6S4yB53Dry4BryurguaH1i4uVdDo+wQe7hZxHUy tW5X2rH75LSSXby5jJE/WucBOpx+MJRo1EOazHNDlNBt/SPQQ5COLLGT+/AVNcDUNJM7 mn91sqExUsVZdmtE+CjKDVCWvvtDx/xAUU33IA78zT1ClWpYicr/muWg7t1xb7OQRXOM JfUg== 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=vmQtSeoAc+Nq1zeZ+fcOy7GISIYvQy3s9Qy54NdzuHU=; b=v4hMA07e8demDcvqbbAdMT4dmvCYor5I2RmiMHdjP137+DJ2nWmTPTJr15CH7cf3zY HcOwxXVN9OcpNaBEX11ebZW+mCqDlraC8P1zYsjHfRWbdWf+k9SCCordThNyV9uIcz+O fBXWCOprhxYD93rWdB7wG4QiZ+hTq9kBgzxnv90Mjjx8GrxG9f+/5f1XFCJaX2JmufrQ TV4CWzQFzjq0a6MyGzyFfy6s+KYiSRY/9VQiirXzGdUjTOTD+L03fW7f0aNktwlBUY41 mZ6p1ATYQXVoPvmFQ7YeHtDKY9WeeOkJYhtR6ey/aCqqW1IUvCEx7FPCbTrlRM9XMYiA UWsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=o04wJ+0Z; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d21-20020a630e15000000b00382274cbb1bsi11284736pgl.873.2022.04.04.19.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 19:28:54 -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=@google.com header.s=20210112 header.b=o04wJ+0Z; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E9A801ADA8; Mon, 4 Apr 2022 17:51:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242858AbiDDXOe (ORCPT + 99 others); Mon, 4 Apr 2022 19:14:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243569AbiDDXLl (ORCPT ); Mon, 4 Apr 2022 19:11:41 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6A19113E for ; Mon, 4 Apr 2022 15:48:44 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id l26so6681262ejx.1 for ; Mon, 04 Apr 2022 15:48:44 -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=vmQtSeoAc+Nq1zeZ+fcOy7GISIYvQy3s9Qy54NdzuHU=; b=o04wJ+0ZKldbQAUg1OrIlnIW+Sx2rrgZN889EJaxXOUiYl1aFr9M2h/mAs5Hq/qfKP TTsqt/3k7wIv4hpJjvaqoJLYI8N+Bs3w+hQCNbH+TXLubgXpeWh9UMVwIGRxTbT+0HRe OYkEmZn4RdjGxdIuFmDsnKDyQOrtx7luLwYQu2jkxEZvv0Yiu0qJGhOT3Zb7QdH6VHX4 lyfyTbnXIgPDJjdPXj+suT0Ge2pmL/GV7WS9mY3h2pmqDceIKSocUZYNRQa/uR3YhX2e 7ywzIGVVVuGNqcwOXumeP3m+tRQvyS2P01JKNHoObHinqn6TKWcZZ9J4CRbY+KGcDH/K P29A== 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=vmQtSeoAc+Nq1zeZ+fcOy7GISIYvQy3s9Qy54NdzuHU=; b=u2VC2Q8FvrmK0hv6TqhaN4mlLizaMOyoqXVWT6xwGjils3642n2etu9d+DbjRMj3fN edZPcC4v88wqZlo3QnKUaIO7q+K5HueqY/b2b51tSAxbxh6soYT/Oa4NDSn5xywPwXmC VvOJpcFXXbgOXjgl7T0QBhNBM0EdioaxhaLMDc3hecgcFyRPSniIeasbndfrpIuP/7CQ lY0kCuoWPCzKAxK4ZGzp5Fn2zNf+b+LpOKSJ5CU9uyfr4NUsqXRQj7io0A1jBsjTKI1a SmxFX6SK8KbZdlSV980LZaz1wdoK/zJd+9koklvTfJFZNCPeTYrTNMHVCDh9d/9ufl4W fHhg== X-Gm-Message-State: AOAM533NAmA642EWWS1/0uaJW1TvPpLw32MtIMlngT2x/mYI6Xwiv0A2 p+HVfcMrJ/hOZjmJtjcQyek7DP1W7QphOUUnBBHR9A== X-Received: by 2002:a17:906:37cd:b0:6e0:bdb6:f309 with SMTP id o13-20020a17090637cd00b006e0bdb6f309mr500240ejc.394.1649112523031; Mon, 04 Apr 2022 15:48:43 -0700 (PDT) MIME-Version: 1.0 References: <20220311072859.2174624-1-brendanhiggins@google.com> <1e1472e8-1813-3903-f934-cb0ae7f09864@linuxfoundation.org> In-Reply-To: <1e1472e8-1813-3903-f934-cb0ae7f09864@linuxfoundation.org> From: Brendan Higgins Date: Mon, 4 Apr 2022 18:48:31 -0400 Message-ID: Subject: Re: [PATCH v1] kunit: add support for kunit_suites that reference init code To: Shuah Khan Cc: shuah@kernel.org, davidgow@google.com, dlatypov@google.com, martin.fernandez@eclypsium.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=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 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? > > base-commit: 330f4c53d3c2d8b11d86ec03a964b86dc81452f5 > > > > thanks, > -- Shuah