pixman: Branch 'master' - 2 commits

Siarhei Siamashka siamashka at kemper.freedesktop.org
Tue Jul 27 06:15:10 PDT 2010


 test/Makefile.am          |    2 
 test/scaling-crash-test.c |  124 ++++++++++++++++++++++++++++++++++++++++++++++
 test/scaling-test.c       |   22 +++++---
 test/utils.h              |    7 ++
 4 files changed, 147 insertions(+), 8 deletions(-)

New commits:
commit 226a6df4f947f718d82e85ca53561a968ec0c0a1
Author: Siarhei Siamashka <siarhei.siamashka at nokia.com>
Date:   Wed Jul 14 16:43:16 2010 +0300

    test: 'scaling-test' updated to provide better coverage
    
    Negative scale factors are now also tested. A small additional
    translate transform helps to stress the use of fractional
    coordinates better.
    
    Also the number of iterations to run by default increased in order
    to compensate increased variety of operations to be tested.

diff --git a/test/scaling-test.c b/test/scaling-test.c
index 16583d0..6aef823 100644
--- a/test/scaling-test.c
+++ b/test/scaling-test.c
@@ -12,10 +12,10 @@
 #include <stdio.h>
 #include "utils.h"
 
-#define MAX_SRC_WIDTH  10
-#define MAX_SRC_HEIGHT 10
-#define MAX_DST_WIDTH  10
-#define MAX_DST_HEIGHT 10
+#define MAX_SRC_WIDTH  16
+#define MAX_SRC_HEIGHT 16
+#define MAX_DST_WIDTH  16
+#define MAX_DST_HEIGHT 16
 #define MAX_STRIDE     4
 
 /*
@@ -38,7 +38,8 @@ test_composite (int      testnum,
     int                src_bpp;
     int                dst_bpp;
     int                w, h;
-    int                scale_x = 32768, scale_y = 32768;
+    pixman_fixed_t     scale_x = 65536, scale_y = 65536;
+    pixman_fixed_t     translate_x = 0, translate_y = 0;
     int                op;
     int                repeat = 0;
     int                src_fmt, dst_fmt;
@@ -98,9 +99,12 @@ test_composite (int      testnum,
 
     if (lcg_rand_n (8) > 0)
     {
-	scale_x = 32768 + lcg_rand_n (65536);
-	scale_y = 32768 + lcg_rand_n (65536);
+	scale_x = -32768 * 3 + lcg_rand_N (65536 * 5);
+	scale_y = -32768 * 3 + lcg_rand_N (65536 * 5);
+	translate_x = lcg_rand_N (65536);
+	translate_y = lcg_rand_N (65536);
 	pixman_transform_init_scale (&transform, scale_x, scale_y);
+	pixman_transform_translate (&transform, NULL, translate_x, translate_y);
 	pixman_image_set_transform (src_img, &transform);
     }
 
@@ -137,6 +141,8 @@ test_composite (int      testnum,
 	printf ("src_fmt=%08X, dst_fmt=%08X\n", src_fmt, dst_fmt);
 	printf ("op=%d, scale_x=%d, scale_y=%d, repeat=%d\n",
 	        op, scale_x, scale_y, repeat);
+	printf ("translate_x=%d, translate_y=%d\n",
+	        translate_x, translate_y);
 	printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n",
 	        src_width, src_height, dst_width, dst_height);
 	printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n",
@@ -236,6 +242,6 @@ main (int argc, const char *argv[])
 {
     pixman_disable_out_of_bounds_workaround ();
 
-    return fuzzer_test_main("scaling", 3000000, 0x7833766A,
+    return fuzzer_test_main("scaling", 8000000, 0x7F1AB59F,
 			    test_composite, argc, argv);
 }
diff --git a/test/utils.h b/test/utils.h
index 8ec7b17..95d809a 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -30,6 +30,13 @@ lcg_rand_n (int max)
     return lcg_rand () % max;
 }
 
+static inline uint32_t
+lcg_rand_N (int max)
+{
+    uint32_t lo = lcg_rand ();
+    uint32_t hi = lcg_rand () << 15;
+    return (lo | hi) % max;
+}
 
 /* CRC 32 computation
  */
commit af3eeaeb1352148ca671a45768d11160fcfd8567
Author: Siarhei Siamashka <siarhei.siamashka at nokia.com>
Date:   Mon Jul 19 20:25:05 2010 +0300

    test: 'scaling-crash-test' added
    
    This test tries to exploit some corner cases and previously known
    bugs in nearest neighbor scaling fast path code, attempting to
    crash pixman or cause some other nasty effect.

diff --git a/test/Makefile.am b/test/Makefile.am
index 20cb00f..2a7aea2 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -13,6 +13,7 @@ TESTPROGRAMS =			\
 	gradient-crash-test	\
 	trap-crasher		\
 	alphamap		\
+	scaling-crash-test	\
 	blitters-test		\
 	scaling-test		\
 	composite
