All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCHv5] tests: add qtest_add_data_func_full
@ 2016-09-08  8:40 Marc-André Lureau
  2016-09-08 13:48 ` Eric Blake
  0 siblings, 1 reply; 3+ messages in thread
From: Marc-André Lureau @ 2016-09-08  8:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: eblake, armbru, peter.maydell, Marc-André Lureau

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 <marcandre.lureau@redhat.com>
---
 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)
+    /* back-compat casts, remove this once we can require new-enough glib */
+    g_test_add_vtable(path, 0, data, NULL,
+                      (void (*)(void)) fn, (void (*)(void)) data_free_func);
+#endif
+    g_free(path);
+}
+
 void qtest_add_data_func(const char *str, const void *data,
                          void (*fn)(const void *))
 {
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 37f37ad..d2b4853 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -425,6 +425,23 @@ void qtest_add_func(const char *str, void (*fn)(void));
 void qtest_add_data_func(const char *str, const void *data,
                          void (*fn)(const void *));
 
+/**
+ * qtest_add_data_func_full:
+ * @str: Test case path.
+ * @data: Test case data
+ * @fn: Test case function
+ * @data_free_func: GDestroyNotify for data
+ *
+ * Add a GTester testcase with the given name, data and function.
+ * The path is prefixed with the architecture under test, as
+ * returned by qtest_get_arch().
+ *
+ * @data is passed to @data_free_func() on test completion.
+ */
+void qtest_add_data_func_full(const char *str, void *data,
+                              void (*fn)(const void *),
+                              GDestroyNotify data_free_func);
+
 /**
  * qtest_add:
  * @testpath: Test case path
-- 
2.10.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCHv5] tests: add qtest_add_data_func_full
  2016-09-08  8:40 [Qemu-devel] [PATCHv5] tests: add qtest_add_data_func_full Marc-André Lureau
@ 2016-09-08 13:48 ` Eric Blake
  2016-09-08 13:57   ` Marc-André Lureau
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Blake @ 2016-09-08 13:48 UTC (permalink / raw)
  To: Marc-André Lureau, qemu-devel; +Cc: armbru, peter.maydell

[-- Attachment #1: Type: text/plain, Size: 1857 bytes --]

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 <marcandre.lureau@redhat.com>
> ---
>  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 <eblake@redhat.com>

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCHv5] tests: add qtest_add_data_func_full
  2016-09-08 13:48 ` Eric Blake
@ 2016-09-08 13:57   ` Marc-André Lureau
  0 siblings, 0 replies; 3+ messages in thread
From: Marc-André Lureau @ 2016-09-08 13:57 UTC (permalink / raw)
  To: Eric Blake; +Cc: Marc-André Lureau, qemu-devel, armbru, peter maydell

Hi

----- Original Message -----
> 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 <marcandre.lureau@redhat.com>
> > ---
> >  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 <eblake@redhat.com>

Ack, I'll change it.

thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-08 13:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-08  8:40 [Qemu-devel] [PATCHv5] tests: add qtest_add_data_func_full Marc-André Lureau
2016-09-08 13:48 ` Eric Blake
2016-09-08 13:57   ` Marc-André Lureau

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.