qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function
@ 2014-08-08 19:03 Eduardo Habkost
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 1/6] test-qdev-global-props: Trivial comment fix Eduardo Habkost
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Eduardo Habkost @ 2014-08-08 19:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Michael S. Tsirkin, Markus Armbruster, Don Slutz,
	Paolo Bonzini, Igor Mammedov, Andreas Färber

New version of what was previously a single patch, submitted as:
  Subject: [PATCH v2] qdev: Move global validation to a single function

Now the test cases run in a subprocess, and we are ensuring the warning messages
are actually printed.

Eduardo Habkost (6):
  test-qdev-global-props: Trivial comment fix
  test-qdev-global-props: Run tests on subprocess
  test-qdev-global-props: Initialize not_used=true for all props
  test-qdev-global-props: Test handling of hotpluggable and non-device
    types
  qdev: Rename qdev_prop_check_global() to qdev_prop_check_globals()
  qdev: Move global validation to a single function

 hw/core/qdev-properties-system.c |  18 +----
 hw/core/qdev-properties.c        |  30 ++++++--
 include/hw/qdev-core.h           |  10 +--
 include/hw/qdev-properties.h     |   2 +-
 tests/test-qdev-global-props.c   | 159 ++++++++++++++++++++++++++++++++++++---
 vl.c                             |   2 +-
 6 files changed, 180 insertions(+), 41 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v3 1/6] test-qdev-global-props: Trivial comment fix
  2014-08-08 19:03 [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function Eduardo Habkost
@ 2014-08-08 19:03 ` Eduardo Habkost
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 2/6] test-qdev-global-props: Run tests on subprocess Eduardo Habkost
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Eduardo Habkost @ 2014-08-08 19:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Michael S. Tsirkin, Markus Armbruster, Don Slutz,
	Paolo Bonzini, Igor Mammedov, Andreas Färber

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 tests/test-qdev-global-props.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c
index 2bef04c..e1a1317 100644
--- a/tests/test-qdev-global-props.c
+++ b/tests/test-qdev-global-props.c
@@ -143,7 +143,7 @@ static const TypeInfo dynamic_prop_type = {
     .class_init = dynamic_class_init,
 };
 
-/* Test setting of static property using global properties */
+/* Test setting of dynamic properties using global properties */
 static void test_dynamic_globalprop(void)
 {
     MyType *mt;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v3 2/6] test-qdev-global-props: Run tests on subprocess
  2014-08-08 19:03 [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function Eduardo Habkost
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 1/6] test-qdev-global-props: Trivial comment fix Eduardo Habkost
@ 2014-08-08 19:03 ` Eduardo Habkost
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 3/6] test-qdev-global-props: Initialize not_used=true for all props Eduardo Habkost
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Eduardo Habkost @ 2014-08-08 19:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Michael S. Tsirkin, Markus Armbruster, Don Slutz,
	Paolo Bonzini, Igor Mammedov, Andreas Färber

There are multiple reasons for running the global property tests on a
subprocess:

* We need the global_props lists to be empty for each test case, so
  global properties from the previous test won't affect the next one;
* We don't want the qdev_prop_check_global() warnings to pollute test
  output;
* With a subprocess, we can ensure qdev_prop_check_global() is printing
  the warning messages it should.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 tests/test-qdev-global-props.c | 49 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 43 insertions(+), 6 deletions(-)

diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c
index e1a1317..34223a7 100644
--- a/tests/test-qdev-global-props.c
+++ b/tests/test-qdev-global-props.c
@@ -65,7 +65,7 @@ static const TypeInfo static_prop_type = {
 };
 
 /* Test simple static property setting to default value */
-static void test_static_prop(void)
+static void test_static_prop_subprocess(void)
 {
     MyType *mt;
 
@@ -75,8 +75,16 @@ static void test_static_prop(void)
     g_assert_cmpuint(mt->prop1, ==, PROP_DEFAULT);
 }
 
+static void test_static_prop(void)
+{
+    g_test_trap_subprocess("/qdev/properties/static/default/subprocess", 0, 0);
+    g_test_trap_assert_passed();
+    g_test_trap_assert_stderr("");
+    g_test_trap_assert_stdout("");
+}
+
 /* Test setting of static property using global properties */
