Received: from eggs.gnu.org ([2001:4830:134:3::10]:57616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bi0A7-0001hM-UL for qemu-devel@nongnu.org; Thu, 08 Sep 2016 10:18:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bi0A6-0000tb-Dq for qemu-devel@nongnu.org; Thu, 08 Sep 2016 10:18:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57328) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bi0A6-0000tL-6M for qemu-devel@nongnu.org; Thu, 08 Sep 2016 10:18:42 -0400 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 8 Sep 2016 18:17:17 +0400 Message-Id: <20160908141720.30641-23-marcandre.lureau@redhat.com> In-Reply-To: <20160908141720.30641-1-marcandre.lureau@redhat.com> References: <20160908141720.30641-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULLv2 22/25] tests: add qtest_add_data_func_full List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, eblake@redhat.com, armbru@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= 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=C3=A9 Lureau Reviewed-by: Eric Blake --- 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..42ccb62 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); } =20 +void qtest_add_data_func_full(const char *str, void *data, + void (*fn)(const void *), + GDestroyNotify data_free_func) +{ + gchar *path =3D 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 gli= b */ + g_test_add_vtable(path, 0, data, NULL, + (GTestFixtureFunc)fn, (GTestFixtureFunc) data_free= _func); +#else + /* back-compat casts, remove this once we can require new-enough gli= b */ + g_test_add_vtable(path, 0, data, NULL, + (void (*)(void)) fn, (void (*)(void)) data_free_fu= nc); +#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 *)); =20 +/** + * 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 --=20 2.10.0