[Libguestfs] [PATCH v2 2/2] tests/mount-local, tests/parallel: Use srandom (time (NULL) + getpid ()).

Richard W.M. Jones rjones at redhat.com
Thu Jan 26 19:31:07 UTC 2017


If two instances of the test start at exactly the same time, they
would have the same random number seed.
---
 tests/mount-local/test-parallel-mount-local.c | 2 +-
 tests/parallel/test-parallel.c                | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tests/mount-local/test-parallel-mount-local.c b/tests/mount-local/test-parallel-mount-local.c
index 3e5d95c..542f1ed 100644
--- a/tests/mount-local/test-parallel-mount-local.c
+++ b/tests/mount-local/test-parallel-mount-local.c
@@ -85,7 +85,7 @@ main (int argc, char *argv[])
   int r, errors = 0;
   void *status;
 
-  srandom (time (NULL));
+  srandom (time (NULL) + getpid ());
 
   /* If the --test flag is given, then this is the test subprocess. */
   if (argc == 3 && STREQ (argv[1], "--test")) {
diff --git a/tests/parallel/test-parallel.c b/tests/parallel/test-parallel.c
index 20100d1..276340e 100644
--- a/tests/parallel/test-parallel.c
+++ b/tests/parallel/test-parallel.c
@@ -31,6 +31,7 @@
 #include <signal.h>
 #include <errno.h>
 #include <error.h>
+#include <sys/types.h>
 
 #include <pthread.h>
 
@@ -74,7 +75,7 @@ main (int argc, char *argv[])
   size_t i, errors = 0;
   void *status;
 
-  srandom (time (NULL));
+  srandom (time (NULL) + getpid ());
 
   /* Only run this test when invoked by check-slow. */
   slow = getenv ("SLOW");
-- 
2.9.3




More information about the Libguestfs mailing list