qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: "Bonzini, Paolo" <pbonzini@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	Laurent Vivier <lvivier@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 10/10] vhost-user-test: create a temporary directory per TestServer
Date: Tue, 20 Nov 2018 12:50:02 +0400	[thread overview]
Message-ID: <CAMxuvazkKuoOSjiBUkLk31G=dTYCYJCXaLOhjsrzcejpR5cFaQ@mail.gmail.com> (raw)
In-Reply-To: <20181115143124.19234-11-pbonzini@redhat.com>

On Thu, Nov 15, 2018 at 6:31 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> This makes the tests more independent, and also the source and destination
> TestServers in the migration test.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  tests/vhost-user-test.c | 75 +++++++++++++++++++----------------------
>  1 file changed, 34 insertions(+), 41 deletions(-)
>
> diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c
> index a282fc57c8..23f129f6fe 100644
> --- a/tests/vhost-user-test.c
> +++ b/tests/vhost-user-test.c
> @@ -139,6 +139,8 @@ typedef struct TestServer {
>      gchar *socket_path;
>      gchar *mig_path;
>      gchar *chr_name;
> +    const gchar *mem_path;
> +    gchar *tmpfs;
>      CharBackend chr;
>      int fds_num;
>      int fds[VHOST_MEMORY_MAX_NREGIONS];
> @@ -159,9 +161,6 @@ static TestServer *test_server_new(const gchar *name);
>  static void test_server_free(TestServer *server);
>  static void test_server_listen(TestServer *server);
>
> -static const char *tmpfs;
> -static const char *root;
> -
>  enum test_memfd {
>      TEST_MEMFD_AUTO,
>      TEST_MEMFD_YES,
> @@ -169,7 +168,7 @@ enum test_memfd {
>  };
>
>  static char *get_qemu_cmd(TestServer *s,
> -                          int mem, enum test_memfd memfd, const char *mem_path,
> +                          int mem, enum test_memfd memfd,
>                            const char *chr_opts, const char *extra)
>  {
>      if (memfd == TEST_MEMFD_AUTO && qemu_memfd_check(0)) {
> @@ -184,7 +183,7 @@ static char *get_qemu_cmd(TestServer *s,
>      } else {
>          return g_strdup_printf(QEMU_CMD_MEM QEMU_CMD_CHR
>                                 QEMU_CMD_NETDEV QEMU_CMD_NET "%s", mem, mem,
> -                               mem_path, s->chr_name, s->socket_path,
> +                               s->mem_path, s->chr_name, s->socket_path,
>                                 chr_opts, s->chr_name, extra);
>      }
>  }
> @@ -499,11 +498,21 @@ static const char *init_hugepagefs(void)
>  static TestServer *test_server_new(const gchar *name)
>  {
>      TestServer *server = g_new0(TestServer, 1);
> +    char template[] = "/tmp/vhost-test-XXXXXX";
> +    const char *tmpfs;
>
>      server->loop = g_main_loop_new(NULL, FALSE);
>      /* run the main loop thread so the chardev may operate */
>      server->thread = g_thread_new(NULL, thread_function, server->loop);
>
> +    tmpfs = mkdtemp(template);
> +    if (!tmpfs) {
> +        g_test_message("mkdtemp on path (%s): %s\n", template, strerror(errno));
> +    }
> +    g_assert(tmpfs);
> +
> +    server->tmpfs = g_strdup(tmpfs);
> +    server->mem_path = init_hugepagefs() ? : server->tmpfs;
>      server->socket_path = g_strdup_printf("%s/%s.sock", tmpfs, name);
>      server->mig_path = g_strdup_printf("%s/%s.mig", tmpfs, name);
>      server->chr_name = g_strdup_printf("chr-%s", name);
> @@ -560,6 +569,18 @@ static void test_server_free(TestServer *server)
>      }
>      g_main_loop_unref(server->loop);
>
> +    unlink(server->socket_path);
> +    g_free(server->socket_path);
> +
> +    unlink(server->mig_path);
> +    g_free(server->mig_path);
> +
> +    ret = rmdir(server->tmpfs);
> +    if (ret != 0) {
> +        g_test_message("unable to rmdir: path (%s): %s\n",
> +                       server->tmpfs, strerror(errno));
> +    }
> +
>      qemu_chr_fe_deinit(&server->chr, true);
>
>      for (i = 0; i < server->fds_num; i++) {
> @@ -570,12 +591,6 @@ static void test_server_free(TestServer *server)
>          close(server->log_fd);
>      }
>
> -    unlink(server->socket_path);
> -    g_free(server->socket_path);
> -
> -    unlink(server->mig_path);
> -    g_free(server->mig_path);
> -
>      g_free(server->chr_name);
>      g_assert(server->bus);
>      qpci_free_pc(server->bus);
> @@ -681,7 +696,7 @@ static void test_read_guest_mem(const void *arg)
>                               "read-guest-memfd" : "read-guest-mem");
>      test_server_listen(server);
>
> -    qemu_cmd = get_qemu_cmd(server, 512, memfd, root, "", "");
> +    qemu_cmd = get_qemu_cmd(server, 512, memfd, "", "");
>
>      s = qtest_start(qemu_cmd);
>      g_free(qemu_cmd);
> @@ -716,7 +731,7 @@ static void test_migrate(void)
>      test_server_listen(s);
>      test_server_listen(dest);
>
> -    cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, "", "");
> +    cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, "", "");
>      from = qtest_start(cmd);
>      g_free(cmd);
>
> @@ -729,7 +744,7 @@ static void test_migrate(void)
>      g_assert_cmpint(size, ==, (2 * 1024 * 1024) / (VHOST_LOG_PAGE * 8));
>
>      tmp = g_strdup_printf(" -incoming %s", uri);
> -    cmd = get_qemu_cmd(dest, 2, TEST_MEMFD_AUTO, root, "", tmp);
> +    cmd = get_qemu_cmd(dest, 2, TEST_MEMFD_AUTO, "", tmp);
>      g_free(tmp);
>      to = qtest_init(cmd);
>      g_free(cmd);
> @@ -839,7 +854,7 @@ static void test_reconnect_subprocess(void)
>      char *cmd;
>
>      g_thread_new("connect", connect_thread, s);
> -    cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, ",server", "");
> +    cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, ",server", "");
>      qtest_start(cmd);
>      g_free(cmd);
>
> @@ -881,7 +896,7 @@ static void test_connect_fail_subprocess(void)
>
>      s->test_fail = true;
>      g_thread_new("connect", connect_thread, s);
> -    cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, ",server", "");
> +    cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, ",server", "");
>      qtest_start(cmd);
>      g_free(cmd);
>
> @@ -914,7 +929,7 @@ static void test_flags_mismatch_subprocess(void)
>
>      s->test_flags = TEST_FLAGS_DISCONNECT;
>      g_thread_new("connect", connect_thread, s);
> -    cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, root, ",server", "");
> +    cmd = get_qemu_cmd(s, 2, TEST_MEMFD_AUTO, ",server", "");
>      qtest_start(cmd);
>      g_free(cmd);
>
> @@ -962,7 +977,7 @@ static void test_multiqueue(void)
>          cmd = g_strdup_printf(
>              QEMU_CMD_MEM QEMU_CMD_CHR QEMU_CMD_NETDEV ",queues=%d "
>              "-device virtio-net-pci,netdev=net0,mq=on,vectors=%d",
> -            512, 512, root, s->chr_name,
> +            512, 512, s->mem_path, s->chr_name,
>              s->socket_path, "", s->chr_name,
>              s->queues, s->queues * 2 + 2);
>      }
> @@ -982,22 +997,11 @@ static void test_multiqueue(void)
>
>  int main(int argc, char **argv)
>  {
> -    int ret;
> -    char template[] = "/tmp/vhost-test-XXXXXX";
> -
>      g_test_init(&argc, &argv, NULL);
>
>      module_call_init(MODULE_INIT_QOM);
>      qemu_add_opts(&qemu_chardev_opts);
>
> -    tmpfs = mkdtemp(template);
> -    if (!tmpfs) {
> -        g_test_message("mkdtemp on path (%s): %s\n", template, strerror(errno));
> -    }
> -    g_assert(tmpfs);
> -
> -    root = init_hugepagefs() ? : tmpfs;
> -
>      if (qemu_memfd_check(0)) {
>          qtest_add_data_func("/vhost-user/read-guest-mem/memfd",
>                              GINT_TO_POINTER(TEST_MEMFD_YES),
> @@ -1021,16 +1025,5 @@ int main(int argc, char **argv)
>          qtest_add_func("/vhost-user/flags-mismatch", test_flags_mismatch);
>      }
>
> -    ret = g_test_run();
> -
> -    /* cleanup */
> -
> -    ret = rmdir(tmpfs);
> -    if (ret != 0) {
> -        g_test_message("unable to rmdir: path (%s): %s\n",
> -                       tmpfs, strerror(errno));
> -    }
> -    g_assert_cmpint(ret, ==, 0);
> -
> -    return ret;
> +    return g_test_run();
>  }
> --
> 2.19.1
>

  reply	other threads:[~2018-11-20  8:50 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-15 14:31 [Qemu-devel] [PATCH for-3.2 00/10] vhost: preparation for qgraph conversion of vhost-user-test Paolo Bonzini
2018-11-15 14:31 ` [Qemu-devel] [PATCH 01/10] vhost-user-test: use g_cond_broadcast Paolo Bonzini
2018-11-20  8:50   ` Marc-André Lureau
2018-11-15 14:31 ` [Qemu-devel] [PATCH 02/10] vhost-user-test: signal data_cond when s->rings changes Paolo Bonzini
2018-11-20  8:50   ` Marc-André Lureau
2018-11-15 14:31 ` [Qemu-devel] [PATCH 03/10] vhost-net: compile it for all targets Paolo Bonzini
2018-11-15 18:42   ` Paolo Bonzini
2018-11-20  8:50     ` Marc-André Lureau
2019-01-15  3:50     ` Michael S. Tsirkin
2019-01-15  7:18       ` Paolo Bonzini
2018-11-15 14:31 ` [Qemu-devel] [PATCH 04/10] vhost-user: support cross-endian vnet headers Paolo Bonzini
2018-11-20  8:50   ` Marc-André Lureau
2018-11-15 14:31 ` [Qemu-devel] [PATCH 05/10] vhost-user-test: support VHOST_USER_PROTOCOL_F_CROSS_ENDIAN Paolo Bonzini
2018-11-20  8:50   ` Marc-André Lureau
2018-11-15 14:31 ` [Qemu-devel] [PATCH 06/10] vhost-user-test: skip if there is no memory at address 0 Paolo Bonzini
2018-11-15 14:31 ` [Qemu-devel] [PATCH 07/10] vhost-user-test: reduce usage of global_qtest Paolo Bonzini
2018-11-20  8:50   ` Marc-André Lureau
2018-11-15 14:31 ` [Qemu-devel] [PATCH 08/10] vhost-user-test: create a main loop per TestServer Paolo Bonzini
2018-11-20  8:50   ` Marc-André Lureau
2018-11-15 14:31 ` [Qemu-devel] [PATCH 09/10] vhost-user-test: small changes to init_hugepagefs Paolo Bonzini
2018-11-15 14:55   ` Philippe Mathieu-Daudé
2018-11-15 18:41     ` Paolo Bonzini
2018-11-15 18:45       ` Philippe Mathieu-Daudé
2018-11-15 18:46         ` Paolo Bonzini
2018-11-15 14:31 ` [Qemu-devel] [PATCH 10/10] vhost-user-test: create a temporary directory per TestServer Paolo Bonzini
2018-11-20  8:50   ` Marc-André Lureau [this message]
2018-11-16  0:43 ` [Qemu-devel] [PATCH for-3.2 00/10] vhost: preparation for qgraph conversion of vhost-user-test no-reply

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='CAMxuvazkKuoOSjiBUkLk31G=dTYCYJCXaLOhjsrzcejpR5cFaQ@mail.gmail.com' \
    --to=marcandre.lureau@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).