<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 29, 2016 at 4:55 AM, Oded Gabbay <span dir="ltr"><<a href="mailto:oded.gabbay@gmail.com" target="_blank">oded.gabbay@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Apr 12, 2016 at 5:36 AM, Søren Sandmann Pedersen<br>
<<a href="mailto:soren.sandmann@gmail.com">soren.sandmann@gmail.com</a>> wrote:<br>
> This new test tests a bunch of bilinear downscalings, where many have<br>
> a transformation such that the BILINEAR filter can be reduced to<br>
> NEAREST (and many don't).<br>
><br>
> A CRC32 is computed for all the resulting images and compared to a<br>
> known-good value for both 4-bit and 7-bit interpolation.<br>
><br>
> V2: Remove leftover comment, some minor formatting fixes, use a<br>
> timestamp as the PRNG seed.<br>
><br>
> Signed-off-by: Søren Sandmann <<a href="mailto:soren.sandmann@gmail.com">soren.sandmann@gmail.com</a>><br>
> ---<br>
> test/Makefile.sources | 1 +<br>
> test/filter-reduction-test.c | 112 +++++++++++++++++++++++++++++++++++++++++++<br>
> 2 files changed, 113 insertions(+)<br>
> create mode 100644 test/filter-reduction-test.c<br>
><br>
> diff --git a/test/Makefile.sources b/test/Makefile.sources<br>
> index 5d55e67..0a56231 100644<br>
> --- a/test/Makefile.sources<br>
> +++ b/test/Makefile.sources<br>
> @@ -21,6 +21,7 @@ TESTPROGRAMS = \<br>
> gradient-crash-test \<br>
> pixel-test \<br>
> matrix-test \<br>
> + filter-reduction-test \<br>
> composite-traps-test \<br>
> region-contains-test \<br>
> glyph-test \<br>
> diff --git a/test/filter-reduction-test.c b/test/filter-reduction-test.c<br>
> new file mode 100644<br>
> index 0000000..705fa4b<br>
> --- /dev/null<br>
> +++ b/test/filter-reduction-test.c<br>
> @@ -0,0 +1,112 @@<br>
> +#include <stdlib.h><br>
> +#include <stdio.h><br>
> +#include "utils.h"<br>
> +<br>
> +static const pixman_fixed_t entries[] =<br>
> +{<br>
> + pixman_double_to_fixed (-1.0),<br>
> + pixman_double_to_fixed (-0.5),<br>
> + pixman_double_to_fixed (-1/3.0),<br>
> + pixman_double_to_fixed (0.0),<br>
> + pixman_double_to_fixed (0.5),<br>
> + pixman_double_to_fixed (1.0),<br>
> + pixman_double_to_fixed (1.5),<br>
> + pixman_double_to_fixed (2.0),<br>
> + pixman_double_to_fixed (3.0),<br>
> +};<br>
> +<br>
> +#define SIZE 12<br>
> +<br>
> +static uint32_t<br>
> +test_scale (const pixman_transform_t *xform, uint32_t crc)<br>
> +{<br>
> + uint32_t *srcbuf, *dstbuf;<br>
> + pixman_image_t *src, *dest;<br>
> +<br>
> + srcbuf = malloc (SIZE * SIZE * 4);<br>
</div></div>I admit I didn't look at other tests, but it really caught my eye we<br>
don't check for memory allocation failure here.<br>
<span class=""><br>
> + prng_randmemset (srcbuf, SIZE * SIZE * 4, 0);<br>
> + src = pixman_image_create_bits (<br>
> + PIXMAN_a8r8g8b8, SIZE, SIZE, srcbuf, SIZE * 4);<br>
> +<br>
> + dstbuf = malloc (SIZE * SIZE * 4);<br>
</span>same comment<br></blockquote><div><br></div><div>I think it is ok to not look for that in unit tests. They will either crash or fail.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5"><br>
> + prng_randmemset (dstbuf, SIZE * SIZE * 4, 0);<br>
> + dest = pixman_image_create_bits (<br>
> + PIXMAN_a8r8g8b8, SIZE, SIZE, dstbuf, SIZE * 4);<br>
> +<br>
> + pixman_image_set_transform (src, xform);<br>
> + pixman_image_set_repeat (src, PIXMAN_REPEAT_NORMAL);<br>
> + pixman_image_set_filter (src, PIXMAN_FILTER_BILINEAR, NULL, 0);<br>
> +<br>
> + image_endian_swap (src);<br>
> + image_endian_swap (dest);<br>
> +<br>
> + pixman_image_composite (PIXMAN_OP_SRC,<br>
> + src, NULL, dest,<br>
> + 0, 0, 0, 0, 0, 0,<br>
> + SIZE, SIZE);<br>
> +<br>
> + crc = compute_crc32_for_image (crc, dest);<br>
> +<br>
> + pixman_image_unref (src);<br>
> + pixman_image_unref (dest);<br>
> +<br>
> + free (srcbuf);<br>
> + free (dstbuf);<br>
> +<br>
> + return crc;<br>
> +}<br>
> +<br>
> +#if BILINEAR_INTERPOLATION_BITS == 7<br>
> +#define CHECKSUM 0x02169677<br>
> +#elif BILINEAR_INTERPOLATION_BITS == 4<br>
> +#define CHECKSUM 0xE44B29AC<br>
> +#else<br>
> +#define CHECKSUM 0x00000000<br>
> +#endif<br>
> +<br>
> +int<br>
> +main (int argc, const char *argv[])<br>
> +{<br>
> + const pixman_fixed_t *end = entries + ARRAY_LENGTH (entries);<br>
> + const pixman_fixed_t *t0, *t1, *t2, *t3, *t4, *t5;<br>
> + uint32_t crc = 0;<br>
> +<br>
> + prng_srand (0x56EA1DBD);<br>
> +<br>
> + for (t0 = entries; t0 < end; ++t0)<br>
> + {<br>
> + for (t1 = entries; t1 < end; ++t1)<br>
> + {<br>
> + for (t2 = entries; t2 < end; ++t2)<br>
> + {<br>
> + for (t3 = entries; t3 < end; ++t3)<br>
> + {<br>
> + for (t4 = entries; t4 < end; ++t4)<br>
> + {<br>
> + for (t5 = entries; t5 < end; ++t5)<br>
> + {<br>
> + pixman_transform_t xform = {<br>
> + { { *t0, *t1, *t2 },<br>
> + { *t3, *t4, *t5 },<br>
> + { 0, 0, pixman_fixed_1 } }<br>
> + };<br>
> +<br>
> + crc = test_scale (&xform, crc);<br>
> + }<br>
> + }<br>
> + }<br>
> + }<br>
> + }<br>
> + }<br>
> +<br>
> + if (crc != CHECKSUM)<br>
> + {<br>
> + printf ("filter-reduction-test failed! (checksum=0x%08X, expected 0x%08X)\n", crc, CHECKSUM);<br>
> + return 1;<br>
> + }<br>
> + else<br>
> + {<br>
> + printf ("filter-reduction-test passed (checksum=0x%08X)\n", crc);<br>
> + return 0;<br>
> + }<br>
> +}<br>
> --<br>
> 1.7.11.7<br>
><br>
</div></div>> _______________________________________________<br>
> Pixman mailing list<br>
> <a href="mailto:Pixman@lists.freedesktop.org">Pixman@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/pixman" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/pixman</a><br>
_______________________________________________<br>
Pixman mailing list<br>
<a href="mailto:Pixman@lists.freedesktop.org">Pixman@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/pixman" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/pixman</a><br>
</blockquote></div><br></div></div>