6 #include "pixman-private.h" /* For 'inline' definition */
8 #define ARRAY_LENGTH(A) ((int) (sizeof (A) / sizeof ((A) [0])))
10 /* A primitive pseudorandom number generator,
11 * taken from POSIX.1-2001 example
14 extern uint32_t lcg_seed;
16 #pragma omp threadprivate(lcg_seed)
19 static inline uint32_t
22 lcg_seed = lcg_seed * 1103515245 + 12345;
23 return ((uint32_t)(lcg_seed / 65536) % 32768);
27 lcg_srand (uint32_t seed)
32 static inline uint32_t
35 return lcg_rand () % max;
38 static inline uint32_t
41 uint32_t lo = lcg_rand ();
42 uint32_t hi = lcg_rand () << 15;
43 return (lo | hi) % max;
46 static inline uint32_t
49 /* This uses the 10/11 most significant bits from the 3 lcg results
50 * (and mixes them with the low from the adjacent one).
52 uint32_t lo = lcg_rand() >> -(32 - 15 - 11 * 2);
53 uint32_t mid = lcg_rand() << (32 - 15 - 11 * 1);
54 uint32_t hi = lcg_rand() << (32 - 15 - 11 * 0);
56 return (hi ^ mid ^ lo);
62 compute_crc32 (uint32_t in_crc32,
66 /* Returns TRUE if running on a little endian system */
68 is_little_endian (void);
70 /* perform endian conversion of pixel data
73 image_endian_swap (pixman_image_t *img);
75 /* Allocate memory that is bounded by protected pages,
76 * so that out-of-bounds access will cause segfaults
79 fence_malloc (int64_t len);
82 fence_free (void *data);
84 /* Generate n_bytes random bytes in fence_malloced memory */
86 make_random_bytes (int n_bytes);
88 /* Return current time in seconds */
93 get_random_seed (void);
95 /* main body of the fuzzer test */
97 fuzzer_test_main (const char *test_name,
98 int default_number_of_iterations,
99 uint32_t expected_checksum,
100 uint32_t (*test_function)(int testnum, int verbose),
105 fail_after (int seconds, const char *msg);
107 /* If possible, enable traps for floating point exceptions */
108 void enable_fp_exceptions(void);
110 /* Converts a8r8g8b8 pixels to pixels that
111 * - are not premultiplied,
112 * - are stored in this order in memory: R, G, B, A, regardless of
113 * the endianness of the computer.
114 * It is allowed for @src and @dst to point to the same memory buffer.
117 a8r8g8b8_to_rgba_np (uint32_t *dst, uint32_t *src, int n_pixels);
120 write_png (pixman_image_t *image, const char *filename);
122 /* A pair of macros which can help to detect corruption of
123 * floating point registers after a function call. This may
124 * happen if _mm_empty() call is forgotten in MMX/SSE2 fast
125 * path code, or ARM NEON assembly optimized function forgets
126 * to save/restore d8-d15 registers before use.
129 #define FLOAT_REGS_CORRUPTION_DETECTOR_START() \
130 static volatile double frcd_volatile_constant1 = 123451; \
131 static volatile double frcd_volatile_constant2 = 123452; \
132 static volatile double frcd_volatile_constant3 = 123453; \
133 static volatile double frcd_volatile_constant4 = 123454; \
134 static volatile double frcd_volatile_constant5 = 123455; \
135 static volatile double frcd_volatile_constant6 = 123456; \
136 static volatile double frcd_volatile_constant7 = 123457; \
137 static volatile double frcd_volatile_constant8 = 123458; \
138 double frcd_canary_variable1 = frcd_volatile_constant1; \
139 double frcd_canary_variable2 = frcd_volatile_constant2; \
140 double frcd_canary_variable3 = frcd_volatile_constant3; \
141 double frcd_canary_variable4 = frcd_volatile_constant4; \
142 double frcd_canary_variable5 = frcd_volatile_constant5; \
143 double frcd_canary_variable6 = frcd_volatile_constant6; \
144 double frcd_canary_variable7 = frcd_volatile_constant7; \
145 double frcd_canary_variable8 = frcd_volatile_constant8;
147 #define FLOAT_REGS_CORRUPTION_DETECTOR_FINISH() \
148 assert (frcd_canary_variable1 == frcd_volatile_constant1); \
149 assert (frcd_canary_variable2 == frcd_volatile_constant2); \
150 assert (frcd_canary_variable3 == frcd_volatile_constant3); \
151 assert (frcd_canary_variable4 == frcd_volatile_constant4); \
152 assert (frcd_canary_variable5 == frcd_volatile_constant5); \
153 assert (frcd_canary_variable6 == frcd_volatile_constant6); \
154 assert (frcd_canary_variable7 == frcd_volatile_constant7); \
155 assert (frcd_canary_variable8 == frcd_volatile_constant8);
157 /* Try to get an aligned memory chunk */
159 aligned_malloc (size_t align, size_t size);
162 initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb);
170 round_color (pixman_format_code_t format, color_t *color);
174 pixman_format_code_t format;
175 uint32_t am, rm, gm, bm;
176 uint32_t as, rs, gs, bs;
177 uint32_t aw, rw, gw, bw;
181 pixel_checker_init (pixel_checker_t *checker, pixman_format_code_t format);
184 pixel_checker_split_pixel (const pixel_checker_t *checker, uint32_t pixel,
185 int *a, int *r, int *g, int *b);
188 pixel_checker_get_max (const pixel_checker_t *checker, color_t *color,
189 int *a, int *r, int *g, int *b);
192 pixel_checker_get_min (const pixel_checker_t *checker, color_t *color,
193 int *a, int *r, int *g, int *b);
196 pixel_checker_check (const pixel_checker_t *checker,
197 uint32_t pixel, color_t *color);