[test] Improve fault injection coverage

In order to exercise the meta-surfaces, we need to inject faults into
cairo_surface_finish().
This commit is contained in:
Chris Wilson 2009-03-30 16:50:10 +01:00
parent 80d5b53b47
commit b580a4a8d6
2 changed files with 48 additions and 3 deletions

View file

@ -76,6 +76,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <errno.h>
#if HAVE_UNISTD_H && HAVE_FCNTL_H && HAVE_SIGNAL_H && HAVE_SYS_STAT_H && HAVE_SYS_SOCKET_H && HAVE_SYS_UN_H
#include <unistd.h>
@ -170,6 +171,9 @@ _cairo_boilerplate_get_image_surface (cairo_surface_t *src,
cairo_surface_t *surface;
cairo_t *cr;
if (cairo_surface_status (src))
return cairo_surface_reference (src);
#if 0
if (cairo_surface_get_type (src) == CAIRO_SURFACE_TYPE_IMAGE) {
int ww = cairo_image_surface_get_width (src);
@ -973,7 +977,7 @@ cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file)
goto FAIL;
}
if (cairo_surface_status (image))
goto FAIL;
return image;
data = cairo_image_surface_get_data (image);
stride = cairo_image_surface_get_stride (image);
@ -1017,8 +1021,14 @@ cairo_boilerplate_convert_to_image (const char *filename, int page)
RETRY:
file = cairo_boilerplate_open_any2ppm (filename, page, flags);
if (file == NULL)
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);
if (file == NULL) {
switch (errno) {
case ENOMEM:
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_NO_MEMORY);
default:
return cairo_boilerplate_surface_create_in_error (CAIRO_STATUS_READ_ERROR);
}
}
image = cairo_boilerplate_image_surface_create_from_ppm_stream (file);
ret = pclose (file);

View file

@ -910,7 +910,42 @@ REPEAT:
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().
*/
VALGRIND_CLEAR_FAULTS ();
last_fault_count = VALGRIND_COUNT_FAULTS ();
VALGRIND_ENABLE_FAULTS ();
#endif
diff_status = target->finish_surface (surface);
#if HAVE_MEMFAULT
VALGRIND_DISABLE_FAULTS ();
if (ctx->malloc_failure &&
VALGRIND_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 (VALGRIND_COUNT_LEAKS () > 0) {
VALGRIND_PRINT_FAULTS ();
VALGRIND_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));