aboutsummaryrefslogtreecommitdiff
path: root/pixman/test/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'pixman/test/utils.c')
-rw-r--r--pixman/test/utils.c89
1 files changed, 87 insertions, 2 deletions
diff --git a/pixman/test/utils.c b/pixman/test/utils.c
index acf494938..883095250 100644
--- a/pixman/test/utils.c
+++ b/pixman/test/utils.c
@@ -1,3 +1,5 @@
+#define _GNU_SOURCE
+
#include "utils.h"
#include <signal.h>
@@ -15,6 +17,10 @@
#include <sys/mman.h>
#endif
+#ifdef HAVE_FENV_H
+#include <fenv.h>
+#endif
+
/* Random number seed
*/
@@ -226,7 +232,7 @@ typedef struct
#endif
void *
-fence_malloc (uint32_t len)
+fence_malloc (int64_t len)
{
unsigned long page_size = getpagesize();
unsigned long page_mask = page_size - 1;
@@ -240,12 +246,15 @@ fence_malloc (uint32_t len)
uint8_t *payload;
uint8_t *addr;
+ if (len < 0)
+ abort();
+
addr = mmap (NULL, n_bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
if (addr == MAP_FAILED)
{
- printf ("mmap failed on %u %u\n", len, n_bytes);
+ printf ("mmap failed on %lld %u\n", (long long int)len, n_bytes);
return NULL;
}
@@ -469,6 +478,26 @@ fail_after (int seconds, const char *msg)
#endif
}
+void
+enable_fp_exceptions (void)
+{
+#ifdef HAVE_FENV_H
+#ifdef HAVE_FEENABLEEXCEPT
+ /* Note: we don't enable the FE_INEXACT trap because
+ * that happens quite commonly. It is possible that
+ * over- and underflow should similarly be considered
+ * okay, but for now the test suite passes with them
+ * enabled, and it's useful to know if they start
+ * occuring.
+ */
+ feenableexcept (FE_DIVBYZERO |
+ FE_INVALID |
+ FE_OVERFLOW |
+ FE_UNDERFLOW);
+#endif
+#endif
+}
+
void *
aligned_malloc (size_t align, size_t size)
{
@@ -483,3 +512,59 @@ aligned_malloc (size_t align, size_t size)
return result;
}
+
+#define CONVERT_15(c, is_rgb) \
+ (is_rgb? \
+ ((((c) >> 3) & 0x001f) | \
+ (((c) >> 6) & 0x03e0) | \
+ (((c) >> 9) & 0x7c00)) : \
+ (((((c) >> 16) & 0xff) * 153 + \
+ (((c) >> 8) & 0xff) * 301 + \
+ (((c) ) & 0xff) * 58) >> 2))
+
+void
+initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb)
+{
+ int i;
+ uint32_t mask = (1 << depth) - 1;
+
+ for (i = 0; i < 32768; ++i)
+ palette->ent[i] = lcg_rand() & mask;
+
+ memset (palette->rgba, 0, sizeof (palette->rgba));
+
+ for (i = 0; i < mask + 1; ++i)
+ {
+ uint32_t rgba24;
+ pixman_bool_t retry;
+ uint32_t i15;
+
+ /* We filled the rgb->index map with random numbers, but we
+ * do need the ability to round trip, that is if some indexed
+ * color expands to an argb24, then the 15 bit version of that
+ * color must map back to the index. Anything else, we don't
+ * care about too much.
+ */
+ do
+ {
+ uint32_t old_idx;
+
+ rgba24 = lcg_rand();
+ i15 = CONVERT_15 (rgba24, is_rgb);
+
+ old_idx = palette->ent[i15];
+ if (CONVERT_15 (palette->rgba[old_idx], is_rgb) == i15)
+ retry = 1;
+ else
+ retry = 0;
+ } while (retry);
+
+ palette->rgba[i] = rgba24;
+ palette->ent[i15] = i;
+ }
+
+ for (i = 0; i < mask + 1; ++i)
+ {
+ assert (palette->ent[CONVERT_15 (palette->rgba[i], is_rgb)] == i);
+ }
+}