1
0
Fork 0

tests/wayland: Add DRM lease device release test

Add a test that:
- Creates 2 clients
- Releases a device for each client
- Checks that releasing a device for one client doesn't affect the other
- Checks that an error is raised if a released client is used

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4031>
This commit is contained in:
José Expósito 2024-09-08 12:49:47 +02:00 committed by Marge Bot
parent 59c4054c91
commit c366e32da6
2 changed files with 90 additions and 0 deletions

View file

@ -43,11 +43,28 @@ test_drm_lease_client_connection (void)
meta_wayland_test_client_finish (wayland_test_client);
}
static void
test_drm_lease_release_device (void)
{
MetaWaylandTestClient *wayland_test_client;
wayland_test_client = meta_wayland_test_client_new_with_args (test_context,
"drm-lease",
"release-device",
NULL);
g_test_expect_message ("libmutter", G_LOG_LEVEL_WARNING,
"WL: error in client communication*");
meta_wayland_test_client_finish (wayland_test_client);
g_test_assert_expected_messages ();
}
static void
init_tests (void)
{
g_test_add_func ("/wayland/drm-lease/client-connection",
test_drm_lease_client_connection);
g_test_add_func ("/wayland/drm-lease/release-device",
test_drm_lease_release_device);
}
static void

View file

@ -241,6 +241,37 @@ drm_lease_device_lookup (DrmLeaseClient *client,
return device;
}
static void
drm_lease_device_get_at_index (guint index,
DrmLeaseClient *client,
struct wp_drm_lease_device_v1 **out_drm_lease_device,
DrmLeaseDevice **out_device)
{
gpointer key, value;
GHashTableIter iter;
guint n = 0;
g_hash_table_iter_init (&iter, client->devices);
while (g_hash_table_iter_next (&iter, &key, &value))
{
if (n != index)
{
n++;
continue;
}
if (out_drm_lease_device)
*out_drm_lease_device = key;
if (out_device)
*out_device = value;
return;
}
g_assert_not_reached ();
}
static void
handle_device_drm_fd (void *user_data,
struct wp_drm_lease_device_v1 *drm_lease_device,
@ -414,6 +445,46 @@ test_drm_lease_client_connection (WaylandDisplay *display)
return EXIT_SUCCESS;
}
static int
test_drm_lease_release_device (WaylandDisplay *display)
{
DrmLeaseClient *client1;
DrmLeaseClient *client2;
struct wp_drm_lease_device_v1 *drm_lease_device;
client1 = drm_lease_client_new (display);
client2 = drm_lease_client_new (display);
/* Release the first client's device */
drm_lease_device_get_at_index (0, client1, &drm_lease_device, NULL);
wp_drm_lease_device_v1_release (drm_lease_device);
g_assert_cmpint (wl_display_roundtrip (display->display), !=, -1);
event_queue_assert_event (client1->event_queue, DEVICE_RELEASED);
event_queue_assert_empty (client1->event_queue);
event_queue_assert_empty (client2->event_queue);
/* Release the second client's device */
drm_lease_device_get_at_index (0, client2, &drm_lease_device, NULL);
wp_drm_lease_device_v1_release (drm_lease_device);
g_assert_cmpint (wl_display_roundtrip (display->display), !=, -1);
event_queue_assert_event (client2->event_queue, DEVICE_RELEASED);
event_queue_assert_empty (client2->event_queue);
event_queue_assert_empty (client1->event_queue);
/* Check that a client error is raised if a released device is used */
g_assert_cmpint (wl_display_get_error (display->display), ==, 0);
wp_drm_lease_device_v1_release (drm_lease_device);
g_assert_cmpint (wl_display_roundtrip (display->display), ==, -1);
g_assert_cmpint (wl_display_get_error (display->display), !=, 0);
drm_lease_client_free (client1);
drm_lease_client_free (client2);
return EXIT_SUCCESS;
}
int
main (int argc,
char **argv)
@ -429,6 +500,8 @@ main (int argc,
if (g_strcmp0 (test_case, "client-connection") == 0)
return test_drm_lease_client_connection (display);
else if (g_strcmp0 (test_case, "release-device") == 0)
return test_drm_lease_release_device (display);
return EXIT_FAILURE;
}