Discussion:
[Pixman] [PATCH 1/8] test: random data from file. Globals variables.
bansan85
2017-12-13 19:41:32 UTC
Permalink
---
test/utils-prng.c | 4 ++++
test/utils-prng.h | 23 +++++++++++++++++++++++
2 files changed, 27 insertions(+)

diff --git a/test/utils-prng.c b/test/utils-prng.c
index c27b5be..1d62129 100644
--- a/test/utils-prng.c
+++ b/test/utils-prng.c
@@ -31,6 +31,10 @@
#include <xmmintrin.h>
#endif

+const uint8_t *random_data;
+size_t size_data;
+size_t running_data;
+
void smallprng_srand_r (smallprng_t *x, uint32_t seed)
{
uint32_t i;
diff --git a/test/utils-prng.h b/test/utils-prng.h
index f9ae8dd..98022d8 100644
--- a/test/utils-prng.h
+++ b/test/utils-prng.h
@@ -79,6 +79,11 @@

/*****************************************************************************/

+/* Used if random data from file. */
+extern const uint8_t *random_data;
+extern size_t size_data;
+extern size_t running_data;
+
#ifdef HAVE_GCC_VECTOR_EXTENSIONS
typedef uint32_t uint32x4 __attribute__ ((vector_size(16)));
typedef uint8_t uint8x16 __attribute__ ((vector_size(16)));
@@ -111,6 +116,24 @@ typedef union

/*****************************************************************************/

+static force_inline uint8_t
+get_rand_data_8() {
+ uint8_t retour = random_data[running_data];
+ running_data = (running_data + 1) % size_data;
+ return retour;
+}
+
+static force_inline uint32_t
+get_rand_data_32() {
+ /* Do not use 4 get_rand_data_8 () in the same line
+ * to be sure of the execution order. */
+ uint8_t un = get_rand_data_8();
+ uint8_t deux = get_rand_data_8();
+ uint8_t trois = get_rand_data_8();
+ uint8_t quatre = get_rand_data_8();
+ return (un << 24) + (deux << 16) + (trois << 8) + (quatre);
+}
+
static force_inline uint32_t
smallprng_rand_r (smallprng_t *x)
{
--
2.15.0
bansan85
2017-12-13 19:41:33 UTC
Permalink
---
.gitignore | 1 +
1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index a245b69..977b66a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,7 @@ libtool
ltmain.sh
missing
stamp-h?
+test-driver
config.h
config.h.in
.*.swp
--
2.15.0
bansan85
2017-12-13 19:41:34 UTC
Permalink
with no infinite random data.
---
test/stress-test.c | 13 +++++++++++--
test/utils.c | 15 +++++++++++++--
test/utils.h | 2 +-
3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/test/stress-test.c b/test/stress-test.c
index 1f03c75..bdd70a8 100644
--- a/test/stress-test.c
+++ b/test/stress-test.c
@@ -256,13 +256,22 @@ create_random_bits_image (alpha_preference_t alpha_preference)
{
indexed = malloc (sizeof (pixman_indexed_t));

- initialize_palette (indexed, PIXMAN_FORMAT_BPP (format), TRUE);
+ if (!initialize_palette (indexed, PIXMAN_FORMAT_BPP (format), TRUE))
+ {
+ free (indexed);
+ return NULL;
+ }
+
}
else if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_GRAY)
{
indexed = malloc (sizeof (pixman_indexed_t));

- initialize_palette (indexed, PIXMAN_FORMAT_BPP (format), FALSE);
+ if (!initialize_palette (indexed, PIXMAN_FORMAT_BPP (format), FALSE))
+ {
+ free (indexed);
+ return NULL;
+ }
}
else
{
diff --git a/test/utils.c b/test/utils.c
index f8e42a5..bfed94c 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -1025,7 +1025,7 @@ convert_linear_to_srgb (double c)
return 1.055 * pow (c, 1.0/2.4) - 0.055;
}

-void
+int
initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb)
{
int i;
@@ -1039,8 +1039,11 @@ initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb)
for (i = 0; i < mask + 1; ++i)
{
uint32_t rgba24;
- pixman_bool_t retry;
+ pixman_bool_t retry;
uint32_t i15;
+ /* With random data from file, there's not infini random data.
+ * So break when add char tried.*/
+ size_t size_data_i = size_data;

/* We filled the rgb->index map with random numbers, but we
* do need the ability to round trip, that is if some indexed
@@ -1060,6 +1063,12 @@ initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb)
retry = 1;
else
retry = 0;
+ if (random_data != NULL)
+ {
+ if (size_data_i == 0)
+ return FALSE;
+ size_data_i--;
+ }
} while (retry);

palette->rgba[i] = rgba24;
@@ -1070,6 +1079,8 @@ initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb)
{
assert (palette->ent[CONVERT_15 (palette->rgba[i], is_rgb)] == i);
}
+
+ return TRUE;
}

struct operator_entry {
diff --git a/test/utils.h b/test/utils.h
index e299d1d..43eca8a 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -205,7 +205,7 @@ convert_srgb_to_linear (double component);
double
convert_linear_to_srgb (double component);

-void
+int
initialize_palette (pixman_indexed_t *palette, uint32_t depth, int is_rgb);

pixman_format_code_t
--
2.15.0
bansan85
2017-12-13 19:41:35 UTC
Permalink
---
test/stress-test.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/test/stress-test.c b/test/stress-test.c
index bdd70a8..273a2a2 100644
--- a/test/stress-test.c
+++ b/test/stress-test.c
@@ -386,13 +386,18 @@ create_random_bits_image (alpha_preference_t alpha_preference)
/* Finally create the image */
image = pixman_image_create_bits (format, width, height, bits, stride);
if (!image)
+ {
+ free (coefficients);
return NULL;
+ }

pixman_image_set_indexed (image, indexed);
pixman_image_set_destroy_function (image, destroy, indexed);
pixman_image_set_accessors (image, read_func, write_func);
pixman_image_set_filter (image, filter, coefficients, n_coefficients);

+ free (coefficients);
+
return image;
}
--
2.15.0
bansan85
2017-12-13 19:41:36 UTC
Permalink
---
test/stress-test.c | 70 +++++++++++++++++++++++++++---------------------------
1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/test/stress-test.c b/test/stress-test.c
index 273a2a2..c4148ff 100644
--- a/test/stress-test.c
+++ b/test/stress-test.c
@@ -221,14 +221,14 @@ random_format (alpha_preference_t alpha)
if (alpha >= PREFER_ALPHA &&
(alpha == REQUIRE_ALPHA || prng_rand_n (4) != 0))
{
- do
- {
- format = image_formats[n++ % ARRAY_LENGTH (image_formats)];
- } while (PIXMAN_FORMAT_TYPE (format) != PIXMAN_TYPE_A);
+ do
+ {
+ format = image_formats[n++ % ARRAY_LENGTH (image_formats)];
+ } while (PIXMAN_FORMAT_TYPE (format) != PIXMAN_TYPE_A);
}
else
{
- format = image_formats[n];
+ format = image_formats[n];
}

