From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:43565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TInOh-00073e-DX for qemu-devel@nongnu.org; Mon, 01 Oct 2012 17:19:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TInOg-0000HG-F3 for qemu-devel@nongnu.org; Mon, 01 Oct 2012 17:19:27 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:42411) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TInOg-0000GI-9u for qemu-devel@nongnu.org; Mon, 01 Oct 2012 17:19:26 -0400 Received: by obbwc18 with SMTP id wc18so3248177obb.4 for ; Mon, 01 Oct 2012 14:19:25 -0700 (PDT) From: Anthony Liguori In-Reply-To: <1349093887-32142-1-git-send-email-pbonzini@redhat.com> References: <1349093887-32142-1-git-send-email-pbonzini@redhat.com> Date: Mon, 01 Oct 2012 16:19:22 -0500 Message-ID: <87ipatgaat.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH] qtest: implement QTEST_STOP List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Paolo Bonzini writes: > It is quite difficult to debug qtest test cases without extra wrapper > scripts for QEMU or similar. This patch adds a simple environment > variable-based trigger that sends a STOP signal to the QEMU instance > under test, before attempting to connect to its QMP session. > > This will block execution of the testcase and give time to attach a > debugger to the stopped QEMU process. > > Signed-off-by: Paolo Bonzini > --- > tests/libqtest.c | 38 +++++++++++++++++++++++++------------- > 1 file modificato, 25 inserzioni(+), 13 rimozioni(-) > > diff --git a/tests/libqtest.c b/tests/libqtest.c > index 02d0392..71b84c1 100644 > --- a/tests/libqtest.c > +++ b/tests/libqtest.c > @@ -85,6 +85,22 @@ static int socket_accept(int sock) > return ret; > } > > +static pid_t qtest_qemu_pid(QTestState *s) > +{ > + FILE *f; > + char buffer[1024]; > + pid_t pid = -1; > + > + f = fopen(s->pid_file, "r"); > + if (f) { > + if (fgets(buffer, sizeof(buffer), f)) { > + pid = atoi(buffer); > + } > + } > + fclose(f); > + return pid; > +} > + > QTestState *qtest_init(const char *extra_args) > { > QTestState *s; > @@ -136,25 +152,21 @@ QTestState *qtest_init(const char *extra_args) > qtest_qmp(s, ""); > qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }"); > > + if (getenv("QTEST_STOP")) { > + kill(qtest_qemu_pid(s), SIGSTOP); > + } > + What about launching the guest with "-S" if that variable is set? That's a bit nicer, right? Regards, Anthony Liguori > return s; > } > > void qtest_quit(QTestState *s) > { > - FILE *f; > - char buffer[1024]; > - > - f = fopen(s->pid_file, "r"); > - if (f) { > - if (fgets(buffer, sizeof(buffer), f)) { > - pid_t pid = atoi(buffer); > - int status = 0; > - > - kill(pid, SIGTERM); > - waitpid(pid, &status, 0); > - } > + int status; > > - fclose(f); > + pid_t pid = qtest_qemu_pid(s); > + if (pid != -1) { > + kill(pid, SIGTERM); > + waitpid(pid, &status, 0); > } > > unlink(s->pid_file); > -- > 1.7.12