From nobody Sun Oct 5 19:07:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532374603589870.631504249958; Mon, 23 Jul 2018 12:36:43 -0700 (PDT) Received: from localhost ([::1]:36185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhgdO-000705-KB for importer@patchew.org; Mon, 23 Jul 2018 15:36:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhgcO-0006ay-6y for qemu-devel@nongnu.org; Mon, 23 Jul 2018 15:35:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhgcL-0002WC-3p for qemu-devel@nongnu.org; Mon, 23 Jul 2018 15:35:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40350 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fhgcK-0002Vp-V7 for qemu-devel@nongnu.org; Mon, 23 Jul 2018 15:35:37 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 397BF40251CE; Mon, 23 Jul 2018 19:35:36 +0000 (UTC) Received: from red.redhat.com (ovpn-124-223.rdu2.redhat.com [10.10.124.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88C932026D65; Mon, 23 Jul 2018 19:35:35 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2018 14:35:30 -0500 Message-Id: <20180723193530.20891-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 23 Jul 2018 19:35:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 23 Jul 2018 19:35:36 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 for-3.0] tests/libqtest: Improve kill_qemu() 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: peter.maydell@linaro.org, rth@twiddle.net, alex.bennee@linaro.org, f4bug@amsat.org, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In kill_qemu() we have an assert that checks that the QEMU process didn't dump core: assert(!WCOREDUMP(wstatus)); Unfortunately the WCOREDUMP macro here means the resulting message is not very easy to comprehend on at least some systems: ahci-test: tests/libqtest.c:113: kill_qemu: Assertion `!(((__extension__ ((= (union { __typeof(wstatus) __in; int __i; }) { .__in =3D (wstatus) }).__i))= ) & 0x80)' failed. and it doesn't identify what signal the process took. Furthermore, we are NOT detecting EINTR (while EINTR shouldn't be happening if we didn't install signal handlers, it's still better to always be robust), and also want to log unexpected non-zero status that was not accompanied by a core dump. Instead of using a raw assert, print the information in an easier to understand way: /i386/ahci/sanity: tests/libqtest.c:119: kill_qemu() detected QEMU death wi= th core dump from signal 11 (Segmentation fault) Aborted (core dumped) (Of course, the really useful information would be why the QEMU process dumped core in the first place, but we don't have that by the time the test program has picked up the exit status.) Suggested-by: Peter Maydell Signed-off-by: Eric Blake Reviewed-by: Richard Henderson --- I've taken the ideas from Peter's patch: https://lists.gnu.org/archive/html/qemu-devel/2018-07/msg04430.html as well as fixing a related issue brought up last time this was touched: https://lists.gnu.org/archive/html/qemu-devel/2018-05/msg05710.html tests/libqtest.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 098af6aec44..f3dabfadd78 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -105,12 +105,47 @@ static void kill_qemu(QTestState *s) if (s->qemu_pid !=3D -1) { int wstatus =3D 0; pid_t pid; + bool die =3D false; kill(s->qemu_pid, SIGTERM); + retry: pid =3D waitpid(s->qemu_pid, &wstatus, 0); + if (pid =3D=3D -1 && errno =3D=3D EINTR) { + goto retry; + } - if (pid =3D=3D s->qemu_pid && WIFSIGNALED(wstatus)) { - assert(!WCOREDUMP(wstatus)); + assert(pid =3D=3D s->qemu_pid); + /* + * We expect qemu to exit with status 0; anything else is + * fishy and should be logged. Abort except when death by + * signal is not accompanied by a coredump (as that's the only + * time it was likely that the user is trying to kill the + * testsuite early). + */ + if (wstatus) { + die =3D true; + if (WIFEXITED(wstatus)) { + fprintf(stderr, "%s:%d: kill_qemu() tried to terminate QEM= U " + "process but encountered exit status %d\n", + __FILE__, __LINE__, WEXITSTATUS(wstatus)); + } else if (WIFSIGNALED(wstatus)) { + int sig =3D WTERMSIG(wstatus); + const char *signame =3D strsignal(sig) ?: "unknown ???"; + + if (!WCOREDUMP(wstatus)) { + die =3D false; + fprintf(stderr, "%s:%d: kill_qemu() ignoring QEMU deat= h " + "by signal %d (%s)\n", + __FILE__, __LINE__, sig, signame); + } else { + fprintf(stderr, "%s:%d: kill_qemu() detected QEMU deat= h " + "with core dump from signal %d (%s)\n", + __FILE__, __LINE__, sig, signame); + } + } + } + if (die) { + abort(); } } } --=20 2.14.4