return format;
@@ -257,10 +257,10 @@ create_random_bits_image (alpha_preference_t alpha_preference)
indexed = malloc (sizeof (pixman_indexed_t));

if (!initialize_palette (indexed, PIXMAN_FORMAT_BPP (format), TRUE))
- {
+ {
free (indexed);
return NULL;
- }
+ }

}
else if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_GRAY)
@@ -268,10 +268,10 @@ create_random_bits_image (alpha_preference_t alpha_preference)
indexed = malloc (sizeof (pixman_indexed_t));

if (!initialize_palette (indexed, PIXMAN_FORMAT_BPP (format), FALSE))
- {
+ {
free (indexed);
return NULL;
- }
+ }
}
else
{
@@ -785,13 +785,13 @@ create_random_trapezoids (int *n_traps, int height, int width)

for (i = 0; i < *n_traps; ++i)
{
- pixman_trapezoid_t *t = &(trapezoids[i]);
+ pixman_trapezoid_t *t = &(trapezoids[i]);

- t->top = prng_rand_n (height) << 16;
- t->bottom = prng_rand_n (height) << 16;
+ t->top = prng_rand_n (height) << 16;
+ t->bottom = prng_rand_n (height) << 16;

- random_line (&t->left, height, width);
- random_line (&t->right, height, width);
+ random_line (&t->left, height, width);
+ random_line (&t->right, height, width);
}

return trapezoids;
@@ -875,8 +875,8 @@ run_test (uint32_t seed, pixman_bool_t verbose, uint32_t mod)

if (prng_rand_n (8) == 0)
{
- int n_traps;
- pixman_trapezoid_t *trapezoids;
+ int n_traps;
+ pixman_trapezoid_t *trapezoids;
int p = prng_rand_n (3);

if (p == 0)
@@ -923,30 +923,30 @@ run_test (uint32_t seed, pixman_bool_t verbose, uint32_t mod)
pixman_add_trapezoids (
dest, rand_x (dest), rand_y (dest), n_traps, trapezoids);
break;
- }
+ }

