All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: "Eric Blake" <eblake@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>
Cc: Kashyap Chamarthy <kchamart@redhat.com>,
	qemu-devel@nongnu.org, libvir-list@redhat.com
Subject: Re: [Qemu-devel] [RFC] Defining firmware (OVMF, et al) metadata format & file
Date: Fri, 6 Apr 2018 20:21:00 +0200	[thread overview]
Message-ID: <721a331e-0ba9-58e2-8659-81b725a0ddff@redhat.com> (raw)
In-Reply-To: <85d1416c-c442-eaf2-c4a5-3308fd63de3a@redhat.com>

On 04/06/18 20:10, Eric Blake wrote:
> On 04/06/2018 12:28 PM, Laszlo Ersek wrote:
>
>> I've created an RFC-level "qapi/firmware.json" schema file, based on
>> this discussion. It "builds", and the generated documentation looks
>> acceptable, superficially speaking.
>>
>> Before I post "qapi/firmware.json" for getting comments, I'd like to
>> write JSON text that (a) describes firmware that I use, and (b)
>> conforms to the schema. IOW, I'd like to validate whether the schema
>> is good enough for describing at least such firmware that I know.
>>
>> Is there a tool that generates example JSON objects from a given
>> schema?
>
> I know the QMP shell (scripts/qmp/qmp-shell) lets you enter commands
> with a lot less typing than full JSON, and has a mode where it will
> then echo the full JSON command it constructed from what you typed. To
> be able to quickly validate examples, it may be sufficient to
> temporarily add a new QMP command 'check-firmware':
>
> { 'command': 'check-firmware', 'boxed': true, 'data': 'Firmware' }
>
> assuming 'Firmware' is your top-level 'struct' in the QAPI file, then
> implement a trivial:
>
> qmp_check_firmware(Firmware *obj, Error **errp) {
>     return 0;
> }
>
> so that you can then run QMP shell, and type:
>
> check-firmware arg1=foo arg2=bar ...
>
> which will then generate the corresponding JSON, then either
> successfully do nothing (what you typed validated, AND you have the
> JSON output printed), or print an error (what you typed failed QAPI
> validation, perhaps because it had an unrecognized key, was missing a
> required key, used a wrong type, etc).
>
>> I vaguely recall there used to be one. Otherwise, writing the
>> examples manually looks arduous (and I wouldn't know how to verify
>> them against the schema).
>
> Similarly, if you generate a command the produces a 'Firmware' as the
> return value, then you can populate the generated C struct (since you
> did manage to run the QAPI generator over your new file, you should be
> able to look at the C struct it generated), then output that over QMP
> to show the counterpart JSON that matches the struct as populated.
>

The top level structure is complex / nested, but that doesn't appear to
be an issue. According to the script,

# key=value pairs also support Python or JSON object literal subset notations,
# without spaces. Dictionaries/objects {} are supported as are arrays [].
#
#    example-command arg-name1={'key':'value','obj'={'prop':"value"}}
#
# Both JSON and Python formatting should work, including both styles of
# string literal quotes. Both paradigms of literal values should work,
# including null/true/false for JSON and None/True/False for Python.

This looks awesome, because it should let me provide messy nested input
(which I'll obviously compose in my $EDITOR and then paste it), and then
the QMP shell will both validate and pretty print that. I'm going to try
this.

Thank you, Eric!
Laszlo

  reply	other threads:[~2018-04-06 18:21 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-07 14:49 [Qemu-devel] [RFC] Defining firmware (OVMF, et al) metadata format & file Kashyap Chamarthy
2018-03-07 15:18 ` Daniel P. Berrangé
2018-03-08  7:52   ` Gerd Hoffmann
2018-03-08 10:17     ` Daniel P. Berrangé
2018-04-06 17:28       ` Laszlo Ersek
2018-04-06 18:10         ` Eric Blake
2018-04-06 18:21           ` Laszlo Ersek [this message]
2018-04-09  9:02             ` Kashyap Chamarthy
2018-04-09 15:32               ` Laszlo Ersek
2018-03-09 10:02     ` Kashyap Chamarthy
2018-03-08  7:45 ` Gerd Hoffmann
2018-03-08 10:16   ` Daniel P. Berrangé
2018-03-08 11:10 ` Laszlo Ersek
2018-03-08 15:47   ` Daniel P. Berrangé
2018-03-08 20:47     ` Laszlo Ersek
2018-03-09 11:27       ` Kashyap Chamarthy
2018-03-09 15:09         ` Laszlo Ersek
2018-03-12 11:17       ` Daniel P. Berrangé
2018-03-09 14:27   ` Gerd Hoffmann
2018-03-09 15:18     ` Laszlo Ersek
2018-03-12 11:13       ` Daniel P. Berrangé

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=721a331e-0ba9-58e2-8659-81b725a0ddff@redhat.com \
    --to=lersek@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kchamart@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=libvir-list@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.