From: Eric Blake <eblake@redhat.com>
To: Max Reitz <mreitz@redhat.com>, qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
Kevin Wolf <kwolf@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH 03/13] tests: Add QAPI optional discriminator tests
Date: Thu, 10 May 2018 09:08:39 -0500 [thread overview]
Message-ID: <ec3886fb-04df-5ee1-5796-12d415335a02@redhat.com> (raw)
In-Reply-To: <20180509165530.29561-4-mreitz@redhat.com>
On 05/09/2018 11:55 AM, Max Reitz wrote:
> There already is an optional discriminator test, although it also noted
> the discriminator name itself as optional. Changing that, and adding a
> default-variant field, makes that test pass instead of failing.
I'm not sure I agree with that one. I think that you should instead add
a positive test of a default variant into qapi-schema-test.json,
especially since that is the one positive test where we also ensure that
the C compiler is happy with the generated code (other positive tests
prove that the generator produced something without error, but not that
what it produced could be compiled).
> 17 files changed, 61 insertions(+), 4 deletions(-)
> create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-invalid-default.json
> create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-no-default.json
> create mode 100644 tests/qapi-schema/flat-union-superfluous-default-variant.json
> create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-invalid-default.err
> create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-invalid-default.exit
> create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-invalid-default.out
> create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-no-default.err
> create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-no-default.exit
> create mode 100644 tests/qapi-schema/flat-union-optional-discriminator-no-default.out
> create mode 100644 tests/qapi-schema/flat-union-superfluous-default-variant.err
> create mode 100644 tests/qapi-schema/flat-union-superfluous-default-variant.exit
> create mode 100644 tests/qapi-schema/flat-union-superfluous-default-variant.out
Patch 1 converted 2 error messages into 6, where 2 of them look identical:
>> - # The value of member 'discriminator' must name a non-optional
>> - # member of the base struct.
>> + # The value of member 'discriminator' must name a member of
>> + # the base struct.
>> check_name(info, "Discriminator of flat union '%s'" % name,
>> discriminator)
[0] check_name() checks that 'discriminator':'*name' is rejected - this
check is unchanged
>> - discriminator_type = base_members.get(discriminator)
>> - if not discriminator_type:
>> - raise QAPISemError(info,
>> - "Discriminator '%s' is not a member of base "
>> - "struct '%s'"
>> - % (discriminator, base))
The old code ensured that 'discriminator':'name' finds 'name' as a
mandatory field in the base type; which changed into:
>> + if default_variant is None:
>> + discriminator_type = base_members.get(discriminator)
>> + if not discriminator_type:
>> + if base_members.get('*' + discriminator) is None:
>> + raise QAPISemError(info,
>> + "Discriminator '%s' is not a member of "
>> + "base struct '%s'"
>> + % (discriminator, base))
[1] the discriminator type must be a member field (we didn't find either
a mandatory or an optional field)
>> + else:
>> + raise QAPISemError(info,
>> + "Default variant must be specified for "
>> + "optional discriminator '%s'"
>> + % discriminator)
[2] without default_variant, the member field must be mandatory
>> + else:
>> + discriminator_type = base_members.get('*' + discriminator)
>> + if not discriminator_type:
>> + if base_members.get(discriminator) is None:
>> + raise QAPISemError(info,
>> + "Discriminator '%s' is not a member of "
>> + "base struct '%s'"
>> + % (discriminator, base))
[3] the discriminator type must be a member field (we didn't find either
a mandatory or an optional field), identical message to [1]
>> + else:
>> + raise QAPISemError(info,
>> + "Must not specify a default variant for "
>> + "non-optional discriminator '%s'"
>> + % discriminator)
[4] with default_variant, the member field must be optional
>> +
>> enum_define = enum_types.get(discriminator_type)
>> allow_metas = ['struct']
>> # Do not allow string discriminator
>> @@ -763,6 +785,15 @@ def check_union(expr, info):
>> "Discriminator '%s' must be of enumeration "
>> "type" % discriminator)
>>
>> + if default_variant is not None:
>> + # Must be a value of the enumeration
>> + if default_variant not in enum_define['data']:
>> + raise QAPISemError(info,
>> + "Default variant '%s' of flat union '%s' is "
>> + "not part of '%s'"
>> + % (default_variant, name,
>> + discriminator_type))
>> +
[5] the default discriminator value must belong to the discriminator's type
Of those 6 messages, you now have coverage of:
>
> +++ b/tests/Makefile.include
> @@ -500,7 +500,10 @@ qapi-schema += flat-union-invalid-branch-key.json
> qapi-schema += flat-union-invalid-discriminator.json
[1] no change to that test
> qapi-schema += flat-union-no-base.json
> qapi-schema += flat-union-optional-discriminator.json
the old test for [0] - you turned it into success. See more below...
> +qapi-schema += flat-union-optional-discriminator-no-default.json
new test for [2]
> +qapi-schema += flat-union-optional-discriminator-invalid-default.json
new test for [5]
> qapi-schema += flat-union-string-discriminator.json
> +qapi-schema += flat-union-superfluous-default-variant.json
new test for [4]
I don't know if it is worth trying to explicitly test for [3], given
that it is identical to [1], but the loss of the test for [0] bothers me.
> +++ b/tests/qapi-schema/flat-union-optional-discriminator.err
> @@ -1 +0,0 @@
> -tests/qapi-schema/flat-union-optional-discriminator.json:6: Discriminator of flat union 'MyUnion' does not allow optional name '*switch'
This used to be covered by [0] - but you rewrote the test by changing
'discriminator':'*switch' to 'discriminator':'switch'.
I'd argue that you WANT to keep 'discriminator':'*switch' in this test,
to keep the testing of error [0] (even when the discriminator type is
optional, we spell it without leading '*' in the 'union' description),
and then only qapi-schema-test.json gets a positive test, which also
gives us the additional coverage that the C compiler likes our generated
code.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2018-05-10 14:08 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-09 16:55 [Qemu-devel] [PATCH 00/13] block: Try to create well typed json:{} filenames Max Reitz
2018-05-09 16:55 ` [Qemu-devel] [PATCH 01/13] qapi: Add default-variant for flat unions Max Reitz
2018-05-10 13:12 ` Eric Blake
2018-05-10 13:18 ` Eric Blake
2018-05-11 17:59 ` Max Reitz
2018-05-11 18:13 ` Eric Blake
2018-05-11 17:38 ` Max Reitz
2018-05-09 16:55 ` [Qemu-devel] [PATCH 02/13] docs/qapi: Document optional discriminators Max Reitz
2018-05-10 13:14 ` Eric Blake
2018-05-09 16:55 ` [Qemu-devel] [PATCH 03/13] tests: Add QAPI optional discriminator tests Max Reitz
2018-05-10 14:08 ` Eric Blake [this message]
2018-05-11 18:06 ` Max Reitz
2018-05-09 16:55 ` [Qemu-devel] [PATCH 04/13] qapi: Formalize qcow2 encryption probing Max Reitz
2018-05-10 7:58 ` Daniel P. Berrangé
2018-05-10 14:22 ` Eric Blake
2018-05-11 17:32 ` Max Reitz
2018-05-09 16:55 ` [Qemu-devel] [PATCH 05/13] qapi: Formalize qcow " Max Reitz
2018-05-10 14:24 ` Eric Blake
2018-05-10 14:32 ` Daniel P. Berrangé
2018-05-11 18:07 ` Max Reitz
2018-05-09 16:55 ` [Qemu-devel] [PATCH 06/13] block: Add block-specific QDict header Max Reitz
2018-05-10 14:54 ` Eric Blake
2018-05-11 18:11 ` Max Reitz
2018-06-06 13:10 ` Markus Armbruster
2018-06-06 13:17 ` Markus Armbruster
2018-06-06 14:19 ` Markus Armbruster
2018-06-06 14:35 ` Markus Armbruster
2018-05-09 16:55 ` [Qemu-devel] [PATCH 07/13] qdict: Add qdict_stringify_for_keyval() Max Reitz
2018-05-11 18:39 ` Eric Blake
2018-05-11 21:42 ` Max Reitz
2018-05-09 16:55 ` [Qemu-devel] [PATCH 08/13] tests: Add qdict_stringify_for_keyval() test Max Reitz
2018-05-10 16:02 ` Eric Blake
2018-05-11 18:13 ` Max Reitz
2018-05-11 18:33 ` Eric Blake
2018-05-09 16:55 ` [Qemu-devel] [PATCH 09/13] qdict: Make qdict_flatten() shallow-clone-friendly Max Reitz
2018-05-11 18:44 ` Eric Blake
2018-05-09 16:55 ` [Qemu-devel] [PATCH 10/13] tests: Add QDict clone-flatten test Max Reitz
2018-05-11 18:46 ` Eric Blake
2018-05-11 21:41 ` Max Reitz
2018-05-09 16:55 ` [Qemu-devel] [PATCH 11/13] block: Try to create well typed json:{} filenames Max Reitz
2018-05-09 16:55 ` [Qemu-devel] [PATCH 12/13] iotests: Test internal option typing Max Reitz
2018-05-09 16:55 ` [Qemu-devel] [PATCH 13/13] iotests: qcow2's encrypt.format is now optional Max Reitz
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=ec3886fb-04df-5ee1-5796-12d415335a02@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--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 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).