free (trapezoids);
}
else
{
- dest = create_random_bits_image (DONT_CARE);
- source = create_random_image ();
- mask = create_random_image ();
-
- if (source && mask && dest)
- {
- set_general_properties (dest, TRUE);
-
- op = op_list [prng_rand_n (ARRAY_LENGTH (op_list))];
-
- pixman_image_composite32 (op,
- source, mask, dest,
- rand_x (source), rand_y (source),
- rand_x (mask), rand_y (mask),
- 0, 0,
- dest->bits.width,
- dest->bits.height);
- }
+ dest = create_random_bits_image (DONT_CARE);
+ source = create_random_image ();
+ mask = create_random_image ();
+
+ if (source && mask && dest)
+ {
+ set_general_properties (dest, TRUE);
+
+ op = op_list [prng_rand_n (ARRAY_LENGTH (op_list))];
+
+ pixman_image_composite32 (op,
+ source, mask, dest,
+ rand_x (source), rand_y (source),
+ rand_x (mask), rand_y (mask),
+ 0, 0,
+ dest->bits.width,
+ dest->bits.height);
+ }
}

out:
--
2.15.0
bansan85
2017-12-13 19:41:37 UTC
Permalink
---
test/stress-test.c | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/test/stress-test.c b/test/stress-test.c
index c4148ff..d997f1b 100644
--- a/test/stress-test.c
+++ b/test/stress-test.c
@@ -1004,17 +1004,42 @@ main (int argc, char **argv)
i++;
}
}
- else if (strcmp (argv[i], "-s") == 0 && i + 1 < argc)
+ else if (strcmp (argv[i], "-s") == 0 && i + 1 < argc &&
+ random_data == NULL)
{
get_int (argv[i + 1], &seed);
use_threads = FALSE;
i++;
}
- else if (strcmp (argv[i], "-n") == 0 && i + 1 < argc)
+ else if (strcmp (argv[i], "-n") == 0 && i + 1 < argc &&
+ random_data == NULL)
{
get_int (argv[i + 1], &n_tests);
i++;
}
+ else if (strcmp (argv[i], "-f") == 0 && i + 1 < argc)
+ {
+ FILE *file = fopen(argv[i + 1], "rb");
+
+ if (!file)
+ {
+ fprintf(stderr, "Unable to open file %s", argv[i + 1]);
+ exit (-1);
+ }
+
+ /* Get file length */
+ fseek (file, 0, SEEK_END);
+ size_data = ftell (file);
+
+ /* Allocate and load memory */
+ random_data = malloc (fileLen);
+ fread (random_data, fileLen, 1, file);
+ fclose (file);
+
+ n_tests = 0;
+
+ i++;
+ }
else
{
if (strcmp (argv[i], "-h") != 0)
@@ -1023,6 +1048,7 @@ main (int argc, char **argv)
printf ("Options:\n\n"
"-n <number> Number of tests to run\n"
"-s <seed> Seed of first test (ignored if PIXMAN_RANDOMIZE_TESTS is set)\n"
+ "-f <file> Use a file as random data. Not with -n and -s.\n"
"-v Print out seeds\n"
"-v <n> Print out every n'th seed\n\n");

@@ -1036,7 +1062,7 @@ main (int argc, char **argv)
printf ("First seed: 0x%08x\n", seed);
}

