qapi: Test for various name collisions
authorEric Blake <eblake@redhat.com>
Tue, 29 Sep 2015 22:21:03 +0000 (16:21 -0600)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 12 Oct 2015 16:44:54 +0000 (18:44 +0200)
commitd220fbcd1db2097de5ff3037e85317fcb5433e4e
tree29f18f7138b620738d72a92a4eae23bfe0eff7c9
parent437db2549be383e52acad6cd4bf2862e98fdfc93
qapi: Test for various name collisions

Expose some weaknesses in the generator: we don't always forbid
the generation of structs that contain multiple members that map
to the same C or QMP name.  This has already been marked FIXME in
qapi.py in commit d90675f, but having more tests will make sure
future patches produce desired behavior; and updating existing
patches to better document things doesn't hurt, either.  Some of
these collisions are already caught in the old-style parser
checks, but ultimately we want all collisions to be caught in the
new-style QAPISchema*.check() methods.

This patch focuses on C struct members, and does not consider
collisions between commands and events (affecting C function
names), or even collisions between generated C type names with
user type names (for things like automatic FOOList struct
representing array types or FOOKind for an implicit enum).

There are two types of struct collisions we want to catch:
 1) Collision between two keys in a JSON object. qapi.py prevents
    that within a single struct (see test duplicate-key), but it is
    possible to have collisions between a type's members and its
    base type's members (existing tests struct-base-clash,
    struct-base-clash-deep), and its flat union variant members
    (renamed test flat-union-clash-member).
 2) Collision between two members of the C struct that is generated
    for a given QAPI type:
    a) Multiple QAPI names map to the same C name (new test
       args-name-clash)
    b) A QAPI name maps to a C name that is used for another purpose
       (new tests flat-union-clash-branch, struct-base-clash-base,
       union-clash-data). We already fixed some such cases in commit
       0f61af3e and 1e6c1616, but more remain.
    c) Two C names generated for other purposes clash
       (updated test alternate-clash, new test union-clash-branches,
       union-clash-type, flat-union-clash-type)

Ultimately, if we need to have a flat union where a tag value
clashes with a base member name, we could change the generator to
name the union (using 'foo.u.value' rather than 'foo.value') or
otherwise munge the C name corresponding to tag values.  But
unless such a need arises, it will probably be easier to just
forbid these collisions.

Some of these negative tests will be deleted later, and positive
tests added to qapi-schema-test.json in their place, when the
generator code is reworked to avoid particular code generation
collisions in class 2).

[Note that viewing this patch with git rename detection enabled
may see some confusion due to renaming some tests while adding
others, but where the content is similar enough that git picks
the wrong pre- and post-patch files to associate]

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1443565276-4535-6-git-send-email-eblake@redhat.com>
[Improve commit message and comments a bit, drop an unrelated test]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
46 files changed:
tests/Makefile
tests/qapi-schema/alternate-clash.err
tests/qapi-schema/alternate-clash.json
tests/qapi-schema/args-name-clash.err [moved from tests/qapi-schema/flat-union-branch-clash.out with 100% similarity]
tests/qapi-schema/args-name-clash.exit [new file with mode: 0644]
tests/qapi-schema/args-name-clash.json [new file with mode: 0644]
tests/qapi-schema/args-name-clash.out [new file with mode: 0644]
tests/qapi-schema/duplicate-key.err
tests/qapi-schema/duplicate-key.json
tests/qapi-schema/flat-union-base-union.err
tests/qapi-schema/flat-union-base-union.json
tests/qapi-schema/flat-union-branch-clash.err [deleted file]
tests/qapi-schema/flat-union-clash-branch.err [new file with mode: 0644]
tests/qapi-schema/flat-union-clash-branch.exit [new file with mode: 0644]
tests/qapi-schema/flat-union-clash-branch.json [new file with mode: 0644]
tests/qapi-schema/flat-union-clash-branch.out [new file with mode: 0644]
tests/qapi-schema/flat-union-clash-member.err [new file with mode: 0644]
tests/qapi-schema/flat-union-clash-member.exit [moved from tests/qapi-schema/flat-union-branch-clash.exit with 100% similarity]
tests/qapi-schema/flat-union-clash-member.json [moved from tests/qapi-schema/flat-union-branch-clash.json with 77% similarity]
tests/qapi-schema/flat-union-clash-member.out [new file with mode: 0644]
tests/qapi-schema/flat-union-clash-type.err [new file with mode: 0644]
tests/qapi-schema/flat-union-clash-type.exit [new file with mode: 0644]
tests/qapi-schema/flat-union-clash-type.json [new file with mode: 0644]
tests/qapi-schema/flat-union-clash-type.out [new file with mode: 0644]
tests/qapi-schema/qapi-schema-test.json
tests/qapi-schema/qapi-schema-test.out
tests/qapi-schema/struct-base-clash-base.err [new file with mode: 0644]
tests/qapi-schema/struct-base-clash-base.exit [new file with mode: 0644]
tests/qapi-schema/struct-base-clash-base.json [new file with mode: 0644]
tests/qapi-schema/struct-base-clash-base.out [new file with mode: 0644]
tests/qapi-schema/struct-base-clash-deep.err
tests/qapi-schema/struct-base-clash-deep.json
tests/qapi-schema/struct-base-clash.err
tests/qapi-schema/struct-base-clash.json
tests/qapi-schema/union-clash-branches.err [new file with mode: 0644]
tests/qapi-schema/union-clash-branches.exit [new file with mode: 0644]
tests/qapi-schema/union-clash-branches.json [new file with mode: 0644]
tests/qapi-schema/union-clash-branches.out [new file with mode: 0644]
tests/qapi-schema/union-clash-data.err [new file with mode: 0644]
tests/qapi-schema/union-clash-data.exit [new file with mode: 0644]
tests/qapi-schema/union-clash-data.json [new file with mode: 0644]
tests/qapi-schema/union-clash-data.out [new file with mode: 0644]
tests/qapi-schema/union-clash-type.err [new file with mode: 0644]
tests/qapi-schema/union-clash-type.exit [new file with mode: 0644]
tests/qapi-schema/union-clash-type.json [new file with mode: 0644]
tests/qapi-schema/union-clash-type.out [new file with mode: 0644]