9 static void startup(void);
10 static void cleanup(void);
12 void (*tet_startup)(void) = startup;
13 void (*tet_cleanup)(void) = cleanup;
15 static void utc_pixman_composite_traps(void);
17 struct tet_testlist tet_testlist[] = {
18 { utc_pixman_composite_traps, 1 },
22 static void startup(void)
27 static void cleanup(void)
32 #define MAX_SRC_WIDTH 48
33 #define MAX_SRC_HEIGHT 48
34 #define MAX_DST_WIDTH 48
35 #define MAX_DST_HEIGHT 48
38 static pixman_format_code_t formats[] =
40 PIXMAN_a8r8g8b8, PIXMAN_a8, PIXMAN_r5g6b5, PIXMAN_a1, PIXMAN_a4
43 static pixman_format_code_t mask_formats[] =
45 PIXMAN_a1, PIXMAN_a4, PIXMAN_a8,
48 static pixman_op_t operators[] =
50 PIXMAN_OP_OVER, PIXMAN_OP_ADD, PIXMAN_OP_SRC, PIXMAN_OP_IN
53 #define RANDOM_ELT(array) \
54 ((array)[lcg_rand_n(ARRAY_LENGTH((array)))])
57 destroy_bits (pixman_image_t *image, void *data)
65 return lcg_rand_N (n << 16);
69 * Composite operation with pseudorandom images
72 test_composite (int testnum,
76 pixman_image_t * src_img;
77 pixman_image_t * dst_img;
78 pixman_region16_t clip;
79 int dst_width, dst_height;
86 pixman_format_code_t mask_format, dst_format;
87 pixman_trapezoid_t *traps;
91 static pixman_color_t colors[] =
93 { 0xffff, 0xffff, 0xffff, 0xffff },
94 { 0x0000, 0x0000, 0x0000, 0x0000 },
95 { 0xabcd, 0xabcd, 0x0000, 0xabcd },
96 { 0x0000, 0x0000, 0x0000, 0xffff },
97 { 0x0101, 0x0101, 0x0101, 0x0101 },
98 { 0x7777, 0x6666, 0x5555, 0x9999 },
101 FLOAT_REGS_CORRUPTION_DETECTOR_START ();
105 op = RANDOM_ELT (operators);
106 mask_format = RANDOM_ELT (mask_formats);
108 /* Create source image */
110 if (lcg_rand_n (4) == 0)
112 src_img = pixman_image_create_solid_fill (
113 &(colors[lcg_rand_n (ARRAY_LENGTH (colors))]));
120 pixman_format_code_t src_format = RANDOM_ELT(formats);
121 int src_bpp = (PIXMAN_FORMAT_BPP (src_format) + 7) / 8;
122 int src_width = lcg_rand_n (MAX_SRC_WIDTH) + 1;
123 int src_height = lcg_rand_n (MAX_SRC_HEIGHT) + 1;
124 int src_stride = src_width * src_bpp + lcg_rand_n (MAX_STRIDE) * src_bpp;
127 src_x = -(src_width / 4) + lcg_rand_n (src_width * 3 / 2);
128 src_y = -(src_height / 4) + lcg_rand_n (src_height * 3 / 2);
130 src_stride = (src_stride + 3) & ~3;
132 bits = (uint32_t *)make_random_bytes (src_stride * src_height);
134 src_img = pixman_image_create_bits (
135 src_format, src_width, src_height, bits, src_stride);
137 pixman_image_set_destroy_function (src_img, destroy_bits, bits);
139 if (lcg_rand_n (8) == 0)
141 pixman_box16_t clip_boxes[2];
142 int n = lcg_rand_n (2) + 1;
144 for (i = 0; i < n; i++)
146 clip_boxes[i].x1 = lcg_rand_n (src_width);
147 clip_boxes[i].y1 = lcg_rand_n (src_height);
149 clip_boxes[i].x1 + lcg_rand_n (src_width - clip_boxes[i].x1);
151 clip_boxes[i].y1 + lcg_rand_n (src_height - clip_boxes[i].y1);
155 printf ("source clip box: [%d,%d-%d,%d]\n",
156 clip_boxes[i].x1, clip_boxes[i].y1,
157 clip_boxes[i].x2, clip_boxes[i].y2);
161 pixman_region_init_rects (&clip, clip_boxes, n);
162 pixman_image_set_clip_region (src_img, &clip);
163 pixman_image_set_source_clipping (src_img, 1);
164 pixman_region_fini (&clip);
167 image_endian_swap (src_img);
170 /* Create destination image */
172 dst_format = RANDOM_ELT(formats);
173 dst_bpp = (PIXMAN_FORMAT_BPP (dst_format) + 7) / 8;
174 dst_width = lcg_rand_n (MAX_DST_WIDTH) + 1;
175 dst_height = lcg_rand_n (MAX_DST_HEIGHT) + 1;
176 dst_stride = dst_width * dst_bpp + lcg_rand_n (MAX_STRIDE) * dst_bpp;
177 dst_stride = (dst_stride + 3) & ~3;
179 dst_bits = (uint32_t *)make_random_bytes (dst_stride * dst_height);
181 dst_x = -(dst_width / 4) + lcg_rand_n (dst_width * 3 / 2);
182 dst_y = -(dst_height / 4) + lcg_rand_n (dst_height * 3 / 2);
184 dst_img = pixman_image_create_bits (
185 dst_format, dst_width, dst_height, dst_bits, dst_stride);
187 image_endian_swap (dst_img);
194 n_traps = lcg_rand_n (25);
195 traps = fence_malloc (n_traps * sizeof (pixman_trapezoid_t));
197 for (i = 0; i < n_traps; ++i)
199 pixman_trapezoid_t *t = &(traps[i]);
201 t->top = random_fixed (MAX_DST_HEIGHT) - MAX_DST_HEIGHT / 2;
202 t->bottom = t->top + random_fixed (MAX_DST_HEIGHT);
203 t->left.p1.x = random_fixed (MAX_DST_WIDTH) - MAX_DST_WIDTH / 2;
204 t->left.p1.y = t->top - random_fixed (50);
205 t->left.p2.x = random_fixed (MAX_DST_WIDTH) - MAX_DST_WIDTH / 2;
206 t->left.p2.y = t->bottom + random_fixed (50);
207 t->right.p1.x = t->left.p1.x + random_fixed (MAX_DST_WIDTH);
208 t->right.p1.y = t->top - random_fixed (50);
209 t->right.p2.x = t->left.p2.x + random_fixed (MAX_DST_WIDTH);
210 t->right.p2.y = t->bottom - random_fixed (50);
214 if (lcg_rand_n (8) == 0)
216 pixman_box16_t clip_boxes[2];
217 int n = lcg_rand_n (2) + 1;
218 for (i = 0; i < n; i++)
220 clip_boxes[i].x1 = lcg_rand_n (dst_width);
221 clip_boxes[i].y1 = lcg_rand_n (dst_height);
223 clip_boxes[i].x1 + lcg_rand_n (dst_width - clip_boxes[i].x1);
225 clip_boxes[i].y1 + lcg_rand_n (dst_height - clip_boxes[i].y1);
229 printf ("destination clip box: [%d,%d-%d,%d]\n",
230 clip_boxes[i].x1, clip_boxes[i].y1,
231 clip_boxes[i].x2, clip_boxes[i].y2);
234 pixman_region_init_rects (&clip, clip_boxes, n);
235 pixman_image_set_clip_region (dst_img, &clip);
236 pixman_region_fini (&clip);
239 pixman_composite_trapezoids (op, src_img, dst_img, mask_format,
240 src_x, src_y, dst_x, dst_y, n_traps, traps);
242 if (dst_format == PIXMAN_x8r8g8b8)
244 /* ignore unused part */
245 for (i = 0; i < dst_stride * dst_height / 4; i++)
246 dst_bits[i] &= 0xFFFFFF;
249 image_endian_swap (dst_img);
255 for (i = 0; i < dst_height; i++)
257 for (j = 0; j < dst_stride; j++)
258 printf ("%02X ", *((uint8_t *)dst_bits + i * dst_stride + j));
264 crc32 = compute_crc32 (0, dst_bits, dst_stride * dst_height);
266 fence_free (dst_bits);
268 pixman_image_unref (src_img);
269 pixman_image_unref (dst_img);
272 FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
276 static void utc_pixman_composite_traps(void)
280 ret = fuzzer_test_main("composite traps", 40000, 0xE3112106,
281 test_composite, 1, NULL);
284 dts_fail("utc_pixman_composite_traps");
286 dts_pass("utc_pixman_composite_traps");