From ed6df8ed1cb6e29f563a506f280c93aac63fec84 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Mon, 24 May 2021 14:27:37 +0300 Subject: [PATCH] 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 --- tests/weston-test-client-helper.c | 12 +++++++++--- tests/weston-test-client-helper.h | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index cc7ceb5b..a9214927 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -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); } diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index 614cc29c..250f256c 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -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;