- if (use_threads)
+ if (use_threads && n_tests != 1)
{
#ifdef USE_OPENMP
# pragma omp parallel for default(none) shared(verbose, n_tests, mod, seed)
--
2.15.0
bansan85
2017-12-13 19:41:39 UTC
Permalink
---
test/stress-test.c | 20 +++++++++++++++-----
test/utils-prng.c | 24 +++++++++++++++++-------
test/utils-prng.h | 11 +++++------
3 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/test/stress-test.c b/test/stress-test.c
index d997f1b..9626786 100644
--- a/test/stress-test.c
+++ b/test/stress-test.c
@@ -1020,6 +1020,7 @@ main (int argc, char **argv)
else if (strcmp (argv[i], "-f") == 0 && i + 1 < argc)
{
FILE *file = fopen(argv[i + 1], "rb");
+ size_t fread_len;

if (!file)
{
@@ -1032,11 +1033,18 @@ main (int argc, char **argv)
size_data = ftell (file);

/* Allocate and load memory */
- random_data = malloc (fileLen);
- fread (random_data, fileLen, 1, file);
+ random_data = malloc (sizeof(char) * size_data);
+ rewind (file);
+ fread_len = fread (random_data, 1, size_data, file);
+ if (fread_len != size_data)
+ {
+ fprintf(stderr, "Failed to read %zu bytes in file %s : (%zu)\n",
+ size_data, argv[i + 1], fread_len);
+ exit (-1);
+ }
fclose (file);

- n_tests = 0;
+ n_tests = 1;

i++;
}
@@ -1047,8 +1055,8 @@ main (int argc, char **argv)

printf ("Options:\n\n"
"-n <number> Number of tests to run\n"
- "-s <seed> Seed of first test (ignored if PIXMAN_RANDOMIZE_TESTS is set)\n"
- "-f <file> Use a file as random data. Not with -n and -s.\n"
+ "-s <seed> Seed of first test (ignored if PIXMAN_RANDOMIZE_TESTS is set)\n"
+ "-f <file> Use a file as random data. Not with -n and -s.\n"
"-v Print out seeds\n"
"-v <n> Print out every n'th seed\n\n");

@@ -1076,5 +1084,7 @@ main (int argc, char **argv)
run_test (seed + i, verbose, mod);
}

+ free (random_data);
+
return 0;
}
diff --git a/test/utils-prng.c b/test/utils-prng.c
index 0981f12..bd59afe 100644
--- a/test/utils-prng.c
+++ b/test/utils-prng.c
@@ -31,7 +31,7 @@
#include <xmmintrin.h>
#endif

-const uint8_t *random_data;
+uint8_t *random_data;
size_t size_data;
size_t running_data;

