From patchwork Wed Nov 2 17:59:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rae Moar X-Patchwork-Id: 14417 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp58131wru; Wed, 2 Nov 2022 11:07:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4wLusEkej4X+kd50SpiNs4n/EEyAEGbrjLndlivGAYgbCjnKgePIK0OjeoXoP5JaQpokeY X-Received: by 2002:a17:907:2d2c:b0:78d:d289:7efd with SMTP id gs44-20020a1709072d2c00b0078dd2897efdmr25720960ejc.166.1667412433736; Wed, 02 Nov 2022 11:07:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667412433; cv=none; d=google.com; s=arc-20160816; b=Y7c3dAidLXWHBJfU8xLAml2K9SQny+d4wfv8hHmF7d4MrE/4j0qKODVfW2etY9BnBH 17lyh19KrWAluVcjoQP1u2MJBjQFB8TmNonmLqQwHwiIrGGdl9pRny/cr/KPoIXcAn6s cG/1a7feBbit6acE0RvMQhy0qva6vDShbiQo8p9yGFrqrzjBohkz77EuTlYJNYODYJzG mC6ZX9SyKKfvoJvDPbiAW2AuAOrVEn/XpUFgsoGtMvnAk19k6uwg97pv1PW5ClRl0eXx /wjNriUjpx4ixpMoigZ/QNMn3cWMSphjNX3UmP5GQRhK1v4hvEbhkCtivp1EGVD89hBi HxVw== 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:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=CAYN6r+yTQvu28IFOFbzBkKteLNKvCbZnYXbZl6k2DY=; b=Jm3CBrarwfOaZRcdpUBazPdggO/MhcfNP4p9TmOWkDnp3GgZUyf4wMVDxGpehyo8U3 TR9RFYFif0fKCYy+SyuRpnlr5kt5z//2O2m3wjkcdBa6YyC8KrQhYZCNiCMM+IqkSTUj hwgtpLvYZUbka9qUYz5vVwY3wFX2P3Qxy8b6ljw/wOm+e0uokFIymSctC59qmFHf3Jjv ks7nvv/aBTDYrvLUXFp4w1eEY+xviHHqzU5S7sVIwAxiCXIRIge/v1I9a/RwxbeIpS0t ueiyZcHrlAVomev/N+Q4hqXV4l6j3a0xlwxEYx0x/YW+UQTZXyvd55XdUI+O75bo+LP2 uFZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FrgvbWPh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di14-20020a170906730e00b007a00aaf659csi19809080ejc.198.2022.11.02.11.06.48; Wed, 02 Nov 2022 11:07:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FrgvbWPh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231346AbiKBSCw (ORCPT + 99 others); Wed, 2 Nov 2022 14:02:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231258AbiKBSCl (ORCPT ); Wed, 2 Nov 2022 14:02:41 -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 819FB1DF02 for ; Wed, 2 Nov 2022 11:02:40 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id b14-20020a056902030e00b006a827d81fd8so16900781ybs.17 for ; Wed, 02 Nov 2022 11:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CAYN6r+yTQvu28IFOFbzBkKteLNKvCbZnYXbZl6k2DY=; b=FrgvbWPhRA4VD87zdgqKKiY5UHCDYtYfe7CjaP2xgmEOG1Y05NjZSf3gzQWW8T0Uct kwK/a9hcGw0YEYKVOJVFR5P9iNYw89sCx6ZHsJggC73BExIAmjho5Pbue4CgNBI3QOgO FoPe42kXbj+qL8yjM5/fdOTg+3rYiSOtiXyjG+vM72l5OUaB8j+A2cgCkgbbQKnrcMOV vjVP5OOJMItX52jvTtAXnPZObQ6EUQSPLAa0t1h0Rw23k0Jw4oAggVMoBX89jk82PyRN zVVthy9iTThict8/JGXYxe/C830qJ3olt0/g7iLirWIKcLukRfjGALBtlSWm2uBgHMk7 3wwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CAYN6r+yTQvu28IFOFbzBkKteLNKvCbZnYXbZl6k2DY=; b=35V+hgzqIILVmr+2R5+vfgm9bPOm1Notv5SvpqUc5dHMi8VfjZzxXjjTYnUyNrVIFE q5BaSBhvppq7mTBUohvrFTq0OGlwYCLc+2WvzIXO7tXjUNEhNjdHW+fcXilVk/fnSO0t Nrj9d6KzxjxnlQvZoxlVYfbUl3GOfmvSI/LCW1fTqI5E2jXHQ6+jLq+AkZO4EtO1w92p YPi0mzf4phtbNX5uZ6FogFgn7I2ls5KhPP4JGT6P+HdmrJ38VdWA18uv+lKDzXGYJSdn OOsMX+Sbhyb5kmpzQ7Lx0Je6WEY2YH1ca34YaLXvQusulCxEJoxvBTACvStTcjD/g4rx ArRw== X-Gm-Message-State: ACrzQf2M4QY1lF6gaMpm3WB4BHVev0x3UlT9PlMqP7ct0x2FkRuF5M0T FAVdlXYHTtO/exzLPaHU4w1o1Wj55A== X-Received: from rmoar.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:4259]) (user=rmoar job=sendgmr) by 2002:a05:6902:1247:b0:6ca:88e8:6f43 with SMTP id t7-20020a056902124700b006ca88e86f43mr24295801ybu.289.1667412159822; Wed, 02 Nov 2022 11:02:39 -0700 (PDT) Date: Wed, 2 Nov 2022 17:59:58 +0000 In-Reply-To: <20221102175959.2921063-1-rmoar@google.com> Mime-Version: 1.0 References: <20221102175959.2921063-1-rmoar@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102175959.2921063-2-rmoar@google.com> Subject: [PATCH v1 1/2] kunit: add macro to allow conditionally exposing static symbols to tests From: Rae Moar To: brendanhiggins@google.com, davidgow@google.com, dlatypov@google.com Cc: skhan@linuxfoundation.org, tales.aparecida@gmail.com, john.johansen@canonical.com, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, apparmor@lists.ubuntu.com, Rae Moar X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748408648503279020?= X-GMAIL-MSGID: =?utf-8?q?1748408660217002552?= Create two macros: VISIBLE_IF_KUNIT - A macro that sets symbols to be static if CONFIG_KUNIT is not enabled. Otherwise if CONFIG_KUNIT is enabled there is no change to the symbol definition. EXPORT_SYMBOL_IF_KUNIT(symbol) - Exports symbol into EXPORTED_FOR_KUNIT_TESTING namespace only if CONFIG_KUNIT is enabled. Must use MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING) in test file in order to use symbols. Signed-off-by: Rae Moar Reviewed-by: John Johansen Reviewed-by: David Gow --- include/kunit/visibility.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 include/kunit/visibility.h diff --git a/include/kunit/visibility.h b/include/kunit/visibility.h new file mode 100644 index 000000000000..eb22c9e6b4eb --- /dev/null +++ b/include/kunit/visibility.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * KUnit API to allow symbols to be conditionally visible during KUnit + * testing + * + * Copyright (C) 2019, Google LLC. + * Author: Brendan Higgins + */ + +#ifndef _KUNIT_VISIBILITY_H +#define _KUNIT_VISIBILITY_H + +/** + * VISIBLE_IF_KUNIT - A macro that sets symbols to be static if CONFIG_KUNIT + * is not enabled. Otherwise if CONFIG_KUNIT is enabled there is no change + * to the symbol definition. + * + * EXPORT_SYMBOL_IF_KUNIT(symbol) - Exports symbol into + * EXPORTED_FOR_KUNIT_TESTING namespace only if CONFIG_KUNIT is + * enabled. Must use MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING) + * in test file in order to use symbols. + */ +#if IS_ENABLED(CONFIG_KUNIT) + #define VISIBLE_IF_KUNIT + #define EXPORT_SYMBOL_IF_KUNIT(symbol) EXPORT_SYMBOL_NS(symbol, \ + EXPORTED_FOR_KUNIT_TESTING) +#else + #define VISIBLE_IF_KUNIT static + #define EXPORT_SYMBOL_IF_KUNIT(symbol) +#endif + +#endif /* _KUNIT_VISIBILITY_H */