diff mbox series

[for-8.2,2/4] tests/migration-test: Add a test for null parameter setups

Message ID 20230814221947.353093-3-peterx@redhat.com
State New
Headers show
Series qapi/migration: Dedup migration parameter objects and fix tls-authz crash | expand

Commit Message

Peter Xu Aug. 14, 2023, 10:19 p.m. UTC
Add a test for StrOrNull parameters (tls-*).

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 tests/qtest/migration-test.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Fabiano Rosas Aug. 15, 2023, 12:46 p.m. UTC | #1
Peter Xu <peterx@redhat.com> writes:

> Add a test for StrOrNull parameters (tls-*).
>
> Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Fabiano Rosas <farosas@suse.de>
diff mbox series

Patch

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 62d3f37021..12e72580a6 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -1471,6 +1471,29 @@  static void test_postcopy_preempt_all(void)
 
 #endif
 
+/*
+ * We have a few parameters that allows null as input, test them to make
+ * sure they won't crash (where some used to).
+ */
+static void test_null_parameters(void)
+{
+    const char *null_params[] = {
+        "tls-authz", "tls-hostname", "tls-creds"};
+    QTestState *vm = qtest_init("");
+    QDict *response;
+    int i;
+
+    for (i = 0; i < sizeof(null_params) / sizeof(const char *); i++) {
+        response = qtest_qmp(vm, "{ 'execute': 'migrate-set-parameters',"
+                             "'arguments': { %s: null } }",
+                             null_params[i]);
+        /* Succeed or fail; as long as not crashing */
+        qobject_unref(response);
+    }
+
+    qtest_quit(vm);
+}
+
 static void test_baddest(void)
 {
     MigrateStart args = {
@@ -2827,6 +2850,7 @@  int main(int argc, char **argv)
         }
     }
 
+    qtest_add_func("/migration/null_parameters", test_null_parameters);
     qtest_add_func("/migration/bad_dest", test_baddest);
     qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain);
     qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle);