diff options
author | Richard Henderson <richard.henderson@linaro.org> | 2018-12-16 19:58:16 -0800 |
---|---|---|
committer | Thomas Huth <thuth@redhat.com> | 2018-12-17 15:37:50 +0100 |
commit | 21f80286cc48142c2df1530eba32bd70131a1bdc (patch) | |
tree | 691406632c7a10e93f1cede7e7f77b6211355b88 /tests/boot-serial-test.c | |
parent | 43497c438d55e0e22369a6c633f9c8e3f6a498f2 (diff) | |
download | qemu-21f80286cc48142c2df1530eba32bd70131a1bdc.zip qemu-21f80286cc48142c2df1530eba32bd70131a1bdc.tar.gz qemu-21f80286cc48142c2df1530eba32bd70131a1bdc.tar.bz2 |
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: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
[thuth: Replaced global_qtest with local qts variable]
Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/boot-serial-test.c')
-rw-r--r-- | tests/boot-serial-test.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/tests/boot-serial-test.c b/tests/boot-serial-test.c index 366fe51..58a48f3 100644 --- a/tests/boot-serial-test.c +++ b/tests/boot-serial-test.c @@ -128,13 +128,14 @@ static testdef_t tests[] = { { 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; - /* 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(qts)) { + break; + } + /* Wait at most 360 seconds. */ + now = time(NULL); + if (now - start >= 360) { + break; + } g_usleep(10000); } @@ -199,7 +209,7 @@ static void test_machine(const void *data) 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'", serialtmp); } |