History

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.

Martin Storsjö committed 12 years ago

Commit df16cd91 parent 3aec3a21 file · +6 −3Browse files

Showing the changes to test/api/simple_test.cpp (1 of 1 file). Show all

Unified · Split

test/api/simple_test.cpp+6−3
@@ -1,9 +1,8 @@
1#include <gtest/gtest.h>1#include <gtest/gtest.h>
2#include <stdlib.h>2#include <stdlib.h>
3#include <time.h>3#include <time.h>
4#if defined (ANDROID_NDK)
5#include <stdio.h>4#include <stdio.h>
6#endif5#include <string.h>
7 6
8 7
9#if (defined(ANDROID_NDK)||defined(APPLE_IOS))8#if (defined(ANDROID_NDK)||defined(APPLE_IOS))
@@ -17,8 +16,12 @@ int main (int argc, char** argv) { · 7 unmodified lines
17 sprintf (xmlPath, "xml:%s", argv[1]);16 sprintf (xmlPath, "xml:%s", argv[1]);
18 ::testing::GTEST_FLAG (output) = xmlPath;17 ::testing::GTEST_FLAG (output) = xmlPath;
19#endif18#endif
20 srand ((unsigned int)time (NULL));
21 ::testing::InitGoogleTest (&argc, argv);19 ::testing::InitGoogleTest (&argc, argv);
20 unsigned int seed = (unsigned int) time (NULL);
21 if (argc >= 2 && !strncmp (argv[1], "--seed=", 7))
22 seed = atoi (argv[1] + 7);
23 printf ("Random seed: %u\n", seed);
24 srand (seed);
22 25
23 return RUN_ALL_TESTS();26 return RUN_ALL_TESTS();
24}27}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t