From: Thomas Huth <thuth@redhat.com>
To: "Yury Kotov" <yury-kotov@yandex-team.ru>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, yc-core@yandex-team.ru
Subject: Re: [Qemu-devel] [PATCH v2 2/3] tests/libqtest: Allow setting expected exit status
Date: Wed, 4 Sep 2019 06:19:34 +0200 [thread overview]
Message-ID: <ced2a481-9089-6d0a-2934-b9714d053254@redhat.com> (raw)
In-Reply-To: <20190903162246.18524-3-yury-kotov@yandex-team.ru>
On 03/09/2019 18.22, Yury Kotov wrote:
> Add qtest_set_expected_status function to set expected exit status of
> child process. By default expected exit status is 0.
>
> Signed-off-by: Yury Kotov <yury-kotov@yandex-team.ru>
> ---
> tests/libqtest.c | 36 +++++++++++++++++++++---------------
> tests/libqtest.h | 9 +++++++++
> 2 files changed, 30 insertions(+), 15 deletions(-)
>
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 2713b86cf7..a79d4887ae 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -43,6 +43,7 @@ struct QTestState
> int qmp_fd;
> pid_t qemu_pid; /* our child QEMU process */
> int wstatus;
> + int expected_status;
> bool big_endian;
> bool irq_level[MAX_IRQ];
> GString *rx;
> @@ -113,6 +114,11 @@ bool qtest_probe_child(QTestState *s)
> return false;
> }
>
> +void qtest_set_expected_status(QTestState *s, int status)
> +{
> + s->expected_status = status;
> +}
> +
> static void kill_qemu(QTestState *s)
> {
> pid_t pid = s->qemu_pid;
> @@ -126,24 +132,23 @@ static void kill_qemu(QTestState *s)
> }
>
> /*
> - * We expect qemu to exit with status 0; anything else is
> + * Check whether qemu exited with expected exit status; 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) && WEXITSTATUS(wstatus) != s->expected_status) {
> + fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
> + "process but encountered exit status %d (expected %d)\n",
> + __FILE__, __LINE__, WEXITSTATUS(wstatus), s->expected_status);
> + abort();
> + } 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();
> }
> }
> @@ -248,6 +253,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
> g_test_message("starting QEMU: %s", command);
>
> s->wstatus = 0;
> + s->expected_status = 0;
> s->qemu_pid = fork();
> if (s->qemu_pid == 0) {
> setenv("QEMU_AUDIO_DRV", "none", true);
> diff --git a/tests/libqtest.h b/tests/libqtest.h
> index 07ea35867c..c00bca94af 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -997,4 +997,13 @@ void qmp_assert_error_class(QDict *rsp, const char *class);
> */
> bool qtest_probe_child(QTestState *s);
>
> +/**
> + * qtest_set_expected_status:
> + * @s: QTestState instance to operate on.
> + * @status: an expected exit status.
> + *
> + * Set expected exit status of the child.
> + */
> +void qtest_set_expected_status(QTestState *s, int status);
> +
> #endif
>
Acked-by: Thomas Huth <thuth@redhat.com>
next prev parent reply other threads:[~2019-09-04 4:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-03 16:22 [Qemu-devel] [PATCH v2 0/3] UUID validation during migration Yury Kotov
2019-09-03 16:22 ` [Qemu-devel] [PATCH v2 1/3] migration: Add validate-uuid capability Yury Kotov
2019-09-11 9:15 ` Dr. David Alan Gilbert
2019-09-03 16:22 ` [Qemu-devel] [PATCH v2 2/3] tests/libqtest: Allow setting expected exit status Yury Kotov
2019-09-04 4:19 ` Thomas Huth [this message]
2019-09-11 9:46 ` Dr. David Alan Gilbert
2019-09-03 16:22 ` [Qemu-devel] [PATCH v2 3/3] tests/migration: Add a test for validate-uuid capability Yury Kotov
2019-09-11 10:02 ` Dr. David Alan Gilbert
2019-09-12 10:20 ` [Qemu-devel] [PATCH v2 0/3] UUID validation during migration Dr. David Alan Gilbert
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=ced2a481-9089-6d0a-2934-b9714d053254@redhat.com \
--to=thuth@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=yc-core@yandex-team.ru \
--cc=yury-kotov@yandex-team.ru \
/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).