Skip to contentSkip to conversation

keyval: Doc improvements and additional tests

PATCH In review Markus Armbruster 3 participants 14 messages Mar 20, 2017 – Mar 21, 2017

lore
Share & tools
lore
#0 lore raw

cover keyval: Doc improvements and additional tests

These are basically leftovers from review of "block: Command line option -blockdev". Non-test code is unchanged. Nice to have in 2.9.

Markus Armbruster (5):
test-keyval: Tweaks to improve list coverage
keyval: Improve some comments
test-keyval: Cover alternate and 'any' type
keyval: Document issues with 'any' and alternate types
MAINTAINERS: Add myself for files I touched recently

 MAINTAINERS            | 11 ++++++++++
 tests/Makefile.include |  2 +-
 tests/test-keyval.c    | 59 +++++++++++++++++++++++++++++++++++++++++++++++---
 util/keyval.c          | 57 ++++++++++++++++++++++++++++++++++--------------
 4 files changed, 109 insertions(+), 20 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/5 test-keyval: Tweaks to improve list coverage

We have a negative test case for a list index with leading zero. Add positive ones.

Tweak the test case for list index greater or equal the number of
elements: test "equal" instead of "greater" to guard against off-by-one mistakes.

---
 tests/test-keyval.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/test-keyval.c +3 -3
index 71288b0..e97f6d5 100644
@@ -218,14 +218,14 @@ static void test_keyval_parse_list(void)
     QDECREF(qdict);
 
     /* Multiple indexes, last one wins */
