Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1145595iob; Wed, 4 May 2022 15:54:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8+/QfmcE2eiR7AXJjvW64fr7PX8Vd9zE6i4TIX0glJ0vMSpAyh6WMDPrTPxoVtsLf5Uk8 X-Received: by 2002:a17:906:4795:b0:6f3:d1cc:7127 with SMTP id cw21-20020a170906479500b006f3d1cc7127mr23462799ejc.461.1651704867958; Wed, 04 May 2022 15:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651704867; cv=none; d=google.com; s=arc-20160816; b=eJpq0JO6+IVfPGA436IHsflvBeXdm8yCrrMiOXJIAPLHpGnV6KS+lOpjPf0LSOEcBQ zI7GEkTNgDRgUttOjpZ9o/gGjT3ulvU/W08A8WFn+1doNqRG1XT3itwoeauS5s9k0jUp dw4rCnV0KTvc+ZTk2F4lb4hCkiKQqwqJfO05UsAjaJufqvuSd7gqLeCC1GXcoKOtS8mR e2uMSdHULJSfMV+pd4PrcL2ucRWzz2aegt8C5Kehp1naO1IqAa3RqVAQEFFOUEDJZ2ff N+sy5TSU9H2Qx5TEheXyNPEoZTL+ALj6/iqyVNuuYT0jl+O1tCutioU30PpQhFNSQq2B wlsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=6MXhFAWbDglpoBwnCNgPXrGcxMNN6VO/SyKkfNQIIaY=; b=BeoKU9ErK+7fgjJmIu9PKvJcPvLokND6UteO7+pOMwpilksthdeXhTiPDQ1b7mxKjy kqh09v+skbQoBON9gHwiYUgJalzLrRvbaGuwohJSD92kEh7uJVs3uMcS3hDGlrQS6G0N /TkT3uA2NToWLYogc5TWw+LYHhNi6Qr2Jb+wwFcpLVSkStLVfVFN2iGnJD1io5se0zNy Nu/zBeMBMhX5sVLGRDq0grmOJ0ulEMHF5oVlcKc3Gx5Bn+xP0mZiDhU95Rc/A2HAvAmk ugGpXyIDgtyGtbQ2x71iq+Sk1gQSWMMCtZE4rRfazac4YIG4gW7unkUUfuUtzRMpVNqA bYKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=od9l1MKX; 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 t9-20020a50d709000000b00423d5e26a5asi16775089edi.576.2022.05.04.15.54.05; Wed, 04 May 2022 15:54:27 -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=od9l1MKX; 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 S1357294AbiEDVTz (ORCPT + 99 others); Wed, 4 May 2022 17:19:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244029AbiEDVTx (ORCPT ); Wed, 4 May 2022 17:19:53 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6B4821253 for ; Wed, 4 May 2022 14:16:15 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id g20so3107148edw.6 for ; Wed, 04 May 2022 14:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=6MXhFAWbDglpoBwnCNgPXrGcxMNN6VO/SyKkfNQIIaY=; b=od9l1MKX7VGnlty0UQGANhz5usp8Mso5lcbHl1nFickQHtjswW8vkxoYHz9GUsdtAU f8AMtgLlad2SEhYwyYKIWXo3yBOyjtzO9GEDXVoigHp78Vy7LNTXXcMjmf5Uh+0y9m1K cU09NofM9Tb/cXEvvtGa01f7Ej2pwrj93rcxtfNEn+TB0eBVG6N7nHffonOwEG2IBFR5 gxRbHIun3AuGBf38wjv/TAmzk+9U+1SlrJLS/pWnEiwf8vyjPM56HObsANDRQztEnBtN p5tIFznUphSsy1ffWktrtVRSvUjRPWXTZrxiMqKQwDZwpWONN3F+s1PqA3ThuATdZT3q pnrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=6MXhFAWbDglpoBwnCNgPXrGcxMNN6VO/SyKkfNQIIaY=; b=M4GdeWsw/v9SWcHWNIG2YONaogDkaYEja3C6tXJurWDsI0QMHKZiXFMJo1P6tv3ffk YD5PLFnTuzPOeT9uUNESg295uIOA9ffcWJrFdy3RMHOcpbHsrZJOZhRuXuhnNhJQ1G4u +z1iq6Hzu9l8Fg/nrvnGGUd8qdZmf6hGoXnANd2Ppzn88IY13RjAJ4I7T9bLSFGkkj4b jWe597wBcrYeCsduEwUDLETFEs18aLviU8UTHka8we8gD9qZPpIZBLMSEGShJ6vyDHLV qR8DMqwqZDzteOd4bsyozBvoZGeBE0/A+M/zPz4Hjmn/yxABnY4axef2fpmnilv1f/iE eFpw== X-Gm-Message-State: AOAM530+Rz3m7uFC0N1duicnJekmRSrQO0G3Q/+tzcCoImzCE4vw6UgN z/Hw4Tq4ENhWfHxzwgGgNrt5SvWO8Jw13ugBaq3s1A== X-Received: by 2002:a05:6402:2995:b0:425:d3a1:28aa with SMTP id eq21-20020a056402299500b00425d3a128aamr25411732edb.247.1651698974303; Wed, 04 May 2022 14:16:14 -0700 (PDT) MIME-Version: 1.0 References: <20220318021314.3225240-1-davidgow@google.com> <20220318021314.3225240-2-davidgow@google.com> In-Reply-To: From: Daniel Latypov Date: Wed, 4 May 2022 16:16:03 -0500 Message-ID: Subject: Re: [RFC PATCH 1/2] kunit: Expose 'static stub' API to redirect functions To: Brendan Higgins Cc: David Gow , Kees Cook , Shuah Khan , Steven Rostedt , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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, T_SCC_BODY_TEXT_LINE,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 Wed, May 4, 2022 at 3:42 PM 'Brendan Higgins' via KUnit Development wrote: > > On Wed, May 4, 2022 at 4:35 PM Daniel Latypov wrote= : > > > > On Thu, Mar 17, 2022 at 9:13 PM David Gow wrote: > > > +#define kunit_activate_static_stub(test, real_fn_addr, replacement_a= ddr) do { \ > > > + typecheck(typeof(real_fn_addr), replacement_addr); = \ > > > > We can't call this macro in the same scope for functions w/ different > > signatures. > > > > E.g. if we add this func to the example test > > static void other_func(void) {} > > then trying to call kunit_activate_static_stub() on it in the same > > test case, we get > > > > ./include/linux/typecheck.h:10:14: error: conflicting types for > > =E2=80=98__dummy=E2=80=99; have =E2=80=98void(void)=E2=80=99 > > 10 | ({ type __dummy; \ > > | ^~~~~~~ > > ./include/kunit/static_stub.h:99:9: note: in expansion of macro =E2=80= =98typecheck=E2=80=99 > > 99 | typecheck(typeof(real_fn_addr), replacement_addr); > > \ > > | ^~~~~~~~~ > > lib/kunit/example-test.c:64:9: note: in expansion of macro > > =E2=80=98kunit_activate_static_stub=E2=80=99 > > 64 | kunit_activate_static_stub(test, other_func, other_func= ); > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~ > > ./include/linux/typecheck.h:10:14: note: previous declaration of > > =E2=80=98__dummy=E2=80=99 with type =E2=80=98int(int)=E2=80=99 > > 10 | ({ type __dummy; \ > > | ^~~~~~~ > > ./include/kunit/static_stub.h:99:9: note: in expansion of macro =E2=80= =98typecheck=E2=80=99 > > 99 | typecheck(typeof(real_fn_addr), replacement_addr); > > \ > > | ^~~~~~~~~ > > lib/kunit/example-test.c:62:9: note: in expansion of macro > > =E2=80=98kunit_activate_static_stub=E2=80=99 > > 62 | kunit_activate_static_stub(test, add_one, subtract_one)= ; > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > Afaict, the problem is that GCC thinks we're declaring a *function* > > called __dummy, not a variable. > > So it bleeds across the scope boundary of do-while unlike normal variab= les. > > Yeah, I ran into that problem too. I posted a fix to gerrit. I have > been meaning to share it here. For others, gerrit =3D=3D https://kunit-review.googlesource.com/c/linux/+/5= 129 > > > There's the typecheck_fn macro, but it doesn't work either. > > That's weird. It worked for me. I'm running on top of 5.5. I tried reproducing w/ a stripped down version on 5.18 and saw the same iss= ues. Huh, I'm trying with #define kunit_activate_static_stub(test, real_fn_addr, replacement_addr) do { \ - typecheck(typeof(real_fn_addr), replacement_addr); \ + typecheck_fn(typeof(real_fn_addr), replacement_addr); \ __kunit_activate_static_stub(test, real_fn_addr, replacement_addr); \ This gives me lib/kunit/example-test.c:62:9: error: function =E2=80=98__tmp=E2=80=99 is i= nitialized like a variable 62 | kunit_activate_static_stub(test, add_one, subtract_one); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ lib/kunit/example-test.c:64:9: error: function =E2=80=98__tmp=E2=80=99 is i= nitialized like a variable 64 | kunit_activate_static_stub(test, other_func, other_func); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ Perhaps I'm missing something silly. Can you post your fix and I can try it out?