[Pixman] [PATCH v2] test: Add new fuzz tester targeting solid images

Pekka Paalanen ppaalanen at gmail.com
Fri May 8 01:38:45 PDT 2015


On Thu,  7 May 2015 19:32:46 +0100
Ben Avison <bavison at riscosopen.org> wrote:

> This places a heavier emphasis on solid images than the other fuzz testers,
> and tests both single-pixel repeating bitmap images as well as those created
> using pixman_image_create_solid_fill(). In the former case, it also
> exercises the case where the bitmap contents are written to after the
> image's first use, which is not a use-case that any other test has
> previously covered.
> ---
>  test/Makefile.sources |    1 +
>  test/solid-test.c     |  348 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 349 insertions(+), 0 deletions(-)
>  create mode 100644 test/solid-test.c

Hi Ben,

ok, let me redo my probability analysis:

Source image:
- 33% chance for multi-pixel bits image
- 33% chance for 1x1 bits image
- 33% chance for solid image

Mask image:
- 33% chance to not be used
- 16.6% chance for multi-pixel without CA
- 8.3% chance for 1x1 bits image without CA
- 8.3% chance for solid image without CA
- 16.6% chance for multi-pixel with CA
- 8.3% chance for 1x1 bits image with CA
- 8.3% chance for solid image with CA

Destination image:
- always multi-pixel

Both source and mask, when they are 1x1 bits images, have:
- 50% chance to start fully opaque 0xFFFFFFFF
- 50% chance to start 0x00000000
and then switch to arbitrary random color for the actual test.

I see initialize_palette() is completely random, which prevents us from
getting a guaranteed opaque or fully transparent color... but even when
a palette talks about rgba, it doesn't actually have alpha? So it's
always opaque?

IOW, for paletted formats, we only ever deal with opaque colors. Right?

In any case, this looks good to me.

> +static uint32_t
> +test_solid (int testnum, int verbose)
> +{
> +    pixman_op_t          op;
> +    uint32_t             src_buf[WIDTH * HEIGHT];
> +    uint32_t             dst_buf[WIDTH * HEIGHT];
> +    uint32_t             mask_buf[WIDTH * HEIGHT];
> +    pixman_image_t      *src_img;
> +    pixman_image_t      *dst_img;
> +    pixman_image_t      *mask_img = NULL;
> +    pixman_format_code_t src_fmt, dst_fmt, mask_fmt = PIXMAN_null;
> +    pixman_bool_t        ca = 0;
> +    uint32_t             crc32;
> +
> +    prng_srand (testnum);
> +
> +    op = op_list[prng_rand_n (ARRAY_LENGTH (op_list))];
> +
> +    dst_img = create_multi_pixel_image (img_fmt_list, dst_buf, &dst_fmt);
> +    switch (prng_rand_n (3))
> +    {
> +    case 0: /* Solid source, no mask */
> +        src_img = create_solid_image (img_fmt_list, src_buf, &src_fmt);
> +        break;
> +    case 1: /* Solid source, bitmap mask */
> +        src_img = create_solid_image (img_fmt_list, src_buf, &src_fmt);
> +        mask_img = create_multi_pixel_image (mask_fmt_list, mask_buf, &mask_fmt);
> +        break;
> +    case 2: /* Bitmap image, solid mask */
> +        src_img = create_multi_pixel_image (img_fmt_list, src_buf, &src_fmt);
> +        mask_img = create_solid_image (mask_fmt_list, mask_buf, &mask_fmt);
> +        break;
> +    }
> +

/home/pq/git/pixman/test/solid-test.c: In function ‘test_solid’:
/home/pq/git/pixman/test/solid-test.c:324:24: warning: ‘src_img’ may be used uninitialized in this function [-Wmaybe-uninitialized]

I tested that putting a default case for the above switch with abort();
fixes that warning.

The warning comes only with my reference build, most likely due to -O1.

> +    if (mask_img)
> +    {
> +        ca = prng_rand_n (2);
> +        pixman_image_set_component_alpha (mask_img, ca);
> +    }
> +
> +    if (verbose)
> +    {
> +        printf ("op=%s\n", operator_name (op));
> +        printf ("src_fmt=%s, dst_fmt=%s, mask_fmt=%s\n",
> +                format_name (src_fmt), format_name (dst_fmt),
> +                format_name (mask_fmt));
> +        printf ("src_size=%u, mask_size=%u, component_alpha=%u\n",
> +                src_fmt == PIXMAN_solid ? 1 : src_img->bits.width,
> +                !mask_img || mask_fmt == PIXMAN_solid ? 1 : mask_img->bits.width,
> +                ca);
> +    }
> +
> +    pixman_image_composite (op, src_img, mask_img, dst_img,
> +                            0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
> +
> +    if (verbose)
> +        print_image (dst_img);
> +
> +    crc32 = compute_crc32_for_image (0, dst_img);
> +
> +    pixman_image_unref (src_img);
> +    pixman_image_unref (dst_img);
> +    if (mask_img)
> +        pixman_image_unref (mask_img);
> +
> +    return crc32;
> +}
> +
> +int
> +main (int argc, const char *argv[])
> +{
> +    int i;
> +
> +    prng_srand (0);
> +
> +    for (i = 1; i <= 8; i++)
> +    {
> +        initialize_palette (&(rgb_palette[i]), i, TRUE);
> +        initialize_palette (&(y_palette[i]), i, FALSE);
> +    }
> +
> +    return fuzzer_test_main ("solid", 500000,
> +			     0x1B6DFF8D,
> +			     test_solid, argc, argv);
> +}

Again, tested with both my reference build and a x86_64 optimized
build, and both pass.

With that one fix added,
Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

I look forward to pushing this, say, mid next week. I can add that fix
myself, too.


Thanks,
pq


More information about the Pixman mailing list