2017-12-14 01:53:24 +01:00
|
|
|
From b7f197720e170281c479d2b892c45e598f428a27 Mon Sep 17 00:00:00 2001
|
2017-03-15 20:38:55 +01:00
|
|
|
From: =?UTF-8?q?Andreas=20F=C3=A4rber?= <afaerber@suse.de>
|
|
|
|
Date: Sun, 6 Sep 2015 20:12:42 +0200
|
|
|
|
Subject: [PATCH] tests: Add QOM property unit tests
|
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
Add a test for parsing and setting a uint64 property.
|
|
|
|
|
|
|
|
Signed-off-by: Andreas Färber <afaerber@suse.de>
|
|
|
|
---
|
|
|
|
MAINTAINERS | 1 +
|
|
|
|
tests/Makefile.include | 3 ++
|
|
|
|
tests/check-qom-props.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
3 files changed, 126 insertions(+)
|
|
|
|
create mode 100644 tests/check-qom-props.c
|
|
|
|
|
|
|
|
diff --git a/MAINTAINERS b/MAINTAINERS
|
2017-12-14 01:53:24 +01:00
|
|
|
index 0255113470..7801583a76 100644
|
2017-03-15 20:38:55 +01:00
|
|
|
--- a/MAINTAINERS
|
|
|
|
+++ b/MAINTAINERS
|
2017-12-14 01:53:24 +01:00
|
|
|
@@ -1521,6 +1521,7 @@ F: qom/
|
2017-03-15 20:38:55 +01:00
|
|
|
X: qom/cpu.c
|
|
|
|
F: tests/check-qom-interface.c
|
|
|
|
F: tests/check-qom-proplist.c
|
|
|
|
+F: tests/check-qom-props.c
|
|
|
|
F: tests/qom-test.c
|
|
|
|
|
|
|
|
QMP
|
|
|
|
diff --git a/tests/Makefile.include b/tests/Makefile.include
|
2017-12-14 01:53:24 +01:00
|
|
|
index c002352134..f777533f1a 100644
|
2017-03-15 20:38:55 +01:00
|
|
|
--- a/tests/Makefile.include
|
|
|
|
+++ b/tests/Makefile.include
|
2017-12-14 01:53:24 +01:00
|
|
|
@@ -116,6 +116,8 @@ check-unit-y += tests/check-qom-interface$(EXESUF)
|
2017-03-15 20:38:55 +01:00
|
|
|
gcov-files-check-qom-interface-y = qom/object.c
|
|
|
|
check-unit-y += tests/check-qom-proplist$(EXESUF)
|
|
|
|
gcov-files-check-qom-proplist-y = qom/object.c
|
|
|
|
+check-unit-y += tests/check-qom-props$(EXESUF)
|
|
|
|
+gcov-files-check-qom-props-y = qom/object.c
|
|
|
|
check-unit-y += tests/test-qemu-opts$(EXESUF)
|
2017-03-29 06:22:10 +02:00
|
|
|
gcov-files-test-qemu-opts-y = util/qemu-option.c
|
|
|
|
check-unit-y += tests/test-keyval$(EXESUF)
|
2017-12-14 01:53:24 +01:00
|
|
|
@@ -586,6 +588,7 @@ tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y)
|
|
|
|
tests/check-qlit$(EXESUF): tests/check-qlit.o $(test-util-obj-y)
|
2017-03-15 20:38:55 +01:00
|
|
|
tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y)
|
|
|
|
tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y)
|
|
|
|
+tests/check-qom-props$(EXESUF): tests/check-qom-props.o $(test-qom-obj-y)
|
|
|
|
|
2017-03-29 06:22:10 +02:00
|
|
|
tests/test-char$(EXESUF): tests/test-char.o $(test-util-obj-y) $(qtest-obj-y) $(test-io-obj-y) $(chardev-obj-y)
|
2017-03-15 20:38:55 +01:00
|
|
|
tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y)
|
|
|
|
diff --git a/tests/check-qom-props.c b/tests/check-qom-props.c
|
|
|
|
new file mode 100644
|
2017-05-05 17:05:43 +02:00
|
|
|
index 0000000000..681e121c07
|
2017-03-15 20:38:55 +01:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/tests/check-qom-props.c
|
|
|
|
@@ -0,0 +1,122 @@
|
|
|
|
+/*
|
|
|
|
+ * Copyright (C) 2015 Red Hat, Inc.
|
|
|
|
+ * Copyright (c) 2015 SUSE Linux GmbH
|
|
|
|
+ *
|
|
|
|
+ * This library is free software; you can redistribute it and/or
|
|
|
|
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
|
+ * License as published by the Free Software Foundation; either
|
|
|
|
+ * version 2.1 of the License, or (at your option) any later version.
|
|
|
|
+ *
|
|
|
|
+ * This library is distributed in the hope that it will be useful,
|
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
+ * Lesser General Public License for more details.
|
|
|
|
+ *
|
|
|
|
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
|
+ * License along with this library. If not, see
|
|
|
|
+ * <http://www.gnu.org/licenses/>.
|
|
|
|
+ *
|
|
|
|
+ * Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
+ * Andreas Färber <afaerber@suse.com>
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#include "qemu/osdep.h"
|
|
|
|
+
|
|
|
|
+#include <glib.h>
|
|
|
|
+
|
|
|
|
+#include "qapi/visitor.h"
|
|
|
|
+#include "qom/object.h"
|
|
|
|
+#include "qemu/module.h"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#define TYPE_DUMMY "qemu-dummy"
|
|
|
|
+
|
|
|
|
+typedef struct DummyObject DummyObject;
|
|
|
|
+typedef struct DummyObjectClass DummyObjectClass;
|
|
|
|
+
|
|
|
|
+#define DUMMY_OBJECT(obj) \
|
|
|
|
+ OBJECT_CHECK(DummyObject, (obj), TYPE_DUMMY)
|
|
|
|
+
|
|
|
|
+struct DummyObject {
|
|
|
|
+ Object parent_obj;
|
|
|
|
+
|
|
|
|
+ uint64_t u64val;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+struct DummyObjectClass {
|
|
|
|
+ ObjectClass parent_class;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static void dummy_set_uint64(Object *obj, Visitor *v,
|
|
|
|
+ const char *name, void *opaque,
|
|
|
|
+ Error **errp)
|
|
|
|
+{
|
|
|
|
+ uint64_t *ptr = (uint64_t *)opaque;
|
|
|
|
+
|
|
|
|
+ visit_type_uint64(v, name, ptr, errp);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void dummy_get_uint64(Object *obj, Visitor *v,
|
|
|
|
+ const char *name, void *opaque,
|
|
|
|
+ Error **errp)
|
|
|
|
+{
|
|
|
|
+ uint64_t value = *(uint64_t *)opaque;
|
|
|
|
+
|
|
|
|
+ visit_type_uint64(v, name, &value, errp);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void dummy_init(Object *obj)
|
|
|
|
+{
|
|
|
|
+ DummyObject *dobj = DUMMY_OBJECT(obj);
|
|
|
|
+
|
|
|
|
+ object_property_add(obj, "u64val", "uint64",
|
|
|
|
+ dummy_get_uint64,
|
|
|
|
+ dummy_set_uint64,
|
|
|
|
+ NULL, &dobj->u64val, NULL);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+static const TypeInfo dummy_info = {
|
|
|
|
+ .name = TYPE_DUMMY,
|
|
|
|
+ .parent = TYPE_OBJECT,
|
|
|
|
+ .instance_size = sizeof(DummyObject),
|
|
|
|
+ .instance_init = dummy_init,
|
|
|
|
+ .class_size = sizeof(DummyObjectClass),
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static void test_dummy_uint64(void)
|
|
|
|
+{
|
|
|
|
+ Error *err = NULL;
|
|
|
|
+ char *str;
|
|
|
|
+ DummyObject *dobj = DUMMY_OBJECT(object_new(TYPE_DUMMY));
|
|
|
|
+
|
|
|
|
+ g_assert(dobj->u64val == 0);
|
|
|
|
+
|
|
|
|
+ str = g_strdup_printf("%" PRIu64, UINT64_MAX);
|
|
|
|
+ object_property_parse(OBJECT(dobj), str, "u64val", &err);
|
|
|
|
+ g_free(str);
|
|
|
|
+ g_assert(!err);
|
|
|
|
+ g_assert_cmpint(dobj->u64val, ==, UINT64_MAX);
|
|
|
|
+
|
|
|
|
+ dobj->u64val = 0;
|
|
|
|
+ str = g_strdup_printf("0x%" PRIx64, UINT64_MAX);
|
|
|
|
+ object_property_parse(OBJECT(dobj), str, "u64val", &err);
|
|
|
|
+ g_free(str);
|
|
|
|
+ g_assert(!err);
|
|
|
|
+ g_assert_cmpint(dobj->u64val, ==, UINT64_MAX);
|
|
|
|
+
|
|
|
|
+ object_unref(OBJECT(dobj));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+int main(int argc, char **argv)
|
|
|
|
+{
|
|
|
|
+ g_test_init(&argc, &argv, NULL);
|
|
|
|
+
|
|
|
|
+ module_call_init(MODULE_INIT_QOM);
|
|
|
|
+ type_register_static(&dummy_info);
|
|
|
|
+
|
|
|
|
+ g_test_add_func("/qom/props/uint64", test_dummy_uint64);
|
|
|
|
+
|
|
|
|
+ return g_test_run();
|
|
|
|
+}
|