diff options
author | Alexandros Frantzis <alexandros.frantzis@collabora.com> | 2022-11-15 11:21:37 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-02-28 11:22:04 +0000 |
commit | e09010f470b28353e29a673ad76e813a92e61a1f (patch) | |
tree | 7c1140cb21823eea6b0b64b791146b4ac54f1b87 | |
parent | 0ba650202e742b23150054cf0740168cd529b010 (diff) | |
download | wayland-e09010f470b28353e29a673ad76e813a92e61a1f.tar.gz |
tests: Support tests that check for client failure
Add the display_destroy_expect_signal() function to check that test
clients exit due to a particular signal. This is useful for checking
that clients fail in an expected way.
Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
-rw-r--r-- | tests/test-compositor.c | 22 | ||||
-rw-r--r-- | tests/test-compositor.h | 2 |
2 files changed, 21 insertions, 3 deletions
diff --git a/tests/test-compositor.c b/tests/test-compositor.c index 587bc2b..49d76d6 100644 --- a/tests/test-compositor.c +++ b/tests/test-compositor.c @@ -114,7 +114,7 @@ handle_client_destroy(void *data) case CLD_DUMPED: fprintf(stderr, "Client '%s' was killed by signal %d\n", ci->name, status.si_status); - ci->exit_code = status.si_status; + ci->kill_code = status.si_status; break; case CLD_EXITED: if (status.si_status != EXIT_SUCCESS) @@ -425,8 +425,10 @@ display_resume(struct display *d) wl_display_run(d->wl_display); } +/* If signum is 0, expect a successful client exit, otherwise + * expect the client to have been killed by that signal. */ void -display_destroy(struct display *d) +display_destroy_expect_signal(struct display *d, int signum) { struct client_info *cl, *next; int failed = 0; @@ -437,7 +439,15 @@ display_destroy(struct display *d) wl_list_for_each_safe(cl, next, &d->clients, link) { assert(cl->wl_client == NULL); - if (cl->exit_code != 0) { + if (signum != 0 && cl->kill_code != signum) { + ++failed; + fprintf(stderr, + "Client '%s' failed, expecting signal %d, " + "got %d\n", + cl->name, signum, cl->kill_code); + } + else if (signum == 0 && + (cl->kill_code != 0 || cl->exit_code != 0)) { ++failed; fprintf(stderr, "Client '%s' failed\n", cl->name); } @@ -457,6 +467,12 @@ display_destroy(struct display *d) } } +void +display_destroy(struct display *d) +{ + display_destroy_expect_signal(d, 0); +} + /* * --- Client helper functions --- */ diff --git a/tests/test-compositor.h b/tests/test-compositor.h index b681b09..3fb390c 100644 --- a/tests/test-compositor.h +++ b/tests/test-compositor.h @@ -40,6 +40,7 @@ struct client_info { int pipe; pid_t pid; int exit_code; + int kill_code; struct wl_list link; void *data; /* for arbitrary use */ @@ -91,6 +92,7 @@ void noop_request(struct client *); */ struct display *display_create(void); void display_destroy(struct display *d); +void display_destroy_expect_signal(struct display *d, int signum); void display_run(struct display *d); /* This function posts the display_resumed event to all waiting clients, |