diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2015-06-22 12:50:30 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2015-06-22 12:50:30 +0100 |
commit | 0a3346f5dea0a679322df804e1e78d7c10d12a9f (patch) | |
tree | c3357e42d47b35f6b2631d16b83c14450ac4f924 /tests | |
parent | cb4e0f9ddf7d45de7e4716cbab661ea568bd0b6c (diff) | |
parent | daeba9699d41ad79e2f3d34acea9c85c5d67a2ac (diff) |
Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-peter' into staging
QOM infrastructure fixes and device conversions
* Changes to name string ownership for alias properties
* Improvements around enum properties
* Cleanups around -object handling
* New helper functions
* Cleanups of qdev init helper functions
* Add path argument to qom-tree script
* QTest cleanup to use new qtest_add_data_func() consistently
# gpg: Signature made Fri Jun 19 18:14:38 2015 BST using RSA key ID 3E7E013F
# gpg: Good signature from "Andreas Färber <afaerber@suse.de>"
# gpg: aka "Andreas Färber <afaerber@suse.com>"
* remotes/afaerber/tags/qom-devices-for-peter:
qdev: Un-deprecate qdev_init_nofail()
qdev: Deprecated qdev_init() is finally unused, drop
qom: Don't pass string table to object_get_enum() function
qom: Add an object_property_add_enum() helper function
qom: Make enum string tables const-correct
qom: Add object_new_with_props() / object_new_withpropv() helpers
qom: Add helper function for getting user objects root
vl: Create (most) objects before creating chardev backends
doc: Document user creatable object types in help text
backends: Fix typename of 'policy' enum property in hostmem obj
scripts: Add support for path as argument of qom-tree
tests: Use qtest_add_data_func() consistently
qdev: Free property names after registering gpio aliases
qom: strdup() target property name on object_property_add_alias()
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile | 5 | ||||
-rw-r--r-- | tests/ahci-test.c | 9 | ||||
-rw-r--r-- | tests/check-qom-proplist.c | 302 | ||||
-rw-r--r-- | tests/e1000-test.c | 4 | ||||
-rw-r--r-- | tests/eepro100-test.c | 5 | ||||
-rw-r--r-- | tests/endianness-test.c | 18 | ||||
-rw-r--r-- | tests/pc-cpu-test.c | 13 | ||||
-rw-r--r-- | tests/qom-test.c | 4 |
9 files changed, 330 insertions, 31 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 0dcb61829c..dc813c2713 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -5,6 +5,7 @@ check-qjson check-qlist check-qstring check-qom-interface +check-qom-proplist rcutorture test-aio test-bitops diff --git a/tests/Makefile b/tests/Makefile index 5dd0c56cbb..eff5e1143d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -68,6 +68,8 @@ check-unit-y += tests/test-bitops$(EXESUF) check-unit-$(CONFIG_HAS_GLIB_SUBPROCESS_TESTS) += tests/test-qdev-global-props$(EXESUF) check-unit-y += tests/check-qom-interface$(EXESUF) 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/test-qemu-opts$(EXESUF) gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c check-unit-y += tests/test-write-threshold$(EXESUF) @@ -267,7 +269,7 @@ test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \ $(test-obj-y): QEMU_INCLUDES += -Itests QEMU_CFLAGS += -I$(SRC_PATH)/tests -qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o +qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o qom/object_interfaces.o tests/check-qint$(EXESUF): tests/check-qint.o libqemuutil.a tests/check-qstring$(EXESUF): tests/check-qstring.o libqemuutil.a @@ -276,6 +278,7 @@ tests/check-qlist$(EXESUF): tests/check-qlist.o libqemuutil.a tests/check-qfloat$(EXESUF): tests/check-qfloat.o libqemuutil.a tests/check-qjson$(EXESUF): tests/check-qjson.o libqemuutil.a libqemustub.a tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(qom-core-obj) libqemuutil.a libqemustub.a +tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(qom-core-obj) libqemuutil.a libqemustub.a tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(block-obj-y) libqemuutil.a libqemustub.a tests/test-aio$(EXESUF): tests/test-aio.o $(block-obj-y) libqemuutil.a libqemustub.a tests/test-rfifolock$(EXESUF): tests/test-rfifolock.o libqemuutil.a libqemustub.a diff --git a/tests/ahci-test.c b/tests/ahci-test.c index 6e3fa819e0..ae9415d74c 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -1486,7 +1486,6 @@ static void test_io_interface(gconstpointer opaque) static void create_ahci_io_test(enum IOMode type, enum AddrMode addr, enum BuffLen len, enum OffsetType offset) { - static const char *arch; char *name; AHCIIOTestOptions *opts = g_malloc(sizeof(AHCIIOTestOptions)); @@ -1495,17 +1494,13 @@ static void create_ahci_io_test(enum IOMode type, enum AddrMode addr, opts->io_type = type; opts->offset = offset; - if (!arch) { - arch = qtest_get_arch(); - } - - name = g_strdup_printf("/%s/ahci/io/%s/%s/%s/%s", arch, + name = g_strdup_printf("ahci/io/%s/%s/%s/%s", io_mode_str[type], addr_mode_str[addr], buff_len_str[len], offset_str[offset]); - g_test_add_data_func(name, opts, test_io_interface); + qtest_add_data_func(name, opts, test_io_interface); g_free(name); } diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c new file mode 100644 index 0000000000..7400b1fce9 --- /dev/null +++ b/tests/check-qom-proplist.c @@ -0,0 +1,302 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * 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> + */ + +#include <glib.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) + +typedef enum DummyAnimal DummyAnimal; + +enum DummyAnimal { + DUMMY_FROG, + DUMMY_ALLIGATOR, + DUMMY_PLATYPUS, + + DUMMY_LAST, +}; + +static const char *const dummy_animal_map[DUMMY_LAST + 1] = { + [DUMMY_FROG] = "frog", + [DUMMY_ALLIGATOR] = "alligator", + [DUMMY_PLATYPUS] = "platypus", + [DUMMY_LAST] = NULL, +}; + +struct DummyObject { + Object parent_obj; + + bool bv; + DummyAnimal av; + char *sv; +}; + +struct DummyObjectClass { + ObjectClass parent_class; +}; + + +static void dummy_set_bv(Object *obj, + bool value, + Error **errp) +{ + DummyObject *dobj = DUMMY_OBJECT(obj); + + dobj->bv = value; +} + +static bool dummy_get_bv(Object *obj, + Error **errp) +{ + DummyObject *dobj = DUMMY_OBJECT(obj); + + return dobj->bv; +} + + +static void dummy_set_av(Object *obj, + int value, + Error **errp) +{ + DummyObject *dobj = DUMMY_OBJECT(obj); + + dobj->av = value; +} + +static int dummy_get_av(Object *obj, + Error **errp) +{ + DummyObject *dobj = DUMMY_OBJECT(obj); + + return dobj->av; +} + + +static void dummy_set_sv(Object *obj, + const char *value, + Error **errp) +{ + DummyObject *dobj = DUMMY_OBJECT(obj); + + g_free(dobj->sv); + dobj->sv = g_strdup(value); +} + +static char *dummy_get_sv(Object *obj, + Error **errp) +{ + DummyObject *dobj = DUMMY_OBJECT(obj); + + return g_strdup(dobj->sv); +} + + +static void dummy_init(Object *obj) +{ + object_property_add_bool(obj, "bv", + dummy_get_bv, + dummy_set_bv, + NULL); + object_property_add_str(obj, "sv", + dummy_get_sv, + dummy_set_sv, + NULL); + object_property_add_enum(obj, "av", + "DummyAnimal", + dummy_animal_map, + dummy_get_av, + dummy_set_av, + NULL); +} + +static void dummy_finalize(Object *obj) +{ + DummyObject *dobj = DUMMY_OBJECT(obj); + + g_free(dobj->sv); +} + + +static const TypeInfo dummy_info = { + .name = TYPE_DUMMY, + .parent = TYPE_OBJECT, + .instance_size = sizeof(DummyObject), + .instance_init = dummy_init, + .instance_finalize = dummy_finalize, + .class_size = sizeof(DummyObjectClass), +}; + +static void test_dummy_createv(void) +{ + Error *err = NULL; + Object *parent = object_get_objects_root(); + DummyObject *dobj = DUMMY_OBJECT( + object_new_with_props(TYPE_DUMMY, + parent, + "dummy0", + &err, + "bv", "yes", + "sv", "Hiss hiss hiss", + "av", "platypus", + NULL)); + + g_assert(err == NULL); + g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); + g_assert(dobj->bv == true); + g_assert(dobj->av == DUMMY_PLATYPUS); + + g_assert(object_resolve_path_component(parent, "dummy0") + == OBJECT(dobj)); + + object_unparent(OBJECT(dobj)); +} + + +static Object *new_helper(Error **errp, + Object *parent, + ...) +{ + va_list vargs; + Object *obj; + + va_start(vargs, parent); + obj = object_new_with_propv(TYPE_DUMMY, + parent, + "dummy0", + errp, + vargs); + va_end(vargs); + return obj; +} + +static void test_dummy_createlist(void) +{ + Error *err = NULL; + Object *parent = object_get_objects_root(); + DummyObject *dobj = DUMMY_OBJECT( + new_helper(&err, + parent, + "bv", "yes", + "sv", "Hiss hiss hiss", + "av", "platypus", + NULL)); + + g_assert(err == NULL); + g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); + g_assert(dobj->bv == true); + g_assert(dobj->av == DUMMY_PLATYPUS); + + g_assert(object_resolve_path_component(parent, "dummy0") + == OBJECT(dobj)); + + object_unparent(OBJECT(dobj)); +} + +static void test_dummy_badenum(void) +{ + Error *err = NULL; + Object *parent = object_get_objects_root(); + Object *dobj = + object_new_with_props(TYPE_DUMMY, + parent, + "dummy0", + &err, + "bv", "yes", + "sv", "Hiss hiss hiss", + "av", "yeti", + NULL); + + g_assert(dobj == NULL); + g_assert(err != NULL); + g_assert_cmpstr(error_get_pretty(err), ==, + "Invalid parameter 'yeti'"); + + g_assert(object_resolve_path_component(parent, "dummy0") + == NULL); + + error_free(err); +} + + +static void test_dummy_getenum(void) +{ + Error *err = NULL; + int val; + Object *parent = object_get_objects_root(); + DummyObject *dobj = DUMMY_OBJECT( + object_new_with_props(TYPE_DUMMY, + parent, + "dummy0", + &err, + "av", "platypus", + NULL)); + + g_assert(err == NULL); + g_assert(dobj->av == DUMMY_PLATYPUS); + + val = object_property_get_enum(OBJECT(dobj), + "av", + "DummyAnimal", + &err); + g_assert(err == NULL); + g_assert(val == DUMMY_PLATYPUS); + + /* A bad enum type name */ + val = object_property_get_enum(OBJECT(dobj), + "av", + "BadAnimal", + &err); + g_assert(err != NULL); + error_free(err); + err = NULL; + + /* A non-enum property name */ + val = object_property_get_enum(OBJECT(dobj), + "iv", + "DummyAnimal", + &err); + g_assert(err != NULL); + error_free(err); +} + + +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/proplist/createlist", test_dummy_createlist); + g_test_add_func("/qom/proplist/createv", test_dummy_createv); + g_test_add_func("/qom/proplist/badenum", test_dummy_badenum); + g_test_add_func("/qom/proplist/getenum", test_dummy_getenum); + + return g_test_run(); +} diff --git a/tests/e1000-test.c b/tests/e1000-test.c index 81f164d9e9..7ca6d7e72e 100644 --- a/tests/e1000-test.c +++ b/tests/e1000-test.c @@ -44,8 +44,8 @@ int main(int argc, char **argv) for (i = 0; i < ARRAY_SIZE(models); i++) { char *path; - path = g_strdup_printf("/%s/e1000/%s", qtest_get_arch(), models[i]); - g_test_add_data_func(path, models[i], test_device); + path = g_strdup_printf("e1000/%s", models[i]); + qtest_add_data_func(path, models[i], test_device); } return g_test_run(); diff --git a/tests/eepro100-test.c b/tests/eepro100-test.c index bf8252627e..8bfaccdcbb 100644 --- a/tests/eepro100-test.c +++ b/tests/eepro100-test.c @@ -54,9 +54,8 @@ int main(int argc, char **argv) for (i = 0; i < ARRAY_SIZE(models); i++) { char *path; - path = g_strdup_printf("/%s/eepro100/%s", - qtest_get_arch(), models[i]); - g_test_add_data_func(path, models[i], test_device); + path = g_strdup_printf("eepro100/%s", models[i]); + qtest_add_data_func(path, models[i], test_device); } return g_test_run(); diff --git a/tests/endianness-test.c b/tests/endianness-test.c index 26ee734f42..2054338e18 100644 --- a/tests/endianness-test.c +++ b/tests/endianness-test.c @@ -296,17 +296,17 @@ int main(int argc, char **argv) if (strcmp(test_cases[i].arch, arch) != 0) { continue; } - path = g_strdup_printf("/%s/endianness/%s", - arch, test_cases[i].machine); - g_test_add_data_func(path, &test_cases[i], test_endianness); + path = g_strdup_printf("endianness/%s", + test_cases[i].machine); + qtest_add_data_func(path, &test_cases[i], test_endianness); - path = g_strdup_printf("/%s/endianness/split/%s", - arch, test_cases[i].machine); - g_test_add_data_func(path, &test_cases[i], test_endianness_split); + path = g_strdup_printf("endianness/split/%s", + test_cases[i].machine); + qtest_add_data_func(path, &test_cases[i], test_endianness_split); - path = g_strdup_printf("/%s/endianness/combine/%s", - arch, test_cases[i].machine); - g_test_add_data_func(path, &test_cases[i], test_endianness_combine); + path = g_strdup_printf("endianness/combine/%s", + test_cases[i].machine); + qtest_add_data_func(path, &test_cases[i], test_endianness_combine); } ret = g_test_run(); diff --git a/tests/pc-cpu-test.c b/tests/pc-cpu-test.c index a0122d3d61..3505c7c43f 100644 --- a/tests/pc-cpu-test.c +++ b/tests/pc-cpu-test.c @@ -75,7 +75,6 @@ static void test_pc_without_cpu_add(gconstpointer data) static void add_pc_test_cases(void) { - const char *arch = qtest_get_arch(); QDict *response, *minfo; QList *list; const QListEntry *p; @@ -119,15 +118,15 @@ static void add_pc_test_cases(void) (strcmp(mname, "pc-0.12") == 0) || (strcmp(mname, "pc-0.11") == 0) || (strcmp(mname, "pc-0.10") == 0)) { - path = g_strdup_printf("/%s/cpu/%s/init/%ux%ux%u&maxcpus=%u", - arch, mname, data->sockets, data->cores, + path = g_strdup_printf("cpu/%s/init/%ux%ux%u&maxcpus=%u", + mname, data->sockets, data->cores, data->threads, data->maxcpus); - g_test_add_data_func(path, data, test_pc_without_cpu_add); + qtest_add_data_func(path, data, test_pc_without_cpu_add); } else { - path = g_strdup_printf("/%s/cpu/%s/add/%ux%ux%u&maxcpus=%u", - arch, mname, data->sockets, data->cores, + path = g_strdup_printf("cpu/%s/add/%ux%ux%u&maxcpus=%u", + mname, data->sockets, data->cores, data->threads, data->maxcpus); - g_test_add_data_func(path, data, test_pc_with_cpu_add); + qtest_add_data_func(path, data, test_pc_with_cpu_add); } } qtest_end(); diff --git a/tests/qom-test.c b/tests/qom-test.c index 4246382d38..fde04e7a19 100644 --- a/tests/qom-test.c +++ b/tests/qom-test.c @@ -128,8 +128,8 @@ static void add_machine_test_cases(void) g_assert(qstr); mname = qstring_get_str(qstr); if (!is_blacklisted(arch, mname)) { - path = g_strdup_printf("/%s/qom/%s", arch, mname); - g_test_add_data_func(path, mname, test_machine); + path = g_strdup_printf("qom/%s", mname); + qtest_add_data_func(path, mname, test_machine); } } qtest_end(); |