From patchwork Mon Dec 17 03:58:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 153955 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2037794ljp; Sun, 16 Dec 2018 19:58:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/WWgaEbxkNZbaPRcGE4Olgk9rTPoPiWs1gNxfbh3TosPGsdWW2KewgQoCz+R+X+C75mwYwe X-Received: by 2002:a0c:afa1:: with SMTP id s30mr11881093qvc.53.1545019118511; Sun, 16 Dec 2018 19:58:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545019118; cv=none; d=google.com; s=arc-20160816; b=KZspxrF/HregAw5WNCwHIaJMN96vf0MaGs8DyNcnDbBZdk0J9OxWhJjiBCOCbaog5r Afo/HVQYeBZO7TYq4l5ov5x6GQL0+jwu/PCTLb8EQt1IRve2qlMvgUGJII/J84ZsKpa+ WSM8Xm6Ooe45dvgOkTL54AlM/QJof35ZbG7oI+3j7wfCjgjD0MP6+B+Bd7yC8q+d4Cis 7cyYeUDYRek+JCh+yhPpDiKIbkQt0fc3AFN0MUuAYgMf8QT+G37bKQavJJVHja54iqTg 52E8/J4aoLG2LjeOFHgyZxAJjSYqXmsyt/VLb5olU03jmxWqFhB8VFxsIE93xs9aO+sj 6UEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:message-id:date:to:from :dkim-signature; bh=w7fWnVzY/WUPJH5roDqudJcuJDnr5Q6BtqUrE7en6Jk=; b=n0x/GD10GxUOVDJnFJPYACbGo1izTp9nPzjY4mTOWgnwpF3WOhc3BjBPkMnKjU82hS 9IcSB994rrbZRQuuZt+rB5eqcuFrlRDaWTdwTkRztsNg2ms6x0WVCtFcmsZzqmWGdO0e qpuV2vQ9fRMPFrm96NH1nckpe1ZjjbMw+EO1oYF+i5ZwXEvMUjH2Q6R6p2rUaAFDxwW/ xhiEhl/Mb5WONBLEFtGpRd8gTtHH1VlSY/GhvXIZG8sA9nTGSprV1odtM7sT4/NzNq+v u71nZOFi9RdeSf3l3LVnWiLVVCkqPfcG3EOk4/GkRlC3ROGs+3KJCdLxNLoUWUDtvZGG Dn6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=B9oqlUCV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v2si5164502qvm.85.2018.12.16.19.58.38 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 16 Dec 2018 19:58:38 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=B9oqlUCV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44748 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYk3C-0006Kx-21 for patch@linaro.org; Sun, 16 Dec 2018 22:58:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYk2z-0006Kq-5R for qemu-devel@nongnu.org; Sun, 16 Dec 2018 22:58:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gYk2v-0004jP-Vk for qemu-devel@nongnu.org; Sun, 16 Dec 2018 22:58:25 -0500 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:36882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gYk2v-0004fT-Ds for qemu-devel@nongnu.org; Sun, 16 Dec 2018 22:58:21 -0500 Received: by mail-pg1-x541.google.com with SMTP id c25so3934189pgb.4 for ; Sun, 16 Dec 2018 19:58:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=w7fWnVzY/WUPJH5roDqudJcuJDnr5Q6BtqUrE7en6Jk=; b=B9oqlUCVDIvCwI5fuSRPQNgtohZ5WEV61bjmDa+dwxrtmFaYpf8JJpvAtcfDkJIr1C Fig1NFTDx9k0L8nGSMcIFJ9zI5WHBUYq7Khur2ULRB5C1/867ljBReqbjr/NENf6anXC AyXdzz8GbejpzkT+qXXIxqqSATAQ0NATJXLCA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=w7fWnVzY/WUPJH5roDqudJcuJDnr5Q6BtqUrE7en6Jk=; b=hJRSP5z2B7tE5z3b4nKfBU2ZfN9uBfDf2NwVMjnZJLufNKr2b/pnwfUKqStid+iX5+ xsvbkAy88VTMG+cx3prQSWtthisNNg0orU3ygTtpa/D1Sso/Yq+4Rjx7MWIZc/obX5Jd Zbdxdcg9AVqR7DKytzVO4Obh5HzqyHUgOaruBXkzCFT67RXkeAI2HUwmml9VuWKV6eZ5 5ngIBYyhjvgxOOn5NNPAfU7mGxIZCmjh0cq/kbh62Bma+anInjnAYzXMAhIXQvZSpz1c ctRR3jFJPeq+R+IKBOE0pNL8PFpQ/Hxb0JuS15/9s3pzZIDXhuFvrktJ5fTx0cJpLnJA Kn5A== X-Gm-Message-State: AA+aEWZ2p7j64rbKEb7pGn+IkzBTzhn5tnbhwPyWX1ol8b3avMRGB4DV c9LQyTfEGt3ZDyoMudL8KP9urP1+Zf8= X-Received: by 2002:a62:870e:: with SMTP id i14mr11758902pfe.41.1545019099469; Sun, 16 Dec 2018 19:58:19 -0800 (PST) Received: from cloudburst.twiddle.net (97-126-115-157.tukw.qwest.net. [97.126.115.157]) by smtp.gmail.com with ESMTPSA id f67sm25727551pff.29.2018.12.16.19.58.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 16 Dec 2018 19:58:18 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 16 Dec 2018 19:58:16 -0800 Message-Id: <20181217035816.21777-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH] tests: Exit boot-serial-test loop if child dies X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Paolo Bonzini , Thomas Huth Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 Cc: Laurent Vivier Cc: Paolo Bonzini Signed-off-by: Richard Henderson --- tests/libqtest.h | 8 +++++ tests/boot-serial-test.c | 16 +++++++-- tests/libqtest.c | 70 +++++++++++++++++++++++++--------------- 3 files changed, 65 insertions(+), 29 deletions(-) -- 2.17.2 Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Wainer dos Santos Moschetta 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);