-static void test_static_globalprop(void)
+static void test_static_globalprop_subprocess(void)
 {
     MyType *mt;
     static GlobalProperty props[] = {
@@ -93,6 +101,14 @@ static void test_static_globalprop(void)
     g_assert_cmpuint(mt->prop2, ==, PROP_DEFAULT);
 }
 
+static void test_static_globalprop(void)
+{
+    g_test_trap_subprocess("/qdev/properties/static/global/subprocess", 0, 0);
+    g_test_trap_assert_passed();
+    g_test_trap_assert_stderr("");
+    g_test_trap_assert_stdout("");
+}
+
 #define TYPE_DYNAMIC_PROPS "dynamic-prop-type"
 #define DYNAMIC_TYPE(obj) \
     OBJECT_CHECK(MyType, (obj), TYPE_DYNAMIC_PROPS)
@@ -144,7 +160,7 @@ static const TypeInfo dynamic_prop_type = {
 };
 
 /* Test setting of dynamic properties using global properties */
-static void test_dynamic_globalprop(void)
+static void test_dynamic_globalprop_subprocess(void)
 {
     MyType *mt;
     static GlobalProperty props[] = {
@@ -166,6 +182,16 @@ static void test_dynamic_globalprop(void)
     g_assert_cmpuint(all_used, ==, 1);
 }
 
+static void test_dynamic_globalprop(void)
+{
+    g_test_trap_subprocess("/qdev/properties/dynamic/global/subprocess", 0, 0);
+    g_test_trap_assert_passed();
+    g_test_trap_assert_stderr_unmatched("*prop1*");
+    g_test_trap_assert_stderr_unmatched("*prop2*");
+    g_test_trap_assert_stderr("*Warning: \"-global dynamic-prop-type-bad.prop3=103\" not used\n*");
+    g_test_trap_assert_stdout("");
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
@@ -174,9 +200,20 @@ int main(int argc, char **argv)
     type_register_static(&static_prop_type);
     type_register_static(&dynamic_prop_type);
 
-    g_test_add_func("/qdev/properties/static/default", test_static_prop);
-    g_test_add_func("/qdev/properties/static/global", test_static_globalprop);
-    g_test_add_func("/qdev/properties/dynamic/global", test_dynamic_globalprop);
+    g_test_add_func("/qdev/properties/static/default/subprocess",
+                    test_static_prop_subprocess);
+    g_test_add_func("/qdev/properties/static/default",
+                    test_static_prop);
+
+    g_test_add_func("/qdev/properties/static/global/subprocess",
+                    test_static_globalprop_subprocess);
+    g_test_add_func("/qdev/properties/static/global",
+                    test_static_globalprop);
+
+    g_test_add_func("/qdev/properties/dynamic/global/subprocess",
+                    test_dynamic_globalprop_subprocess);
+    g_test_add_func("/qdev/properties/dynamic/global",
+                    test_dynamic_globalprop);
 
     g_test_run();
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v3 3/6] test-qdev-global-props: Initialize not_used=true for all props
  2014-08-08 19:03 [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function Eduardo Habkost
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 1/6] test-qdev-global-props: Trivial comment fix Eduardo Habkost
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 2/6] test-qdev-global-props: Run tests on subprocess Eduardo Habkost
@ 2014-08-08 19:03 ` Eduardo Habkost
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 4/6] test-qdev-global-props: Test handling of hotpluggable and non-device types Eduardo Habkost
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Eduardo Habkost @ 2014-08-08 19:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Michael S. Tsirkin, Markus Armbruster, Don Slutz,
	Paolo Bonzini, Igor Mammedov, Andreas Färber

This will ensure we are actually testing the code which sets
not_used=false when the property is used.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 tests/test-qdev-global-props.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c
index 34223a7..5488937 100644
--- a/tests/test-qdev-global-props.c
+++ b/tests/test-qdev-global-props.c
@@ -164,8 +164,8 @@ static void test_dynamic_globalprop_subprocess(void)
 {
     MyType *mt;
     static GlobalProperty props[] = {
-        { TYPE_DYNAMIC_PROPS, "prop1", "101" },
-        { TYPE_DYNAMIC_PROPS, "prop2", "102" },
+        { TYPE_DYNAMIC_PROPS, "prop1", "101", true },
+        { TYPE_DYNAMIC_PROPS, "prop2", "102", true },
         { TYPE_DYNAMIC_PROPS"-bad", "prop3", "103", true },
         {}
     };
@@ -180,6 +180,9 @@ static void test_dynamic_globalprop_subprocess(void)
     g_assert_cmpuint(mt->prop2, ==, 102);
     all_used = qdev_prop_check_global();
     g_assert_cmpuint(all_used, ==, 1);
+    g_assert(!props[0].not_used);
+    g_assert(!props[1].not_used);
+    g_assert(props[2].not_used);
 }
 
 static void test_dynamic_globalprop(void)
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v3 4/6] test-qdev-global-props: Test handling of hotpluggable and non-device types
  2014-08-08 19:03 [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function Eduardo Habkost
                   ` (2 preceding siblings ...)
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 3/6] test-qdev-global-props: Initialize not_used=true for all props Eduardo Habkost
@ 2014-08-08 19:03 ` Eduardo Habkost
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 5/6] qdev: Rename qdev_prop_check_global() to qdev_prop_check_globals() Eduardo Habkost
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Eduardo Habkost @ 2014-08-08 19:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Michael S. Tsirkin, Markus Armbruster, Don Slutz,
	Paolo Bonzini, Igor Mammedov, Andreas Färber

Ensure no warning will be printed for hotpluggable types, and warnings
will be printed for non-device types.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 tests/test-qdev-global-props.c | 55 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c
index 5488937..26d8cb2 100644
--- a/tests/test-qdev-global-props.c
+++ b/tests/test-qdev-global-props.c
@@ -113,6 +113,9 @@ static void test_static_globalprop(void)
 #define DYNAMIC_TYPE(obj) \
     OBJECT_CHECK(MyType, (obj), TYPE_DYNAMIC_PROPS)
 
+#define TYPE_UNUSED_HOTPLUG   "hotplug-type"
+#define TYPE_UNUSED_NOHOTPLUG "nohotplug-type"
+
 static void prop1_accessor(Object *obj,
                            Visitor *v,
                            void *opaque,
@@ -159,6 +162,45 @@ static const TypeInfo dynamic_prop_type = {
     .class_init = dynamic_class_init,
 };
 
+static void hotplug_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->realize = NULL;
+    dc->hotpluggable = true;
+}
+
+static const TypeInfo hotplug_type = {
+    .name = TYPE_UNUSED_HOTPLUG,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(MyType),
+    .instance_init = dynamic_instance_init,
+    .class_init = hotplug_class_init,
+};
+
+static void nohotplug_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->realize = NULL;
+    dc->hotpluggable = false;
+}
+
+static const TypeInfo nohotplug_type = {
+    .name = TYPE_UNUSED_NOHOTPLUG,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(MyType),
+    .instance_init = dynamic_instance_init,
+    .class_init = nohotplug_class_init,
+};
+
+#define TYPE_NONDEVICE "nondevice-type"
+
+static const TypeInfo nondevice_type = {
+    .name = TYPE_NONDEVICE,
+    .parent = TYPE_OBJECT,
+};
+
 /* Test setting of dynamic properties using global properties */
 static void test_dynamic_globalprop_subprocess(void)
 {
@@ -167,6 +209,10 @@ static void test_dynamic_globalprop_subprocess(void)
         { TYPE_DYNAMIC_PROPS, "prop1", "101", true },
         { TYPE_DYNAMIC_PROPS, "prop2", "102", true },
         { TYPE_DYNAMIC_PROPS"-bad", "prop3", "103", true },
+        /* .not_used=false to emulate what qdev_add_one_global() does: */
+        { TYPE_UNUSED_HOTPLUG, "prop4", "104", false },
+        { TYPE_UNUSED_NOHOTPLUG, "prop5", "105", true },
+        { TYPE_NONDEVICE, "prop6", "106", true },
         {}
     };
     int all_used;
@@ -183,6 +229,9 @@ static void test_dynamic_globalprop_subprocess(void)
     g_assert(!props[0].not_used);
     g_assert(!props[1].not_used);
     g_assert(props[2].not_used);
+    g_assert(!props[3].not_used);
+    g_assert(props[4].not_used);
+    g_assert(props[5].not_used);
 }
 
 static void test_dynamic_globalprop(void)
@@ -192,6 +241,9 @@ static void test_dynamic_globalprop(void)
     g_test_trap_assert_stderr_unmatched("*prop1*");
     g_test_trap_assert_stderr_unmatched("*prop2*");
     g_test_trap_assert_stderr("*Warning: \"-global dynamic-prop-type-bad.prop3=103\" not used\n*");
+    g_test_trap_assert_stderr_unmatched("*prop4*");
+    g_test_trap_assert_stderr("*Warning: \"-global nohotplug-type.prop5=105\" not used\n*");
+    g_test_trap_assert_stderr("*Warning: \"-global nondevice-type.prop6=106\" not used\n*");
     g_test_trap_assert_stdout("");
 }
 
@@ -202,6 +254,9 @@ int main(int argc, char **argv)
     module_call_init(MODULE_INIT_QOM);
     type_register_static(&static_prop_type);
     type_register_static(&dynamic_prop_type);
+    type_register_static(&hotplug_type);
+    type_register_static(&nohotplug_type);
+    type_register_static(&nondevice_type);
 
     g_test_add_func("/qdev/properties/static/default/subprocess",
                     test_static_prop_subprocess);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v3 5/6] qdev: Rename qdev_prop_check_global() to qdev_prop_check_globals()
  2014-08-08 19:03 [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function Eduardo Habkost
                   ` (3 preceding siblings ...)
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 4/6] test-qdev-global-props: Test handling of hotpluggable and non-device types Eduardo Habkost
@ 2014-08-08 19:03 ` Eduardo Habkost
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 6/6] qdev: Move global validation to a single function Eduardo Habkost
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Eduardo Habkost @ 2014-08-08 19:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Michael S. Tsirkin, Markus Armbruster, Don Slutz,
	Paolo Bonzini, Igor Mammedov, Andreas Färber

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/core/qdev-properties.c      | 2 +-
 include/hw/qdev-properties.h   | 2 +-
 tests/test-qdev-global-props.c | 2 +-
 vl.c                           | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 3d12560..9075453 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -955,7 +955,7 @@ void qdev_prop_register_global_list(GlobalProperty *props)
     }
 }
 
-int qdev_prop_check_global(void)
+int qdev_prop_check_globals(void)
 {
     GlobalProperty *prop;
     int ret = 0;
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 77fe3a1..ae56ee5 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -177,7 +177,7 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 
 void qdev_prop_register_global(GlobalProperty *prop);
 void qdev_prop_register_global_list(GlobalProperty *props);
-int qdev_prop_check_global(void);
+int qdev_prop_check_globals(void);
 void qdev_prop_set_globals(DeviceState *dev, Error **errp);
 void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,
                                     Error **errp);
diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c
index 26d8cb2..e1b008a 100644
--- a/tests/test-qdev-global-props.c
+++ b/tests/test-qdev-global-props.c
@@ -224,7 +224,7 @@ static void test_dynamic_globalprop_subprocess(void)
 
     g_assert_cmpuint(mt->prop1, ==, 101);
     g_assert_cmpuint(mt->prop2, ==, 102);
-    all_used = qdev_prop_check_global();
+    all_used = qdev_prop_check_globals();
     g_assert_cmpuint(all_used, ==, 1);
     g_assert(!props[0].not_used);
     g_assert(!props[1].not_used);
diff --git a/vl.c b/vl.c
index a8029d5..d69b884 100644
--- a/vl.c
+++ b/vl.c
@@ -4535,7 +4535,7 @@ int main(int argc, char **argv, char **envp)
         }
     }
 
-    qdev_prop_check_global();
+    qdev_prop_check_globals();
     if (vmstate_dump_file) {
         /* dump and exit */
         dump_vmstate_json_to_file(vmstate_dump_file);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v3 6/6] qdev: Move global validation to a single function
  2014-08-08 19:03 [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function Eduardo Habkost
                   ` (4 preceding siblings ...)
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 5/6] qdev: Rename qdev_prop_check_global() to qdev_prop_check_globals() Eduardo Habkost
@ 2014-08-08 19:03 ` Eduardo Habkost
  2014-08-21 20:26 ` [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move " Eduardo Habkost
  2014-09-04 16:05 ` Michael S. Tsirkin
  7 siblings, 0 replies; 10+ messages in thread
From: Eduardo Habkost @ 2014-08-08 19:03 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Michael S. Tsirkin, Markus Armbruster, Don Slutz,
	Paolo Bonzini, Igor Mammedov, Andreas Färber

Currently GlobalProperty.not_used=false has multiple meanings:

* It may be a property for a hotpluggable device, which may or may not
  have been used by a device;
* It may be a machine-type-provided property, which may or may not have
  been used by a device.
* It may be a user-provided property that was actually not used by
  any device.

Simplify the logic by having two separate fields: 'user_provided' and
'used'. This allows the entire global property validation logic to be
contained in a single function, and allows more specific error messages.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v3:
 * Rebase to QEMU 2.1.0

Changes v2:
 * Rename qdev_prop_check_global() to qdev_prop_check_globals()
 * Don't generate any warnings from global options that were not
   user-provided
---
 hw/core/qdev-properties-system.c | 18 +----------
 hw/core/qdev-properties.c        | 28 +++++++++++++----
 include/hw/qdev-core.h           | 10 +++---
 tests/test-qdev-global-props.c   | 66 +++++++++++++++++++++++++++++++++-------
 4 files changed, 83 insertions(+), 39 deletions(-)

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index ae0900f..84caa1d 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -388,28 +388,12 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
 static int qdev_add_one_global(QemuOpts *opts, void *opaque)
 {
     GlobalProperty *g;
-    ObjectClass *oc;
 
     g = g_malloc0(sizeof(*g));
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
-    oc = object_class_dynamic_cast(object_class_by_name(g->driver),
-                                   TYPE_DEVICE);
-    if (oc) {
-        DeviceClass *dc = DEVICE_CLASS(oc);
-
-        if (dc->hotpluggable) {
-            /* If hotpluggable then skip not_used checking. */
-            g->not_used = false;
-        } else {
-            /* Maybe a typo. */
-            g->not_used = true;
-        }
-    } else {
-        /* Maybe a typo. */
-        g->not_used = true;
-    }
+    g->user_provided = true;
     qdev_prop_register_global(g);
     return 0;
 }
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 9075453..66556d3 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -961,13 +961,29 @@ int qdev_prop_check_globals(void)
     int ret = 0;
 
     QTAILQ_FOREACH(prop, &global_props, next) {
-        if (!prop->not_used) {
+        ObjectClass *oc;
+        DeviceClass *dc;
+        if (prop->used) {
+            continue;
+        }
+        if (!prop->user_provided) {
+            continue;
+        }
+        oc = object_class_by_name(prop->driver);
+        oc = object_class_dynamic_cast(oc, TYPE_DEVICE);
+        if (!oc) {
+            error_report("Warning: global %s.%s has invalid class name",
+                       prop->driver, prop->property);
+            ret = 1;
+            continue;
+        }
+        dc = DEVICE_CLASS(oc);
+        if (!dc->hotpluggable && !prop->used) {
+            error_report("Warning: global %s.%s=%s not used",
+                       prop->driver, prop->property, prop->value);
+            ret = 1;
             continue;
         }
-        ret = 1;
-        error_report("Warning: \"-global %s.%s=%s\" not used",
-                     prop->driver, prop->property, prop->value);
-
     }
     return ret;
 }
@@ -983,7 +999,7 @@ void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename,
         if (strcmp(typename, prop->driver) != 0) {
             continue;
         }
-        prop->not_used = false;
+        prop->used = true;
         object_property_parse(OBJECT(dev), prop->value, prop->property, &err);
         if (err != NULL) {
             error_propagate(errp, err);
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 0799ff2..178fee2 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -242,16 +242,16 @@ struct PropertyInfo {
 
 /**
  * GlobalProperty:
- * @not_used: Track use of a global property.  Defaults to false in all C99
- * struct initializations.
- *
- * This prevents reports of .compat_props when they are not used.
+ * @user_provided: Set to true if property comes from user-provided config
+ * (command-line or config file).
+ * @used: Set to true if property was used when initializing a device.
  */
 typedef struct GlobalProperty {
     const char *driver;
     const char *property;
     const char *value;
-    bool not_used;
+    bool user_provided;
+    bool used;
     QTAILQ_ENTRY(GlobalProperty) next;
 } GlobalProperty;
 
diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c
index e1b008a..0be9835 100644
--- a/tests/test-qdev-global-props.c
+++ b/tests/test-qdev-global-props.c
@@ -209,8 +209,7 @@ static void test_dynamic_globalprop_subprocess(void)
         { TYPE_DYNAMIC_PROPS, "prop1", "101", true },
         { TYPE_DYNAMIC_PROPS, "prop2", "102", true },
         { TYPE_DYNAMIC_PROPS"-bad", "prop3", "103", true },
-        /* .not_used=false to emulate what qdev_add_one_global() does: */
-        { TYPE_UNUSED_HOTPLUG, "prop4", "104", false },
+        { TYPE_UNUSED_HOTPLUG, "prop4", "104", true },
         { TYPE_UNUSED_NOHOTPLUG, "prop5", "105", true },
         { TYPE_NONDEVICE, "prop6", "106", true },
         {}
@@ -226,12 +225,12 @@ static void test_dynamic_globalprop_subprocess(void)
     g_assert_cmpuint(mt->prop2, ==, 102);
     all_used = qdev_prop_check_globals();
     g_assert_cmpuint(all_used, ==, 1);
-    g_assert(!props[0].not_used);
-    g_assert(!props[1].not_used);
-    g_assert(props[2].not_used);
-    g_assert(!props[3].not_used);
-    g_assert(props[4].not_used);
-    g_assert(props[5].not_used);
+    g_assert(props[0].used);
+    g_assert(props[1].used);
+    g_assert(!props[2].used);
+    g_assert(!props[3].used);
+    g_assert(!props[4].used);
+    g_assert(!props[5].used);
 }
 
 static void test_dynamic_globalprop(void)
@@ -240,10 +239,50 @@ static void test_dynamic_globalprop(void)
     g_test_trap_assert_passed();
     g_test_trap_assert_stderr_unmatched("*prop1*");
     g_test_trap_assert_stderr_unmatched("*prop2*");
-    g_test_trap_assert_stderr("*Warning: \"-global dynamic-prop-type-bad.prop3=103\" not used\n*");
+    g_test_trap_assert_stderr("*Warning: global dynamic-prop-type-bad.prop3 has invalid class name\n*");
     g_test_trap_assert_stderr_unmatched("*prop4*");
-    g_test_trap_assert_stderr("*Warning: \"-global nohotplug-type.prop5=105\" not used\n*");
-    g_test_trap_assert_stderr("*Warning: \"-global nondevice-type.prop6=106\" not used\n*");
+    g_test_trap_assert_stderr("*Warning: global nohotplug-type.prop5=105 not used\n*");
+    g_test_trap_assert_stderr("*Warning: global nondevice-type.prop6 has invalid class name\n*");
+    g_test_trap_assert_stdout("");
+}
+
+/* Test setting of dynamic properties using user_provided=false properties */
+static void test_dynamic_globalprop_nouser_subprocess(void)
+{
+    MyType *mt;
+    static GlobalProperty props[] = {
+        { TYPE_DYNAMIC_PROPS, "prop1", "101" },
+        { TYPE_DYNAMIC_PROPS, "prop2", "102" },
+        { TYPE_DYNAMIC_PROPS"-bad", "prop3", "103" },
+        { TYPE_UNUSED_HOTPLUG, "prop4", "104" },
+        { TYPE_UNUSED_NOHOTPLUG, "prop5", "105" },
+        { TYPE_NONDEVICE, "prop6", "106" },
+        {}
+    };
+    int all_used;
+
+    qdev_prop_register_global_list(props);
+
+    mt = DYNAMIC_TYPE(object_new(TYPE_DYNAMIC_PROPS));
+    qdev_init_nofail(DEVICE(mt));
+
+    g_assert_cmpuint(mt->prop1, ==, 101);
+    g_assert_cmpuint(mt->prop2, ==, 102);
+    all_used = qdev_prop_check_globals();
+    g_assert_cmpuint(all_used, ==, 0);
+    g_assert(props[0].used);
+    g_assert(props[1].used);
+    g_assert(!props[2].used);
+    g_assert(!props[3].used);
+    g_assert(!props[4].used);
+    g_assert(!props[5].used);
+}
+
+static void test_dynamic_globalprop_nouser(void)
+{
+    g_test_trap_subprocess("/qdev/properties/dynamic/global/nouser/subprocess", 0, 0);
+    g_test_trap_assert_passed();
+    g_test_trap_assert_stderr("");
     g_test_trap_assert_stdout("");
 }
 
@@ -273,6 +312,11 @@ int main(int argc, char **argv)
     g_test_add_func("/qdev/properties/dynamic/global",
                     test_dynamic_globalprop);
 
+    g_test_add_func("/qdev/properties/dynamic/global/nouser/subprocess",
+                    test_dynamic_globalprop_nouser_subprocess);
+    g_test_add_func("/qdev/properties/dynamic/global/nouser",
+                    test_dynamic_globalprop_nouser);
+
     g_test_run();
 
     return 0;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function
  2014-08-08 19:03 [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function Eduardo Habkost
                   ` (5 preceding siblings ...)
  2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 6/6] qdev: Move global validation to a single function Eduardo Habkost
