qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Fabiano Rosas <farosas@suse.de>
Cc: qemu-devel@nongnu.org, "Thomas Huth" <thuth@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Fiona Ebner" <f.ebner@proxmox.com>,
	"Het Gala" <het.gala@nutanix.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [RFC PATCH 2/4] tests/qtest/migration: Add a test that runs vmstate-static-checker
Date: Mon, 27 May 2024 17:06:29 -0400	[thread overview]
Message-ID: <ZlT11c-9IDwVfm52@x1n> (raw)
In-Reply-To: <20240523201922.28007-3-farosas@suse.de>

On Thu, May 23, 2024 at 05:19:20PM -0300, Fabiano Rosas wrote:
> We have the vmstate-static-checker script that takes the output of:
> '$QEMU -M $machine -dump-vmstate' for two different QEMU versions and
> compares them to check for compatibility breakages. This is just too
> simple and useful for us to pass on it. Add a test that runs the
> script.
> 
> Since this needs to use two different QEMU versions, the test is
> skipped if only one QEMU is provided. The infrastructure for passing
> more than one binary is already in place:
> 
> $ PYTHON=$(which python3.11) \
>  QTEST_QEMU_BINARY_SRC=../build-previous/qemu-system-x86_64 \
>  QTEST_QEMU_BINARY=./qemu-system-x86_64 \
>  ./tests/qtest/migration-test -p /x86_64/migration/vmstate-checker-script
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
> some code duplication for now, just so we can reason about this
> without too much noise
> ---
>  tests/qtest/migration-test.c | 82 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 82 insertions(+)
> 
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index e8d3555f56..2253e0fc5b 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -63,6 +63,7 @@ static QTestMigrationState dst_state;
>  #define DIRTYLIMIT_TOLERANCE_RANGE  25  /* MB/s */
>  
>  #define ANALYZE_SCRIPT "scripts/analyze-migration.py"
> +#define VMSTATE_CHECKER_SCRIPT "scripts/vmstate-static-checker.py"
>  
>  #define QEMU_VM_FILE_MAGIC 0x5145564d
>  #define FILE_TEST_FILENAME "migfile"
> @@ -1611,6 +1612,85 @@ static void test_analyze_script(void)
>      test_migrate_end(from, to, false);
>      cleanup("migfile");
>  }
> +
> +static void test_vmstate_checker_script(void)
> +{
> +    g_autofree gchar *cmd_src = NULL;
> +    g_autofree gchar *cmd_dst = NULL;
> +    g_autofree gchar *vmstate_src = NULL;
> +    g_autofree gchar *vmstate_dst = NULL;
> +    const char *machine_alias, *machine_opts = "";
> +    g_autofree char *machine = NULL;
> +    const char *arch = qtest_get_arch();
> +    int pid, wstatus;
> +    const char *python = g_getenv("PYTHON");
> +
> +    if (!getenv(QEMU_ENV_SRC) && !getenv(QEMU_ENV_DST)) {
> +        g_test_skip("Test needs two different QEMU versions");
> +        return;
> +    }
> +
> +    if (!python) {
> +        g_test_skip("PYTHON variable not set");
> +        return;
> +    }
> +
> +    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
> +        if (g_str_equal(arch, "i386")) {
> +            machine_alias = "pc";
> +        } else {
> +            machine_alias = "q35";
> +        }
> +    } else if (g_str_equal(arch, "s390x")) {
> +        machine_alias = "s390-ccw-virtio";
> +    } else if (strcmp(arch, "ppc64") == 0) {
> +        machine_alias = "pseries";
> +    } else if (strcmp(arch, "aarch64") == 0) {
> +        machine_alias = "virt";
> +    } else {
> +        g_assert_not_reached();
> +    }
> +
> +    if (!qtest_has_machine(machine_alias)) {
> +        g_autofree char *msg = g_strdup_printf("machine %s not supported", machine_alias);
> +        g_test_skip(msg);
> +        return;
> +    }
> +
> +    machine = resolve_machine_version(machine_alias, QEMU_ENV_SRC,
> +                                      QEMU_ENV_DST);
> +
> +    vmstate_src = g_strdup_printf("%s/vmstate-src", tmpfs);
> +    vmstate_dst = g_strdup_printf("%s/vmstate-dst", tmpfs);
> +
> +    cmd_dst = g_strdup_printf("-machine %s,%s -dump-vmstate %s",
> +                              machine, machine_opts, vmstate_dst);
> +    cmd_src = g_strdup_printf("-machine %s,%s -dump-vmstate %s",
> +                              machine, machine_opts, vmstate_src);
> +
> +    qtest_init_with_env_no_handshake(QEMU_ENV_SRC, cmd_src);
> +    qtest_init_with_env_no_handshake(QEMU_ENV_DST, cmd_dst);
> +
> +    pid = fork();
> +    if (!pid) {
> +        close(1);
> +        open("/dev/null", O_WRONLY);
> +        execl(python, python, VMSTATE_CHECKER_SCRIPT,
> +              "-s", vmstate_src,
> +              "-d", vmstate_dst,
> +              NULL);
> +        g_assert_not_reached();
> +    }
> +
> +    g_assert(waitpid(pid, &wstatus, 0) == pid);
> +    if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus) != 0) {
> +        g_test_message("Failed to run vmstate-static-checker.py");
> +        g_test_fail();
> +    }
> +
> +    cleanup("vmstate-src");
> +    cleanup("vmstate-dst");
> +}

