From patchwork Thu Sep 8 08:40:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 667532 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sVJtV0p10z9ryT for ; Thu, 8 Sep 2016 22:05:06 +1000 (AEST) Received: from localhost ([::1]:47499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhy4l-0005dn-2e for incoming@patchwork.ozlabs.org; Thu, 08 Sep 2016 08:05:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhut7-0000LY-CB for qemu-devel@nongnu.org; Thu, 08 Sep 2016 04:40:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhut1-0007jC-7d for qemu-devel@nongnu.org; Thu, 08 Sep 2016 04:40:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50694) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhut1-0007j2-07 for qemu-devel@nongnu.org; Thu, 08 Sep 2016 04:40:43 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE0A961E41; Thu, 8 Sep 2016 08:40:41 +0000 (UTC) Received: from localhost (ovpn-116-47.phx2.redhat.com [10.3.116.47]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u888edSf025509; Thu, 8 Sep 2016 04:40:40 -0400 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 8 Sep 2016 12:40:36 +0400 Message-Id: <20160908084036.5938-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 08 Sep 2016 08:40:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCHv5] tests: add qtest_add_data_func_full X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, armbru@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 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..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