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);
111 write_png (pixman_image_t *image, const char *filename);
113 /* A pair of macros which can help to detect corruption of
114 * floating point registers after a function call. This may
115 * happen if _mm_empty() call is forgotten in MMX/SSE2 fast
116 * path code, or ARM NEON assembly optimized function forgets
117 * to save/restore d8-d15 registers before use.
120 #define FLOAT_REGS_CORRUPTION_DETECTOR_START() \
121 static volatile double frcd_volatile_constant1 = 123451; \
122 static volatile double frcd_volatile_constant2 = 123452; \
123 static volatile double frcd_volatile_constant3 = 123453; \
124 static volatile double frcd_volatile_constant4 = 123454; \
125 static volatile double frcd_volatile_constant5 = 123455; \
126 static volatile double frcd_volatile_constant6 = 123456; \
127 static volatile double frcd_volatile_constant7 = 123457; \
128 static volatile double frcd_volatile_constant8 = 123458; \
129 double frcd_canary_variable1 = frcd_volatile_constant1; \
130 double frcd_canary_variable2 = frcd_volatile_constant2; \
131 double frcd_canary_variable3 = frcd_volatile_constant3; \
132 double frcd_canary_variable4 = frcd_volatile_constant4; \
133 double frcd_canary_variable5 = frcd_volatile_constant5; \
134 double frcd_canary_variable6 = frcd_volatile_constant6; \
135 double frcd_canary_variable7 = frcd_volatile_constant7; \
136 double frcd_canary_variable8 = frcd_volatile_constant8;
138 #define FLOAT_REGS_CORRUPTION_DETECTOR_FINISH() \
139 assert (frcd_canary_variable1 == frcd_volatile_constant1); \
140 assert (frcd_canary_variable2 == frcd_volatile_constant2); \
141 assert (frcd_canary_variable3 == frcd_volatile_constant3); \
142 assert (frcd_canary_variable4 == frcd_volatile_constant4); \
143 assert (frcd_canary_variable5 == frcd_volatile_constant5); \
144 assert (frcd_canary_variable6 == frcd_volatile_constant6); \
145 assert (frcd_canary_variable7 == frcd_volatile_constant7); \
146 assert (frcd_canary_variable8 == frcd_volatile_constant8);
148 /* Try to get an aligned memory chunk */
150 aligned_malloc (size_t align, size_t size);
153 initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb);
161 round_color (pixman_format_code_t format, color_t *color);
165 pixman_format_code_t format;
166 uint32_t am, rm, gm, bm;
167 uint32_t as, rs, gs, bs;
168 uint32_t aw, rw, gw, bw;
172 pixel_checker_init (pixel_checker_t *checker, pixman_format_code_t format);
175 pixel_checker_split_pixel (const pixel_checker_t *checker, uint32_t pixel,
176 int *a, int *r, int *g, int *b);
179 pixel_checker_get_max (const pixel_checker_t *checker, color_t *color,
180 int *a, int *r, int *g, int *b);
183 pixel_checker_get_min (const pixel_checker_t *checker, color_t *color,
184 int *a, int *r, int *g, int *b);
187 pixel_checker_check (const pixel_checker_t *checker,
188 uint32_t pixel, color_t *color);