From nobody Mon May 11 01:27:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7345C433F5 for ; Tue, 19 Apr 2022 04:05:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348178AbiDSEIL (ORCPT ); Tue, 19 Apr 2022 00:08:11 -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-Google-Smtp-Source: ABdhPJzlNyTz4ZcPX1ZcP0aN3Q/D3Va+r3K/NAXGD0co8t3sQljhVn3IORJ4o7KD0DIZbhTrRzDt9Nr2UXHcdxhSZPH9+Q== 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) =20 #define kunit_test_suite(suite) kunit_test_suites(&suite) =20 +/** + * 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 suppr= esses + * 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 nam= ed 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 =3D suite->test_cases; test_case->run_case; test_case++) =20 base-commit: b2d229d4ddb17db541098b83524d901257e93845 --=20 2.36.0.rc0.470.gd361397f0d-goog