[Cogl] [PATCH 1/2] Add test that Cogl doesn't crash when freeing unallocated texture

Robert Bragg robert at sixbynine.org
Wed Jun 12 03:40:34 PDT 2013


This looks good to land to me:

Reviewed-by: Robert Bragg <robert at linux.intel.com>

thanks,
- Robert

On Tue, Jun 11, 2013 at 3:57 PM, Neil Roberts <neil at linux.intel.com> wrote:
> It looks like Cogl doesn't currently clean up an unallocated atlas
> texture properly so if it fails to allocate it. It will then crash
> when it is freed. This adds a conformance test to verify that all of
> the various texture types can be freed without allocating them.
> ---
>  tests/conform/Makefile.am                |  1 +
>  tests/conform/test-conform-main.c        |  2 +
>  tests/conform/test-texture-no-allocate.c | 85 ++++++++++++++++++++++++++++++++
>  3 files changed, 88 insertions(+)
>  create mode 100644 tests/conform/test-texture-no-allocate.c
>
> diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
> index d57c8e5..d12c90d 100644
> --- a/tests/conform/Makefile.am
> +++ b/tests/conform/Makefile.am
> @@ -65,6 +65,7 @@ test_sources = \
>         test-primitive-and-journal.c \
>         test-copy-replace-texture.c \
>         test-pipeline-cache-unrefs-texture.c \
> +       test-texture-no-allocate.c \
>         $(NULL)
>
>  if !USING_EMSCRIPTEN
> diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
> index ca2525d..02f0256 100644
> --- a/tests/conform/test-conform-main.c
> +++ b/tests/conform/test-conform-main.c
> @@ -141,6 +141,8 @@ main (int argc, char **argv)
>
>    ADD_TEST (test_fence, TEST_REQUIREMENT_FENCE, 0);
>
> +  ADD_TEST (test_texture_no_allocate, 0, TEST_KNOWN_FAILURE);
> +
>    g_printerr ("Unknown test name \"%s\"\n", argv[1]);
>
>    return 1;
> diff --git a/tests/conform/test-texture-no-allocate.c b/tests/conform/test-texture-no-allocate.c
> new file mode 100644
> index 0000000..56cca44
> --- /dev/null
> +++ b/tests/conform/test-texture-no-allocate.c
> @@ -0,0 +1,85 @@
> +#include <cogl/cogl.h>
> +
> +#include "test-utils.h"
> +
> +/* Tests that the various texture types can be freed without being
> + * allocated */
> +
> +/* Texture size that is probably to big to fit within the texture
> + * limits */
> +#define BIG_TEX_WIDTH 16384
> +#define BIG_TEX_HEIGHT 128
> +
> +void
> +test_texture_no_allocate (void)
> +{
> +  uint8_t *tex_data;
> +  CoglTexture *texture;
> +  CoglTexture2D *texture_2d;
> +  CoglError *error = NULL;
> +
> +  tex_data = g_malloc (BIG_TEX_WIDTH * BIG_TEX_HEIGHT * 4);
> +
> +  /* NB: if we make the atlas and sliced texture APIs public then this
> +   * could changed to explicitly use that instead of the magic texture
> +   * API */
> +
> +  /* Try to create an atlas texture that is too big so it will
> +   * internally be freed without allocating */
> +  texture = cogl_texture_new_from_data (test_ctx,
> +                                        BIG_TEX_WIDTH,
> +                                        BIG_TEX_HEIGHT,
> +                                        COGL_TEXTURE_NONE, /* flags */
> +                                        /* format */
> +                                        COGL_PIXEL_FORMAT_RGBA_8888_PRE,
> +                                        /* internal format */
> +                                        COGL_PIXEL_FORMAT_ANY,
> +                                        /* rowstride */
> +                                        BIG_TEX_WIDTH * 4,
> +                                        tex_data,
> +                                        &error);
> +
> +  g_free (tex_data);
> +
> +  /* It's ok if this causes an error, we just don't want it to
> +   * crash */
> +
> +  if (texture == NULL)
> +    cogl_error_free (error);
> +  else
> +    cogl_object_unref (texture);
> +
> +  /* Try to create a sliced texture without allocating it */
> +  texture = cogl_texture_new_with_size (test_ctx,
> +                                        BIG_TEX_WIDTH,
> +                                        BIG_TEX_HEIGHT,
> +                                        COGL_TEXTURE_NO_ATLAS,
> +                                        COGL_PIXEL_FORMAT_RGBA_8888_PRE);
> +  cogl_object_unref (texture);
> +
> +  /* 2D texture */
> +  texture_2d = cogl_texture_2d_new_with_size (test_ctx,
> +                                              64, 64,
> +                                              COGL_PIXEL_FORMAT_RGBA_8888_PRE);
> +  cogl_object_unref (texture_2d);
> +
> +  /* 3D texture */
> +  if (cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_3D))
> +    {
> +      CoglTexture3D *texture_3d =
> +        cogl_texture_3d_new_with_size (test_ctx,
> +                                       64, 64, 64,
> +                                       COGL_PIXEL_FORMAT_RGBA_8888_PRE);
> +      cogl_object_unref (texture_3d);
> +    }
> +
> +  /* Rectangle texture */
> +  if (cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_RECTANGLE))
> +    {
> +      CoglTextureRectangle *texture_rect =
> +        cogl_texture_rectangle_new_with_size (test_ctx,
> +                                              64, 64,
> +                                              COGL_PIXEL_FORMAT_RGBA_8888_PRE);
> +      cogl_object_unref (texture_rect);
> +    }
> +}
> --
> 1.7.11.3.g3c3efa5
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl


More information about the Cogl mailing list