qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: mprivozn@redhat.com, pbonzini@redhat.com, berrange@redhat.com,
	qemu-devel@nongnu.org, quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 4/6] tests: add qtest_expect_exit_status()
Date: Fri, 13 Sep 2019 14:33:43 +0100	[thread overview]
Message-ID: <20190913133343.GD2682@work-vm> (raw)
In-Reply-To: <20190912122514.22504-5-marcandre.lureau@redhat.com>

* Marc-André Lureau (marcandre.lureau@redhat.com) wrote:
> Modify the behaviour of qtest_quit() to check against the expected
> exit status value. The default remains 0.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

This looks similar to the one in the current pending migration pull
by Yury Kotov:
   'tests/libqtest: Allow setting expected exit status'

Dave

> ---
>  tests/libqtest.c | 41 ++++++++++++++++++++++-------------------
>  tests/libqtest.h |  9 +++++++++
>  2 files changed, 31 insertions(+), 19 deletions(-)
> 
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 0a6b91737e..1f7910e583 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -44,6 +44,7 @@ struct QTestState
>      bool big_endian;
>      bool irq_level[MAX_IRQ];
>      GString *rx;
> +    int exit_status;
>  };
>  
>  static GHookList abrt_hooks;
> @@ -123,27 +124,29 @@ static void kill_qemu(QTestState *s)
>          assert(pid == s->qemu_pid);
>      }
>  
> -    /*
> -     * We expect qemu to exit with status 0; anything else is
> -     * fishy and should be logged with as much detail as possible.
> -     */
>      wstatus = s->wstatus;
> -    if (wstatus) {
> -        if (WIFEXITED(wstatus)) {
> -            fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
> -                    "process but encountered exit status %d\n",
> -                    __FILE__, __LINE__, WEXITSTATUS(wstatus));
> -        } else if (WIFSIGNALED(wstatus)) {
> -            int sig = WTERMSIG(wstatus);
> -            const char *signame = strsignal(sig) ?: "unknown ???";
> -            const char *dump = WCOREDUMP(wstatus) ? " (core dumped)" : "";
> -
> -            fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death "
> -                    "from signal %d (%s)%s\n",
> -                    __FILE__, __LINE__, sig, signame, dump);
> +    if (WIFEXITED(wstatus)) {
> +        if (WEXITSTATUS(wstatus) == s->exit_status) {
> +            return;
>          }
> -        abort();
> +        fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
> +                "process but encountered exit status %d\n",
> +                __FILE__, __LINE__, WEXITSTATUS(wstatus));
> +    } else if (WIFSIGNALED(wstatus)) {
> +        int sig = WTERMSIG(wstatus);
> +        const char *signame = strsignal(sig) ?: "unknown ???";
> +        const char *dump = WCOREDUMP(wstatus) ? " (core dumped)" : "";
> +
> +        fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death "
> +                "from signal %d (%s)%s\n",
> +                __FILE__, __LINE__, sig, signame, dump);
>      }
> +    abort();
> +}
> +
> +void qtest_expect_exit_status(QTestState *s, int status)
> +{
> +    s->exit_status = status;
>  }
>  
>  static void kill_qemu_hook_func(void *s)
> @@ -213,7 +216,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>      gchar *command;
>      const char *qemu_binary = qtest_qemu_binary();
>  
> -    s = g_new(QTestState, 1);
> +    s = g_new0(QTestState, 1);
>  
>      socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
>      qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
> diff --git a/tests/libqtest.h b/tests/libqtest.h
> index c8cffe5d68..d41229d7fd 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -82,6 +82,15 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
>   */
>  void qtest_quit(QTestState *s);
>  
> +/**
> + * qtest_expect_exit_status:
> + * @s: #QTestState instance to operate on.
> + * @status: the expected exit status
> + *
> + * Set the expected exit status when calling qtest_quit().
> + */
> +void qtest_expect_exit_status(QTestState *s, int status);
> +
>  /**
>   * qtest_qmp_fds:
>   * @s: #QTestState instance to operate on.
> -- 
> 2.23.0
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK


  reply	other threads:[~2019-09-13 13:39 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12 12:25 [Qemu-devel] [PATCH v3 0/6] Add dbus-vmstate Marc-André Lureau
2019-09-12 12:25 ` [Qemu-devel] [PATCH v3 1/6] migration: fix vmdesc leak on vmstate_save() error Marc-André Lureau
2019-09-13 13:29   ` Dr. David Alan Gilbert
2019-09-17 12:31   ` Daniel P. Berrangé
2019-09-25  9:49   ` Dr. David Alan Gilbert
2019-09-12 12:25 ` [Qemu-devel] [PATCH v3 2/6] vmstate: add qom interface to get id Marc-André Lureau
2019-09-16  9:54   ` Dr. David Alan Gilbert
2019-09-17 12:33   ` Daniel P. Berrangé
2019-09-12 12:25 ` [Qemu-devel] [PATCH v3 3/6] vmstate: replace DeviceState with VMStateIf Marc-André Lureau
2019-09-12 16:18   ` Halil Pasic
2019-09-13  7:12     ` Marc-André Lureau
2019-09-16  9:06   ` Dr. David Alan Gilbert
2019-09-17 12:35   ` Daniel P. Berrangé
2019-09-12 12:25 ` [Qemu-devel] [PATCH v3 4/6] tests: add qtest_expect_exit_status() Marc-André Lureau
2019-09-13 13:33   ` Dr. David Alan Gilbert [this message]
2019-09-17 12:36   ` Daniel P. Berrangé
2019-09-12 12:25 ` [Qemu-devel] [PATCH v3 5/6] docs: start a document to describe D-Bus usage Marc-André Lureau
2019-09-16 10:00   ` Dr. David Alan Gilbert
2019-09-16 10:57     ` Marc-André Lureau
2019-09-16 13:15       ` Dr. David Alan Gilbert
2019-09-16 19:13         ` Marc-André Lureau
2019-09-17  8:12           ` Dr. David Alan Gilbert
2019-09-17  8:23             ` Marc-André Lureau
2019-09-17 12:47     ` Daniel P. Berrangé
2019-09-17 13:03       ` Dr. David Alan Gilbert
2019-09-19  9:23     ` Stefan Hajnoczi
2019-09-17 13:07   ` Daniel P. Berrangé
2019-09-12 12:25 ` [Qemu-devel] [PATCH v3 6/6] Add dbus-vmstate object Marc-André Lureau
2019-09-12 14:29   ` Eric Blake
2019-09-16 10:43   ` Dr. David Alan Gilbert
2019-09-17 13:21   ` Daniel P. Berrangé
2019-09-12 13:50 ` [Qemu-devel] [PATCH v3 0/6] Add dbus-vmstate 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=20190913133343.GD2682@work-vm \
    --to=dgilbert@redhat.com \
    --cc=berrange@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mprivozn@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@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).