@@ -24,6 +25,7 @@ gradient_crash_test_LDADD = $(TEST_LDADD)
 trap_crasher_LDADD = $(TEST_LDADD)
 oob_test_LDADD = $(TEST_LDADD)
 window_test_LDADD = $(TEST_LDADD)
+scaling_crash_test_LDADD = $(TEST_LDADD)
 
 region_test_LDADD = $(TEST_LDADD)
 region_test_SOURCES = region-test.c utils.c utils.h
diff --git a/test/scaling-crash-test.c b/test/scaling-crash-test.c
new file mode 100644
index 0000000..4ab01e3
--- /dev/null
+++ b/test/scaling-crash-test.c
@@ -0,0 +1,124 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "pixman.h"
+
+/*
+ * We have a source image filled with solid color, set NORMAL or PAD repeat,
+ * and some transform which results in nearest neighbour scaling.
+ *
+ * The expected result is the destination image filled with this solid
+ * color.
+ */
+static int
+do_test (int32_t		dst_size,
+	 int32_t		src_size,
+	 int32_t		src_offs,
+	 int32_t		scale_factor,
+	 pixman_repeat_t	repeat)
+{
+    int i;
+    pixman_image_t *   src_img;
+    pixman_image_t *   dst_img;
+    pixman_transform_t transform;
+    uint32_t *         srcbuf;
+    uint32_t *         dstbuf;
+
+    srcbuf = (uint32_t *)malloc (src_size * 4);
+    dstbuf = (uint32_t *)malloc (dst_size * 4);
+
+    /* horizontal test */
+    memset (srcbuf, 0xCC, src_size * 4);
+    memset (dstbuf, 0x33, dst_size * 4);
+
+    src_img = pixman_image_create_bits (
+        PIXMAN_a8r8g8b8, src_size, 1, srcbuf, src_size * 4);
+    dst_img = pixman_image_create_bits (
+        PIXMAN_a8r8g8b8, dst_size, 1, dstbuf, dst_size * 4);
+
+    pixman_transform_init_scale (&transform, scale_factor, 65536);
+    pixman_image_set_transform (src_img, &transform);
+    pixman_image_set_repeat (src_img, repeat);
+    pixman_image_set_filter (src_img, PIXMAN_FILTER_NEAREST, NULL, 0);
+
+    pixman_image_composite (PIXMAN_OP_SRC, src_img, NULL, dst_img,
+                            src_offs, 0, 0, 0, 0, 0, dst_size, 1);
+
+    pixman_image_unref (src_img);
+    pixman_image_unref (dst_img);
+
+    for (i = 0; i < dst_size; i++)
+    {
+	if (dstbuf[i] != 0xCCCCCCCC)
+	{
+	    free (srcbuf);
+	    free (dstbuf);
+	    return 1;
+	}
+    }
+
+    /* vertical test */
+    memset (srcbuf, 0xCC, src_size * 4);
+    memset (dstbuf, 0x33, dst_size * 4);
+
+    src_img = pixman_image_create_bits (
+        PIXMAN_a8r8g8b8, 1, src_size, srcbuf, 4);
+    dst_img = pixman_image_create_bits (
+        PIXMAN_a8r8g8b8, 1, dst_size, dstbuf, 4);
+
+    pixman_transform_init_scale (&transform, 65536, scale_factor);
+    pixman_image_set_transform (src_img, &transform);
+    pixman_image_set_repeat (src_img, repeat);
+    pixman_image_set_filter (src_img, PIXMAN_FILTER_NEAREST, NULL, 0);
+
+    pixman_image_composite (PIXMAN_OP_SRC, src_img, NULL, dst_img,
+                            0, src_offs, 0, 0, 0, 0, 1, dst_size);
+
+    pixman_image_unref (src_img);
+    pixman_image_unref (dst_img);
+
+    for (i = 0; i < dst_size; i++)
+    {
+	if (dstbuf[i] != 0xCCCCCCCC)
+	{
+	    free (srcbuf);
+	    free (dstbuf);
+	    return 1;
+	}
+    }
+
+    free (srcbuf);
+    free (dstbuf);
+    return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+    pixman_disable_out_of_bounds_workaround ();
+
+    /* can potentially crash */
+    assert (do_test (
+	48000, 32767, 1, 65536 * 128, PIXMAN_REPEAT_NORMAL) == 0);
+
+    /* can potentially get into a deadloop */
+    assert (do_test (
+	16384, 65536, 32, 32768, PIXMAN_REPEAT_NORMAL) == 0);
+
+#if 0
+    /* can potentially access memory outside source image buffer */
+    assert (do_test (
+	10, 10, 0, 1, PIXMAN_REPEAT_PAD) == 0);
+    assert (do_test (
+	10, 10, 0, 0, PIXMAN_REPEAT_PAD) == 0);
+#endif
+
+#if 0
+    /* can potentially provide invalid results (out of range matrix stuff) */
+    assert (do_test (
+	48000, 32767, 16384, 65536 * 128, PIXMAN_REPEAT_NORMAL) == 0);
+#endif
+
+    return 0;
+}


More information about the xorg-commit mailing list