Eric Blake <ebl...@redhat.com> writes: > On 3/17/20 6:54 AM, Markus Armbruster wrote: >> This policy suppresses deprecated bits in output, and thus permits >> "testing the future". Implement it for QMP event data: suppress >> deprecated members. >> >> No QMP event data is deprecated right now. >> >> Signed-off-by: Markus Armbruster <arm...@redhat.com> >> --- > >> +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': { 'foo': 42 } }"); >> + qapi_event_send_test_event_features0(42); >> + g_assert(data->emitted); >> + >> + qobject_unref(data->expect); >> + >> + compat_policy.deprecated_output = COMPAT_POLICY_OUTPUT_HIDE; > > Again, playing fast-and-loose with compat_policy.has_deprecated_output.
I'll clean it up. >> +++ b/scripts/qapi/events.py >> @@ -104,7 +104,7 @@ def gen_event_send(name, arg_type, features, boxed, >> if have_args: >> ret += mcgen(''' >> - v = qobject_output_visitor_new(&obj); >> + v = qobject_output_visitor_new_qmp(&obj); >> ''') >> if not arg_type.is_implicit(): >> ret += mcgen(''' >> @@ -123,7 +123,11 @@ def gen_event_send(name, arg_type, features, boxed, >> ret += mcgen(''' >> visit_complete(v, &obj); >> - qdict_put_obj(qmp, "data", obj); >> + if (qdict_size(qobject_to(QDict, obj))) { >> + qdict_put_obj(qmp, "data", obj); >> + } else { >> + qobject_unref(obj); >> + } > > So you'd rather omit data altogether than emit "data":{} when all > deprecated members disappear. Fair enough; both approaches work. I initially didn't do this until my testing demonstrated that "data" goes away entirely when I delete the last member from the schema. To actually fulfill the "test the future" mission, I need policy hide drop data, too. > Reviewed-by: Eric Blake <ebl...@redhat.com> Thanks!