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

qapi: Enforce (or whitelist) case conventions on qapi members

We document that members of enums and objects should be
'lower-case', although we were not enforcing it. We have to
whitelist a few pre-existing entities that violate the norms.
Add three new tests to expose the new error message, each of
which first uses the whitelisted name 'UuidInfo' to prove the
whitelist works, then triggers the failure (this is the same
pattern used in the existing returns-whitelist.json test).

Note that by adding this check, we have effectively forbidden
an entity with a case-insensitive clash of member names, for
any entity that is not on the whitelist (although there is
still the possibility to clash via '-' vs. '_').

Not done here: a future patch should also add naming convention
support and whitelist exceptions for command, event, and type
names.

The additions to QAPISchemaMember.check_clash() check whether
info['name'] is in the whitelist (the top-most entity name at
the point 'info' tracks), rather than self.owner (the type,
possibly implicit, that directly owns the member), because it
is easier to maintain the whitelist by the names actually in
the user's .json file, rather than worrying about the names
of implicit types.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1449033659-25497-14-git-send-email-eblake@redhat.com>
[Simplified a bit as per discussion with Eric]
Signed-off-by: Markus Armbruster <armbru@redhat.com>

authored by

Eric Blake and committed by
Markus Armbruster
893e1f2c 93bda4dd

+33
+17
scripts/qapi.py
··· 59 59 'guest-sync-delimited', 60 60 ] 61 61 62 + # Whitelist of entities allowed to violate case conventions 63 + case_whitelist = [ 64 + # From QMP: 65 + 'ACPISlotType', # DIMM, visible through query-acpi-ospm-status 66 + 'CpuInfoBase', # CPU, visible through query-cpu 67 + 'CpuInfoMIPS', # PC, visible through query-cpu 68 + 'CpuInfoTricore', # PC, visible through query-cpu 69 + 'InputAxis', # TODO: drop when x-input-send-event is fixed 70 + 'InputButton', # TODO: drop when x-input-send-event is fixed 71 + 'QapiErrorClass', # all members, visible through errors 72 + 'UuidInfo', # UUID, visible through query-uuid 73 + 'X86CPURegister32', # all members, visible indirectly through qom-get 74 + ] 75 + 62 76 enum_types = [] 63 77 struct_types = [] 64 78 union_types = [] ··· 1038 1052 1039 1053 def check_clash(self, info, seen): 1040 1054 cname = c_name(self.name) 1055 + if cname.lower() != cname and self.owner not in case_whitelist: 1056 + raise QAPIExprError(info, 1057 + "%s should not use uppercase" % self.describe()) 1041 1058 if cname in seen: 1042 1059 raise QAPIExprError(info, 1043 1060 "%s collides with %s"
+3
tests/Makefile
··· 246 246 qapi-schema += args-int.json 247 247 qapi-schema += args-invalid.json 248 248 qapi-schema += args-member-array-bad.json 249 + qapi-schema += args-member-case.json 249 250 qapi-schema += args-member-unknown.json 250 251 qapi-schema += args-name-clash.json 251 252 qapi-schema += args-union.json ··· 267 268 qapi-schema += enum-clash-member.json 268 269 qapi-schema += enum-dict-member.json 269 270 qapi-schema += enum-int-member.json 271 + qapi-schema += enum-member-case.json 270 272 qapi-schema += enum-missing-data.json 271 273 qapi-schema += enum-wrong-data.json 272 274 qapi-schema += escape-outside-string.json ··· 341 343 qapi-schema += unicode-str.json 342 344 qapi-schema += union-bad-branch.json 343 345 qapi-schema += union-base-no-discriminator.json 346 + qapi-schema += union-branch-case.json 344 347 qapi-schema += union-clash-branches.json 345 348 qapi-schema += union-clash-data.json 346 349 qapi-schema += union-empty.json
+1
tests/qapi-schema/args-member-case.err
··· 1 + tests/qapi-schema/args-member-case.json:2: 'Arg' (parameter of no-way-this-will-get-whitelisted) should not use uppercase
+1
tests/qapi-schema/args-member-case.exit
··· 1 + 1
+2
tests/qapi-schema/args-member-case.json
··· 1 + # Member names should be 'lower-case' unless the struct/command is whitelisted 2 + { 'command': 'no-way-this-will-get-whitelisted', 'data': { 'Arg': 'int' } }
tests/qapi-schema/args-member-case.out

This is a binary file and will not be displayed.

+1
tests/qapi-schema/enum-member-case.err
··· 1 + tests/qapi-schema/enum-member-case.json:3: 'Value' (member of NoWayThisWillGetWhitelisted) should not use uppercase
+1
tests/qapi-schema/enum-member-case.exit
··· 1 + 1
+3
tests/qapi-schema/enum-member-case.json
··· 1 + # Member names should be 'lower-case' unless the enum is whitelisted 2 + { 'enum': 'UuidInfo', 'data': [ 'Value' ] } # UuidInfo is whitelisted 3 + { 'enum': 'NoWayThisWillGetWhitelisted', 'data': [ 'Value' ] }
tests/qapi-schema/enum-member-case.out

This is a binary file and will not be displayed.

+1
tests/qapi-schema/union-branch-case.err
··· 1 + tests/qapi-schema/union-branch-case.json:2: 'Branch' (branch of NoWayThisWillGetWhitelisted) should not use uppercase
+1
tests/qapi-schema/union-branch-case.exit
··· 1 + 1
+2
tests/qapi-schema/union-branch-case.json
··· 1 + # Branch names should be 'lower-case' unless the union is whitelisted 2 + { 'union': 'NoWayThisWillGetWhitelisted', 'data': { 'Branch': 'int' } }
tests/qapi-schema/union-branch-case.out

This is a binary file and will not be displayed.