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>
This commit is contained in:
Pekka Paalanen 2021-05-24 14:27:37 +03:00
parent 6ae243f91e
commit ed6df8ed1c
2 changed files with 16 additions and 3 deletions

View File

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

View File

@ -42,6 +42,13 @@
struct client {
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_compositor *wl_compositor;
struct wl_shm *wl_shm;