diff mbox series

[v4,3/3] libqtest: add more exit status checks

Message ID 1527186303-192100-4-git-send-email-mst@redhat.com
State New
Headers show
Series libqtest: verify QEMU exit status | expand

Commit Message

Michael S. Tsirkin May 24, 2018, 6:25 p.m. UTC
Add more checks on how did QEMU exit.

Legal ways to exit right now:
- exit(0) or return from main
- kill(SIGTERM) - sent by testing infrastructure

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 tests/libqtest.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Michael S. Tsirkin May 25, 2018, 2:07 p.m. UTC | #1
On Thu, May 24, 2018 at 09:25:28PM +0300, Michael S. Tsirkin wrote:
> Add more checks on how did QEMU exit.
> 
> Legal ways to exit right now:
> - exit(0) or return from main
> - kill(SIGTERM) - sent by testing infrastructure
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---

This turned out to be messy since
- abort itself might trigger a signal
- waitpid might in theory get interrupted

I'll drop this patch for now, and merge just patches 1 and 2
in my tree.

>  tests/libqtest.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index f869854..36ca859 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -109,9 +109,19 @@ static void kill_qemu(QTestState *s)
>          kill(s->qemu_pid, SIGTERM);
>          pid = waitpid(s->qemu_pid, &wstatus, 0);
>  
> -        if (pid == s->qemu_pid && WIFSIGNALED(wstatus)) {
> +        /* waitpid returns child PID on success */
> +        assert(pid == s->qemu_pid);
> +
> +        /* If exited on signal - check the reason: core dump is never OK */
> +        if (WIFSIGNALED(wstatus)) {
>              assert(!WCOREDUMP(wstatus));
>          }
> +        /* If exited normally - check exit status */
> +        if (WIFEXITED(wstatus)) {
> +            assert(!WEXITSTATUS(wstatus));
> +        }
> +        /* Valid ways to exit: right now only return from main or exit */
> +        assert(WIFEXITED(wstatus));
>      }
>  }
>  
> -- 
> MST
>
diff mbox series

Patch

diff --git a/tests/libqtest.c b/tests/libqtest.c
index f869854..36ca859 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -109,9 +109,19 @@  static void kill_qemu(QTestState *s)
         kill(s->qemu_pid, SIGTERM);
         pid = waitpid(s->qemu_pid, &wstatus, 0);
 
-        if (pid == s->qemu_pid && WIFSIGNALED(wstatus)) {
+        /* waitpid returns child PID on success */
+        assert(pid == s->qemu_pid);
+
+        /* If exited on signal - check the reason: core dump is never OK */
+        if (WIFSIGNALED(wstatus)) {
             assert(!WCOREDUMP(wstatus));
         }
+        /* If exited normally - check exit status */
+        if (WIFEXITED(wstatus)) {
+            assert(!WEXITSTATUS(wstatus));
+        }
+        /* Valid ways to exit: right now only return from main or exit */
+        assert(WIFEXITED(wstatus));
     }
 }