From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqjtZ-0002Et-9j for qemu-devel@nongnu.org; Thu, 14 Apr 2016 12:13:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aqjtV-0008Iu-8q for qemu-devel@nongnu.org; Thu, 14 Apr 2016 12:13:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56715) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqjtV-0008In-1P for qemu-devel@nongnu.org; Thu, 14 Apr 2016 12:13:25 -0400 From: Markus Armbruster References: <1460131992-32278-1-git-send-email-eblake@redhat.com> <1460131992-32278-10-git-send-email-eblake@redhat.com> Date: Thu, 14 Apr 2016 18:13:22 +0200 In-Reply-To: <1460131992-32278-10-git-send-email-eblake@redhat.com> (Eric Blake's message of "Fri, 8 Apr 2016 10:13:02 -0600") Message-ID: <87bn5c2mot.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v14 09/19] tests: Add check-qnull List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org, Michael Roth Eric Blake writes: > Add a new test, for checking reference counting of qnull(). As > part of the new file, move a previous reference counting change > added in commit a861564 into a more logical place. into or to? Those darn prepositions... > Signed-off-by: Eric Blake > > --- > v14: no change > v13: no change > v12: new patch > --- > tests/check-qnull.c | 60 +++++++++++++++++++++++++++++++++++++++++ > tests/test-qmp-output-visitor.c | 2 -- > tests/.gitignore | 1 + > tests/Makefile | 6 ++++- > 4 files changed, 66 insertions(+), 3 deletions(-) > create mode 100644 tests/check-qnull.c > > diff --git a/tests/check-qnull.c b/tests/check-qnull.c > new file mode 100644 > index 0000000..b0fb1e6 > --- /dev/null > +++ b/tests/check-qnull.c > @@ -0,0 +1,60 @@ > +/* > + * QNull unit-tests. > + * > + * Copyright (C) 2016 Red Hat Inc. > + * > + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. > + * See the COPYING.LIB file in the top-level directory. > + */ > +#include "qemu/osdep.h" > +#include > + > +#include "qapi/qmp/qobject.h" > +#include "qemu-common.h" > +#include "qapi/qmp-output-visitor.h" > + > +/* > + * Public Interface test-cases > + * > + * (with some violations to access 'private' data) > + */ > + > +static void qnull_ref_test(void) > +{ > + QObject *obj; > + > + g_assert(qnull_.refcnt == 1); > + obj = qnull(); > + g_assert(obj); > + g_assert(obj == &qnull_); This one's an implementation detail, but the reference count checks that follow need to rely on it. Okay. > + g_assert(qnull_.refcnt == 2); > + g_assert(qobject_type(obj) == QTYPE_QNULL); > + qobject_decref(obj); > + g_assert(qnull_.refcnt == 1); > +} > + > +static void qnull_visit_test(void) > +{ > + QObject *obj; > + QmpOutputVisitor *qov; > + > + g_assert(qnull_.refcnt == 1); > + qov = qmp_output_visitor_new(); > + /* FIXME: Empty visits are ugly, we should have a visit_type_null(). */ > + obj = qmp_output_get_qobject(qov); > + g_assert(obj == &qnull_); > + qobject_decref(obj); > + > + qmp_output_visitor_cleanup(qov); > + g_assert(qnull_.refcnt == 1); > +} > + > +int main(int argc, char **argv) > +{ > + g_test_init(&argc, &argv, NULL); > + > + g_test_add_func("/public/qnull_ref", qnull_ref_test); > + g_test_add_func("/public/qnull_visit", qnull_visit_test); > + > + return g_test_run(); > +} [...] Nice & simple patch, welcome relief after the big & subtle PATCH 08.