qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCHv5] tests: add qtest_add_data_func_full


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCHv5] tests: add qtest_add_data_func_full
Date: Thu, 8 Sep 2016 08:48:07 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 09/08/2016 03:40 AM, Marc-André Lureau wrote:
> Allows one to specify a destroy function for the test data.
> 
> Add a fallback using glib g_test_add_vtable() internal function, whose
> signature changed over time. Tested with glib 2.22, 2.26 and 2.48, which
> according to git log should be enough to cover all variations.
> 
> Signed-off-by: Marc-André Lureau <address@hidden>
> ---
>  tests/libqtest.c | 19 +++++++++++++++++++
>  tests/libqtest.h | 17 +++++++++++++++++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index eb00f13..5f4450f 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -758,6 +758,25 @@ void qtest_add_func(const char *str, void (*fn)(void))
>      g_free(path);
>  }
>  
> +void qtest_add_data_func_full(const char *str, void *data,
> +                              void (*fn)(const void *),
> +                              GDestroyNotify data_free_func)
> +{
> +    gchar *path = g_strdup_printf("/%s/%s", qtest_get_arch(), str);
> +#if GLIB_CHECK_VERSION(2, 34, 0)
> +    g_test_add_data_func_full(path, data, fn, data_free_func);
> +#elif GLIB_CHECK_VERSION(2, 26, 0)
> +    /* back-compat casts, remove this once we can require new-enough glib */
> +    g_test_add_vtable(path, 0, data, NULL,
> +                      (GTestFixtureFunc)fn, (GTestFixtureFunc) 
> data_free_func);
> +#elif GLIB_CHECK_VERSION(2, 22, 0)

Perhaps this could be written as #else, since we have no further
alternatives (2.22.0 being our minimum).  Up to the maintainer if it is
worth changing.  Otherwise I think the end result is reasonable, and you
were able to avoid the leaks.

Reviewed-by: Eric Blake <address@hidden>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]