qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Victor Toso <victortoso@redhat.com>
Cc: qemu-devel@nongnu.org,  Eric Blake <eblake@redhat.com>,
	 John Snow <jsnow@redhat.com>,
	 Michael Roth <michael.roth@amd.com>
Subject: Re: [PATCH v1 16/16] RFC: add a generator for qapi's examples
Date: Wed, 31 Aug 2022 16:57:20 +0200	[thread overview]
Message-ID: <87sflc5ulr.fsf@pond.sub.org> (raw)
In-Reply-To: <20220831133255.os2xaxtkolbvmcq5@tapioca> (Victor Toso's message of "Wed, 31 Aug 2022 15:32:55 +0200")

Victor Toso <victortoso@redhat.com> writes:

> Hi,
>
> On Wed, Aug 31, 2022 at 02:01:54PM +0200, Markus Armbruster wrote:
>> Victor Toso <victortoso@redhat.com> writes:
>>
>> > The goal of this generator is to validate QAPI examples and transform
>> > them into a format that can be used for 3rd party applications to
>> > validate their QAPI/QMP introspection.
>> >
>> > For each Example section, we parse server and client messages into a
>> > python dictionary. This step alone has found several ill formatted
>> > JSON messages in the examples.
>> >
>> > The generator outputs another JSON file with all the examples in the
>> > QAPI module that they came from. This can be used to validate the
>> > introspection between QAPI/QMP to language bindings.
>> >
>> > When used with the POC qapi-go branch, we have found bad QMP messages
>> > with wrong member names, mandatory members that were missing and
>> > optional members that were being set with null (not needed).
>> >
>> > A simple example of the output format is:
>> >
>> >  { "examples": [
>> >    {
>> >      "id": "ksuxwzfayw",
>> >      "client": [
>> >      {
>> >        "sequence-order": 1
>> >        "message-type": "command",
>> >        "message":
>> >        { "arguments":
>> >          { "device": "scratch", "size": 1073741824 },
>> >          "execute": "block_resize"
>> >        },
>> >     } ],
>> >     "server": [
>> >     {
>> >       "sequence-order": 2
>> >       "message-type": "return",
>> >       "message": { "return": {} },
>> >     } ]
>> >     }
>> >   ] }
>> >
>> > If this idea seems reasonable, we can add python-qemu-qmp to validate
>> > each message at generation time already.
>> >
>> > Signed-off-by: Victor Toso <victortoso@redhat.com>
>>
>> If I understand you correctly, there are two benefits:
>>
>> 1. Mechanical syntax check for examples
>>
>>    Love it.
>
> Not just JSON syntax but can be extend to the introspection
> layer. Errors like wrong member names would fail while parsing
> the examples (issues such as fixed by patches 11 and 13/16 should
> not happen anymore).

It's also a mechanical check against the schema.  Still love it :)

>> 2. Can extract examples for use as test cases
>>
>>    Sounds good to me.  Possible redundancy with existing tests.
>>    Probably nothing to worry about.
>>
>>    Can you explain in a bit more detail how the extracted data
>>    is (to be) used?
>
> Sure.
>
> The Golang test that consumes this is 152 lines of code [0]. The
> idea is that we can use the examples to feed Golang unmarshalling
> code and then marshall it back to JSON and compare input JSON
> with output JSON and see that their content matches.
>
> [0] https://gitlab.com/victortoso/qapi-go/-/blob/wip-v3/test/examples_test.go
>
> I have generated the examples with this patch series and stored
> the output here [1]
>
> [1] https://gitlab.com/victortoso/qapi-go/-/tree/wip-v3/test/data/examples
>
> The examples are QMP messages that are either sent by Client "->"
> or sent by Server "<-". The order matters so I take the order set
> in the examples and store it as "sequence-order".
>
> In the Go test code, I follow the sequence-order. One example of
> this being useful is that we know which Return type to expect
> after a Command is issued.
>
> I've also included metadata about the type of message, which is
> one of three options: command, event or return. (Errors are
> return too).
>
> This is important because it makes the tests very easy to write.
> Different Unmarshal/Marshal code can be set in the code block of
> the specific message type.
>
> --
>
> The things that makes me quite excited with this idea are:
>
>  1. We have valid functional examples documented. If the examples
>     break, we would have the software in place to know it (plug
>     to ci or some other ninja check seems reasonable to me)
>
>  2. Developers should get more interested in documenting examples
>     as that alone is is a valid test case, even if only useful
>     for language binding's syntax.

Thanks!  Would you like to work some of this into your commit message?



  reply	other threads:[~2022-08-31 14:59 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 16:15 [PATCH v1 00/16] qapi examples fixes and rfc for another generator Victor Toso
2022-08-30 16:15 ` [PATCH v1 01/16] qapi: fix example of query-ballon command Victor Toso
2022-08-30 16:15 ` [PATCH v1 02/16] qapi: fix example of query-vnc command Victor Toso
2022-08-30 16:15 ` [PATCH v1 03/16] qapi: fix example of query-spice command Victor Toso
2022-08-31 11:50   ` Markus Armbruster
2022-08-31 12:55     ` Victor Toso
2022-08-31 13:22       ` Markus Armbruster
2022-09-01 14:08         ` Gerd Hoffmann
2022-08-30 16:15 ` [PATCH v1 04/16] qapi: fix example of query-rocker-of-dpa-flows command Victor Toso
2022-08-31 11:51   ` Markus Armbruster
2022-08-30 16:15 ` [PATCH v1 05/16] qapi: fix example of query-dump-guest-memory-capability command Victor Toso
2022-08-30 16:15 ` [PATCH v1 06/16] qapi: fix example of query-blockstats command Victor Toso
2022-08-30 16:15 ` [PATCH v1 07/16] qapi: fix example of BLOCK_JOB_READY event Victor Toso
2022-08-30 16:15 ` [PATCH v1 08/16] qapi: fix example of NIC_RX_FILTER_CHANGED event Victor Toso
2022-08-31 11:37   ` Markus Armbruster
2022-08-30 16:15 ` [PATCH v1 09/16] qapi: fix example of DEVICE_UNPLUG_GUEST_ERROR event Victor Toso
2022-08-30 16:15 ` [PATCH v1 10/16] qapi: fix example of MEM_UNPLUG_ERROR event Victor Toso
2022-08-30 16:15 ` [PATCH v1 11/16] qapi: fix examples of blockdev-add with qcow2 Victor Toso
2022-08-30 16:15 ` [PATCH v1 12/16] qapi: fix example of blockdev-add command Victor Toso
2022-08-31 11:40   ` Markus Armbruster
2022-08-31 12:45     ` Victor Toso
2022-08-31 13:16       ` Markus Armbruster
2022-08-31 13:47         ` Victor Toso
2022-08-31 14:53           ` Markus Armbruster
2022-09-01  7:56             ` Victor Toso
2022-09-01 11:13               ` Markus Armbruster
2022-09-02  8:02                 ` Victor Toso
2022-08-30 16:15 ` [PATCH v1 13/16] qapi: fix example of query-hotpluggable-cpus command Victor Toso
2022-08-30 16:15 ` [PATCH v1 14/16] qapi: fix example of query-migrate command Victor Toso
2022-08-31 11:52   ` Markus Armbruster
2022-08-30 16:15 ` [PATCH v1 15/16] qapi: fix examples of events missing timestamp Victor Toso
2022-08-30 16:15 ` [PATCH v1 16/16] RFC: add a generator for qapi's examples Victor Toso
2022-08-31 12:01   ` Markus Armbruster
2022-08-31 13:32     ` Victor Toso
2022-08-31 14:57       ` Markus Armbruster [this message]
2022-09-01  8:37         ` Victor Toso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sflc5ulr.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=qemu-devel@nongnu.org \
    --cc=victortoso@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).