-    qdict = keyval_parse("list.1=goner,list.0=null,list.1=eins,list.2=zwei",
+    qdict = keyval_parse("list.1=goner,list.0=null,list.01=eins,list.2=zwei",
                          NULL, &error_abort);
     g_assert_cmpint(qdict_size(qdict), ==, 1);
     check_list012(qdict_get_qlist(qdict, "list"));
     QDECREF(qdict);
 
     /* List at deeper nesting */
-    qdict = keyval_parse("a.list.1=eins,a.list.0=null,a.list.2=zwei",
+    qdict = keyval_parse("a.list.1=eins,a.list.00=null,a.list.2=zwei",
                          NULL, &error_abort);
     g_assert_cmpint(qdict_size(qdict), ==, 1);
     sub_qdict = qdict_get_qdict(qdict, "a");
@@ -242,7 +242,7 @@ static void test_keyval_parse_list(void)
     g_assert(!qdict);
 
     /* Missing list indexes */
-    qdict = keyval_parse("list.2=lonely", NULL, &err);
+    qdict = keyval_parse("list.1=lonely", NULL, &err);
     error_free_or_abort(&err);
     g_assert(!qdict);
     qdict = keyval_parse("list.0=null,list.2=eins,list.02=zwei", NULL, &err);
Signature · 1 line
2.7.4
Reviewed-by on v1 1/5
#2 lore raw

Re: [Qemu-devel] [PATCH for-2.9 1/5] test-keyval: Tweaks to improve list coverage

Quoted 12 lines · Markus Armbruster

We have a negative test case for a list index with leading zero. Add positive ones.

Tweak the test case for list index greater or equal the number of
elements: test "equal" instead of "greater" to guard against off-by-one mistakes.

---
 tests/test-keyval.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

PATCH 2/5 keyval: Improve some comments

In reply to Markus Armbruster
---
 util/keyval.c | 47 +++++++++++++++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 16 deletions(-)
util/keyval.c +31 -16
index f646b36..46cd540 100644
@@ -21,22 +21,36 @@
  *
  * Semantics defined by reduction to JSON:
  *
- *   key-vals is a tree of objects and arrays rooted at object R
- *   where for each key-val = key-fragment . ... = val in key-vals
- *       R op key-fragment op ... = val'
- *       where (left-associative) op is
- *                 array subscript L[key-fragment] for numeric key-fragment
- *                 member reference L.key-fragment otherwise
- *             val' is val with ',,' replaced by ','
- *   and only R may be empty.
+ *   key-vals specifies a JSON object, i.e. a tree whose root is an
+ *   object, inner nodes other than the root are objects or arrays,
+ *   and leaves are strings.
  *
- *   Duplicate keys are permitted; all but the last one are ignored.
+ *   Each key-val = key-fragment '.' ... '=' val specifies a path from
+ *   root to a leaf (left of '='), and the leaf's value (right of
+ *   '=').
  *
- *   The equations must have a solution.  Counter-example: a.b=1,a=2
- *   doesn't have one, because R.a must be an object to satisfy a.b=1
- *   and a string to satisfy a=2.
+ *   A path from the root is defined recursively:
+ *       L '.' key-fragment is a child of the node denoted by path L
+ *       key-fragment is a child of the tree root
+ *   If key-fragment is numeric, the parent is an array and the child
+ *   is its key-fragment-th member, counting from zero.
+ *   Else, the parent is an object, and the child is its member named
+ *   key-fragment.
  *
- * Key-fragments must be valid QAPI names or consist only of digits.
+ *   This constrains inner nodes to be either array or object.  The
+ *   constraints must be satisfiable.  Counter-example: a.b=1,a=2 is
+ *   not, because root.a must be an object to satisfy a.b=1 and a
+ *   string to satisfy a=2.
+ *
+ *   Array subscripts can occur in any order, but the set of
+ *   subscripts must not have gaps.  For instance, a.1=v is not okay,
+ *   because root.a[0] is missing.
+ *
+ *   If multiple key-val denote the same leaf, the last one determines
+ *   the value.
+ *
+ * Key-fragments must be valid QAPI names or consist only of decimal
+ * digits.
  *
  * The length of any key-fragment must be between 1 and 127.
  *
@@ -64,8 +78,8 @@
 
 /*
  * Convert @key to a list index.
- * Convert all leading digits to a (non-negative) number, capped at
- * INT_MAX.
+ * Convert all leading decimal digits to a (non-negative) number,
+ * capped at INT_MAX.
  * If @end is non-null, assign a pointer to the first character after
  * the number to *@end.
  * Else, fail if any characters follow.
@@ -337,7 +351,8 @@ static QObject *keyval_listify(QDict *cur, GSList *key_of_cur, Error **errp)
     }
 
     /*
-     * Make a list from @elt[], reporting any missing elements.
+     * Make a list from @elt[], reporting the first missing element,
+     * if any.
      * If we dropped an index >= nelt in the previous loop, this loop
      * will run into the sentinel and report index @nelt missing.
      */
Signature · 1 line
2.7.4
Reviewed-by on v1 2/5
#4 lore raw

Re: [Qemu-devel] [PATCH for-2.9 2/5] keyval: Improve some comments

Quoted 5 lines · Markus Armbruster
---
 util/keyval.c | 47 +++++++++++++++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 16 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw

PATCH 3/5 test-keyval: Cover alternate and 'any' type

In reply to Markus Armbruster
---
 tests/Makefile.include |  2 +-
 tests/test-keyval.c    | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)
tests/Makefile.include +1 -1
index 402e71c..86f9490 100644
@@ -736,7 +736,7 @@ tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o $(test-util-obj-y) \
 	$(chardev-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
 tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y)
-tests/test-keyval$(EXESUF): tests/test-keyval.o $(test-util-obj-y)
+tests/test-keyval$(EXESUF): tests/test-keyval.o $(test-util-obj-y) $(test-qapi-obj-y)
 tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y)
 tests/test-netfilter$(EXESUF): tests/test-netfilter.o $(qtest-obj-y)
 tests/test-filter-mirror$(EXESUF): tests/test-filter-mirror.o $(qtest-obj-y)
tests/test-keyval.c +53 -0

71 lines not on this page · raw message

Signature · 1 line
2.7.4
Reviewed-by on v1 3/5
#6 lore raw

