提交 21f80286 编写于 作者: R Richard Henderson 提交者: Thomas Huth

tests: Exit boot-serial-test loop if child dies

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: NRichard Henderson <richard.henderson@linaro.org>
Reviewed-by: NPhilippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: NWainer dos Santos Moschetta <wainersm@redhat.com>
[thuth: Replaced global_qtest with local qts variable]
Signed-off-by: NThomas Huth <thuth@redhat.com>
上级 43497c43
...@@ -128,13 +128,14 @@ static testdef_t tests[] = { ...@@ -128,13 +128,14 @@ static testdef_t tests[] = {
{ NULL } { NULL }
}; };
static bool check_guest_output(const testdef_t *test, int fd) static bool check_guest_output(QTestState *qts, 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; char ch;
/* Poll serial output... Wait at most 360 seconds */ /* Poll serial output... */
for (i = 0; i < 36000; ++i) { while (1) {
ccnt = 0; ccnt = 0;
while (ccnt++ < 512 && (nbr = read(fd, &ch, 1)) == 1) { while (ccnt++ < 512 && (nbr = read(fd, &ch, 1)) == 1) {
if (ch == test->expect[pos]) { if (ch == test->expect[pos]) {
...@@ -148,6 +149,15 @@ static bool check_guest_output(const testdef_t *test, int fd) ...@@ -148,6 +149,15 @@ static bool check_guest_output(const testdef_t *test, int fd)
} }
} }
g_assert(nbr >= 0); g_assert(nbr >= 0);
/* Wait only if the child is still alive. */
if (!qtest_probe_child(qts)) {
break;
}
/* Wait at most 360 seconds. */
now = time(NULL);
if (now - start >= 360) {
break;
}
g_usleep(10000); g_usleep(10000);
} }
...@@ -199,7 +209,7 @@ static void test_machine(const void *data) ...@@ -199,7 +209,7 @@ static void test_machine(const void *data)
unlink(codetmp); unlink(codetmp);
} }
if (!check_guest_output(test, ser_fd)) { if (!check_guest_output(qts, test, ser_fd)) {
g_error("Failed to find expected string. Please check '%s'", g_error("Failed to find expected string. Please check '%s'",
serialtmp); serialtmp);
} }
......
...@@ -39,10 +39,11 @@ struct QTestState ...@@ -39,10 +39,11 @@ struct QTestState
{ {
int fd; int fd;
int qmp_fd; int qmp_fd;
bool irq_level[MAX_IRQ];
GString *rx;
pid_t qemu_pid; /* our child QEMU process */ pid_t qemu_pid; /* our child QEMU process */
int wstatus;
bool big_endian; bool big_endian;
bool irq_level[MAX_IRQ];
GString *rx;
}; };
static GHookList abrt_hooks; static GHookList abrt_hooks;
...@@ -96,36 +97,52 @@ static int socket_accept(int sock) ...@@ -96,36 +97,52 @@ static int socket_accept(int sock)
return ret; return ret;
} }
static void kill_qemu(QTestState *s) bool qtest_probe_child(QTestState *s)
{ {
if (s->qemu_pid != -1) { pid_t pid = s->qemu_pid;
int wstatus = 0;
pid_t pid;
kill(s->qemu_pid, SIGTERM); if (pid != -1) {
TFR(pid = waitpid(s->qemu_pid, &wstatus, 0)); pid = waitpid(pid, &s->wstatus, WNOHANG);
if (pid == 0) {
return true;
}
s->qemu_pid = -1;
}
return false;
}
static void kill_qemu(QTestState *s)
{
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); 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. /*
*/ * We expect qemu to exit with status 0; anything else is
if (wstatus) { * fishy and should be logged with as much detail as possible.
if (WIFEXITED(wstatus)) { */
fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU " wstatus = s->wstatus;
"process but encountered exit status %d\n", if (wstatus) {
__FILE__, __LINE__, WEXITSTATUS(wstatus)); if (WIFEXITED(wstatus)) {
} else if (WIFSIGNALED(wstatus)) { fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEMU "
int sig = WTERMSIG(wstatus); "process but encountered exit status %d\n",
const char *signame = strsignal(sig) ?: "unknown ???"; __FILE__, __LINE__, WEXITSTATUS(wstatus));
const char *dump = WCOREDUMP(wstatus) ? " (core dumped)" : ""; } else if (WIFSIGNALED(wstatus)) {
int sig = WTERMSIG(wstatus);
fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death " const char *signame = strsignal(sig) ?: "unknown ???";
"from signal %d (%s)%s\n", const char *dump = WCOREDUMP(wstatus) ? " (core dumped)" : "";
__FILE__, __LINE__, sig, signame, dump);
} fprintf(stderr, "%s:%d: kill_qemu() detected QEMU death "
abort(); "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) ...@@ -228,6 +245,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
g_test_message("starting QEMU: %s", command); g_test_message("starting QEMU: %s", command);
s->wstatus = 0;
s->qemu_pid = fork(); s->qemu_pid = fork();
if (s->qemu_pid == 0) { if (s->qemu_pid == 0) {
setenv("QEMU_AUDIO_DRV", "none", true); setenv("QEMU_AUDIO_DRV", "none", true);
......
...@@ -1011,4 +1011,12 @@ bool qmp_rsp_is_err(QDict *rsp); ...@@ -1011,4 +1011,12 @@ bool qmp_rsp_is_err(QDict *rsp);
*/ */
void qmp_assert_error_class(QDict *rsp, const char *class); 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 #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册