* [Qemu-devel] [PATCH] tests: Exit boot-serial-test loop if child dies
@ 2018-12-17 3:58 Richard Henderson
2018-12-17 10:39 ` Thomas Huth
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Richard Henderson @ 2018-12-17 3:58 UTC (permalink / raw)
To: qemu-devel; +Cc: Thomas Huth, Laurent Vivier, Paolo Bonzini
There's no point in waiting 5 full minutes when there will be
no more output. Compute timeout based on elapsed wall clock
time instead of N * delays, as the delay is a minimum sleep time.
Cc: Thomas Huth <thuth@redhat.com>
Cc: Laurent Vivier <lvivier@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tests/libqtest.h | 8 +++++
tests/boot-serial-test.c | 16 +++++++--
tests/libqtest.c | 70 +++++++++++++++++++++++++---------------
3 files changed, 65 insertions(+), 29 deletions(-)
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 96a6c01352..9758c51be6 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -1011,4 +1011,12 @@ bool qmp_rsp_is_err(QDict *rsp);
*/
void qmp_assert_error_class(QDict *rsp, const char *class);
+/**
+ * qtest_probe_child:
+ * @s: QTestState instance to operate on.
+ *
+ * Returns: true if the child is still alive.
+ */
+bool qtest_probe_child(QTestState *s);
+
#endif
diff --git a/tests/boot-serial-test.c b/tests/boot-serial-test.c
index 8ec6aed35d..54b9347325 100644
--- a/tests/boot-serial-test.c
+++ b/tests/boot-serial-test.c
@@ -130,11 +130,12 @@ static testdef_t tests[] = {
static bool check_guest_output(const testdef_t *test, int fd)
{
- int i, nbr = 0, pos = 0, ccnt;
+ int nbr = 0, pos = 0, ccnt;
+ time_t now, start = time(NULL);
char ch;
- /* Poll serial output... Wait at most 360 seconds */
- for (i = 0; i < 36000; ++i) {
+ /* Poll serial output... */
+ while (1) {
ccnt = 0;
while (ccnt++ < 512 && (nbr = read(fd, &ch, 1)) == 1) {
if (ch == test->expect[pos]) {
@@ -148,6 +149,15 @@ static bool check_guest_output(const testdef_t *test, int fd)
}
}
g_assert(nbr >= 0);
+ /* Wait only if the child is still alive. */
+ if (!qtest_probe_child(global_qtest)) {
+ break;
+ }
+ /* Wait at most 360 seconds. */
+ now = time(NULL);
+ if (now - start >= 360) {
+ break;
+ }
g_usleep(10000);
}
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 43be078518..1d75d3c936 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -39,10 +39,11 @@ struct QTestState
{
int fd;
int qmp_fd;
+ pid_t qemu_pid; /* our child QEMU process */
+ int wstatus;
+ bool big_endian;
bool irq_level[MAX_IRQ];
GString *rx;
- pid_t qemu_pid; /* our child QEMU process */
- bool big_endian;
};
static GHookList abrt_hooks;
@@ -96,36 +97,52 @@ static int socket_accept(int sock)
return ret;
}
+bool qtest_probe_child(QTestState *s)
+{
+ pid_t pid = s->qemu_pid;
+
+ if (pid != -1) {
+ pid = waitpid(pid, &s->wstatus, WNOHANG);
+ if (pid == 0) {
+ return true;
+ }
+ s->qemu_pid = -1;
+ }
+ return false;
+}
+
static void kill_qemu(QTestState *s)
{
- if (s->qemu_pid != -1) {
- int wstatus = 0;
- pid_t pid;
-
- kill(s->qemu_pid, SIGTERM);
- TFR(pid = waitpid(s->qemu_pid, &wstatus, 0));
+ pid_t pid = s->qemu_pid;
+ int wstatus;
+ /* Skip wait if qtest_probe_child already reaped. */
+ if (pid != -1) {
+ kill(pid, SIGTERM);
+ TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
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.
- */
- 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);
- }
- abort();
+ /*
+ * 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);
}
+ abort();
}
}
@@ -228,6 +245,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
g_test_message("starting QEMU: %s", command);
+ s->wstatus = 0;
s->qemu_pid = fork();
if (s->qemu_pid == 0) {
setenv("QEMU_AUDIO_DRV", "none", true);
--
2.17.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] tests: Exit boot-serial-test loop if child dies
2018-12-17 3:58 [Qemu-devel] [PATCH] tests: Exit boot-serial-test loop if child dies Richard Henderson
@ 2018-12-17 10:39 ` Thomas Huth
2018-12-17 10:52 ` Philippe Mathieu-Daudé
2018-12-17 14:12 ` Wainer dos Santos Moschetta
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2018-12-17 10:39 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Laurent Vivier, Paolo Bonzini, Eric Blake, Michael S . Tsirkin
On 2018-12-17 04:58, Richard Henderson wrote:
> There's no point in waiting 5 full minutes when there will be
> no more output.
Sounds like a very good idea, indeed.
As a follow up patch, we should likely use this in the other tests that
use TCG, too (i.e. in boot_sector_test() in tests/boot-sector.c).
> Compute timeout based on elapsed wall clock
> time instead of N * delays, as the delay is a minimum sleep time.
>
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Laurent Vivier <lvivier@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> tests/libqtest.h | 8 +++++
> tests/boot-serial-test.c | 16 +++++++--
> tests/libqtest.c | 70 +++++++++++++++++++++++++---------------
> 3 files changed, 65 insertions(+), 29 deletions(-)
>
> diff --git a/tests/libqtest.h b/tests/libqtest.h
> index 96a6c01352..9758c51be6 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -1011,4 +1011,12 @@ bool qmp_rsp_is_err(QDict *rsp);
> */
> void qmp_assert_error_class(QDict *rsp, const char *class);
>
> +/**
> + * qtest_probe_child:
> + * @s: QTestState instance to operate on.
> + *
> + * Returns: true if the child is still alive.
> + */
> +bool qtest_probe_child(QTestState *s);
> +
> #endif
> diff --git a/tests/boot-serial-test.c b/tests/boot-serial-test.c
> index 8ec6aed35d..54b9347325 100644
> --- a/tests/boot-serial-test.c
> +++ b/tests/boot-serial-test.c
> @@ -130,11 +130,12 @@ static testdef_t tests[] = {
>
> static bool check_guest_output(const testdef_t *test, int fd)
> {
> - int i, nbr = 0, pos = 0, ccnt;
> + int nbr = 0, pos = 0, ccnt;
> + time_t now, start = time(NULL);
> char ch;
>
> - /* Poll serial output... Wait at most 360 seconds */
> - for (i = 0; i < 36000; ++i) {
> + /* Poll serial output... */
> + while (1) {
> ccnt = 0;
> while (ccnt++ < 512 && (nbr = read(fd, &ch, 1)) == 1) {
> if (ch == test->expect[pos]) {
> @@ -148,6 +149,15 @@ static bool check_guest_output(const testdef_t *test, int fd)
> }
> }
> g_assert(nbr >= 0);
> + /* Wait only if the child is still alive. */
> + if (!qtest_probe_child(global_qtest)) {
> + break;
> + }
> + /* Wait at most 360 seconds. */
> + now = time(NULL);
> + if (now - start >= 360) {
> + break;
> + }
> g_usleep(10000);
> }
>
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 43be078518..1d75d3c936 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -39,10 +39,11 @@ struct QTestState
> {
> int fd;
> int qmp_fd;
> + pid_t qemu_pid; /* our child QEMU process */
> + int wstatus;
> + bool big_endian;
> bool irq_level[MAX_IRQ];
> GString *rx;
> - pid_t qemu_pid; /* our child QEMU process */
> - bool big_endian;
> };
>
> static GHookList abrt_hooks;
> @@ -96,36 +97,52 @@ static int socket_accept(int sock)
> return ret;
> }
>
> +bool qtest_probe_child(QTestState *s)
> +{
> + pid_t pid = s->qemu_pid;
> +
> + if (pid != -1) {
> + pid = waitpid(pid, &s->wstatus, WNOHANG);
> + if (pid == 0) {
> + return true;
> + }
> + s->qemu_pid = -1;
> + }
> + return false;
> +}
> +
> static void kill_qemu(QTestState *s)
> {
> - if (s->qemu_pid != -1) {
> - int wstatus = 0;
> - pid_t pid;
> -
> - kill(s->qemu_pid, SIGTERM);
> - TFR(pid = waitpid(s->qemu_pid, &wstatus, 0));
> + pid_t pid = s->qemu_pid;
> + int wstatus;
>
> + /* Skip wait if qtest_probe_child already reaped. */
> + if (pid != -1) {
> + kill(pid, SIGTERM);
> + TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
> 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.
> - */
> - 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);
> - }
> - abort();
> + /*
> + * 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",
The string is not 100% accurate now anymore - we might not have tried to
kill QEMU here since it exited earlier already. It's not that important,
but in case you respin, you could maybe adjust this text a little bit.
> + __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();
> }
> }
>
> @@ -228,6 +245,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>
> g_test_message("starting QEMU: %s", command);
>
> + s->wstatus = 0;
> s->qemu_pid = fork();
> if (s->qemu_pid == 0) {
> setenv("QEMU_AUDIO_DRV", "none", true);
>
Patch looks fine to me, I'm going to queue this for the next qtests pull
request (unless you want to respin because of the error string or other
reasons).
Reviewed-by: Thomas Huth <thuth@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] tests: Exit boot-serial-test loop if child dies
2018-12-17 3:58 [Qemu-devel] [PATCH] tests: Exit boot-serial-test loop if child dies Richard Henderson
2018-12-17 10:39 ` Thomas Huth
@ 2018-12-17 10:52 ` Philippe Mathieu-Daudé
2018-12-17 14:12 ` Wainer dos Santos Moschetta
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-12-17 10:52 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini, Thomas Huth
On 12/17/18 4:58 AM, Richard Henderson wrote:
> There's no point in waiting 5 full minutes when there will be
> no more output. Compute timeout based on elapsed wall clock
> time instead of N * delays, as the delay is a minimum sleep time.
>
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Laurent Vivier <lvivier@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> tests/libqtest.h | 8 +++++
> tests/boot-serial-test.c | 16 +++++++--
> tests/libqtest.c | 70 +++++++++++++++++++++++++---------------
> 3 files changed, 65 insertions(+), 29 deletions(-)
>
> diff --git a/tests/libqtest.h b/tests/libqtest.h
> index 96a6c01352..9758c51be6 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -1011,4 +1011,12 @@ bool qmp_rsp_is_err(QDict *rsp);
> */
> void qmp_assert_error_class(QDict *rsp, const char *class);
>
> +/**
> + * qtest_probe_child:
> + * @s: QTestState instance to operate on.
> + *
> + * Returns: true if the child is still alive.
> + */
> +bool qtest_probe_child(QTestState *s);
> +
> #endif
> diff --git a/tests/boot-serial-test.c b/tests/boot-serial-test.c
> index 8ec6aed35d..54b9347325 100644
> --- a/tests/boot-serial-test.c
> +++ b/tests/boot-serial-test.c
> @@ -130,11 +130,12 @@ static testdef_t tests[] = {
>
> static bool check_guest_output(const testdef_t *test, int fd)
> {
> - int i, nbr = 0, pos = 0, ccnt;
> + int nbr = 0, pos = 0, ccnt;
> + time_t now, start = time(NULL);
> char ch;
>
> - /* Poll serial output... Wait at most 360 seconds */
> - for (i = 0; i < 36000; ++i) {
> + /* Poll serial output... */
> + while (1) {
> ccnt = 0;
> while (ccnt++ < 512 && (nbr = read(fd, &ch, 1)) == 1) {
> if (ch == test->expect[pos]) {
> @@ -148,6 +149,15 @@ static bool check_guest_output(const testdef_t *test, int fd)
> }
> }
> g_assert(nbr >= 0);
> + /* Wait only if the child is still alive. */
> + if (!qtest_probe_child(global_qtest)) {
> + break;
> + }
> + /* Wait at most 360 seconds. */
> + now = time(NULL);
> + if (now - start >= 360) {
> + break;
> + }
> g_usleep(10000);
> }
>
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 43be078518..1d75d3c936 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -39,10 +39,11 @@ struct QTestState
> {
> int fd;
> int qmp_fd;
> + pid_t qemu_pid; /* our child QEMU process */
> + int wstatus;
> + bool big_endian;
> bool irq_level[MAX_IRQ];
> GString *rx;
> - pid_t qemu_pid; /* our child QEMU process */
> - bool big_endian;
> };
>
> static GHookList abrt_hooks;
> @@ -96,36 +97,52 @@ static int socket_accept(int sock)
> return ret;
> }
>
> +bool qtest_probe_child(QTestState *s)
> +{
> + pid_t pid = s->qemu_pid;
> +
> + if (pid != -1) {
> + pid = waitpid(pid, &s->wstatus, WNOHANG);
> + if (pid == 0) {
> + return true;
> + }
> + s->qemu_pid = -1;
> + }
> + return false;
> +}
> +
> static void kill_qemu(QTestState *s)
> {
> - if (s->qemu_pid != -1) {
> - int wstatus = 0;
> - pid_t pid;
> -
> - kill(s->qemu_pid, SIGTERM);
> - TFR(pid = waitpid(s->qemu_pid, &wstatus, 0));
> + pid_t pid = s->qemu_pid;
> + int wstatus;
>
> + /* Skip wait if qtest_probe_child already reaped. */
> + if (pid != -1) {
> + kill(pid, SIGTERM);
> + TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
> 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.
> - */
> - 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);
> - }
> - abort();
> + /*
> + * 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);
> }
> + abort();
> }
> }
>
> @@ -228,6 +245,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>
> g_test_message("starting QEMU: %s", command);
>
> + s->wstatus = 0;
> s->qemu_pid = fork();
> if (s->qemu_pid == 0) {
> setenv("QEMU_AUDIO_DRV", "none", true);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] tests: Exit boot-serial-test loop if child dies
2018-12-17 3:58 [Qemu-devel] [PATCH] tests: Exit boot-serial-test loop if child dies Richard Henderson
2018-12-17 10:39 ` Thomas Huth
2018-12-17 10:52 ` Philippe Mathieu-Daudé
@ 2018-12-17 14:12 ` Wainer dos Santos Moschetta
2 siblings, 0 replies; 4+ messages in thread
From: Wainer dos Santos Moschetta @ 2018-12-17 14:12 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini, Thomas Huth
On 12/17/2018 01:58 AM, Richard Henderson wrote:
> There's no point in waiting 5 full minutes when there will be
> no more output. Compute timeout based on elapsed wall clock
> time instead of N * delays, as the delay is a minimum sleep time.
>
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Laurent Vivier <lvivier@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> tests/libqtest.h | 8 +++++
> tests/boot-serial-test.c | 16 +++++++--
> tests/libqtest.c | 70 +++++++++++++++++++++++++---------------
> 3 files changed, 65 insertions(+), 29 deletions(-)
Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
>
> diff --git a/tests/libqtest.h b/tests/libqtest.h
> index 96a6c01352..9758c51be6 100644
> --- a/tests/libqtest.h
> +++ b/tests/libqtest.h
> @@ -1011,4 +1011,12 @@ bool qmp_rsp_is_err(QDict *rsp);
> */
> void qmp_assert_error_class(QDict *rsp, const char *class);
>
> +/**
> + * qtest_probe_child:
> + * @s: QTestState instance to operate on.
> + *
> + * Returns: true if the child is still alive.
> + */
> +bool qtest_probe_child(QTestState *s);
> +
> #endif
> diff --git a/tests/boot-serial-test.c b/tests/boot-serial-test.c
> index 8ec6aed35d..54b9347325 100644
> --- a/tests/boot-serial-test.c
> +++ b/tests/boot-serial-test.c
> @@ -130,11 +130,12 @@ static testdef_t tests[] = {
>
> static bool check_guest_output(const testdef_t *test, int fd)
> {
> - int i, nbr = 0, pos = 0, ccnt;
> + int nbr = 0, pos = 0, ccnt;
> + time_t now, start = time(NULL);
> char ch;
>
> - /* Poll serial output... Wait at most 360 seconds */
> - for (i = 0; i < 36000; ++i) {
> + /* Poll serial output... */
> + while (1) {
> ccnt = 0;
> while (ccnt++ < 512 && (nbr = read(fd, &ch, 1)) == 1) {
> if (ch == test->expect[pos]) {
> @@ -148,6 +149,15 @@ static bool check_guest_output(const testdef_t *test, int fd)
> }
> }
> g_assert(nbr >= 0);
> + /* Wait only if the child is still alive. */
> + if (!qtest_probe_child(global_qtest)) {
> + break;
> + }
> + /* Wait at most 360 seconds. */
> + now = time(NULL);
> + if (now - start >= 360) {
> + break;
> + }
> g_usleep(10000);
> }
>
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 43be078518..1d75d3c936 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -39,10 +39,11 @@ struct QTestState
> {
> int fd;
> int qmp_fd;
> + pid_t qemu_pid; /* our child QEMU process */
> + int wstatus;
> + bool big_endian;
> bool irq_level[MAX_IRQ];
> GString *rx;
> - pid_t qemu_pid; /* our child QEMU process */
> - bool big_endian;
> };
>
> static GHookList abrt_hooks;
> @@ -96,36 +97,52 @@ static int socket_accept(int sock)
> return ret;
> }
>
> +bool qtest_probe_child(QTestState *s)
> +{
> + pid_t pid = s->qemu_pid;
> +
> + if (pid != -1) {
> + pid = waitpid(pid, &s->wstatus, WNOHANG);
> + if (pid == 0) {
> + return true;
> + }
> + s->qemu_pid = -1;
> + }
> + return false;
> +}
> +
> static void kill_qemu(QTestState *s)
> {
> - if (s->qemu_pid != -1) {
> - int wstatus = 0;
> - pid_t pid;
> -
> - kill(s->qemu_pid, SIGTERM);
> - TFR(pid = waitpid(s->qemu_pid, &wstatus, 0));
> + pid_t pid = s->qemu_pid;
> + int wstatus;
>
> + /* Skip wait if qtest_probe_child already reaped. */
> + if (pid != -1) {
> + kill(pid, SIGTERM);
> + TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
> 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.
> - */
> - 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);
> - }
> - abort();
> + /*
> + * 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);
> }
> + abort();
> }
> }
>
> @@ -228,6 +245,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
>
> g_test_message("starting QEMU: %s", command);
>
> + s->wstatus = 0;
> s->qemu_pid = fork();
> if (s->qemu_pid == 0) {
> setenv("QEMU_AUDIO_DRV", "none", true);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-12-17 14:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-17 3:58 [Qemu-devel] [PATCH] tests: Exit boot-serial-test loop if child dies Richard Henderson
2018-12-17 10:39 ` Thomas Huth
2018-12-17 10:52 ` Philippe Mathieu-Daudé
2018-12-17 14:12 ` Wainer dos Santos Moschetta
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).