[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/59] tests: Fix test-qdev-global-props on anonymous qdev realize
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 05/59] tests: Fix test-qdev-global-props on anonymous qdev realize() |
Date: |
Fri, 20 Dec 2024 17:14:56 +0100 |
From: Peter Xu <peterx@redhat.com>
test-qdev-global-props creates a few subprocesses and test things based on
qdev realize(). One thing was overlooked since the start, that anonymous
creations of qdev (then realize() the device) requires the machine object's
presence, as all these devices need to be attached to QOM tree, by default
to path "/machine/unattached".
The test didn't crash simply because container_get() has an implicit
semantic to silently create any missing container, hence what happened here
is container_get() (when running these tests) will try to create containers
at QOM path "/machine" on the fly. That's probably unexpected by the test,
but worked like charm before.
We're going to fix device_set_realized() soon, but before that make the
test case prepared, by creating the machine object on its own.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-ID: <20241121192202.4155849-4-peterx@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
tests/unit/test-qdev-global-props.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/tests/unit/test-qdev-global-props.c
b/tests/unit/test-qdev-global-props.c
index 1eb95d2429b..d2f9800148d 100644
--- a/tests/unit/test-qdev-global-props.c
+++ b/tests/unit/test-qdev-global-props.c
@@ -72,6 +72,26 @@ static const TypeInfo subclass_type = {
.parent = TYPE_STATIC_PROPS,
};
+/*
+ * Initialize a fake machine, being prepared for future tests.
+ *
+ * All the tests later (even if to be run in subprocesses.. which will
+ * inherit the global states of the parent process) will try to create qdev
+ * and realize the device.
+ *
+ * Realization of such anonymous qdev (with no parent object) requires both
+ * the machine object and its "unattached" container to be at least present.
+ */
+static void test_init_machine(void)
+{
+ /* This is a fake machine - it doesn't need to be a machine object */
+ Object *machine = object_property_add_new_container(
+ object_get_root(), "machine");
+
+ /* This container must exist for anonymous qdevs to realize() */
+ object_property_add_new_container(machine, "unattached");
+}
+
/* Test simple static property setting to default value */
static void test_static_prop_subprocess(void)
{
@@ -295,6 +315,8 @@ int main(int argc, char **argv)
type_register_static(&nohotplug_type);
type_register_static(&nondevice_type);
+ test_init_machine();
+
g_test_add_func("/qdev/properties/static/default/subprocess",
test_static_prop_subprocess);
g_test_add_func("/qdev/properties/static/default",
--
2.47.1
- [PULL 00/59] Accel & exec patches for 2024-12-20, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 02/59] log: Add separate debug option for logging invalid memory accesses, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 01/59] hvf: arm: Ignore writes to CNTP_CTL_EL0, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 03/59] qom: Add TYPE_CONTAINER macro, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 04/59] qom: New object_property_add_new_container(), Philippe Mathieu-Daudé, 2024/12/20
- [PULL 05/59] tests: Fix test-qdev-global-props on anonymous qdev realize(),
Philippe Mathieu-Daudé <=
- [PULL 06/59] tests: Explicitly create containers in test_qom_partial_path(), Philippe Mathieu-Daudé, 2024/12/20
- [PULL 07/59] ppc/e500: Avoid abuse of container_get(), Philippe Mathieu-Daudé, 2024/12/20
- [PULL 08/59] hw/ppc: Explicitly create the drc container, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 09/59] qom: Create system containers explicitly, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 10/59] target/i386/sev: Reduce system specific declarations, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 11/59] include: Rename sysemu/ -> system/, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 12/59] system: Move 'exec/confidential-guest-support.h' to system/, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 13/59] tcg/tci: Include missing 'disas/dis-asm.h' header, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 14/59] accel/tcg: Include missing 'exec/tswap.h' header in translator.c, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 15/59] accel/tcg: Have tlb_vaddr_to_host() use vaddr type, Philippe Mathieu-Daudé, 2024/12/20