[PATCH V1 05/11] tests/qtest: qtest_init_after_exec

Steve Sistare posted 11 patches 4 months, 3 weeks ago
Maintainers: Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>, Steve Sistare <steven.sistare@oracle.com>
[PATCH V1 05/11] tests/qtest: qtest_init_after_exec
Posted by Steve Sistare 4 months, 3 weeks ago
Define a function to create a QTestState object representing the state
of QEMU after old QEMU exec's new QEMU.  This is needed for testing
the cpr-exec migration mode.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
 tests/qtest/libqtest.h |  8 ++++++++
 tests/qtest/libqtest.c | 19 +++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index a164f58..ce6b9b0 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -57,6 +57,14 @@ QTestState *qtest_vinitf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
 const char *qtest_qemu_binary(const char *var);
 
 /**
+ * qtest_init_after_exec:
+ * @from: the previous QEMU state
+ *
+ * Return a test state representing new QEMU after @from exec's it.
+ */
+QTestState *qtest_init_after_exec(QTestState *from);
+
+/**
  * qtest_qemu_args:
  * @extra_args: Other arguments to pass to QEMU.
  *
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index d97144e..3522d75 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -615,6 +615,25 @@ QTestState *qtest_init_ext(const char *var, const char *extra_args,
     return s;
 }
 
+static QTestState *qtest_attach_qemu(const char *qemu_bin,
+                                     const char *extra_args,
+                                     void *opaque)
+{
+    int pid = *(int *)opaque;
+    return qtest_create_test_state(pid);
+}
+
+QTestState *qtest_init_after_exec(QTestState *from)
+{
+    void *opaque = (void *)&from->qemu_pid;
+    QTestState *s;
+
+    s = qtest_init_internal(NULL, NULL, true, qtest_attach_qemu, opaque);
+    from->qemu_pid = -1;
+    qtest_qmp_handshake(s, NULL);
+    return s;
+}
+
 QTestState *qtest_init(const char *extra_args)
 {
     return qtest_init_ext(NULL, extra_args, NULL, true);
-- 
1.8.3.1
Re: [PATCH V1 05/11] tests/qtest: qtest_init_after_exec
Posted by Fabiano Rosas 4 months, 1 week ago
Steve Sistare <steven.sistare@oracle.com> writes:

> Define a function to create a QTestState object representing the state
> of QEMU after old QEMU exec's new QEMU.  This is needed for testing
> the cpr-exec migration mode.
>
> Signed-off-by: Steve Sistare <steven.sistare@oracle.com>

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

> ---
>  tests/qtest/libqtest.h |  8 ++++++++
>  tests/qtest/libqtest.c | 19 +++++++++++++++++++
>  2 files changed, 27 insertions(+)
>
> diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
> index a164f58..ce6b9b0 100644
> --- a/tests/qtest/libqtest.h
> +++ b/tests/qtest/libqtest.h
> @@ -57,6 +57,14 @@ QTestState *qtest_vinitf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
>  const char *qtest_qemu_binary(const char *var);
>  
>  /**
> + * qtest_init_after_exec:
> + * @from: the previous QEMU state

qts is the term used in libqtest. I'll amend it myself.

> + *
> + * Return a test state representing new QEMU after @from exec's it.
> + */
> +QTestState *qtest_init_after_exec(QTestState *from);
> +
> +/**
>   * qtest_qemu_args:
>   * @extra_args: Other arguments to pass to QEMU.
>   *
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index d97144e..3522d75 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -615,6 +615,25 @@ QTestState *qtest_init_ext(const char *var, const char *extra_args,
>      return s;
>  }
>  
> +static QTestState *qtest_attach_qemu(const char *qemu_bin,
> +                                     const char *extra_args,
> +                                     void *opaque)
> +{
> +    int pid = *(int *)opaque;
> +    return qtest_create_test_state(pid);
> +}
> +
> +QTestState *qtest_init_after_exec(QTestState *from)
> +{
> +    void *opaque = (void *)&from->qemu_pid;
> +    QTestState *s;
> +
> +    s = qtest_init_internal(NULL, NULL, true, qtest_attach_qemu, opaque);
> +    from->qemu_pid = -1;
> +    qtest_qmp_handshake(s, NULL);
> +    return s;
> +}
> +
>  QTestState *qtest_init(const char *extra_args)
>  {
>      return qtest_init_ext(NULL, extra_args, NULL, true);