diff mbox series

[3/7] tests/qtest/migration: Initialize MigrationTestEnv::arch early

Message ID 20250128135429.8500-4-philmd@linaro.org
State New
Headers show
Series tests/qtest/migration: Update framework to allow using HVF accelerator | expand

Commit Message

Philippe Mathieu-Daudé Jan. 28, 2025, 1:54 p.m. UTC
Some tests expect MigrationTestEnv::arch to be set. Initialize
it early enough to avoid SIGSEGV, for example like the following
g_str_equal() call in migration/precopy-tests.c:

   954 void migration_test_add_precopy(MigrationTestEnv *env)
   955 {
   ...
  1001     if (g_str_equal(env->arch, "x86_64") && env->has_dirty_ring) {
  1002
  1003         migration_test_add("/migration/dirty_ring",
  1004                            test_precopy_unix_dirty_ring);

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 tests/qtest/migration/framework.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Fabiano Rosas Jan. 28, 2025, 2:43 p.m. UTC | #1
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Some tests expect MigrationTestEnv::arch to be set. Initialize
> it early enough to avoid SIGSEGV, for example like the following
> g_str_equal() call in migration/precopy-tests.c:
>
>    954 void migration_test_add_precopy(MigrationTestEnv *env)
>    955 {
>    ...
>   1001     if (g_str_equal(env->arch, "x86_64") && env->has_dirty_ring) {
>   1002
>   1003         migration_test_add("/migration/dirty_ring",
>   1004                            test_precopy_unix_dirty_ring);
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  tests/qtest/migration/framework.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
> index a3bd92a9519..38a0a1a5264 100644
> --- a/tests/qtest/migration/framework.c
> +++ b/tests/qtest/migration/framework.c
> @@ -938,6 +938,8 @@ MigrationTestEnv *migration_get_env(void)
>          exit(1);
>      }
>  
> +    env->arch = qtest_get_arch();
> +
>      env->has_kvm = qtest_has_accel("kvm");
>      env->has_tcg = qtest_has_accel("tcg");
>  
> @@ -948,7 +950,6 @@ MigrationTestEnv *migration_get_env(void)
>  
>      env->has_dirty_ring = env->has_kvm && kvm_dirty_ring_supported();
>      env->has_uffd = ufd_version_check(&env->uffd_feature_thread_id);
> -    env->arch = qtest_get_arch();
>      env->is_x86 = !strcmp(env->arch, "i386") || !strcmp(env->arch, "x86_64");
>  
>      env->tmpfs = g_dir_make_tmp("migration-test-XXXXXX", &err);

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

The change itself is fine, but I think the actual issue is that we
shouldn't be calling g_test_skip() from migration_get_env(). There's no
point adding a bunch of tests if none of them will run because there's
no supported accel present. So:

    if (!env->has_tcg && !env->has_kvm) {
-        g_test_skip("No KVM or TCG accelerator available");
-        return env;
+        g_test_message("No KVM or TCG accelerator available");
+        exit(0);
    }
Richard Henderson Jan. 28, 2025, 7:20 p.m. UTC | #2
On 1/28/25 05:54, Philippe Mathieu-Daudé wrote:
> Some tests expectMigrationTestEnv::arch to be set. Initialize
> it early enough to avoid SIGSEGV, for example like the following
> g_str_equal() call in migration/precopy-tests.c:
> 
>     954 void migration_test_add_precopy(MigrationTestEnv *env)
>     955 {
>     ...
>    1001     if (g_str_equal(env->arch, "x86_64") && env->has_dirty_ring) {
>    1002
>    1003         migration_test_add("/migration/dirty_ring",
>    1004                            test_precopy_unix_dirty_ring);
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   tests/qtest/migration/framework.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
index a3bd92a9519..38a0a1a5264 100644
--- a/tests/qtest/migration/framework.c
+++ b/tests/qtest/migration/framework.c
@@ -938,6 +938,8 @@  MigrationTestEnv *migration_get_env(void)
         exit(1);
     }
 
+    env->arch = qtest_get_arch();
+
     env->has_kvm = qtest_has_accel("kvm");
     env->has_tcg = qtest_has_accel("tcg");
 
@@ -948,7 +950,6 @@  MigrationTestEnv *migration_get_env(void)
 
     env->has_dirty_ring = env->has_kvm && kvm_dirty_ring_supported();
     env->has_uffd = ufd_version_check(&env->uffd_feature_thread_id);
-    env->arch = qtest_get_arch();
     env->is_x86 = !strcmp(env->arch, "i386") || !strcmp(env->arch, "x86_64");
 
     env->tmpfs = g_dir_make_tmp("migration-test-XXXXXX", &err);