@@ -69,14 +69,24 @@ void prng_srand_r (prng_t *x, uint32_t seed)
x->b[3] = x->c[3] = x->d[3] = (seed = seed * 1103515245 + 12345);
for (i = 0; i < 20; ++i)
prng_rand_128_r (x, &dummy);
- return;
}
+ else
+ {
+ /* Hugly hack */
+ smallprng_srand_r (&x->p0, get_rand_data_32 ());
+ smallprng_srand_r ((smallprng_t *)&x->a, get_rand_data_32 ());
+ smallprng_srand_r ((smallprng_t *)&x->b, get_rand_data_32 ());
+ smallprng_srand_r ((smallprng_t *)&x->c, get_rand_data_32 ());
+ smallprng_srand_r ((smallprng_t *)&x->d, get_rand_data_32 ());
+ }
+ return;
+#else
+ smallprng_srand_r (&x->p0, get_rand_data_32 ());
+ smallprng_srand_r (&x->p1, get_rand_data_32 ());
+ smallprng_srand_r (&x->p2, get_rand_data_32 ());
+ smallprng_srand_r (&x->p3, get_rand_data_32 ());
+ smallprng_srand_r (&x->p4, get_rand_data_32 ());
#endif
- smallprng_srand_r (&x->p0, seed);
- smallprng_srand_r (&x->p1, (seed = seed * 1103515245 + 12345));
- smallprng_srand_r (&x->p2, (seed = seed * 1103515245 + 12345));
- smallprng_srand_r (&x->p3, (seed = seed * 1103515245 + 12345));
- smallprng_srand_r (&x->p4, (seed = seed * 1103515245 + 12345));
}

static force_inline void
diff --git a/test/utils-prng.h b/test/utils-prng.h
index cb36517..4f1ecf0 100644
--- a/test/utils-prng.h
+++ b/test/utils-prng.h
@@ -80,7 +80,7 @@
/*****************************************************************************/

/* Used if random data from file. */
-extern const uint8_t *random_data;
+extern uint8_t *random_data;
extern size_t size_data;
extern size_t running_data;

@@ -102,7 +102,6 @@ typedef struct
smallprng_t p1, p2, p3, p4;
#endif
smallprng_t p0;
-#else
} prng_t;

typedef union
@@ -130,10 +129,10 @@ get_rand_data_32 ()
{
/* Do not use 4 get_rand_data_8 () in the same line
* to be sure of the execution order. */
- uint8_t un = get_rand_data_8();
- uint8_t deux = get_rand_data_8();
- uint8_t trois = get_rand_data_8();
- uint8_t quatre = get_rand_data_8();
+ uint8_t un = get_rand_data_8 ();
+ uint8_t deux = get_rand_data_8 ();
+ uint8_t trois = get_rand_data_8 ();
+ uint8_t quatre = get_rand_data_8 ();
return (un << 24) + (deux << 16) + (trois << 8) + (quatre);
}
--
2.15.0
bansan85
2017-12-13 19:41:38 UTC
Permalink
---
test/utils-prng.c | 27 +++++++++++++++------------
test/utils-prng.h | 43 ++++++++++++++++++++++++++++++-------------
2 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/test/utils-prng.c b/test/utils-prng.c
index 1d62129..0981f12 100644
--- a/test/utils-prng.c
+++ b/test/utils-prng.c
@@ -57,23 +57,26 @@ void smallprng_srand_r (smallprng_t *x, uint32_t seed)
void prng_srand_r (prng_t *x, uint32_t seed)
{
#ifdef HAVE_GCC_VECTOR_EXTENSIONS
- int i;
- prng_rand_128_data_t dummy;
- smallprng_srand_r (&x->p0, seed);
- x->a[0] = x->a[1] = x->a[2] = x->a[3] = 0xf1ea5eed;
- x->b[0] = x->c[0] = x->d[0] = (seed = seed * 1103515245 + 12345);
- x->b[1] = x->c[1] = x->d[1] = (seed = seed * 1103515245 + 12345);
- x->b[2] = x->c[2] = x->d[2] = (seed = seed * 1103515245 + 12345);
- x->b[3] = x->c[3] = x->d[3] = (seed = seed * 1103515245 + 12345);
- for (i = 0; i < 20; ++i)
- prng_rand_128_r (x, &dummy);
-#else
+ if (random_data == NULL)
+ {
+ int i;
+ prng_rand_128_data_t dummy;
+ smallprng_srand_r (&x->p0, seed);
+ x->a[0] = x->a[1] = x->a[2] = x->a[3] = 0xf1ea5eed;
+ x->b[0] = x->c[0] = x->d[0] = (seed = seed * 1103515245 + 12345);
+ x->b[1] = x->c[1] = x->d[1] = (seed = seed * 1103515245 + 12345);
+ x->b[2] = x->c[2] = x->d[2] = (seed = seed * 1103515245 + 12345);
+ x->b[3] = x->c[3] = x->d[3] = (seed = seed * 1103515245 + 12345);
+ for (i = 0; i < 20; ++i)
+ prng_rand_128_r (x, &dummy);
+ return;
+ }
+#endif
smallprng_srand_r (&x->p0, seed);
smallprng_srand_r (&x->p1, (seed = seed * 1103515245 + 12345));
smallprng_srand_r (&x->p2, (seed = seed * 1103515245 + 12345));
smallprng_srand_r (&x->p3, (seed = seed * 1103515245 + 12345));
smallprng_srand_r (&x->p4, (seed = seed * 1103515245 + 12345));
-#endif
}

