Message ID | 20200624124301.7112-3-eric.auger@redhat.com |
---|---|
State | New |
Headers | show |
Series | Avoid abort on QMP attempt to add an object with duplicate id | expand |
On 24/06/2020 14.43, Eric Auger wrote: > This new test checks that attempting to create an object > with an existing ID gracefully fails. > > Signed-off-by: Eric Auger <eric.auger@redhat.com> > --- > tests/qtest/qmp-cmd-test.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) Acked-by: Thomas Huth <thuth@redhat.com>
Hi Thomas, On 6/24/20 2:43 PM, Eric Auger wrote: > This new test checks that attempting to create an object > with an existing ID gracefully fails. > > Signed-off-by: Eric Auger <eric.auger@redhat.com> > --- > tests/qtest/qmp-cmd-test.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c > index 9f5228cd99..9510051c35 100644 > --- a/tests/qtest/qmp-cmd-test.c > +++ b/tests/qtest/qmp-cmd-test.c > @@ -213,6 +213,22 @@ static void test_object_add_without_props(void) > qtest_quit(qts); > } > > +static void test_object_add_with_duplicate_id(void) > +{ > + QTestState *qts; > + QDict *resp; > + > + qts = qtest_init(common_args); > + resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" > + " {'qom-type': 'memory-backend-ram', 'id': 'ram1', 'props': {'size': 4294967296 } } }"); > + g_assert_nonnull(resp); > + g_assert(qdict_haskey(resp, "return")); > + resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" > + " {'qom-type': 'memory-backend-ram', 'id': 'ram1', 'props': {'size': 4294967296 } } }"); in v3 I will add here: g_assert_nonnull(resp); Thanks Eric > + qmp_assert_error_class(resp, "GenericError"); > + qtest_quit(qts); > +} > + > int main(int argc, char *argv[]) > { > QmpSchema schema; > @@ -225,6 +241,8 @@ int main(int argc, char *argv[]) > > qtest_add_func("qmp/object-add-without-props", > test_object_add_without_props); > + qtest_add_func("qmp/object-add-duplicate-id", > + test_object_add_with_duplicate_id); > /* TODO: add coverage of generic object-add failure modes */ > > ret = g_test_run(); >
diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c index 9f5228cd99..9510051c35 100644 --- a/tests/qtest/qmp-cmd-test.c +++ b/tests/qtest/qmp-cmd-test.c @@ -213,6 +213,22 @@ static void test_object_add_without_props(void) qtest_quit(qts); } +static void test_object_add_with_duplicate_id(void) +{ + QTestState *qts; + QDict *resp; + + qts = qtest_init(common_args); + resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" + " {'qom-type': 'memory-backend-ram', 'id': 'ram1', 'props': {'size': 4294967296 } } }"); + g_assert_nonnull(resp); + g_assert(qdict_haskey(resp, "return")); + resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" + " {'qom-type': 'memory-backend-ram', 'id': 'ram1', 'props': {'size': 4294967296 } } }"); + qmp_assert_error_class(resp, "GenericError"); + qtest_quit(qts); +} + int main(int argc, char *argv[]) { QmpSchema schema; @@ -225,6 +241,8 @@ int main(int argc, char *argv[]) qtest_add_func("qmp/object-add-without-props", test_object_add_without_props); + qtest_add_func("qmp/object-add-duplicate-id", + test_object_add_with_duplicate_id); /* TODO: add coverage of generic object-add failure modes */ ret = g_test_run();
This new test checks that attempting to create an object with an existing ID gracefully fails. Signed-off-by: Eric Auger <eric.auger@redhat.com> --- tests/qtest/qmp-cmd-test.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)