tests: allow client_destroy() after expect_protocol_error()

expect_protocol_error() ensures that the connection has failed in the
expected way. To satisfy ASan leak detection, we still need to tear down
everything, including call client_destroy().

client_destroy() needs to check that tear-down does not cause protocol
errors, so it does one last roundtrip that checks that is succeeds. But
if the connection is already down in an expected way, this roundtrip
cannot succeed and must be skipped.

Also moves the roundtrip under 'if (wl_display)', assuming the 'if' is
there for a reason - but obviously that reason was never used as it
would have crashed.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 4 years ago
parent 6ae243f91e
commit ed6df8ed1c
  1. 12
      tests/weston-test-client-helper.c
  2. 7
      tests/weston-test-client-helper.h

@ -927,6 +927,8 @@ expect_protocol_error(struct client *client,
/* all OK */ /* all OK */
testlog("Got expected protocol error on '%s' (object id: %d) " testlog("Got expected protocol error on '%s' (object id: %d) "
"with code %d\n", interface->name, id, errcode); "with code %d\n", interface->name, id, errcode);
client->errored_ok = true;
} }
static void static void
@ -1046,6 +1048,8 @@ create_client_and_test_surface(int x, int y, int width, int height)
void void
client_destroy(struct client *client) client_destroy(struct client *client)
{ {
int ret;
if (client->surface) if (client->surface)
surface_destroy(client->surface); surface_destroy(client->surface);
@ -1078,10 +1082,12 @@ client_destroy(struct client *client)
if (client->wl_registry) if (client->wl_registry)
wl_registry_destroy(client->wl_registry); wl_registry_destroy(client->wl_registry);
client_roundtrip(client); if (client->wl_display) {
ret = wl_display_roundtrip(client->wl_display);
if (client->wl_display) assert(client->errored_ok || ret >= 0);
wl_display_disconnect(client->wl_display); wl_display_disconnect(client->wl_display);
}
free(client); free(client);
} }

@ -42,6 +42,13 @@
struct client { struct client {
struct wl_display *wl_display; struct wl_display *wl_display;
/*
* Have successfully received an expected protocol error, the
* connection is in error state, and that is ok.
*/
bool errored_ok;
struct wl_registry *wl_registry; struct wl_registry *wl_registry;
struct wl_compositor *wl_compositor; struct wl_compositor *wl_compositor;
struct wl_shm *wl_shm; struct wl_shm *wl_shm;

Loading…
Cancel
Save