@ 2014-08-21 20:26 ` Eduardo Habkost
  2014-09-04 15:37   ` Eduardo Habkost
  2014-09-04 16:05 ` Michael S. Tsirkin
  7 siblings, 1 reply; 10+ messages in thread
From: Eduardo Habkost @ 2014-08-21 20:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Michael S. Tsirkin, Markus Armbruster, Don Slutz,
	Paolo Bonzini, Igor Mammedov, Andreas Färber

Ping?

On Fri, Aug 08, 2014 at 04:03:25PM -0300, Eduardo Habkost wrote:
> New version of what was previously a single patch, submitted as:
>   Subject: [PATCH v2] qdev: Move global validation to a single function
> 
> Now the test cases run in a subprocess, and we are ensuring the warning messages
> are actually printed.
> 
> Eduardo Habkost (6):
>   test-qdev-global-props: Trivial comment fix
>   test-qdev-global-props: Run tests on subprocess
>   test-qdev-global-props: Initialize not_used=true for all props
>   test-qdev-global-props: Test handling of hotpluggable and non-device
>     types
>   qdev: Rename qdev_prop_check_global() to qdev_prop_check_globals()
>   qdev: Move global validation to a single function
> 
>  hw/core/qdev-properties-system.c |  18 +----
>  hw/core/qdev-properties.c        |  30 ++++++--
>  include/hw/qdev-core.h           |  10 +--
>  include/hw/qdev-properties.h     |   2 +-
>  tests/test-qdev-global-props.c   | 159 ++++++++++++++++++++++++++++++++++++---
>  vl.c                             |   2 +-
>  6 files changed, 180 insertions(+), 41 deletions(-)
> 
> -- 
> 1.9.3
> 
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function
  2014-08-21 20:26 ` [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move " Eduardo Habkost
@ 2014-09-04 15:37   ` Eduardo Habkost
  0 siblings, 0 replies; 10+ messages in thread
From: Eduardo Habkost @ 2014-09-04 15:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Michael S. Tsirkin, Markus Armbruster, Don Slutz,
	Paolo Bonzini, Igor Mammedov, Andreas Färber

Ping, again?

If people are too busy to review the qdev changes, can we at least get
the unit test changes included?


On Thu, Aug 21, 2014 at 05:26:15PM -0300, Eduardo Habkost wrote:
> Ping?
> 
> On Fri, Aug 08, 2014 at 04:03:25PM -0300, Eduardo Habkost wrote:
> > New version of what was previously a single patch, submitted as:
> >   Subject: [PATCH v2] qdev: Move global validation to a single function
> > 
> > Now the test cases run in a subprocess, and we are ensuring the warning messages
> > are actually printed.
> > 
> > Eduardo Habkost (6):
> >   test-qdev-global-props: Trivial comment fix
> >   test-qdev-global-props: Run tests on subprocess
> >   test-qdev-global-props: Initialize not_used=true for all props
> >   test-qdev-global-props: Test handling of hotpluggable and non-device
> >     types
> >   qdev: Rename qdev_prop_check_global() to qdev_prop_check_globals()
> >   qdev: Move global validation to a single function
> > 
> >  hw/core/qdev-properties-system.c |  18 +----
> >  hw/core/qdev-properties.c        |  30 ++++++--
> >  include/hw/qdev-core.h           |  10 +--
> >  include/hw/qdev-properties.h     |   2 +-
> >  tests/test-qdev-global-props.c   | 159 ++++++++++++++++++++++++++++++++++++---
> >  vl.c                             |   2 +-
> >  6 files changed, 180 insertions(+), 41 deletions(-)
> > 
> > -- 
> > 1.9.3
> > 
> > 
> 
> -- 
> Eduardo
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function
  2014-08-08 19:03 [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function Eduardo Habkost
                   ` (6 preceding siblings ...)
  2014-08-21 20:26 ` [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move " Eduardo Habkost
@ 2014-09-04 16:05 ` Michael S. Tsirkin
  7 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2014-09-04 16:05 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Peter Maydell, qemu-devel, Don Slutz, Markus Armbruster,
	Paolo Bonzini, Igor Mammedov, Andreas Färber

On Fri, Aug 08, 2014 at 04:03:25PM -0300, Eduardo Habkost wrote:
> New version of what was previously a single patch, submitted as:
>   Subject: [PATCH v2] qdev: Move global validation to a single function
> 
> Now the test cases run in a subprocess, and we are ensuring the warning messages
> are actually printed.

Applied, thanks!

> Eduardo Habkost (6):
>   test-qdev-global-props: Trivial comment fix
>   test-qdev-global-props: Run tests on subprocess
>   test-qdev-global-props: Initialize not_used=true for all props
>   test-qdev-global-props: Test handling of hotpluggable and non-device
>     types
>   qdev: Rename qdev_prop_check_global() to qdev_prop_check_globals()
>   qdev: Move global validation to a single function
> 
>  hw/core/qdev-properties-system.c |  18 +----
>  hw/core/qdev-properties.c        |  30 ++++++--
>  include/hw/qdev-core.h           |  10 +--
>  include/hw/qdev-properties.h     |   2 +-
>  tests/test-qdev-global-props.c   | 159 ++++++++++++++++++++++++++++++++++++---
>  vl.c                             |   2 +-
>  6 files changed, 180 insertions(+), 41 deletions(-)
> 
> -- 
> 1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-09-04 16:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-08 19:03 [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move validation to a single function Eduardo Habkost
2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 1/6] test-qdev-global-props: Trivial comment fix Eduardo Habkost
2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 2/6] test-qdev-global-props: Run tests on subprocess Eduardo Habkost
2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 3/6] test-qdev-global-props: Initialize not_used=true for all props Eduardo Habkost
2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 4/6] test-qdev-global-props: Test handling of hotpluggable and non-device types Eduardo Habkost
2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 5/6] qdev: Rename qdev_prop_check_global() to qdev_prop_check_globals() Eduardo Habkost
2014-08-08 19:03 ` [Qemu-devel] [PATCH v3 6/6] qdev: Move global validation to a single function Eduardo Habkost
2014-08-21 20:26 ` [Qemu-devel] [PATCH v3 0/6] Improve global validation test cases, move " Eduardo Habkost
2014-09-04 15:37   ` Eduardo Habkost
2014-09-04 16:05 ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).