Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3746147rwb; Fri, 16 Dec 2022 21:45:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf4H08zIzQbYRntSwkAsf6gCLUexVt9GjoDbXr4PLxaDZa5HGXH5YQx3cHJ8ICwgb6ZQrcFp X-Received: by 2002:a17:902:e211:b0:189:d025:aa23 with SMTP id u17-20020a170902e21100b00189d025aa23mr30577582plb.53.1671255907249; Fri, 16 Dec 2022 21:45:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671255907; cv=none; d=google.com; s=arc-20160816; b=in0ptlwFlycV05sRKeyCX1yIswBoaio375QN/dnkOrt4AfUX/K3teHzugtJnioeVV/ d40E9pa6ZdOPqdjh4NpHJxkCJB6SP8Yi98TF5zXCMVpFvFjUnbKd0yS9Tw9k0Jh6X1zC JPum/SG4P+gq3EAlLKLwmsF0DKTPPzcGiJDsGR9B5sUfdr7qlm1RkXM4Q1zu5SFXla2K Ke7oOR8ZLaORJsCoSDrTHPHjZ7yxFE3bOFBCyO3xd/3kJ44NTzcghP6oq3lPL33iaOx9 ds2SUNRoAhaivSG36oyh4uzI/Y60x2MQx8DUUrIy2jy+18wr+yOTQ7xuVqMaiV9SGX+/ FlBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RDYnJGBhM5VrUDJCjc6PATa5BNNW24FWGhwz7O2VUXc=; b=BQjkEEawLcU8Wcqh29Fv3MEO79K9ovQtAFjzMTtLlM6AgmTEeb7kOVYS7Li+4Yq14E jgPXOmjVtz3mqjQ5p0dyT/af39cPueO2qE/po2/8+xVx8kujYVCX6Ed2l8wqkvSepLUU 4BJiKDDOZ/NAE/Tqs1LkDhNmYqKYmKdfpzHtp2F+rM2IF3F10RmMmzq94qsL6O1oOBLz 1D2YYHcYjD05YUpDeBOhv3EQUrHt14dkPfZVxpr81x6Essnc65EcJ6M4RlzcHD1XOTjA 0SF2HSjA2r0N2uw7e39uzB3x51N0/lrIF5u5EWz/UlezUqFOHOjFfQqmkheW0Y/RanDT e5Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=k3R+xAcK; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020a1709027e8400b001893627cc84si4213719pla.243.2022.12.16.21.44.53; Fri, 16 Dec 2022 21:45:07 -0800 (PST) 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=k3R+xAcK; 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 S230246AbiLQFJ4 (ORCPT + 70 others); Sat, 17 Dec 2022 00:09:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbiLQFJv (ORCPT ); Sat, 17 Dec 2022 00:09:51 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B647A6C714 for ; Fri, 16 Dec 2022 21:09:50 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id h7so4309619wrs.6 for ; Fri, 16 Dec 2022 21:09:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=RDYnJGBhM5VrUDJCjc6PATa5BNNW24FWGhwz7O2VUXc=; b=k3R+xAcKLpJlOELwxDJJbBbzR0MuxQ1X5Xc/SJxPXsoS4wAMR2Rg1a59EmfGU8B4tk TgJzngqoPPD+tz2iW5BRaZbyH4TC8dN3pUFv91gD9Q805DjrWDnTbjYz+iYfS9EJR1L9 VIQFyJ7aL59UTPBt+26qayATDT/Z/yJ23Gm4WCeuJL7QQGD2sYPW6lwNK8ZUSG5kXDtt OWbi9GiwrVD3Ed9ovAgueirkub0f01NkqdT4yDTfnzDgabYcwI5w4oRkw8MxU6HzLbeK X3qIJYc1WjT1ZGEDqCZaHKTdq13vnMIBfAFyNXDvWKQpYr0Rn1zKBFXHYa6JGaOJMEfe w/5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=RDYnJGBhM5VrUDJCjc6PATa5BNNW24FWGhwz7O2VUXc=; b=r2n3+7RVrVbfSAxaVEVlUhKMiCNCDVCQBni3DiFRqYh+Z6jeol4Bu8eS9cOfk7xpMO +ZPVe0MwUmRmADx74VGS3FJzVQq9DIxbepFeoccgdbv/e7s+xafSdr//BKVPzA7pDRaF QnEzVYAGBYVwVtCZD/Hz8HmzgIlrk02gMYQAAPrqPpWme3UWPPrVMXzLUpsH5YABgz3l c00NEoperrn3nlSh1QI7hfIkOGSYOAoA9D1B02+P4oTVv2PX6SJPzo1h5CFVGR2Tusnq zk4yI37/YLVjXfA/RddTBBYngWt6WkgcyABIOCAksk5Peo9bsThTyNAn51QIStDpebl1 AIQw== X-Gm-Message-State: ANoB5pmmyt/Pt9MLUQZIY7izhEE+H0DlnTeOym58S6IWJR0qdyoOa6V+ ANScAT/GREFn32b9WAZQSPvn6iN4+ZtVT8Lor+4JQg== X-Received: by 2002:a05:6000:16ca:b0:242:8bf7:27fe with SMTP id h10-20020a05600016ca00b002428bf727femr2134626wrf.278.1671253789220; Fri, 16 Dec 2022 21:09:49 -0800 (PST) MIME-Version: 1.0 References: <20221208061841.2186447-1-davidgow@google.com> <20221208061841.2186447-2-davidgow@google.com> In-Reply-To: <20221208061841.2186447-2-davidgow@google.com> From: Brendan Higgins Date: Sat, 17 Dec 2022 00:09:38 -0500 Message-ID: Subject: Re: [PATCH 1/2] kunit: Expose 'static stub' API to redirect functions To: David Gow Cc: Brendan Higgins , Shuah Khan , Daniel Latypov , Kees Cook , Steven Rostedt , Joe Fradley , Steve Muckle , Jonathan Corbet , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 On Thu, Dec 8, 2022 at 1:18 AM 'David Gow' via KUnit Development wrote: > > Add a simple way of redirecting calls to functions by including a > special prologue in the "real" function which checks to see if the > replacement function should be called (and, if so, calls it). > > To redirect calls to a function, make the first (non-declaration) line > of the function: > > KUNIT_STATIC_STUB_REDIRECT(function_name, [function arguments]); > > (This will compile away to nothing if KUnit is not enabled, otherwise it > will check if a redirection is active, call the replacement function, > and return. This check is protected by a static branch, so has very > little overhead when there are no KUnit tests running.) > > Calls to the real function can be redirected to a replacement using: > > kunit_activate_static_stub(test, real_fn, replacement_fn); > > The redirection will only affect calls made from within the kthread of > the current test, and will be automatically disabled when the test > completes. It can also be manually disabled with > kunit_deactivate_static_stub(). > > The 'example' KUnit test suite has a more complete example. > > Co-developed-by: Daniel Latypov > Signed-off-by: Daniel Latypov > Signed-off-by: David Gow Reviewed-by: Brendan Higgins