Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp927119pxb; Fri, 22 Apr 2022 14:31:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbQddnl8mlUea0qn4L1Dlga6WoWOllP2aDnv2ghnh8zx6J8RVpJqW+bqdG33d/VzyvKUZn X-Received: by 2002:a17:902:9684:b0:158:b28c:41e0 with SMTP id n4-20020a170902968400b00158b28c41e0mr6578897plp.85.1650663116122; Fri, 22 Apr 2022 14:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650663116; cv=none; d=google.com; s=arc-20160816; b=09aYr3bwgG2V2aZUfxITTLb1pikdoBbaHLLLwbJ5osTEveiWEDzEjGR2Qe4iaQUSCn WmNFYgIJb8+nZjXx9Oc57UpOvLLj5pTt+50iXecl8+rHr6sS3SLBHUBpMCrp+4RKdtsB oLAY1Yadi9rUPm4jwX2QokNa/lnlnNKX9Q41jfqFGx7/ns4gQZy7ThuozLFK9pp7Jnph 8KwePnj7WSfD6nZNQwUgicPxpaxDRYkUTT/eRbO3XDbSe/BmYW2evF8tgT/dZjPkHdNX 1Kg8GYc8MTBCTUdEnxEOEse0Xa2BcLfsuai3OAT3nzmcOqatVMO82ZKkSOzeGpOxPBPk 2JtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=2kvo4cKjgLSkZi0ORkIKm30VEiLgu1BUEUNx8foAAG8=; b=ABwvUkT10r3UzaXu3oRReyBhCXG4Z1AhYHcI0gDdI+Ud9RVYX4dU6nso1WspsN97W7 8oLaXUY/nrFh37vV9UnqEJmonBYgMGc6qapn2PCD8FmFiiAYrHGwHimoaxjNj/0r1Bt2 pPiLGJw4x1/7u1nB9kCaRcTDRl8UmuPAc3XZbW8IDFvAJPK62iajywfoReJnKnvYBKTp Q6eubt6Wd7hM+0TpZNE/AqgfyzYM2G7ec2v9rATn0apRzmzVdBwlXf4ZOfW/dDiWInno ub1SxIyAtnZYG7edejP0OYnLYTYco/nVBB/2hPttXsUmnEGX9/3feLTDq7fBU1A+Wu69 IKRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=eEembY2G; 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 s82-20020a632c55000000b003a0bfc020ecsi9650979pgs.32.2022.04.22.14.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 14:31:56 -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=eEembY2G; 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 584731F8EFC; Fri, 22 Apr 2022 12:40:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348177AbiDSEIK (ORCPT + 99 others); Tue, 19 Apr 2022 00:08:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347355AbiDSEIC (ORCPT ); Tue, 19 Apr 2022 00:08:02 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B9E41A049 for ; Mon, 18 Apr 2022 21:05:21 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id d129-20020a254f87000000b006411bf3f331so13785988ybb.4 for ; Mon, 18 Apr 2022 21:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=2kvo4cKjgLSkZi0ORkIKm30VEiLgu1BUEUNx8foAAG8=; b=eEembY2GsRtYsEYySYFlinuBVUlW5yxKUGielw9ewu8TxjrkRmZ2CQLu9Pc0BYrccx 6hhIyK8vlTzr3br6uMeijPkKCHPDKM7b/k0ho/M3aBxaj6OfzC+ZyU/FsGwssN+czllA ctIslHRU87mKRu6oNVxEjtf9uWituD/2nKYCBqXjQf0PQIMvl5ofxDr90mQBsR4xEl67 bnA78s4LcoplzlYfK4p7kqBd/TUkE3imotT7I18vhEhWg/0mFQ1Gvq4wwzyPKgttQMBX mcswzT5FdXz1/uvs9DCmsuUFUGC1R2OFVQKPfAGXPLgUNKT9mFvY4HCUpmbEOKq7nW/k /gLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=2kvo4cKjgLSkZi0ORkIKm30VEiLgu1BUEUNx8foAAG8=; b=OVh+fgsl6eFWKtaJQFnL5+fpFqSQgDdRgT39hh6YAeEAzmYYiremAnhIuC1EazqarK tJ9AJthG9QyA+oRZIDRQ7BbsEecLobBpCvcv6YcT2TVK3LPktmR7ms4VKhnguTn05Ark zcLUaNvmYQUHXK5l2gxz+YtxY8wER2DbLupZDLC8kUEmjnRgV3btr33IuXinCKaChY+R HgurRRKcjVgmo/f1vMMdyfRl3DInUBf39NBjlTWV/NufLck6skKPlx3KERNnZ4OoHwJa Vloxy+ZvLSgAsGX6AbigHUrkt9IyriKyE2n+usLUroRhpIdlvH1moSHR++fwlhxr989l Vgfw== X-Gm-Message-State: AOAM5337059+CmuLzs8dUxHVfUgb6lerJ/23ndIxTWMcohbxW+LUaSpn 2P78dOE7GA7uEJ4ew1iRT6hLn18C06XVkdgMx+navw== X-Received: from mactruck.svl.corp.google.com ([2620:15c:2cb:201:d2c9:6361:2665:49a6]) (user=brendanhiggins job=sendgmr) by 2002:a25:c554:0:b0:645:42e2:fa59 with SMTP id v81-20020a25c554000000b0064542e2fa59mr210554ybe.571.1650341119990; Mon, 18 Apr 2022 21:05:19 -0700 (PDT) Date: Mon, 18 Apr 2022 21:05:15 -0700 Message-Id: <20220419040515.43693-1-brendanhiggins@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [PATCH v2] kunit: add support for kunit_suites that reference init code From: Brendan Higgins To: 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, Brendan Higgins 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,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 Add support for a new kind of kunit_suite registration macro called kunit_test_init_section_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 --- Changes since last version: Renamed the new kunit_suite registration macro for init functions to a more readable name. --- include/kunit/test.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/kunit/test.h b/include/kunit/test.h index 00b9ff7783ab..5a870f2d81f4 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -380,6 +380,34 @@ static inline int kunit_run_all_tests(void) #define kunit_test_suite(suite) kunit_test_suites(&suite) +/** + * kunit_test_init_section_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_section_suites(__suites...) \ + __kunit_test_suites(CONCATENATE(__UNIQUE_ID(array), _probe), \ + CONCATENATE(__UNIQUE_ID(suites), _probe), \ + ##__suites) + +#define kunit_test_init_section_suite(suite) \ + kunit_test_init_section_suites(&suite) + #define kunit_suite_for_each_test_case(suite, test_case) \ for (test_case = suite->test_cases; test_case->run_case; test_case++) base-commit: b2d229d4ddb17db541098b83524d901257e93845 -- 2.36.0.rc0.470.gd361397f0d-goog