ref: df16cd9d0c3c73added0d06dde93af1789ad8c8f
parent: 3aec3a2606abb2e28f0753aaec96292dd3f5c47e
author: Martin Storsjö <[email protected]>
date: Wed Aug 6 15:32:25 EDT 2014
Print the random seed at startup Also add an option for overriding the seed at startup. This allows reproducing temporary issues by rerunning the test suite with the same random seed. Note that if tests are added or removed (or tests are skipped by passing the --gtest_filter option), or if running on a different libc, the same seed might result in different random values.
--- a/test/api/simple_test.cpp
+++ b/test/api/simple_test.cpp
@@ -1,9 +1,8 @@
#include <gtest/gtest.h>
#include <stdlib.h>
#include <time.h>
-#if defined (ANDROID_NDK)
#include <stdio.h>
-#endif
+#include <string.h>
#if (defined(ANDROID_NDK)||defined(APPLE_IOS))
@@ -17,8 +16,12 @@
sprintf (xmlPath, "xml:%s", argv[1]);
::testing::GTEST_FLAG (output) = xmlPath;
#endif
- srand ((unsigned int)time (NULL));
::testing::InitGoogleTest (&argc, argv);
+ unsigned int seed = (unsigned int) time (NULL);
+ if (argc >= 2 && !strncmp (argv[1], "--seed=", 7))
+ seed = atoi (argv[1] + 7);
+ printf ("Random seed: %u\n", seed);
+ srand (seed);
return RUN_ALL_TESTS();
}