mirror of https://gitee.com/openkylin/qemu.git
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:
parent
00ffe242d6
commit
d4f4cae8de
|
@ -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,
|
||||
|
|
|
@ -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' }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -272,7 +272,7 @@ Example
|
|||
<- out
|
||||
|
||||
|
||||
"EVT-BOXED" (Event)
|
||||
"EVT_BOXED" (Event)
|
||||
-------------------
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Events can't have 'Returns' section
|
||||
|
||||
##
|
||||
# @foo:
|
||||
# @FOO:
|
||||
# Returns: blah
|
||||
##
|
||||
{ 'event': 'foo' }
|
||||
{ 'event': 'FOO' }
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
event-case.json: In event 'oops':
|
||||
event-case.json:1: name of event must not use lowercase or '-'
|
|
@ -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' }
|
||||
|
|
|
@ -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
|
|
@ -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' ] }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue