Skip to content

Commit

Permalink
Introduce QInt unit-tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
  • Loading branch information
Luiz Capitulino authored and Anthony Liguori committed Sep 4, 2009
1 parent 5495ed1 commit 33837ba
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
110 changes: 110 additions & 0 deletions check-qint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* QInt unit-tests.
*
* Copyright (C) 2009 Red Hat Inc.
*
* Authors:
* Luiz Capitulino <[email protected]>
*/
#include <check.h>

#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;
}
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 33837ba

Please sign in to comment.