static force_inline void
diff --git a/test/utils-prng.h b/test/utils-prng.h
index 98022d8..cb36517 100644
--- a/test/utils-prng.h
+++ b/test/utils-prng.h
@@ -102,6 +102,7 @@ typedef struct
smallprng_t p1, p2, p3, p4;
#endif
smallprng_t p0;
+#else
} prng_t;

typedef union
@@ -117,14 +118,16 @@ typedef union
/*****************************************************************************/

static force_inline uint8_t
-get_rand_data_8() {
+get_rand_data_8 ()
+{
uint8_t retour = random_data[running_data];
running_data = (running_data + 1) % size_data;
return retour;
}

static force_inline uint32_t
-get_rand_data_32() {
+get_rand_data_32 ()
+{
/* Do not use 4 get_rand_data_8 () in the same line
* to be sure of the execution order. */
uint8_t un = get_rand_data_8();
@@ -137,11 +140,21 @@ get_rand_data_32() {
static force_inline uint32_t
smallprng_rand_r (smallprng_t *x)
{
- uint32_t e = x->a - ((x->b << 27) + (x->b >> (32 - 27)));
- x->a = x->b ^ ((x->c << 17) ^ (x->c >> (32 - 17)));
- x->b = x->c + x->d;
- x->c = x->d + e;
- x->d = e + x->a;
+ if (random_data == NULL)
+ {
+ uint32_t e = x->a - ((x->b << 27) + (x->b >> (32 - 27)));
+ x->a = x->b ^ ((x->c << 17) ^ (x->c >> (32 - 17)));
+ x->b = x->c + x->d;
+ x->c = x->d + e;
+ x->d = e + x->a;
+ }
+ else
+ {
+ x->a = get_rand_data_32 ();
+ x->b = get_rand_data_32 ();
+ x->c = get_rand_data_32 ();
+ x->d = get_rand_data_32 ();
+ }
return x->d;
}

@@ -157,12 +170,16 @@ static force_inline void
prng_rand_128_r (prng_t *x, prng_rand_128_data_t *data)
{
#ifdef HAVE_GCC_VECTOR_EXTENSIONS
- uint32x4 e = x->a - ((x->b << 27) + (x->b >> (32 - 27)));
- x->a = x->b ^ ((x->c << 17) ^ (x->c >> (32 - 17)));
- x->b = x->c + x->d;
- x->c = x->d + e;
- x->d = e + x->a;
- data->vw = x->d;
+ if (random_data == NULL)
+ {
+ uint32x4 e = x->a - ((x->b << 27) + (x->b >> (32 - 27)));
+ x->a = x->b ^ ((x->c << 17) ^ (x->c >> (32 - 17)));
+ x->b = x->c + x->d;
+ x->c = x->d + e;
+ x->d = e + x->a;
+ data->vw = x->d;
+ return;
+ }
#else
data->w[0] = smallprng_rand_r (&x->p1);
data->w[1] = smallprng_rand_r (&x->p2);
--
2.15.0
Loading...