qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v4 1/3] tests/libqtest: Introduce qtest_init_wit


From: Thomas Huth
Subject: Re: [Qemu-devel] [PATCH v4 1/3] tests/libqtest: Introduce qtest_init_with_serial()
Date: Mon, 21 Jan 2019 13:07:21 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

On 2019-01-17 17:16, Julia Suvorova wrote:
> Run qtest with a socket that connects QEMU chardev and test code.
> 
> Signed-off-by: Julia Suvorova <address@hidden>
> ---
>  tests/libqtest.c | 26 ++++++++++++++++++++++++++
>  tests/libqtest.h | 11 +++++++++++
>  2 files changed, 37 insertions(+)
> 
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 55750dd68d..3a015cfe13 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -315,6 +315,32 @@ QTestState *qtest_initf(const char *fmt, ...)
>      return s;
>  }
>  
> +QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
> +{
> +    int sock_fd_init;
> +    char *sock_path, sock_dir[] = "/tmp/qtest-serial-XXXXXX";
> +    QTestState *qts;
> +
> +    g_assert(mkdtemp(sock_dir));

We normally don't do it in QEMU, but still, it theoretically possible to
turn of g_assert() by defining G_DISABLE_ASSER, so the content should be
free of side effects. See also the doc of g_assert() here:

 https://developer.gnome.org/glib/unstable/glib-Testing.html#g-assert

Thus could you please rewrite this as:

    ptr = mkdtemp(sock_dir);
    g_assert(ptr != NULL);

?

> +    sock_path = g_strdup_printf("%s/sock", sock_dir);
> +
> +    sock_fd_init = init_socket(sock_path);
> +
> +    qts = qtest_initf("-chardev socket,id=s0,path=%s,nowait "

Daniel just posted a patch that will disallow "nowait" without "server":

 https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg03334.html

So I think you've got to drop the "nowait" here.

> +                      "-serial chardev:s0 %s",
> +                      sock_path, extra_args);
> +
> +    *sock_fd = socket_accept(sock_fd_init);
> +
> +    unlink(sock_path);
> +    g_free(sock_path);
> +    rmdir(sock_dir);
> +
> +    g_assert(*sock_fd >= 0);
> +
> +    return qts;
> +}
> +
>  void qtest_quit(QTestState *s)
>  {
>      g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s));
> diff --git a/tests/libqtest.h b/tests/libqtest.h
> index 7ea94139b0..5937f91912 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -62,6 +62,17 @@ QTestState *qtest_init(const char *extra_args);
>   */
>  QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
>  
> +/**
> + * qtest_init_with_serial:
> + * @extra_args: other arguments to pass to QEMU.  CAUTION: these
> + * arguments are subject to word splitting and shell evaluation.
> + * @sock_fd: pointer to store the socket file descriptor for
> + * connection with serial.
> + *
> + * Returns: #QTestState instance.
> + */
> +QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
> +
>  /**
>   * qtest_quit:
>   * @s: #QTestState instance to operate on.
> 

 Thomas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]