All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Fehlig <jfehlig@suse.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: libvir-list@redhat.com, xen-devel@lists.xensource.com,
	Ian Campbell <Ian.Campbell@citrix.com>
Subject: Re: [libvirt] [PATCH v2 3/4] tests: Add more test suite mock helpers
Date: Tue, 03 Jun 2014 15:30:56 -0600	[thread overview]
Message-ID: <538E3E90.7050209@suse.com> (raw)
In-Reply-To: <1401793373-26680-4-git-send-email-berrange@redhat.com>

Daniel P. Berrange wrote:
> Rename the VIR_MOCK_IMPL* macros to VIR_MOCK_WRAP*
> and add new VIR_MOCK_IMPL macros which let you directly
> implement overrides in the preloaded source.
>
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  tests/virfirewalltest.c |  4 ++--
>  tests/virmock.h         | 54 +++++++++++++++++++++++++++++++++++++------------
>  tests/virsystemdtest.c  |  4 ++--
>  3 files changed, 45 insertions(+), 17 deletions(-)
>
> diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c
> index ba2e6ad..81c5557 100644
> --- a/tests/virfirewalltest.c
> +++ b/tests/virfirewalltest.c
> @@ -67,7 +67,7 @@ static bool fwError;
>      "target     prot opt source               destination\n"
>  
>  # if WITH_DBUS
> -VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
> +VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block,
>                         DBusMessage *,
>                         DBusConnection *, connection,
>                         DBusMessage *, message,
> @@ -82,7 +82,7 @@ VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
>      char **args = NULL;
>      char *type = NULL;
>  
> -    VIR_MOCK_IMPL_INIT_REAL(dbus_connection_send_with_reply_and_block);
> +    VIR_MOCK_REAL_INIT(dbus_connection_send_with_reply_and_block);
>  
>      if (STREQ(service, "org.freedesktop.DBus") &&
>          STREQ(member, "ListNames")) {
> diff --git a/tests/virmock.h b/tests/virmock.h
> index 0dd8bb5..8352e30 100644
> --- a/tests/virmock.h
> +++ b/tests/virmock.h
> @@ -234,33 +234,61 @@
>   */
>  
>  # define VIR_MOCK_IMPL_RET_ARGS(name, rettype, ...)                     \
> +    rettype name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__));                   \
> +    static rettype (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__));      \
> +    rettype name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__))
> +
> +# define VIR_MOCK_IMPL_RET_VOID(name, rettype)                          \
> +    rettype name(void);                                                 \
> +    static rettype (*real_##name)(void);                                \
> +    rettype name(void)
> +
> +# define VIR_MOCK_IMPL_VOID_ARGS(name, ...)                             \
> +    void name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__));                      \
> +    static void (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__));         \
> +    void name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__))
> +
> +# define VIR_MOCK_IMPL_VOID_VOID(name)                                  \
> +    void name(void);                                                    \
> +    static void (*real_##name)(void);                                   \
> +    void name(void)
> +
> +/*
> + * The VIR_MOCK_WRAP_NNN_MMM() macros are intended for use in the
> + * individual test suites. The define a stub implementation of
>   

s/The/They/ or s/The/The macros/

This is the first time I've looked at virmock.h in any detail, but
didn't notice any problems with this patch.  ACK.

Regards,
Jim

> + * the wrapped method and insert the caller provided code snippet
> + * as the body of the method.
> + */
> +
> +# define VIR_MOCK_WRAP_RET_ARGS(name, rettype, ...)                     \
>      rettype wrap_##name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__));            \
>      static rettype (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__));      \
>      rettype wrap_##name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__))
>  
> -# define VIR_MOCK_IMPL_INIT_REAL(name)                                  \
> -    do {                                                                \
> -        if (real_##name == NULL &&                                      \
> -            !(real_##name = dlsym(RTLD_NEXT,                            \
> -                                  #name))) {                            \
> -            fprintf(stderr, "Missing symbol '" #name "'\n");            \
> -            abort();                                                    \
> -        }                                                               \
> -    } while (0)
> -
> -# define VIR_MOCK_IMPL_RET_VOID(name, rettype)                          \
> +# define VIR_MOCK_WRAP_RET_VOID(name, rettype)                          \
>      rettype wrap_##name(void);                                          \
>      static rettype (*real_##name)(void);                                \
>      rettype wrap_##name(void)
>  
> -# define VIR_MOCK_IMPL_VOID_ARGS(name, ...)                             \
> +# define VIR_MOCK_WRAP_VOID_ARGS(name, ...)                             \
>      void wrap_##name(VIR_MOCK_ARGTYPENAMES(__VA_ARGS__));               \
>      static void (*real_##name)(VIR_MOCK_ARGTYPES(__VA_ARGS__));         \
>      void wrap_##name(VIR_MOCK_ARGTYPENAMES_UNUSED(__VA_ARGS__))
>  
> -# define VIR_MOCK_IMPL_VOID_VOID(name)                                  \
> +# define VIR_MOCK_WRAP_VOID_VOID(name)                                  \
>      void wrap_##name(void);                                             \
>      static void (*real_##name)(void);                                   \
>      void wrap_##name(void)
>  
> +
> +# define VIR_MOCK_REAL_INIT(name)                                       \
> +    do {                                                                \
> +        if (real_##name == NULL &&                                      \
> +            !(real_##name = dlsym(RTLD_NEXT,                            \
> +                                  #name))) {                            \
> +            fprintf(stderr, "Missing symbol '" #name "'\n");            \
> +            abort();                                                    \
> +        }                                                               \
> +    } while (0)
> +
>  #endif /* __VIR_MOCK_H__ */
> diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
> index 8f7b47e..0d57a6a 100644
> --- a/tests/virsystemdtest.c
> +++ b/tests/virsystemdtest.c
> @@ -34,7 +34,7 @@
>  
>  VIR_LOG_INIT("tests.systemdtest");
>  
> -VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
> +VIR_MOCK_WRAP_RET_ARGS(dbus_connection_send_with_reply_and_block,
>                         DBusMessage *,
>                         DBusConnection *, connection,
>                         DBusMessage *, message,
> @@ -45,7 +45,7 @@ VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
>      const char *service = dbus_message_get_destination(message);
>      const char *member = dbus_message_get_member(message);
>  
> -    VIR_MOCK_IMPL_INIT_REAL(dbus_connection_send_with_reply_and_block);
> +    VIR_MOCK_REAL_INIT(dbus_connection_send_with_reply_and_block);
>  
>      if (STREQ(service, "org.freedesktop.machine1")) {
>          if (getenv("FAIL_BAD_SERVICE")) {
>   

  reply	other threads:[~2014-06-03 21:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-03 11:02 [PATCH v2 0/4] Testing libvirt XML -> libxl_domain_config conversion Daniel P. Berrange
2014-06-03 11:02 ` [libvirt] [PATCH v2 1/4] util: Introduce virJSONStringCompare for JSON doc comparisons Daniel P. Berrange
2014-06-03 21:18   ` Jim Fehlig
2014-06-03 11:02 ` [PATCH v2 2/4] util: Allow port allocator to skip bind() check Daniel P. Berrange
2014-06-03 21:25   ` [libvirt] " Jim Fehlig
2014-06-03 11:02 ` [PATCH v2 3/4] tests: Add more test suite mock helpers Daniel P. Berrange
2014-06-03 21:30   ` Jim Fehlig [this message]
2014-06-03 11:02 ` [PATCH v2 4/4] libxl: Add a test suite for libxl option generator Daniel P. Berrange
2014-06-03 21:45   ` [libvirt] " Jim Fehlig
2014-06-16 23:11     ` Jim Fehlig
2014-06-17  8:52       ` Ian Campbell
2014-06-17 18:40         ` Jim Fehlig
2014-06-18  8:33           ` Ian Campbell
2014-06-18  9:07           ` Daniel P. Berrange

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=538E3E90.7050209@suse.com \
    --to=jfehlig@suse.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=berrange@redhat.com \
    --cc=libvir-list@redhat.com \
    --cc=xen-devel@lists.xensource.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.