qapi: Enforce event naming rules

Event names should be ALL_CAPS with words separated by underscore.
Enforce this.  The only offenders are in tests/.  Fix them.  Existing
test event-case covers the new error.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210323094025.3569441-14-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Markus Armbruster 2021-03-23 10:40:10 +01:00
parent 00ffe242d6
commit d4f4cae8de
11 changed files with 22 additions and 34 deletions

View File

@ -45,7 +45,9 @@ def check_name_str(name, info, source):
def check_name_upper(name, info, source):
stem = check_name_str(name, info, source)
# TODO reject '[a-z-]' in @stem
if re.search(r'[a-z-]', stem):
raise QAPISemError(
info, "name of %s must not use lowercase or '-'" % source)
def check_name_lower(name, info, source,

View File

@ -179,10 +179,10 @@
'features': [ 'cmd-feat1', 'cmd-feat2' ] }
##
# @EVT-BOXED:
# @EVT_BOXED:
# Features:
# @feat3: a feature
##
{ 'event': 'EVT-BOXED', 'boxed': true,
{ 'event': 'EVT_BOXED', 'boxed': true,
'features': [ 'feat3' ],
'data': 'Object' }

View File

@ -63,7 +63,7 @@ command cmd-boxed Object -> None
gen=True success_response=True boxed=True oob=False preconfig=False
feature cmd-feat1
feature cmd-feat2
event EVT-BOXED Object
event EVT_BOXED Object
boxed=True
feature feat3
doc freeform
@ -211,7 +211,7 @@ another feature
-> in
<- out
doc symbol=EVT-BOXED
doc symbol=EVT_BOXED
body=
feature=feat3

View File

@ -272,7 +272,7 @@ Example
<- out
"EVT-BOXED" (Event)
"EVT_BOXED" (Event)
-------------------

View File

@ -1,7 +1,7 @@
# Events can't have 'Returns' section
##
# @foo:
# @FOO:
# Returns: blah
##
{ 'event': 'foo' }
{ 'event': 'FOO' }

View File

@ -0,0 +1,2 @@
event-case.json: In event 'oops':
event-case.json:1: name of event must not use lowercase or '-'

View File

@ -1,3 +1 @@
# TODO: might be nice to enforce naming conventions; but until then this works
# even though events should usually be ALL_CAPS
{ 'event': 'oops' }

View File

@ -1,14 +0,0 @@
module ./builtin
object q_empty
enum QType
prefix QTYPE
member none
member qnull
member qnum
member qstring
member qdict
member qlist
member qbool
module event-case.json
event oops None
boxed=False

View File

@ -249,7 +249,7 @@
{ 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' }
{ 'event': 'TestIfEvent', 'data':
{ 'event': 'TEST_IF_EVENT', 'data':
{ 'foo': 'TestIfStruct',
'bar': { 'type': ['TestIfEnum'], 'if': 'defined(TEST_IF_EVT_BAR)' } },
'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' }
@ -324,8 +324,8 @@
'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)',
'defined(TEST_IF_COND_2)'] } ] }
{ 'event': 'TEST-EVENT-FEATURES0',
{ 'event': 'TEST_EVENT_FEATURES0',
'data': 'FeatureStruct1' }
{ 'event': 'TEST-EVENT-FEATURES1',
{ 'event': 'TEST_EVENT_FEATURES1',
'features': [ 'deprecated' ] }

View File

@ -349,12 +349,12 @@ command TestCmdReturnDefThree None -> UserDefThree
gen=True success_response=True boxed=False oob=False preconfig=False
array TestIfEnumList TestIfEnum
if ['defined(TEST_IF_ENUM)']
object q_obj_TestIfEvent-arg
object q_obj_TEST_IF_EVENT-arg
member foo: TestIfStruct optional=False
member bar: TestIfEnumList optional=False
if ['defined(TEST_IF_EVT_BAR)']
if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)']
event TestIfEvent q_obj_TestIfEvent-arg
event TEST_IF_EVENT q_obj_TEST_IF_EVENT-arg
boxed=False
if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)']
object FeatureStruct0
@ -440,9 +440,9 @@ command test-command-cond-features3 None -> None
gen=True success_response=True boxed=False oob=False preconfig=False
feature feature1
if ['defined(TEST_IF_COND_1)', 'defined(TEST_IF_COND_2)']
event TEST-EVENT-FEATURES0 FeatureStruct1
event TEST_EVENT_FEATURES0 FeatureStruct1
boxed=False
event TEST-EVENT-FEATURES1 None
event TEST_EVENT_FEATURES1 None
boxed=False
feature deprecated
module include/sub-module.json

View File

@ -143,7 +143,7 @@ static void test_event_d(TestEventData *data,
static void test_event_deprecated(TestEventData *data, const void *unused)
{
data->expect = qdict_from_jsonf_nofail("{ 'event': 'TEST-EVENT-FEATURES1' }");
data->expect = qdict_from_jsonf_nofail("{ 'event': 'TEST_EVENT_FEATURES1' }");
memset(&compat_policy, 0, sizeof(compat_policy));
@ -163,7 +163,7 @@ static void test_event_deprecated_data(TestEventData *data, const void *unused)
{
memset(&compat_policy, 0, sizeof(compat_policy));
data->expect = qdict_from_jsonf_nofail("{ 'event': 'TEST-EVENT-FEATURES0',"
data->expect = qdict_from_jsonf_nofail("{ 'event': 'TEST_EVENT_FEATURES0',"
" 'data': { 'foo': 42 } }");
qapi_event_send_test_event_features0(42);
g_assert(data->emitted);
@ -172,7 +172,7 @@ static void test_event_deprecated_data(TestEventData *data, const void *unused)
compat_policy.has_deprecated_output = true;
compat_policy.deprecated_output = COMPAT_POLICY_OUTPUT_HIDE;
data->expect = qdict_from_jsonf_nofail("{ 'event': 'TEST-EVENT-FEATURES0' }");
data->expect = qdict_from_jsonf_nofail("{ 'event': 'TEST_EVENT_FEATURES0' }");
qapi_event_send_test_event_features0(42);
g_assert(data->emitted);