linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Latypov <dlatypov@google.com>
To: David Gow <davidgow@google.com>
Cc: Brendan Higgins <brendanhiggins@google.com>,
	Kees Cook <keescook@chromium.org>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/2] kunit: Expose 'static stub' API to redirect functions
Date: Wed, 4 May 2022 15:35:15 -0500	[thread overview]
Message-ID: <CAGS_qxqm1ys1qUz__4uXWOgs=34M5MB3QMnhg40FHtRhatF3+g@mail.gmail.com> (raw)
In-Reply-To: <20220318021314.3225240-2-davidgow@google.com>

On Thu, Mar 17, 2022 at 9:13 PM David Gow <davidgow@google.com> wrote:
> +#define kunit_activate_static_stub(test, real_fn_addr, replacement_addr) 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
‘__dummy’; have ‘void(void)’
   10 | ({      type __dummy; \
      |              ^~~~~~~
./include/kunit/static_stub.h:99:9: note: in expansion of macro ‘typecheck’
   99 |         typecheck(typeof(real_fn_addr), replacement_addr);
                 \
      |         ^~~~~~~~~
lib/kunit/example-test.c:64:9: note: in expansion of macro
‘kunit_activate_static_stub’
   64 |         kunit_activate_static_stub(test, other_func, other_func);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
./include/linux/typecheck.h:10:14: note: previous declaration of
‘__dummy’ with type ‘int(int)’
   10 | ({      type __dummy; \
      |              ^~~~~~~
./include/kunit/static_stub.h:99:9: note: in expansion of macro ‘typecheck’
   99 |         typecheck(typeof(real_fn_addr), replacement_addr);
                 \
      |         ^~~~~~~~~
lib/kunit/example-test.c:62:9: note: in expansion of macro
‘kunit_activate_static_stub’
   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 variables.

There's the typecheck_fn macro, but it doesn't work either.

  parent reply	other threads:[~2022-05-04 20:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-18  2:13 [RFC PATCH 0/2] kunit: Support redirecting function calls David Gow
2022-03-18  2:13 ` [RFC PATCH 1/2] kunit: Expose 'static stub' API to redirect functions David Gow
2022-04-04 20:16   ` Brendan Higgins
2022-04-15 22:05     ` Steve Muckle
2022-05-04 20:35   ` Daniel Latypov [this message]
2022-05-04 20:42     ` Brendan Higgins
2022-05-04 21:16       ` Daniel Latypov
2022-03-18  2:13 ` [RFC PATCH 2/2] kunit: expose ftrace-based API for stubbing out functions during tests David Gow
2022-04-04 20:17   ` Brendan Higgins
2022-04-04 21:13   ` Daniel Latypov
2022-03-18 13:21 ` [RFC PATCH 0/2] kunit: Support redirecting function calls Steven Rostedt
2022-04-04 20:13   ` Brendan Higgins
2022-04-15 21:43     ` Steve Muckle
2022-04-15 21:44       ` Steve Muckle
2022-04-04 20:14 ` Brendan Higgins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGS_qxqm1ys1qUz__4uXWOgs=34M5MB3QMnhg40FHtRhatF3+g@mail.gmail.com' \
    --to=dlatypov@google.com \
    --cc=brendanhiggins@google.com \
    --cc=davidgow@google.com \
    --cc=keescook@chromium.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).