qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qapi: Require all branches of flat union enum to be covered

We were previously enforcing that all flat union branches were
found in the corresponding enum, but not that all enum values
were covered by branches. The resulting generated code would
abort() if the user passes the uncovered enum value.

We don't automatically treat non-present branches in a flat
union as empty types, for symmetry with simple unions (there,
the enum type is generated from the list of all branches, so
there is no way to omit a branch but still have it be part of
the union).

A later patch will add shorthand so that branches that are empty
in flat unions can be declared as 'branch':{} instead of
'branch':'Empty', to avoid the need for an otherwise useless
explicit empty type. [Such shorthand for simple unions is a bit
harder to justify, since we would still have to generate a
wrapper type that parses 'data':{}, rather than truly being an
empty branch with no additional siblings to the 'type' member.]

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-3-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>

authored by

Eric Blake and committed by
Markus Armbruster
d0b18239 cebea510

+20
+8
scripts/qapi.py
··· 612 612 "enum '%s'" % 613 613 (key, enum_define["enum_name"])) 614 614 615 + # If discriminator is user-defined, ensure all values are covered 616 + if enum_define: 617 + for value in enum_define['enum_values']: 618 + if value not in members.keys(): 619 + raise QAPIExprError(expr_info, 620 + "Union '%s' data missing '%s' branch" 621 + % (name, value)) 622 + 615 623 616 624 def check_alternate(expr, expr_info): 617 625 name = expr['alternate']
+1
tests/Makefile.include
··· 326 326 qapi-schema += flat-union-base-union.json 327 327 qapi-schema += flat-union-clash-member.json 328 328 qapi-schema += flat-union-empty.json 329 + qapi-schema += flat-union-incomplete-branch.json 329 330 qapi-schema += flat-union-inline.json 330 331 qapi-schema += flat-union-int-branch.json 331 332 qapi-schema += flat-union-invalid-branch-key.json
+1
tests/qapi-schema/flat-union-incomplete-branch.err
··· 1 + tests/qapi-schema/flat-union-incomplete-branch.json:6: Union 'TestUnion' data missing 'value2' branch
+1
tests/qapi-schema/flat-union-incomplete-branch.exit
··· 1 + 1
+9
tests/qapi-schema/flat-union-incomplete-branch.json
··· 1 + # we require all branches of the union to be covered 2 + { 'enum': 'TestEnum', 3 + 'data': [ 'value1', 'value2' ] } 4 + { 'struct': 'TestTypeA', 5 + 'data': { 'string': 'str' } } 6 + { 'union': 'TestUnion', 7 + 'base': { 'type': 'TestEnum' }, 8 + 'discriminator': 'type', 9 + 'data': { 'value1': 'TestTypeA' } }
tests/qapi-schema/flat-union-incomplete-branch.out

This is a binary file and will not be displayed.