about summary refs log tree commit diff
path: root/shared/nm-utils
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2018-07-25 13:12:18 +0200
committerMichael Biebl <biebl@debian.org>2018-07-25 13:12:18 +0200
commitcaf1db9d6fbc056cc6c76a24574890f6c7895f3d (patch)
treec323cf856ee0bb8e44590670dd54c19653a55748 /shared/nm-utils
parent429393567647935d9123e21fd27a7529d50255eb (diff)
New upstream version 1.12.2 upstream/1.12.2
Diffstat (limited to 'shared/nm-utils')
-rw-r--r--shared/nm-utils/nm-test-utils.h27
1 files changed, 17 insertions, 10 deletions
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h
index efb41454..743893f0 100644
--- a/shared/nm-utils/nm-test-utils.h
+++ b/shared/nm-utils/nm-test-utils.h
@@ -43,9 +43,10 @@
  *   and g_test_assert_expected_messages() will not fail.
  *
  * NMTST_SEED_RAND environment variable:
- *   Tests that use random numbers from nmtst_get_rand() get seeded randomly at each start.
- *   You can specify the seed by setting NMTST_SEED_RAND. Also, tests will print the seed
- *   to stdout, so that you know the chosen seed.
+ *   Tests that use random numbers from nmtst_get_rand() get seeded at each start.
+ *   You can specify the seed by setting NMTST_SEED_RAND to a particular number or empty ("")
+ *   for a random one. If NMTST_SEED_RAND is not set (default) a stable seed gets chosen.
+ *   Tests will print the seed to stdout, so that you know which one was chosen or generated.
  *
  *
  * NMTST_DEBUG environment variable:
@@ -790,9 +791,20 @@ nmtst_get_rand (void)
 
 	if (G_UNLIKELY (!__nmtst_internal.rand)) {
 		guint32 seed;
-		const char *str;
+		const char *str = g_getenv ("NMTST_SEED_RAND");
 
-		if ((str = g_getenv ("NMTST_SEED_RAND"))) {
+		if (!str) {
+			/* No NMTST_SEED_RAND. Pick a stable one. */
+			seed = 0;
+			__nmtst_internal.rand = g_rand_new_with_seed (seed);
+		} else if (str[0] == '\0') {
+			/* NMTST_SEED_RAND is set but empty. Pick a random one. */
+			__nmtst_internal.rand = g_rand_new ();
+
+			seed = g_rand_int (__nmtst_internal.rand);
+			g_rand_set_seed (__nmtst_internal.rand, seed);
+		} else {
+			/* NMTST_SEED_RAND is set. Use it as a seed. */
 			gchar *s;
 			gint64 i;
 
@@ -801,11 +813,6 @@ nmtst_get_rand (void)
 
 			seed = i;
 			__nmtst_internal.rand = g_rand_new_with_seed (seed);
-		} else {
-			__nmtst_internal.rand = g_rand_new ();
-
-			seed = g_rand_int (__nmtst_internal.rand);
-			g_rand_set_seed (__nmtst_internal.rand, seed);
 		}
 		__nmtst_internal.rand_seed = seed;