Did I ask before on whether this can be written without C?

I think this and also the analyze-script are more suitable to be written in
other ways, e.g., bash or python, no?

>  #endif
>  
>  static void test_precopy_common(MigrateCommon *args)
> @@ -3495,6 +3575,8 @@ int main(int argc, char **argv)
>  #ifndef _WIN32
>      if (!g_str_equal(arch, "s390x")) {
>          migration_test_add("/migration/analyze-script", test_analyze_script);
> +        migration_test_add("/migration/vmstate-checker-script",
> +                           test_vmstate_checker_script);
>      }
>  #endif
>      migration_test_add("/migration/precopy/unix/plain",
> -- 
> 2.35.3
> 

-- 
Peter Xu



  reply	other threads:[~2024-05-27 21:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-23 20:19 [RFC PATCH 0/4] migration-test: Device migration smoke tests Fabiano Rosas
2024-05-23 20:19 ` [RFC PATCH 1/4] tests/qtest/libqtest: Introduce another qtest_init version with no handshake Fabiano Rosas
2024-05-23 20:19 ` [RFC PATCH 2/4] tests/qtest/migration: Add a test that runs vmstate-static-checker Fabiano Rosas
2024-05-27 21:06   ` Peter Xu [this message]
2024-05-27 22:52     ` Fabiano Rosas
2024-05-28 15:52       ` Peter Xu
2024-05-23 20:19 ` [RFC PATCH 3/4] tests/qtest/migration: Add support for simple device tests Fabiano Rosas
2024-05-27 21:12   ` Peter Xu
2024-05-27 22:59     ` Fabiano Rosas
2024-05-28 15:35       ` Peter Xu
2024-05-23 20:19 ` [RFC PATCH 4/4] ci: Add the new migration " Fabiano Rosas
2024-05-27 21:17   ` Peter Xu
2024-05-27 23:59     ` Fabiano Rosas
2024-05-28 15:48       ` Peter Xu
2024-05-28 18:10         ` Fabiano Rosas
2024-05-28 18:52           ` Peter Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZlT11c-9IDwVfm52@x1n \
    --to=peterx@redhat.com \
    --cc=f.ebner@proxmox.com \
    --cc=farosas@suse.de \
    --cc=het.gala@nutanix.com \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).