qtest: implement QTEST_STOP
PATCH 1/1 qtest: implement QTEST_STOP
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.
--- tests/libqtest.c | 38 +++++++++++++++++++++++++-------------
1 file modificato, 25 inserzioni(+), 13 rimozioni(-)
tests/libqtest.c +25 -13
@@ -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 ); + } +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);
Signature · 1 line
1.7.12
Quoted 41 lines · Paolo Bonzini
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 <[email protected]>--- tests/libqtest.c | 38 +++++++++++++++++++++++++-------------1 file modificato, 25 inserzioni(+), 13 rimozioni(-)
tests/libqtest.c +16
-0@@ -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;
tests/libqtest.c QTestState *qtest_init(const char *extra_args) · line 158
Quoted 7 lines
tests/libqtest.c +4
-0@@ -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
Quoted 29 lines
tests/libqtest.c +5
-13return 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);Signature · 1 line
1.7.12
Il 01/10/2012 23:19, Anthony Liguori ha scritto:
Quoted 2 lines
What about launching the guest with "-S" if that variable is set? That's a bit nicer, right?
That also requires that -S block reads from the qtest socket, which is not yet the case.
Paolo
Anthony Liguori
AppliedQuoted 9 lines · Paolo Bonzini
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 <[email protected]>
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 68 lines
--- tests/libqtest.c | 38 +++++++++++++++++++++++++-------------1 file modificato, 25 inserzioni(+), 13 rimozioni(-)
tests/libqtest.c +25
-13@@ -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 ); + } +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);Signature · 1 line
1.7.12