tests: Ensure wl_shm format support before testing

Tests shouldn't fail on platforms lacking support for a particular
format.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
This commit is contained in:
Loïc Molinari 2024-11-13 14:32:11 +01:00 committed by Daniel Stone
parent b9ae1eb4a9
commit ad85a4a2d1
3 changed files with 43 additions and 7 deletions

View file

@ -472,6 +472,18 @@ static const struct wl_surface_listener surface_listener = {
surface_leave
};
bool
support_shm_format(struct client *client, uint32_t shm_format)
{
uint32_t *p;
wl_array_for_each(p, &client->shm_formats)
if (*p == shm_format)
return true;
return false;
}
struct buffer *
create_shm_buffer(struct client *client, int width, int height,
uint32_t drm_format)
@ -484,6 +496,7 @@ create_shm_buffer(struct client *client, int width, int height,
int fd;
void *data;
size_t bytes_pp;
uint32_t shm_format;
assert(width > 0);
assert(height > 0);
@ -491,6 +504,10 @@ create_shm_buffer(struct client *client, int width, int height,
pfmt = pixel_format_get_info(drm_format);
assert(pfmt);
assert(pixel_format_get_plane_count(pfmt) == 1);
shm_format = pixel_format_get_shm_format(pfmt);
if (!support_shm_format(client, shm_format))
return NULL;
buf = xzalloc(sizeof *buf);
@ -532,8 +549,6 @@ create_shm_buffer(struct client *client, int width, int height,
struct buffer *
create_shm_buffer_a8r8g8b8(struct client *client, int width, int height)
{
assert(client->has_argb);
return create_shm_buffer(client, width, height, DRM_FORMAT_ARGB8888);
}
@ -574,9 +589,11 @@ static void
shm_format(void *data, struct wl_shm *wl_shm, uint32_t format)
{
struct client *client = data;
uint32_t *p;
if (format == WL_SHM_FORMAT_ARGB8888)
client->has_argb = 1;
p = wl_array_add(&client->shm_formats, sizeof *p);
assert(p);
*p = format;
}
struct wl_shm_listener shm_listener = {
@ -1014,6 +1031,7 @@ create_client(void)
client = xzalloc(sizeof *client);
client->wl_display = wl_display_connect(NULL);
assert(client->wl_display);
wl_array_init(&client->shm_formats);
wl_list_init(&client->global_list);
wl_list_init(&client->inputs);
wl_list_init(&client->output_list);
@ -1029,8 +1047,9 @@ create_client(void)
* events */
client_roundtrip(client);
/* must have WL_SHM_FORMAT_ARGB32 */
assert(client->has_argb);
/* must have WL_SHM_FORMAT_*RGB8888 */
assert(support_shm_format(client, WL_SHM_FORMAT_ARGB8888));
assert(support_shm_format(client, WL_SHM_FORMAT_XRGB8888));
/* must have weston_test interface */
assert(client->test);
@ -1130,6 +1149,8 @@ client_destroy(struct client *client)
if (client->surface)
surface_destroy(client->surface);
wl_array_release(&client->shm_formats);
while (!wl_list_empty(&client->inputs)) {
input_destroy(container_of(client->inputs.next,
struct input, link));

View file

@ -65,7 +65,7 @@ struct client {
struct wl_list inputs;
struct output *output;
struct surface *surface;
int has_argb;
struct wl_array shm_formats;
struct wl_list global_list;
struct wl_list output_list; /* struct output::link */
};
@ -215,6 +215,9 @@ surface_set_opaque_rect(struct surface *surface, const struct rectangle *rect);
struct client *
create_client_and_test_surface(int x, int y, int width, int height);
bool
support_shm_format(struct client *client, uint32_t shm_format);
struct buffer *
create_shm_buffer(struct client *client, int width, int height,
uint32_t drm_format);

View file

@ -83,6 +83,11 @@ yuv_buffer_create(struct client *client,
struct yuv_buffer *buf;
int fd;
/* wl_shm format codes match DRM format codes except argb8888 and
* xrgb8888 but we don't mind because we're testing YUV formats here. */
if (!support_shm_format(client, drm_format))
return NULL;
buf = xzalloc(sizeof *buf);
buf->bytes = bytes;
buf->width = width;
@ -588,12 +593,19 @@ TEST_P(yuv_buffer_shm, yuv_cases)
client = create_client();
client->surface = create_test_surface(client);
buf = my_case->create_buffer(client, my_case->drm_format, img);
if (!buf) {
testlog("%s: Skipped: format %s not supported by compositor\n",
get_test_name(), my_case->drm_format_name);
goto format_not_supported;
}
show_window_with_yuv(client, buf);
match = verify_screen_content(client, "yuv-buffer", 0, NULL, 0, NULL);
assert(match);
yuv_buffer_destroy(buf);
format_not_supported:
pixman_image_unref(img);
client_destroy(client);
}