Test for partial path lookup using object_resolve_path*().
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
index 8e432e9..abafbd7 100644
--- a/tests/check-qom-proplist.c
+++ b/tests/check-qom-proplist.c
@@ -568,6 +568,46 @@ static void test_dummy_delchild(void)
object_unparent(OBJECT(dev));
}
+static void test_qom_partial_path(void)
+{
+ Object *root = object_get_objects_root();
+ Object *cont1 = container_get(root, "/cont1");
+ Object *obj1 = object_new(TYPE_DUMMY);
+ Object *obj2a = object_new(TYPE_DUMMY);
+ Object *obj2b = object_new(TYPE_DUMMY);
+ bool ambiguous;
+
+ /* Objects created:
+ * /cont1
+ * /cont1/obj1
+ * /cont1/obj2 (obj2a)
+ * /obj2 (obj2b)
+ */
+ object_property_add_child(cont1, "obj1", obj1, &error_abort);
+ object_unref(obj1);
+ object_property_add_child(cont1, "obj2", obj2a, &error_abort);
+ object_unref(obj2a);
+ object_property_add_child(root, "obj2", obj2b, &error_abort);
+ object_unref(obj2b);
+
+ ambiguous = false;
+ g_assert(!object_resolve_path_type("", TYPE_DUMMY, &ambiguous));
+ g_assert(ambiguous);
+
+ ambiguous = false;
+ g_assert(!object_resolve_path("obj2", &ambiguous));
+ g_assert(ambiguous);
+
+ ambiguous = false;
+ g_assert(object_resolve_path("obj1", &ambiguous) == obj1);
+ g_assert(!ambiguous);
+
+ object_unparent(obj1);
+ object_unparent(obj2a);
+ object_unparent(obj2b);
+ object_unparent(cont1);
+}
+
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
@@ -585,6 +625,7 @@ int main(int argc, char **argv)
g_test_add_func("/qom/proplist/getenum", test_dummy_getenum);
g_test_add_func("/qom/proplist/iterator", test_dummy_iterator);
g_test_add_func("/qom/proplist/delchild", test_dummy_delchild);
+ g_test_add_func("/qom/resolve/partial", test_qom_partial_path);
return g_test_run();
}
--
2.9.4
On Fri, 7 Jul 2017 18:30:51 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:
> Test for partial path lookup using object_resolve_path*().
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
> diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> index 8e432e9..abafbd7 100644
> --- a/tests/check-qom-proplist.c
> +++ b/tests/check-qom-proplist.c
> @@ -568,6 +568,46 @@ static void test_dummy_delchild(void)
> object_unparent(OBJECT(dev));
> }
>
> +static void test_qom_partial_path(void)
> +{
> + Object *root = object_get_objects_root();
> + Object *cont1 = container_get(root, "/cont1");
> + Object *obj1 = object_new(TYPE_DUMMY);
> + Object *obj2a = object_new(TYPE_DUMMY);
> + Object *obj2b = object_new(TYPE_DUMMY);
> + bool ambiguous;
> +
> + /* Objects created:
> + * /cont1
> + * /cont1/obj1
> + * /cont1/obj2 (obj2a)
> + * /obj2 (obj2b)
> + */
> + object_property_add_child(cont1, "obj1", obj1, &error_abort);
> + object_unref(obj1);
> + object_property_add_child(cont1, "obj2", obj2a, &error_abort);
> + object_unref(obj2a);
> + object_property_add_child(root, "obj2", obj2b, &error_abort);
> + object_unref(obj2b);
> +
> + ambiguous = false;
> + g_assert(!object_resolve_path_type("", TYPE_DUMMY, &ambiguous));
> + g_assert(ambiguous);
> +
> + ambiguous = false;
> + g_assert(!object_resolve_path("obj2", &ambiguous));
> + g_assert(ambiguous);
> +
> + ambiguous = false;
> + g_assert(object_resolve_path("obj1", &ambiguous) == obj1);
> + g_assert(!ambiguous);
I'd also add test case for
object_resolve_path(..., NULL)
> +
> + object_unparent(obj1);
> + object_unparent(obj2a);
> + object_unparent(obj2b);
Are above unparenting is necessary?
> + object_unparent(cont1);
Wouldn't parent destruction sufficient to trigger
implicit destruction of children?
> +}
> +
> int main(int argc, char **argv)
> {
> g_test_init(&argc, &argv, NULL);
> @@ -585,6 +625,7 @@ int main(int argc, char **argv)
> g_test_add_func("/qom/proplist/getenum", test_dummy_getenum);
> g_test_add_func("/qom/proplist/iterator", test_dummy_iterator);
> g_test_add_func("/qom/proplist/delchild", test_dummy_delchild);
> + g_test_add_func("/qom/resolve/partial", test_qom_partial_path);
>
> return g_test_run();
> }
On Mon, Jul 10, 2017 at 10:10:41AM +0200, Igor Mammedov wrote:
> On Fri, 7 Jul 2017 18:30:51 -0300
> Eduardo Habkost <ehabkost@redhat.com> wrote:
>
> > Test for partial path lookup using object_resolve_path*().
> >
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> > tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 41 insertions(+)
> >
> > diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> > index 8e432e9..abafbd7 100644
> > --- a/tests/check-qom-proplist.c
> > +++ b/tests/check-qom-proplist.c
> > @@ -568,6 +568,46 @@ static void test_dummy_delchild(void)
> > object_unparent(OBJECT(dev));
> > }
> >
> > +static void test_qom_partial_path(void)
> > +{
> > + Object *root = object_get_objects_root();
> > + Object *cont1 = container_get(root, "/cont1");
> > + Object *obj1 = object_new(TYPE_DUMMY);
> > + Object *obj2a = object_new(TYPE_DUMMY);
> > + Object *obj2b = object_new(TYPE_DUMMY);
> > + bool ambiguous;
> > +
> > + /* Objects created:
> > + * /cont1
> > + * /cont1/obj1
> > + * /cont1/obj2 (obj2a)
> > + * /obj2 (obj2b)
> > + */
> > + object_property_add_child(cont1, "obj1", obj1, &error_abort);
> > + object_unref(obj1);
> > + object_property_add_child(cont1, "obj2", obj2a, &error_abort);
> > + object_unref(obj2a);
> > + object_property_add_child(root, "obj2", obj2b, &error_abort);
> > + object_unref(obj2b);
> > +
> > + ambiguous = false;
> > + g_assert(!object_resolve_path_type("", TYPE_DUMMY, &ambiguous));
> > + g_assert(ambiguous);
> > +
> > + ambiguous = false;
> > + g_assert(!object_resolve_path("obj2", &ambiguous));
> > + g_assert(ambiguous);
> > +
> > + ambiguous = false;
> > + g_assert(object_resolve_path("obj1", &ambiguous) == obj1);
> > + g_assert(!ambiguous);
>
> I'd also add test case for
> object_resolve_path(..., NULL)
They are added by patch 2/2, after the bug is fixed.
>
> > +
> > + object_unparent(obj1);
> > + object_unparent(obj2a);
> > + object_unparent(obj2b);
> Are above unparenting is necessary?
>
> > + object_unparent(cont1);
> Wouldn't parent destruction sufficient to trigger
> implicit destruction of children?
Probably it is. I will test it.
--
Eduardo
On Mon, 10 Jul 2017 11:45:57 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:
> On Mon, Jul 10, 2017 at 10:10:41AM +0200, Igor Mammedov wrote:
> > On Fri, 7 Jul 2017 18:30:51 -0300
> > Eduardo Habkost <ehabkost@redhat.com> wrote:
> >
> > > Test for partial path lookup using object_resolve_path*().
> > >
> > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > ---
> > > tests/check-qom-proplist.c | 41 +++++++++++++++++++++++++++++++++++++++++
> > > 1 file changed, 41 insertions(+)
> > >
> > > diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> > > index 8e432e9..abafbd7 100644
> > > --- a/tests/check-qom-proplist.c
> > > +++ b/tests/check-qom-proplist.c
> > > @@ -568,6 +568,46 @@ static void test_dummy_delchild(void)
> > > object_unparent(OBJECT(dev));
> > > }
> > >
> > > +static void test_qom_partial_path(void)
> > > +{
> > > + Object *root = object_get_objects_root();
> > > + Object *cont1 = container_get(root, "/cont1");
> > > + Object *obj1 = object_new(TYPE_DUMMY);
> > > + Object *obj2a = object_new(TYPE_DUMMY);
> > > + Object *obj2b = object_new(TYPE_DUMMY);
> > > + bool ambiguous;
> > > +
> > > + /* Objects created:
> > > + * /cont1
> > > + * /cont1/obj1
> > > + * /cont1/obj2 (obj2a)
> > > + * /obj2 (obj2b)
> > > + */
> > > + object_property_add_child(cont1, "obj1", obj1, &error_abort);
> > > + object_unref(obj1);
> > > + object_property_add_child(cont1, "obj2", obj2a, &error_abort);
> > > + object_unref(obj2a);
> > > + object_property_add_child(root, "obj2", obj2b, &error_abort);
> > > + object_unref(obj2b);
> > > +
> > > + ambiguous = false;
> > > + g_assert(!object_resolve_path_type("", TYPE_DUMMY, &ambiguous));
> > > + g_assert(ambiguous);
> > > +
> > > + ambiguous = false;
> > > + g_assert(!object_resolve_path("obj2", &ambiguous));
> > > + g_assert(ambiguous);
> > > +
> > > + ambiguous = false;
> > > + g_assert(object_resolve_path("obj1", &ambiguous) == obj1);
> > > + g_assert(!ambiguous);
> >
> > I'd also add test case for
> > object_resolve_path(..., NULL)
>
> They are added by patch 2/2, after the bug is fixed.
>
> >
> > > +
> > > + object_unparent(obj1);
> > > + object_unparent(obj2a);
> > > + object_unparent(obj2b);
> > Are above unparenting is necessary?
> >
> > > + object_unparent(cont1);
> > Wouldn't parent destruction sufficient to trigger
> > implicit destruction of children?
>
> Probably it is. I will test it.
It would be better to avoid not necessary calls if it works,
but either way:
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
On Mon, Jul 10, 2017 at 11:45:57AM -0300, Eduardo Habkost wrote:
> On Mon, Jul 10, 2017 at 10:10:41AM +0200, Igor Mammedov wrote:
> > On Fri, 7 Jul 2017 18:30:51 -0300
> > Eduardo Habkost <ehabkost@redhat.com> wrote:
[...]
> > > +
> > > + object_unparent(obj1);
> > > + object_unparent(obj2a);
> > > + object_unparent(obj2b);
> > Are above unparenting is necessary?
> >
> > > + object_unparent(cont1);
> > Wouldn't parent destruction sufficient to trigger
> > implicit destruction of children?
>
> Probably it is. I will test it.
The obj1 and obj2a object_unparent() calls are really
unnecessary. object_unparent(obj2b) is still necessary because
it is attached direcly to root.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
tests/check-qom-proplist.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
index 381532c..432b665 100644
--- a/tests/check-qom-proplist.c
+++ b/tests/check-qom-proplist.c
@@ -605,8 +605,6 @@ static void test_qom_partial_path(void)
g_assert(!ambiguous);
g_assert(object_resolve_path("obj1", NULL) == obj1);
- object_unparent(obj1);
- object_unparent(obj2a);
object_unparent(obj2b);
object_unparent(cont1);
}
--
2.9.4
--
Eduardo
On Mon, 10 Jul 2017 12:33:31 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:
> On Mon, Jul 10, 2017 at 11:45:57AM -0300, Eduardo Habkost wrote:
> > On Mon, Jul 10, 2017 at 10:10:41AM +0200, Igor Mammedov wrote:
> > > On Fri, 7 Jul 2017 18:30:51 -0300
> > > Eduardo Habkost <ehabkost@redhat.com> wrote:
> [...]
> > > > +
> > > > + object_unparent(obj1);
> > > > + object_unparent(obj2a);
> > > > + object_unparent(obj2b);
> > > Are above unparenting is necessary?
> > >
> > > > + object_unparent(cont1);
> > > Wouldn't parent destruction sufficient to trigger
> > > implicit destruction of children?
> >
> > Probably it is. I will test it.
>
> The obj1 and obj2a object_unparent() calls are really
> unnecessary. object_unparent(obj2b) is still necessary because
> it is attached direcly to root.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
> tests/check-qom-proplist.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c
> index 381532c..432b665 100644
> --- a/tests/check-qom-proplist.c
> +++ b/tests/check-qom-proplist.c
> @@ -605,8 +605,6 @@ static void test_qom_partial_path(void)
> g_assert(!ambiguous);
> g_assert(object_resolve_path("obj1", NULL) == obj1);
>
> - object_unparent(obj1);
> - object_unparent(obj2a);
> object_unparent(obj2b);
> object_unparent(cont1);
> }
© 2016 - 2025 Red Hat, Inc.