Re: [Qemu-devel] [PATCH for-2.9 3/5] test-keyval: Cover alternate and 'any' type

Quoted 6 lines · Markus Armbruster
---
 tests/Makefile.include |  2 +-
 tests/test-keyval.c    | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#7 lore raw

PATCH 4/5 keyval: Document issues with 'any' and alternate types

In reply to Markus Armbruster
---
 util/keyval.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
util/keyval.c +10 -0
index 46cd540..93d5db6 100644
@@ -61,6 +61,16 @@
  * "key absent" already means "optional object/array absent", which
  * isn't the same as "empty object/array present".
  *
+ * Design flaw: scalar values can only be strings; there is no way to
+ * denote numbers, true, false or null.  The special QObject input
+ * visitor returned by qobject_input_visitor_new_keyval() mostly hides
+ * this by automatically converting strings to the type the visitor
+ * expects.  Breaks down for alternate types and type 'any', where the
+ * visitor's expectation isn't clear.  Code visiting such types needs
+ * to do the conversion itself, but only when using this keyval
+ * visitor.  Awkward.  Alternate types without a string member don't
+ * work at all.
+ *
  * Additional syntax for use with an implied key:
  *
  *   key-vals-ik  = val-no-key [ ',' key-vals ]
Signature · 1 line
2.7.4
Reviewed-by on v1 4/5
#8 lore raw

Re: [Qemu-devel] [PATCH for-2.9 4/5] keyval: Document issues with 'any' and alternate types

Quoted 12 lines · Markus Armbruster
---
 util/keyval.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
util/keyval.c +0 -0
index 46cd540..93d5db6 100644
@@ -61,6 +61,16 @@
  * "key absent" already means "optional object/array absent", which
  * isn't the same as "empty object/array present".

util/keyval.c line 72

Quoted 10 lines
util/keyval.c +9 -0
  *
+ * Design flaw: scalar values can only be strings; there is no way to
+ * denote numbers, true, false or null.  The special QObject input
+ * visitor returned by qobject_input_visitor_new_keyval() mostly hides
+ * this by automatically converting strings to the type the visitor
+ * expects.  Breaks down for alternate types and type 'any', where the
+ * visitor's expectation isn't clear.  Code visiting such types needs
+ * to do the conversion itself, but only when using this keyval
+ * visitor.  Awkward.  Alternate types without a string member don't
+ * work at all.

We've toyed with the idea of making socket parsing accept an alternate between string and integer (right now it's string due to named port support, even though most users end up accessing an integer causing a lot of in-tree parsing/formatting between integers and strings) - that will be one case that is particularly impacted by this design flaw, if we ever go through with that idea. But enough speculation about the future - your patch as written is accurate for the present.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#9 lore raw

Re: [Qemu-devel] [PATCH for-2.9 4/5] keyval: Document issues with 'any' and alternate types

Quoted 22 lines · Eric Blake
Quoted 21 lines · Markus Armbruster
---
 util/keyval.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
util/keyval.c +8 -0
index 46cd540..93d5db6 100644
@@ -61,6 +61,16 @@
  * "key absent" already means "optional object/array absent", which
  * isn't the same as "empty object/array present".
  *
+ * Design flaw: scalar values can only be strings; there is no way to
+ * denote numbers, true, false or null.  The special QObject input
+ * visitor returned by qobject_input_visitor_new_keyval() mostly hides
+ * this by automatically converting strings to the type the visitor
+ * expects.  Breaks down for alternate types and type 'any', where the
+ * visitor's expectation isn't clear.  Code visiting such types needs
+ * to do the conversion itself, but only when using this keyval
+ * visitor.  Awkward.  Alternate types without a string member don't
Quoted 8 lines

util/keyval.c line 72

Quoted 1 line
util/keyval.c +1 -0
+ * work at all.

We've toyed with the idea of making socket parsing accept an alternate between string and integer (right now it's string due to named port support, even though most users end up accessing an integer causing a lot of in-tree parsing/formatting between integers and strings) - that will be one case that is particularly impacted by this design flaw, if we ever go through with that idea.

