Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1137784rdd; Wed, 10 Jan 2024 09:39:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnrIZvlkEQiXVEnWuervZLNAQLuyNY9n1tyXhf7M4z/8rTncIoeyHnOeAjymHIa58pSu08 X-Received: by 2002:a05:620a:f:b0:783:3d12:9240 with SMTP id j15-20020a05620a000f00b007833d129240mr187351qki.6.1704908394274; Wed, 10 Jan 2024 09:39:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704908394; cv=none; d=google.com; s=arc-20160816; b=DGZ8z9O2S884tqIr/eOGSeAxO+e1H65ye66a0N+11zwxkClLzQdLxm0uThkQ8x6PMW P7kAe4oFyBZ3IxfxLuh080bl3B1IxouTicvyEOVz+xrtZJtK2Fvvj8K94oAmcfvMDytf eUFRcoqLkx3YDIBTBgC04g5lBXr0WT49PZKG7Fvy7GlhLvkhjoqUgDC5xWWHBfD1Y1PH k9s8WxbSTBGkm8+9CyHwdF24SbZuiB5HczJzoN58IS+fgqWNxCoW2tI8LrRyTF+QkGnb T1YOHMUeY+r9dIJzbxDnNTGYaR1M+tZKSe+vSeoGpwW+in5R1JRWOQvHDl9Seh+iGqB3 avTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=AeoZ+6TJRxZqxOW8iOtV/aRkaBXVJf7Ozy+PLRI0WH8=; fh=6ogMhKipg2f6Slv5YIQT+1jbpZtHI3/rGA5slOBRaI8=; b=Pnd46ne1jSo9GOJJCbCor9ElhiP6tjOHjaHIoz76R8U0DQV5h/XQIA/7wjqiAJ820X IYlaqqXpLbzqiub2Zd9IYfEQfx5Zf/Krlelyy7xmnIPmYgZGJqgHjxH0HtWpXXLwUZhm 4gGZkZJRuln+uiva9oliTpM5cSEgoV8iWl5S0M/Th/CG5uNP7EArzZnBenYt6St3LYt+ UXrWX8O/eDBvHKJ+LPML6T5UCizLROY+qFdRsVSUjwpUnYK8mqHFojlJR19c6xnVK0PE v7eEDp20+3NDqZEKR0kO9xbESFy6i1UiOsu/1k3QzT2s3ifkMQGrLxlDNQVcehBBp9MB LjMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@riseup.net header.s=squak header.b="f9SIZXN/"; spf=pass (google.com: domain of linux-kernel+bounces-22542-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22542-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=riseup.net Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id de5-20020a05620a370500b007833ae04ed7si787625qkb.603.2024.01.10.09.39.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 09:39:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22542-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@riseup.net header.s=squak header.b="f9SIZXN/"; spf=pass (google.com: domain of linux-kernel+bounces-22542-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22542-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=riseup.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9D42C1C226BC for ; Wed, 10 Jan 2024 17:39:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC2C44D107; Wed, 10 Jan 2024 17:39:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=riseup.net header.i=@riseup.net header.b="f9SIZXN/" Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57A464CB4E; Wed, 10 Jan 2024 17:39:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riseup.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riseup.net Received: from fews02-sea.riseup.net (fews02-sea-pn.riseup.net [10.0.1.112]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx0.riseup.net (Postfix) with ESMTPS id 4T9FRX2QMFz9x54; Wed, 10 Jan 2024 17:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1704908376; bh=/3ieUSPDCtVqH9T3w3PB7MTKo77k/gatkBOL9tmqqsc=; h=From:Date:Subject:To:Cc:From; b=f9SIZXN/UtWynuh574nJRON412qgn99Gc/E9x6iFR/aiiI6U0zWyUFdBlyGvVwqtc Z0ne9S8flYNNjdS6NPFsV1m0tuvgw8EB8A1kCQKVQjrU26a0GCur4iXa/gtSQhlXHB 4FqR2YybKt3XvIxjZlhb1FlE8X6IM11qOApF30Mw= X-Riseup-User-ID: 9C3CCADC7C9C36867288DF9C044829AFC3062AC692DF9283689F2DA18DCAC7E7 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews02-sea.riseup.net (Postfix) with ESMTPSA id 4T9FRT4Wn3zFsZS; Wed, 10 Jan 2024 17:39:33 +0000 (UTC) From: Arthur Grillo Date: Wed, 10 Jan 2024 14:39:28 -0300 Subject: [PATCH v3] Documentation: KUnit: Update the instructions on how to test static functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240110-kunit-doc-export-v3-1-9b4221763401@riseup.net> X-B4-Tracking: v=1; b=H4sIAE/WnmUC/4XNzQ6CMAzA8VchOzuzD0XGyfcwHpB20phsZBsLh vDuDm5eND39m/TXhUUMhJG11cICZorkXQl9qFg/dO6JnKA0U0KdhBQNf02OEgffc5xHHxJH7KU 1UnSP+sLK2RjQ0ryTt3vpgWLy4b1/yHLb/sCy5GWk0XUDVoCpr4EiTuPRYWKbltU/QRWhsQpAa 3O2CF/Cuq4fMVVnAfMAAAA= To: Brendan Higgins , David Gow , Jonathan Corbet Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Arthur Grillo Now that we have the VISIBLE_IF_KUNIT and EXPORT_SYMBOL_IF_KUNIT macros, update the instructions to recommend this way of testing static functions. Signed-off-by: Arthur Grillo --- Changes in v3: - Maintain the old '#include' way - Link to v2: https://lore.kernel.org/r/20240108-kunit-doc-export-v2-1-8f2dd3395fed@riseup.net Changes in v2: - Fix #if condition - Link to v1: https://lore.kernel.org/r/20240108-kunit-doc-export-v1-1-119368df0d96@riseup.net --- Documentation/dev-tools/kunit/usage.rst | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst index c27e1646ecd9..8e35b94a17ec 100644 --- a/Documentation/dev-tools/kunit/usage.rst +++ b/Documentation/dev-tools/kunit/usage.rst @@ -671,8 +671,23 @@ Testing Static Functions ------------------------ If we do not want to expose functions or variables for testing, one option is to -conditionally ``#include`` the test file at the end of your .c file. For -example: +conditionally export the used symbol. For example: + +.. code-block:: c + + /* In my_file.c */ + + VISIBLE_IF_KUNIT int do_interesting_thing(); + EXPORT_SYMBOL_IF_KUNIT(do_interesting_thing); + + /* In my_file.h */ + + #if IS_ENABLED(CONFIG_KUNIT) + int do_interesting_thing(void); + #endif + +Alternatively, you could conditionally ``#include`` the test file at the end of +your .c file. For example: .. code-block:: c --- base-commit: eeb8e8d9f124f279e80ae679f4ba6e822ce4f95f change-id: 20240108-kunit-doc-export-eec1f910ab67 Best regards, -- Arthur Grillo