Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mbair-0001OQ-Fx for qemu-devel@nongnu.org; Thu, 13 Aug 2009 09:52:05 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mbaik-0001Df-Gr for qemu-devel@nongnu.org; Thu, 13 Aug 2009 09:52:02 -0400 Received: from [199.232.76.173] (port=33522 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mbaij-0001DD-VS for qemu-devel@nongnu.org; Thu, 13 Aug 2009 09:51:58 -0400 Received: from mx2.redhat.com ([66.187.237.31]:45148) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mbaij-0003Oz-Ch for qemu-devel@nongnu.org; Thu, 13 Aug 2009 09:51:57 -0400 From: Luiz Capitulino Date: Thu, 13 Aug 2009 10:50:25 -0300 Message-Id: <1250171428-29308-27-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1250171428-29308-1-git-send-email-lcapitulino@redhat.com> References: <1250171428-29308-1-git-send-email-lcapitulino@redhat.com> Subject: [Qemu-devel] [PATCH 26/29] Introduce QInt unit-tests List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, avi@redhat.com 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) and then run: $ ./check-qint Signed-off-by: Luiz Capitulino --- Makefile | 1 + check-qint.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ configure | 2 +- 3 files changed, 126 insertions(+), 1 deletions(-) create mode 100644 check-qint.c diff --git a/Makefile b/Makefile index d90c126..f97ae4c 100644 --- a/Makefile +++ b/Makefile @@ -182,6 +182,7 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx ifdef CONFIG_CHECK LIBS += $(CHECK_LIBS) +check-qint: check-qint.o qint.o qemu-malloc.o endif clean: diff --git a/check-qint.c b/check-qint.c new file mode 100644 index 0000000..1a0ef17 --- /dev/null +++ b/check-qint.c @@ -0,0 +1,124 @@ +/* + * 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->number == 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_from_int64_test) +{ + QInt *qi; + const int64_t value = 0xffffffffffffffff; + + qi = qint_from_int64(value); + fail_unless(qi->number == value); + + // destroy doesn't exit yet + qemu_free(qi); +} +END_TEST + +START_TEST(qint_destroy_test) +{ + QInt *qi = qint_from_int(0); + qobject_decref(QOBJECT(qi)); +} +END_TEST + +START_TEST(qint_to_int_test) +{ + QInt *qi; + const int value = 123456; + + qi = qint_from_int(value); + fail_unless(qint_to_int(qi) == value); + + qobject_decref(QOBJECT(qi)); +} +END_TEST + +START_TEST(qint_to_uint64_test) +{ + QInt *qi; + const uint64_t value = 0xffffffffffffffff; + + qi = qint_from_int64(value); + fail_unless(qint_to_uint64(qi) == value); + + qobject_decref(QOBJECT(qi)); +} +END_TEST + +START_TEST(qobject_to_qint_test) +{ + QInt *qi; + + qi = qint_from_int(0); + fail_unless(qobject_to_qint(QOBJECT(qi)) == qi); + + qobject_decref(QOBJECT(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_from_int64_test); + tcase_add_test(qint_public_tcase, qint_destroy_test); + tcase_add_test(qint_public_tcase, qint_to_int_test); + tcase_add_test(qint_public_tcase, qint_to_uint64_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 df89dd6..8fbed8f 100755 --- a/configure +++ b/configure @@ -1783,7 +1783,7 @@ if test `expr "$target_list" : ".*softmmu.*"` != 0 ; then if [ "$linux" = "yes" ] ; then tools="qemu-nbd\$(EXESUF) qemu-io\$(EXESUF) $tools" if [ "$check" = "yes" ]; then - tools="$tools" + tools="check-qint $tools" fi fi fi -- 1.6.4.67.gea5b1