[Pixman] [PATCH 8/8] stress-test: correct all remaining bugs.

bansan85 legarrec.vincent at gmail.com
Wed Dec 13 19:41:39 UTC 2017


---
 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



More information about the Pixman mailing list