mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-07 07:50:19 +01:00
[boilerplate/xcb] Check for connection errors during test
This commit is contained in:
parent
395555b116
commit
8e4e0aa7ee
2 changed files with 88 additions and 59 deletions
|
|
@ -30,11 +30,23 @@
|
|||
|
||||
#include <xcb/xcb_renderutil.h>
|
||||
|
||||
static const cairo_user_data_key_t xcb_closure_key;
|
||||
|
||||
typedef struct _xcb_target_closure {
|
||||
xcb_connection_t *c;
|
||||
xcb_pixmap_t pixmap;
|
||||
} xcb_target_closure_t;
|
||||
|
||||
static void
|
||||
_cairo_boilerplate_xcb_cleanup (void *closure)
|
||||
{
|
||||
xcb_target_closure_t *xtc = closure;
|
||||
|
||||
xcb_free_pixmap (xtc->c, xtc->pixmap);
|
||||
xcb_disconnect (xtc->c);
|
||||
free (xtc);
|
||||
}
|
||||
|
||||
static void
|
||||
_cairo_boilerplate_xcb_synchronize (void *closure)
|
||||
{
|
||||
|
|
@ -61,6 +73,8 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
|
|||
xcb_connection_t *c;
|
||||
xcb_render_pictforminfo_t *render_format;
|
||||
xcb_pict_standard_t format;
|
||||
cairo_surface_t *surface;
|
||||
cairo_status_t status;
|
||||
|
||||
*closure = xtc = xmalloc (sizeof (xcb_target_closure_t));
|
||||
|
||||
|
|
@ -98,19 +112,32 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
|
|||
if (render_format->id == 0)
|
||||
return NULL;
|
||||
|
||||
return cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root,
|
||||
render_format,
|
||||
width, height);
|
||||
surface = cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root,
|
||||
render_format,
|
||||
width, height);
|
||||
|
||||
status = cairo_surface_set_user_data (surface, &xcb_closure_key, xtc, NULL);
|
||||
if (status == CAIRO_STATUS_SUCCESS)
|
||||
return surface;
|
||||
|
||||
cairo_surface_destroy (surface);
|
||||
surface = cairo_boilerplate_surface_create_in_error (status);
|
||||
|
||||
_cairo_boilerplate_xcb_cleanup (xtc);
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
static void
|
||||
_cairo_boilerplate_xcb_cleanup (void *closure)
|
||||
static cairo_status_t
|
||||
_cairo_boilerplate_xcb_finish_surface (cairo_surface_t *surface)
|
||||
{
|
||||
xcb_target_closure_t *xtc = closure;
|
||||
xcb_target_closure_t *xtc = cairo_surface_get_user_data (surface,
|
||||
&xcb_closure_key);
|
||||
|
||||
xcb_free_pixmap (xtc->c, xtc->pixmap);
|
||||
xcb_disconnect (xtc->c);
|
||||
free (xtc);
|
||||
if (xcb_connection_has_error (xtc->c))
|
||||
return CAIRO_STATUS_WRITE_ERROR;
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static const cairo_boilerplate_target_t targets[] = {
|
||||
|
|
@ -121,7 +148,8 @@ static const cairo_boilerplate_target_t targets[] = {
|
|||
CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA, 1,
|
||||
"cairo_xcb_surface_create_with_xrender_format",
|
||||
_cairo_boilerplate_xcb_create_surface,
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
_cairo_boilerplate_xcb_finish_surface,
|
||||
_cairo_boilerplate_get_image_surface,
|
||||
cairo_surface_write_to_png,
|
||||
_cairo_boilerplate_xcb_cleanup,
|
||||
|
|
@ -132,7 +160,8 @@ static const cairo_boilerplate_target_t targets[] = {
|
|||
CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR, 1,
|
||||
"cairo_xcb_surface_create_with_xrender_format",
|
||||
_cairo_boilerplate_xcb_create_surface,
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
_cairo_boilerplate_xcb_finish_surface,
|
||||
_cairo_boilerplate_get_image_surface,
|
||||
cairo_surface_write_to_png,
|
||||
_cairo_boilerplate_xcb_cleanup,
|
||||
|
|
|
|||
|
|
@ -1014,6 +1014,54 @@ REPEAT:
|
|||
}
|
||||
#endif
|
||||
|
||||
if (target->finish_surface != NULL) {
|
||||
#if HAVE_MEMFAULT
|
||||
/* We need to re-enable faults as most meta-surface processing
|
||||
* is done during cairo_surface_finish().
|
||||
*/
|
||||
MEMFAULT_CLEAR_FAULTS ();
|
||||
last_fault_count = MEMFAULT_COUNT_FAULTS ();
|
||||
MEMFAULT_ENABLE_FAULTS ();
|
||||
#endif
|
||||
|
||||
/* also check for infinite loops whilst replaying */
|
||||
alarm (ctx->timeout);
|
||||
status = target->finish_surface (surface);
|
||||
alarm (0);
|
||||
|
||||
#if HAVE_MEMFAULT
|
||||
MEMFAULT_DISABLE_FAULTS ();
|
||||
|
||||
if (ctx->malloc_failure &&
|
||||
MEMFAULT_COUNT_FAULTS () - last_fault_count > 0 &&
|
||||
status == CAIRO_STATUS_NO_MEMORY)
|
||||
{
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_destroy (surface);
|
||||
if (target->cleanup)
|
||||
target->cleanup (closure);
|
||||
if (ctx->thread == 0) {
|
||||
cairo_debug_reset_static_data ();
|
||||
#if HAVE_FCFINI
|
||||
FcFini ();
|
||||
#endif
|
||||
if (MEMFAULT_COUNT_LEAKS () > 0) {
|
||||
MEMFAULT_PRINT_FAULTS ();
|
||||
MEMFAULT_PRINT_LEAKS ();
|
||||
}
|
||||
}
|
||||
|
||||
goto REPEAT;
|
||||
}
|
||||
#endif
|
||||
if (status) {
|
||||
cairo_test_log (ctx, "Error: Failed to finish surface: %s\n",
|
||||
cairo_status_to_string (status));
|
||||
ret = CAIRO_TEST_FAILURE;
|
||||
goto UNWIND_CAIRO;
|
||||
}
|
||||
}
|
||||
|
||||
/* Skip image check for tests with no image (width,height == 0,0) */
|
||||
if (ctx->test->width != 0 && ctx->test->height != 0) {
|
||||
cairo_surface_t *ref_image;
|
||||
|
|
@ -1022,54 +1070,6 @@ REPEAT:
|
|||
buffer_diff_result_t result;
|
||||
cairo_status_t diff_status;
|
||||
|
||||
if (target->finish_surface != NULL) {
|
||||
#if HAVE_MEMFAULT
|
||||
/* We need to re-enable faults as most meta-surface processing
|
||||
* is done during cairo_surface_finish().
|
||||
*/
|
||||
MEMFAULT_CLEAR_FAULTS ();
|
||||
last_fault_count = MEMFAULT_COUNT_FAULTS ();
|
||||
MEMFAULT_ENABLE_FAULTS ();
|
||||
#endif
|
||||
|
||||
/* also check for infinite loops whilst replaying */
|
||||
alarm (ctx->timeout);
|
||||
diff_status = target->finish_surface (surface);
|
||||
alarm (0);
|
||||
|
||||
#if HAVE_MEMFAULT
|
||||
MEMFAULT_DISABLE_FAULTS ();
|
||||
|
||||
if (ctx->malloc_failure &&
|
||||
MEMFAULT_COUNT_FAULTS () - last_fault_count > 0 &&
|
||||
diff_status == CAIRO_STATUS_NO_MEMORY)
|
||||
{
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_destroy (surface);
|
||||
if (target->cleanup)
|
||||
target->cleanup (closure);
|
||||
if (ctx->thread == 0) {
|
||||
cairo_debug_reset_static_data ();
|
||||
#if HAVE_FCFINI
|
||||
FcFini ();
|
||||
#endif
|
||||
if (MEMFAULT_COUNT_LEAKS () > 0) {
|
||||
MEMFAULT_PRINT_FAULTS ();
|
||||
MEMFAULT_PRINT_LEAKS ();
|
||||
}
|
||||
}
|
||||
|
||||
goto REPEAT;
|
||||
}
|
||||
#endif
|
||||
if (diff_status) {
|
||||
cairo_test_log (ctx, "Error: Failed to finish surface: %s\n",
|
||||
cairo_status_to_string (diff_status));
|
||||
ret = CAIRO_TEST_FAILURE;
|
||||
goto UNWIND_CAIRO;
|
||||
}
|
||||
}
|
||||
|
||||
if (ref_png_path == NULL) {
|
||||
cairo_test_log (ctx, "Error: Cannot find reference image for %s\n",
|
||||
base_name);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue