From patchwork Fri Aug 28 18:27:29 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 32431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 122E1B7088 for ; Sat, 29 Aug 2009 05:23:38 +1000 (EST) Received: from localhost ([127.0.0.1]:60953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mh72s-0006EK-N6 for incoming@patchwork.ozlabs.org; Fri, 28 Aug 2009 15:23:34 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mh6C8-00080g-9j for qemu-devel@nongnu.org; Fri, 28 Aug 2009 14:29:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mh6C3-0007xc-KI for qemu-devel@nongnu.org; Fri, 28 Aug 2009 14:29:03 -0400 Received: from [199.232.76.173] (port=41323 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mh6C3-0007xU-F9 for qemu-devel@nongnu.org; Fri, 28 Aug 2009 14:28:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50285) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mh6C2-0003Cv-VG for qemu-devel@nongnu.org; Fri, 28 Aug 2009 14:28:59 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7SISwBd022784; Fri, 28 Aug 2009 14:28:58 -0400 Received: from localhost (vpn-10-114.bos.redhat.com [10.16.10.114]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7SISuAB022325; Fri, 28 Aug 2009 14:28:57 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 28 Aug 2009 15:27:29 -0300 Message-Id: <1251484052-3939-27-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1251484052-3939-1-git-send-email-lcapitulino@redhat.com> References: <1251484052-3939-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, avi@redhat.com Subject: [Qemu-devel] [PATCH 26/29] Introduce QInt unit-tests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This suite contains tests to assure that QInt API works as expected. To execute it you should have check installed and build QEMU with check support enabled (--enable-check-utests) and then run: $ ./check-qint Signed-off-by: Luiz Capitulino --- Makefile | 2 + check-qint.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ configure | 2 +- 3 files changed, 113 insertions(+), 1 deletions(-) create mode 100644 check-qint.c diff --git a/Makefile b/Makefile index 983fe39..d08df6c 100644 --- a/Makefile +++ b/Makefile @@ -181,6 +181,8 @@ qemu-io$(EXESUF): qemu-io.o qemu-tool.o cmd.o $(block-obj-y) qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@," GEN $@") +check-qint: check-qint.o qint.o qemu-malloc.o + clean: # avoid old build problems by removing potentially incorrect old files rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h diff --git a/check-qint.c b/check-qint.c new file mode 100644 index 0000000..ae5d22f --- /dev/null +++ b/check-qint.c @@ -0,0 +1,110 @@ +/* + * QInt unit-tests. + * + * Copyright (C) 2009 Red Hat Inc. + * + * Authors: + * Luiz Capitulino + */ +#include + +#include "qint.h" +#include "qemu-common.h" + +/* + * Public Interface test-cases + * + * (with some violations to access 'private' data) + */ + +START_TEST(qint_from_int_test) +{ + QInt *qi; + const int value = -42; + + qi = qint_from_int(value); + fail_unless(qi != NULL); + fail_unless(qi->value == value); + fail_unless(qi->base.refcnt == 1); + fail_unless(qobject_type(QOBJECT(qi)) == QTYPE_QINT); + + // destroy doesn't exit yet + qemu_free(qi); +} +END_TEST + +START_TEST(qint_destroy_test) +{ + QInt *qi = qint_from_int(0); + QDECREF(qi); +} +END_TEST + +START_TEST(qint_from_int64_test) +{ + QInt *qi; + const int64_t value = 0xffffffffffffffff; + + qi = qint_from_int(value); + fail_unless(qi->value == value); + + QDECREF(qi); +} +END_TEST + +START_TEST(qint_get_int_test) +{ + QInt *qi; + const int value = 123456; + + qi = qint_from_int(value); + fail_unless(qint_get_int(qi) == value); + + QDECREF(qi); +} +END_TEST + +START_TEST(qobject_to_qint_test) +{ + QInt *qi; + + qi = qint_from_int(0); + fail_unless(qobject_to_qint(QOBJECT(qi)) == qi); + + QDECREF(qi); +} +END_TEST + +static Suite *qint_suite(void) +{ + Suite *s; + TCase *qint_public_tcase; + + s = suite_create("QInt test-suite"); + + qint_public_tcase = tcase_create("Public Interface"); + suite_add_tcase(s, qint_public_tcase); + tcase_add_test(qint_public_tcase, qint_from_int_test); + tcase_add_test(qint_public_tcase, qint_destroy_test); + tcase_add_test(qint_public_tcase, qint_from_int64_test); + tcase_add_test(qint_public_tcase, qint_get_int_test); + tcase_add_test(qint_public_tcase, qobject_to_qint_test); + + return s; +} + +int main(void) +{ + int nf; + Suite *s; + SRunner *sr; + + s = qint_suite(); + sr = srunner_create(s); + + srunner_run_all(sr, CK_NORMAL); + nf = srunner_ntests_failed(sr); + srunner_free(sr); + + return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/configure b/configure index 92d29c9..248cc0b 100755 --- a/configure +++ b/configure @@ -1927,7 +1927,7 @@ if test `expr "$target_list" : ".*softmmu.*"` != 0 ; then if [ "$linux" = "yes" ] ; then tools="qemu-nbd\$(EXESUF) qemu-io\$(EXESUF) $tools" if [ "$check_utests" = "yes" ]; then - tools="$tools" + tools="check-qint $tools" fi fi fi