aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-03-19 16:40:00 +0000
committerPeter Maydell <peter.maydell@linaro.org>2021-03-19 16:40:00 +0000
commit2e1293cbaac75e84f541f9acfa8e26749f4c3562 (patch)
tree0d59e90331072297512f782638e511a5dd25611d /tests
parent8631a430e65ef73b3d8a297128be2ef3c7317b90 (diff)
parentdbb675c19aa6ca328f4449ccd1ff605f9cb744e9 (diff)
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-03-16-v4' into staging
QAPI patches patches for 2021-03-16 # gpg: Signature made Fri 19 Mar 2021 15:06:52 GMT # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "armbru@redhat.com" # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2021-03-16-v4: qapi: New -compat deprecated-input=crash qapi: Implement deprecated-input=reject for QMP command arguments qapi: Implement deprecated-input=reject for QMP commands test-util-sockets: Add stub for monitor_set_cur() qapi: Implement deprecated-output=hide for QMP introspection monitor: Drop query-qmp-schema 'gen': false hack qapi: Implement deprecated-output=hide for QMP event data qapi: Implement deprecated-output=hide for QMP events qapi: Implement deprecated-output=hide for QMP command results qemu-options: New -compat to set policy for deprecated interfaces qemuutil: remove qemu_set_fd_handler duplicate symbol Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/qapi-schema/qapi-schema-test.json20
-rw-r--r--tests/qapi-schema/qapi-schema-test.out20
-rw-r--r--tests/unit/test-qmp-cmds.c91
-rw-r--r--tests/unit/test-qmp-event.c41
-rw-r--r--tests/unit/test-util-sockets.c1
5 files changed, 151 insertions, 22 deletions
diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index 63f92adf68..12ec588b52 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -299,14 +299,15 @@
'features': [ 'feature1' ] }
{ 'command': 'test-features0',
- 'data': { 'fs0': 'FeatureStruct0',
- 'fs1': 'FeatureStruct1',
- 'fs2': 'FeatureStruct2',
- 'fs3': 'FeatureStruct3',
- 'fs4': 'FeatureStruct4',
- 'cfs1': 'CondFeatureStruct1',
- 'cfs2': 'CondFeatureStruct2',
- 'cfs3': 'CondFeatureStruct3' },
+ 'data': { '*fs0': 'FeatureStruct0',
+ '*fs1': 'FeatureStruct1',
+ '*fs2': 'FeatureStruct2',
+ '*fs3': 'FeatureStruct3',
+ '*fs4': 'FeatureStruct4',
+ '*cfs1': 'CondFeatureStruct1',
+ '*cfs2': 'CondFeatureStruct2',
+ '*cfs3': 'CondFeatureStruct3' },
+ 'returns': 'FeatureStruct1',
'features': [] }
{ 'command': 'test-command-features1',
@@ -323,5 +324,8 @@
'features': [ { 'name': 'feature1', 'if': [ 'defined(TEST_IF_COND_1)',
'defined(TEST_IF_COND_2)'] } ] }
+{ 'event': 'TEST-EVENT-FEATURES0',
+ 'data': 'FeatureStruct1' }
+
{ 'event': 'TEST-EVENT-FEATURES1',
'features': [ 'deprecated' ] }
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index 3b1387d9f1..f5741df97f 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -409,15 +409,15 @@ alternate FeatureAlternate1
case eins: FeatureStruct1
feature feature1
object q_obj_test-features0-arg
- member fs0: FeatureStruct0 optional=False
- member fs1: FeatureStruct1 optional=False
- member fs2: FeatureStruct2 optional=False
- member fs3: FeatureStruct3 optional=False
- member fs4: FeatureStruct4 optional=False
- member cfs1: CondFeatureStruct1 optional=False
- member cfs2: CondFeatureStruct2 optional=False
- member cfs3: CondFeatureStruct3 optional=False
-command test-features0 q_obj_test-features0-arg -> None
+ member fs0: FeatureStruct0 optional=True
+ member fs1: FeatureStruct1 optional=True
+ member fs2: FeatureStruct2 optional=True
+ member fs3: FeatureStruct3 optional=True
+ member fs4: FeatureStruct4 optional=True
+ member cfs1: CondFeatureStruct1 optional=True
+ member cfs2: CondFeatureStruct2 optional=True
+ member cfs3: CondFeatureStruct3 optional=True
+command test-features0 q_obj_test-features0-arg -> FeatureStruct1
gen=True success_response=True boxed=False oob=False preconfig=False
command test-command-features1 None -> None
gen=True success_response=True boxed=False oob=False preconfig=False
@@ -440,6 +440,8 @@ 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
+ boxed=False
event TEST-EVENT-FEATURES1 None
boxed=False
feature deprecated
diff --git a/tests/unit/test-qmp-cmds.c b/tests/unit/test-qmp-cmds.c
index d3413bfef0..266db074b4 100644
--- a/tests/unit/test-qmp-cmds.c
+++ b/tests/unit/test-qmp-cmds.c
@@ -1,4 +1,5 @@
#include "qemu/osdep.h"
+#include "qapi/compat-policy.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qjson.h"
#include "qapi/qmp/qnum.h"
@@ -49,12 +50,17 @@ void qmp_user_def_cmd1(UserDefOne * ud1, Error **errp)
{
}
-void qmp_test_features0(FeatureStruct0 *fs0, FeatureStruct1 *fs1,
- FeatureStruct2 *fs2, FeatureStruct3 *fs3,
- FeatureStruct4 *fs4, CondFeatureStruct1 *cfs1,
- CondFeatureStruct2 *cfs2, CondFeatureStruct3 *cfs3,
- Error **errp)
+FeatureStruct1 *qmp_test_features0(bool has_fs0, FeatureStruct0 *fs0,
+ bool has_fs1, FeatureStruct1 *fs1,
+ bool has_fs2, FeatureStruct2 *fs2,
+ bool has_fs3, FeatureStruct3 *fs3,
+ bool has_fs4, FeatureStruct4 *fs4,
+ bool has_cfs1, CondFeatureStruct1 *cfs1,
+ bool has_cfs2, CondFeatureStruct2 *cfs2,
+ bool has_cfs3, CondFeatureStruct3 *cfs3,
+ Error **errp)
{
+ return g_new0(FeatureStruct1, 1);
}
void qmp_test_command_features1(Error **errp)
@@ -275,6 +281,75 @@ static void test_dispatch_cmd_io(void)
qobject_unref(ret3);
}
+static void test_dispatch_cmd_deprecated(void)
+{
+ const char *cmd = "{ 'execute': 'test-command-features1' }";
+ QDict *ret;
+
+ memset(&compat_policy, 0, sizeof(compat_policy));
+
+ /* accept */
+ ret = qobject_to(QDict, do_qmp_dispatch(false, cmd));
+ assert(ret && qdict_size(ret) == 0);
+ qobject_unref(ret);
+
+ compat_policy.has_deprecated_input = true;
+ compat_policy.deprecated_input = COMPAT_POLICY_INPUT_ACCEPT;
+ ret = qobject_to(QDict, do_qmp_dispatch(false, cmd));
+ assert(ret && qdict_size(ret) == 0);
+ qobject_unref(ret);
+
+ compat_policy.deprecated_input = COMPAT_POLICY_INPUT_REJECT;
+ do_qmp_dispatch_error(false, ERROR_CLASS_COMMAND_NOT_FOUND, cmd);
+}
+
+static void test_dispatch_cmd_arg_deprecated(void)
+{
+ const char *cmd = "{ 'execute': 'test-features0',"
+ " 'arguments': { 'fs1': { 'foo': 42 } } }";
+ QDict *ret;
+
+ memset(&compat_policy, 0, sizeof(compat_policy));
+
+ /* accept */
+ ret = qobject_to(QDict, do_qmp_dispatch(false, cmd));
+ assert(ret && qdict_size(ret) == 1);
+ qobject_unref(ret);
+
+ compat_policy.has_deprecated_input = true;
+ compat_policy.deprecated_input = COMPAT_POLICY_INPUT_ACCEPT;
+ ret = qobject_to(QDict, do_qmp_dispatch(false, cmd));
+ assert(ret && qdict_size(ret) == 1);
+ qobject_unref(ret);
+
+ compat_policy.deprecated_input = COMPAT_POLICY_INPUT_REJECT;
+ do_qmp_dispatch_error(false, ERROR_CLASS_GENERIC_ERROR, cmd);
+}
+
+static void test_dispatch_cmd_ret_deprecated(void)
+{
+ const char *cmd = "{ 'execute': 'test-features0' }";
+ QDict *ret;
+
+ memset(&compat_policy, 0, sizeof(compat_policy));
+
+ /* default accept */
+ ret = qobject_to(QDict, do_qmp_dispatch(false, cmd));
+ assert(ret && qdict_size(ret) == 1);
+ qobject_unref(ret);
+
+ compat_policy.has_deprecated_output = true;
+ compat_policy.deprecated_output = COMPAT_POLICY_OUTPUT_ACCEPT;
+ ret = qobject_to(QDict, do_qmp_dispatch(false, cmd));
+ assert(ret && qdict_size(ret) == 1);
+ qobject_unref(ret);
+
+ compat_policy.deprecated_output = COMPAT_POLICY_OUTPUT_HIDE;
+ ret = qobject_to(QDict, do_qmp_dispatch(false, cmd));
+ assert(ret && qdict_size(ret) == 0);
+ qobject_unref(ret);
+}
+
/* test generated dealloc functions for generated types */
static void test_dealloc_types(void)
{
@@ -349,6 +424,12 @@ int main(int argc, char **argv)
g_test_add_func("/qmp/dispatch_cmd_io", test_dispatch_cmd_io);
g_test_add_func("/qmp/dispatch_cmd_success_response",
test_dispatch_cmd_success_response);
+ g_test_add_func("/qmp/dispatch_cmd_deprecated",
+ test_dispatch_cmd_deprecated);
+ g_test_add_func("/qmp/dispatch_cmd_arg_deprecated",
+ test_dispatch_cmd_arg_deprecated);
+ g_test_add_func("/qmp/dispatch_cmd_ret_deprecated",
+ test_dispatch_cmd_ret_deprecated);
g_test_add_func("/qmp/dealloc_types", test_dealloc_types);
g_test_add_func("/qmp/dealloc_partial", test_dealloc_partial);
diff --git a/tests/unit/test-qmp-event.c b/tests/unit/test-qmp-event.c
index 7dd0053190..047f44ff9a 100644
--- a/tests/unit/test-qmp-event.c
+++ b/tests/unit/test-qmp-event.c
@@ -14,6 +14,7 @@
#include "qemu/osdep.h"
#include "qemu-common.h"
+#include "qapi/compat-policy.h"
#include "qapi/error.h"
#include "qapi/qmp/qbool.h"
#include "qapi/qmp/qdict.h"
@@ -140,6 +141,44 @@ static void test_event_d(TestEventData *data,
qobject_unref(data->expect);
}
+static void test_event_deprecated(TestEventData *data, const void *unused)
+{
+ data->expect = qdict_from_jsonf_nofail("{ 'event': 'TEST-EVENT-FEATURES1' }");
+
+ memset(&compat_policy, 0, sizeof(compat_policy));
+
+ qapi_event_send_test_event_features1();
+ g_assert(data->emitted);
+
+ compat_policy.has_deprecated_output = true;
+ compat_policy.deprecated_output = COMPAT_POLICY_OUTPUT_HIDE;
+ data->emitted = false;
+ qapi_event_send_test_event_features1();
+ g_assert(!data->emitted);
+
+ qobject_unref(data->expect);
+}
+
+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.has_deprecated_output = true;
+ compat_policy.deprecated_output = COMPAT_POLICY_OUTPUT_HIDE;
+ data->expect = qdict_from_jsonf_nofail("{ 'event': 'TEST-EVENT-FEATURES0' }");
+ qapi_event_send_test_event_features0(42);
+ g_assert(data->emitted);
+
+ qobject_unref(data->expect);
+}
+
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
@@ -148,6 +187,8 @@ int main(int argc, char **argv)
event_test_add("/event/event_b", test_event_b);
event_test_add("/event/event_c", test_event_c);
event_test_add("/event/event_d", test_event_d);
+ event_test_add("/event/deprecated", test_event_deprecated);
+ event_test_add("/event/deprecated_data", test_event_deprecated_data);
g_test_run();
return 0;
diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c
index 67486055ed..72b9246529 100644
--- a/tests/unit/test-util-sockets.c
+++ b/tests/unit/test-util-sockets.c
@@ -73,6 +73,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
* otherwise we get duplicate syms at link time.
*/
Monitor *monitor_cur(void) { return cur_mon; }
+Monitor *monitor_set_cur(Coroutine *co, Monitor *mon) { abort(); }
int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
#ifndef _WIN32