Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp235957rdb; Tue, 19 Dec 2023 15:17:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSlxskctYxCtaaszo75NDzhrBSspOcliQuCsI8KDUdDBl34PfhnZGENtBx8rt/lfAZE/1g X-Received: by 2002:a17:903:22ca:b0:1d0:ae31:779e with SMTP id y10-20020a17090322ca00b001d0ae31779emr11281056plg.20.1703027847032; Tue, 19 Dec 2023 15:17:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703027847; cv=none; d=google.com; s=arc-20160816; b=evIOV1lr3tICkhz3AoQa5cbvvZYgXokGU27JUpt8WAM5Bh0gQPLLcZ86bZ0v+/iFzi M4m3OOTOWfadBIz9jYsCKfcrvRfTZ9TA8nNVvfaR9IzRvYXKoVPxwH1DGdRBcDiNnTaa Yd34gm1llep4jBALUsDxE9hM025mG6TtGNCm5UjzgXDdraiXPe1kiXn1Dp+lW5ft3xMD 1sqV/bJlOnB3veQK5FFsfODGytI6OttNA4C5NKKKwoKQKUzbUWruHrMUHHv+5AItQ6BY NOcZpCfNIGDVJzH0Wk09MeTUaGCgYGmIHfu81GoMtKFvOtH+iR5lPKfC1bpYRHMOy/lz nUHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=kahqyf6EB8HB0c0Ey1lJeYZwJGl+WMUYDsC/ZwyeTQc=; fh=VgtnJUKslQWC1J4hSraUCaGGwBrlwsv9kzwfY7I3kHA=; b=H5GmeA0hJYY/5tMSZNruhd/oFG0jeVwNTBErZ2QBYG7mLbrj3ajMjn2/67O1YPJxED 8XvUTakqZNLpkHmCuad2vewIm744iqYCUk12iNzloBUWvUiDAzDL3MgyT9kCr7VS1MuW WAwE1v6y4v/VdE9QK0d1g3905OUouhM8KGBzIHzSr3qUXeijMlMU3m5VHEhnu2G6Zgub l1b1PRZD9SpQ4i4v3pzA4Q5x0e3rFMxlJ16YWwJR1PTun+OQXwHVTl5sFI1xsONHRKaK EcgzWO3Ek+Ikncu1k1WmhWOHBqaVnNSypNAdWff4l1S7rOzpJ2nl+mCPS4jC5yU4YthY O6Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UzsTN0Z6; spf=pass (google.com: domain of linux-kernel+bounces-6085-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6085-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x19-20020a170902b41300b001d071eb5904si19973670plr.276.2023.12.19.15.17.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 15:17:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6085-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UzsTN0Z6; spf=pass (google.com: domain of linux-kernel+bounces-6085-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6085-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0A7C5B25443 for ; Tue, 19 Dec 2023 23:16:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 340433D0CC; Tue, 19 Dec 2023 23:16:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UzsTN0Z6" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0A9840BE8 for ; Tue, 19 Dec 2023 23:16:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-40c2db0ca48so6755e9.1 for ; Tue, 19 Dec 2023 15:16:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1703027761; x=1703632561; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kahqyf6EB8HB0c0Ey1lJeYZwJGl+WMUYDsC/ZwyeTQc=; b=UzsTN0Z6D+M/liSrurBeqyj8Ypt5Uf7FrEZhFlS0KD8KM6j8gmpuajcaraxiWEnofp JKD6CKUeEzinEI4nRF0T/0xFlyH64xu971wVzMWG7vlBf8wNmAH7RGoczW2P+Mc9q9VV yQp7dINUWME9Z28g2wB9sY/cCbZhA7VNTU+g39myD9evTpk7WjuhCTi5ToNrORsgdUlq vxU/SFFwHXCPUTtdoZ9rKLKV2DaEpJlQ4JlCVYmgQWtogP5nRHVZo2/4yvQH0e+HXHlV 7QgCbAso3uFWa9tkB9Xl3FomvlNm+e8LalL5yJAi6/cpcJInYcrwqKPLh4oVpReR682h AH9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703027761; x=1703632561; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kahqyf6EB8HB0c0Ey1lJeYZwJGl+WMUYDsC/ZwyeTQc=; b=CfJ8ajVUxrwAiYxwag1vumuwppnZqAGoCqOZcqas/PDVBHnf3s53CuudpA+RPSbATO tOmkmkDGtgl+J8pI6OOdQPuqi2jAZuNoFuv8v7r4vHUkpOYbGCr2sgA8ZwwRH+lnNX65 NZuQMxNTjztCEuGAby5kX0JE077cfYl8az2/PuVsRuLMP3TwgFiHwZNN20sSQSjwb3fT XkK+LuDCYkZmZzk1vRAJAE1DkvL51FNzoOQReHh9bnG6xpnW2cgq+uKTie4XwCqNKmRq eMlYAilxgFe99CMQajFgv73etCio6y4lXW7Sysy1/pxULp16JGeLvWGO72zxmp/In3Sg DwyA== X-Gm-Message-State: AOJu0Yxvbj9PM7zUZcIaB5oOV2iNFuaqAxD8afVH8MtlhZ0+EzdswmpE yWrT738Aj0X5+IOyxtsGsDvwgUePDsSO8Ya7IiE5eygVdtdI X-Received: by 2002:a1c:4b19:0:b0:40d:174c:9295 with SMTP id y25-20020a1c4b19000000b0040d174c9295mr29772wma.3.1703027760939; Tue, 19 Dec 2023 15:16:00 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231218161044.215640-1-rf@opensource.cirrus.com> <20231218161044.215640-2-rf@opensource.cirrus.com> In-Reply-To: <20231218161044.215640-2-rf@opensource.cirrus.com> From: Rae Moar Date: Tue, 19 Dec 2023 18:15:48 -0500 Message-ID: Subject: Re: [PATCH 2/2] kunit: Add example of kunit_activate_static_stub() with pointer-to-function To: Richard Fitzgerald Cc: brendan.higgins@linux.dev, davidgow@google.com, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 18, 2023 at 11:10=E2=80=AFAM Richard Fitzgerald wrote: > > Adds a variant of example_static_stub_test() that shows use of a > pointer-to-function with kunit_activate_static_stub(). > > A const pointer to the add_one() function is declared. This > pointer-to-function is passed to kunit_activate_static_stub() and > kunit_deactivate_static_stub() instead of passing add_one directly. > > Signed-off-by: Richard Fitzgerald Hello! This test looks good to me. However, I had issues applying this patch so I think it needs rebasing due to the newest additions to kselftest/kunit. But otherwise this patch looks good other than my very small comment below. Thanks! -Rae > --- > lib/kunit/kunit-example-test.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-tes= t.c > index d2f7a3c62c18..9e57f341dc37 100644 > --- a/lib/kunit/kunit-example-test.c > +++ b/lib/kunit/kunit-example-test.c > @@ -168,6 +168,8 @@ static int subtract_one(int i) > return i - 1; > } > > +static int (* const add_one_fn_ptr)(int i) =3D add_one; This is a bit of a nit but could you add a brief comment above this pointer definition? This would then match the commenting on the other functions in kunit-example-test and provide more context for those looking at the example tests. > + > /* > * This test shows the use of static stubs. > */ > @@ -187,6 +189,30 @@ static void example_static_stub_test(struct kunit *t= est) > KUNIT_EXPECT_EQ(test, add_one(1), 2); > } > > +/* > + * This test shows the use of static stubs when the function being > + * replaced is provided as a pointer-to-function instead of the > + * actual function. This is useful for providing access to static > + * functions in a module by exporting a pointer to that function > + * instead of having to change the static function to a non-static > + * exported function. > + */ > +static void example_static_stub_using_fn_ptr_test(struct kunit *test) > +{ > + /* By default, function is not stubbed. */ > + KUNIT_EXPECT_EQ(test, add_one(1), 2); > + > + /* Replace add_one() with subtract_one(). */ > + kunit_activate_static_stub(test, add_one_fn_ptr, subtract_one); > + > + /* add_one() is now replaced. */ > + KUNIT_EXPECT_EQ(test, add_one(1), 0); > + > + /* Return add_one() to normal. */ > + kunit_deactivate_static_stub(test, add_one_fn_ptr); > + KUNIT_EXPECT_EQ(test, add_one(1), 2); > +} > + > static const struct example_param { > int value; > } example_params_array[] =3D { > @@ -245,6 +271,7 @@ static struct kunit_case example_test_cases[] =3D { > KUNIT_CASE(example_mark_skipped_test), > KUNIT_CASE(example_all_expect_macros_test), > KUNIT_CASE(example_static_stub_test), > + KUNIT_CASE(example_static_stub_using_fn_ptr_test), > KUNIT_CASE_PARAM(example_params_test, example_gen_params), > KUNIT_CASE_SLOW(example_slow_test), > {} > -- > 2.30.2 >