[PULL 05/18] tests: switch MigrateStart struct to be stack allocated
From: Daniel P. Berrangé There's no compelling reason why the MigrateStart struct needs to be heap allocated. Using stack allocation and static initializers is simpler. Signed-off-by: Daniel P. Berrangé Message-Id: <20220310171821.3724080-8-berra...@redhat.com> Reviewed-by: Peter Xu Signed-off-by: Dr. David Alan Gilbert --- tests/qtest/migration-test.c | 134 +++ 1 file changed, 56 insertions(+), 78 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 0870656d82..36e5408702 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -474,28 +474,12 @@ typedef struct { bool only_target; /* Use dirty ring if true; dirty logging otherwise */ bool use_dirty_ring; -char *opts_source; -char *opts_target; +const char *opts_source; +const char *opts_target; } MigrateStart; -static MigrateStart *migrate_start_new(void) -{ -MigrateStart *args = g_new0(MigrateStart, 1); - -args->opts_source = g_strdup(""); -args->opts_target = g_strdup(""); -return args; -} - -static void migrate_start_destroy(MigrateStart *args) -{ -g_free(args->opts_source); -g_free(args->opts_target); -g_free(args); -} - static int test_migrate_start(QTestState **from, QTestState **to, - const char *uri, MigrateStart **pargs) + const char *uri, MigrateStart *args) { g_autofree gchar *arch_source = NULL; g_autofree gchar *arch_target = NULL; @@ -507,15 +491,12 @@ static int test_migrate_start(QTestState **from, QTestState **to, g_autofree char *shmem_path = NULL; const char *arch = qtest_get_arch(); const char *machine_opts = NULL; -MigrateStart *args = *pargs; const char *memory_size; -int ret = 0; if (args->use_shmem) { if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) { g_test_skip("/dev/shm is not supported"); -ret = -1; -goto out; +return -1; } } @@ -591,7 +572,8 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_opts ? " -machine " : "", machine_opts ? machine_opts : "", memory_size, tmpfs, - arch_source, shmem_opts, args->opts_source, + arch_source, shmem_opts, + args->opts_source ? args->opts_source : "", ignore_stderr); if (!args->only_target) { *from = qtest_init(cmd_source); @@ -609,7 +591,8 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_opts ? machine_opts : "", memory_size, tmpfs, uri, arch_target, shmem_opts, - args->opts_target, ignore_stderr); + args->opts_target ? args->opts_target : "", + ignore_stderr); *to = qtest_init(cmd_target); /* @@ -620,11 +603,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, unlink(shmem_path); } -out: -migrate_start_destroy(args); -/* This tells the caller that this structure is gone */ -*pargs = NULL; -return ret; +return 0; } static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest) @@ -668,7 +647,7 @@ static int migrate_postcopy_prepare(QTestState **from_ptr, g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *from, *to; -if (test_migrate_start(, , uri, )) { +if (test_migrate_start(, , uri, args)) { return -1; } @@ -712,10 +691,10 @@ static void migrate_postcopy_complete(QTestState *from, QTestState *to) static void test_postcopy(void) { -MigrateStart *args = migrate_start_new(); +MigrateStart args = {}; QTestState *from, *to; -if (migrate_postcopy_prepare(, , args)) { +if (migrate_postcopy_prepare(, , )) { return; } migrate_postcopy_start(from, to); @@ -724,13 +703,13 @@ static void test_postcopy(void) static void test_postcopy_recovery(void) { -MigrateStart *args = migrate_start_new(); +MigrateStart args = { +.hide_stderr = true, +}; QTestState *from, *to; g_autofree char *uri = NULL; -args->hide_stderr = true; - -if (migrate_postcopy_prepare(, , args)) { +if (migrate_postcopy_prepare(, , )) { return; } @@ -786,11 +765,11 @@ static void test_postcopy_recovery(void) static void test_baddest(void) { -MigrateStart *args = migrate_start_new(); +MigrateStart args = { +.hide_stderr = true +}; QTestState *from, *to; -args->hide_stderr = true; - if (test_migrate_start(, ,
[PULL 05/18] tests: switch MigrateStart struct to be stack allocated
From: Daniel P. Berrangé There's no compelling reason why the MigrateStart struct needs to be heap allocated. Using stack allocation and static initializers is simpler. Signed-off-by: Daniel P. Berrangé Message-Id: <20220310171821.3724080-8-berra...@redhat.com> Reviewed-by: Peter Xu Signed-off-by: Dr. David Alan Gilbert --- tests/qtest/migration-test.c | 134 +++ 1 file changed, 56 insertions(+), 78 deletions(-) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 0870656d82..36e5408702 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -474,28 +474,12 @@ typedef struct { bool only_target; /* Use dirty ring if true; dirty logging otherwise */ bool use_dirty_ring; -char *opts_source; -char *opts_target; +const char *opts_source; +const char *opts_target; } MigrateStart; -static MigrateStart *migrate_start_new(void) -{ -MigrateStart *args = g_new0(MigrateStart, 1); - -args->opts_source = g_strdup(""); -args->opts_target = g_strdup(""); -return args; -} - -static void migrate_start_destroy(MigrateStart *args) -{ -g_free(args->opts_source); -g_free(args->opts_target); -g_free(args); -} - static int test_migrate_start(QTestState **from, QTestState **to, - const char *uri, MigrateStart **pargs) + const char *uri, MigrateStart *args) { g_autofree gchar *arch_source = NULL; g_autofree gchar *arch_target = NULL; @@ -507,15 +491,12 @@ static int test_migrate_start(QTestState **from, QTestState **to, g_autofree char *shmem_path = NULL; const char *arch = qtest_get_arch(); const char *machine_opts = NULL; -MigrateStart *args = *pargs; const char *memory_size; -int ret = 0; if (args->use_shmem) { if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) { g_test_skip("/dev/shm is not supported"); -ret = -1; -goto out; +return -1; } } @@ -591,7 +572,8 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_opts ? " -machine " : "", machine_opts ? machine_opts : "", memory_size, tmpfs, - arch_source, shmem_opts, args->opts_source, + arch_source, shmem_opts, + args->opts_source ? args->opts_source : "", ignore_stderr); if (!args->only_target) { *from = qtest_init(cmd_source); @@ -609,7 +591,8 @@ static int test_migrate_start(QTestState **from, QTestState **to, machine_opts ? machine_opts : "", memory_size, tmpfs, uri, arch_target, shmem_opts, - args->opts_target, ignore_stderr); + args->opts_target ? args->opts_target : "", + ignore_stderr); *to = qtest_init(cmd_target); /* @@ -620,11 +603,7 @@ static int test_migrate_start(QTestState **from, QTestState **to, unlink(shmem_path); } -out: -migrate_start_destroy(args); -/* This tells the caller that this structure is gone */ -*pargs = NULL; -return ret; +return 0; } static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest) @@ -668,7 +647,7 @@ static int migrate_postcopy_prepare(QTestState **from_ptr, g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *from, *to; -if (test_migrate_start(, , uri, )) { +if (test_migrate_start(, , uri, args)) { return -1; } @@ -712,10 +691,10 @@ static void migrate_postcopy_complete(QTestState *from, QTestState *to) static void test_postcopy(void) { -MigrateStart *args = migrate_start_new(); +MigrateStart args = {}; QTestState *from, *to; -if (migrate_postcopy_prepare(, , args)) { +if (migrate_postcopy_prepare(, , )) { return; } migrate_postcopy_start(from, to); @@ -724,13 +703,13 @@ static void test_postcopy(void) static void test_postcopy_recovery(void) { -MigrateStart *args = migrate_start_new(); +MigrateStart args = { +.hide_stderr = true, +}; QTestState *from, *to; g_autofree char *uri = NULL; -args->hide_stderr = true; - -if (migrate_postcopy_prepare(, , args)) { +if (migrate_postcopy_prepare(, , )) { return; } @@ -786,11 +765,11 @@ static void test_postcopy_recovery(void) static void test_baddest(void) { -MigrateStart *args = migrate_start_new(); +MigrateStart args = { +.hide_stderr = true +}; QTestState *from, *to; -args->hide_stderr = true; - if (test_migrate_start(, ,