From: Anthony Liguori <anthony@codemonkey.ws>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qtest: implement QTEST_STOP
Date: Mon, 01 Oct 2012 16:19:22 -0500 [thread overview]
Message-ID: <87ipatgaat.fsf@codemonkey.ws> (raw)
In-Reply-To: <1349093887-32142-1-git-send-email-pbonzini@redhat.com>
Paolo Bonzini <pbonzini@redhat.com> 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 <pbonzini@redhat.com>
> ---
> 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
next prev parent reply other threads:[~2012-10-01 21:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-01 12:18 [Qemu-devel] [PATCH] qtest: implement QTEST_STOP Paolo Bonzini
2012-10-01 21:19 ` Anthony Liguori [this message]
2012-10-02 6:07 ` Paolo Bonzini
2012-10-05 21:20 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ipatgaat.fsf@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).