[6/8] stress-test: add -f <file> arg.

Submitted by bansan85 on Dec. 13, 2017, 7:41 p.m.

Details

Message ID 20171213194139.19359-6-legarrec.vincent@gmail.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Pixman

Not browsing as part of any series.

Commit Message

bansan85 Dec. 13, 2017, 7:41 p.m.
---
 test/stress-test.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

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)