I'll reply to this in "Re: Non-flat command line option argument syntax".

Quoted 4 lines

But enough speculation about the
future - your patch as written is accurate for the present.

Thanks!

#10 lore raw

PATCH 5/5 MAINTAINERS: Add myself for files I touched recently

In reply to Markus Armbruster
---
 MAINTAINERS | 11 +++++++++++
 1 file changed, 11 insertions(+)
MAINTAINERS +11 -0
index bf1aafb..3f20288 100644
@@ -1218,6 +1218,15 @@ M: Samuel Thibault <[email protected]>
 S: Maintained
 F: backends/baum.c
 
+Command line option argument parsing
+M: Markus Armbruster <[email protected]>
+S: Supported
+F: include/qemu/option.h
+F: tests/test-keyval.c
+F: tests/test-qemu-opts.c
+F: util/keyval.c
+F: util/qemu-option.c
+
 Coverity model
 M: Markus Armbruster <[email protected]>
 S: Supported
@@ -1352,7 +1361,9 @@ X: include/qapi/qmp/
 F: include/qapi/qmp/dispatch.h
 F: tests/qapi-schema/
 F: tests/test-*-visitor.c
+F: tests/test-qapi-*.c
 F: tests/test-qmp-*.c
+F: tests/test-visitor-serialization.c
 F: scripts/qapi*
 F: docs/qapi*
 T: git git://repo.or.cz/qemu/armbru.git qapi-next
Signature · 1 line
2.7.4
Reviewed-by on v1 5/5
#11 lore raw

Re: [Qemu-devel] [PATCH for-2.9 5/5] MAINTAINERS: Add myself for files I touched recently

Quoted 4 lines · Markus Armbruster
---
 MAINTAINERS | 11 +++++++++++
 1 file changed, 11 insertions(+)

By the way, where do we stand on the idea of having checkpatch.pl reject patches that introduce new files without mentioning a maintainer?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#12 lore raw

Re: [Qemu-devel] [PATCH for-2.9 5/5] MAINTAINERS: Add myself for files I touched recently

Quoted 10 lines · Eric Blake
Quoted 4 lines · Markus Armbruster
---
 MAINTAINERS | 11 +++++++++++
 1 file changed, 11 insertions(+)

By the way, where do we stand on the idea of having checkpatch.pl reject patches that introduce new files without mentioning a maintainer?

Stuck. Thomas hasn't followed up on his RFC PATCH because he's afraid of false positives. I encouraged him to rescue at least "[RFC PATCH 4/5] checkpatch: emit a reminder about MAINTAINERS on file add/move/delete", and I'm now encouraging him again.

#13 lore raw

Re: [Qemu-devel] [PATCH for-2.9 5/5] MAINTAINERS: Add myself for files I touched recently

Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Eric Blake
Quoted 4 lines · Markus Armbruster
---
 MAINTAINERS | 11 +++++++++++
 1 file changed, 11 insertions(+)
Quoted 7 lines
Quoted 2 lines

By the way, where do we stand on the idea of having checkpatch.pl reject patches that introduce new files without mentioning a maintainer?

Stuck. Thomas hasn't followed up on his RFC PATCH because he's afraid of false positives. I encouraged him to rescue at least "[RFC PATCH 4/5] checkpatch: emit a reminder about MAINTAINERS on file add/move/delete", and I'm now encouraging him again.

Well, the patch series is out there, and there haven't been any (valid) requests to rework it, so if you like, feel free to merge it:

https://lists.gnu.org/archive/html/qemu-devel/2017-01/msg05740.html

But as mentioned here:

https://lists.gnu.org/archive/html/qemu-devel/2017-01/msg05753.html

there will be quite a bunch of false-positives. So we'd either have to live with those or we have to come up with a smarter approach to handle this issue (e.g. by running get_maintainers.pl on the affected files).

Thomas