summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2020-12-03 11:00:24 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2020-12-03 11:00:24 +0900
commit9769b40b54cf010a0c41c4ab05a7a88e17d70613 (patch)
tree324f20fd9a2c520b6869e1f150ee9d92ba7eec1e
parent9485ca7b5bf11194cff59edbfa6a0fba3bf6162a (diff)
downloadlibgcrypt-9769b40b54cf010a0c41c4ab05a7a88e17d70613.tar.gz
tests: Put a work around to tests/random for macOS.
* configure.ac [*-apple-darwin*] (USE_POSIX_SPAWN_FOR_TESTS): New. * tests/random.c [USE_POSIX_SPAWN_FOR_TESTS] (run_all_rng_tests): New. -- GnuPG-bug-id: 5159 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r--configure.ac2
-rw-r--r--tests/random.c60
2 files changed, 62 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 1b36cd8c..e90d46e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -297,6 +297,8 @@ case "${host}" in
*-apple-darwin*)
AC_DEFINE(_DARWIN_C_SOURCE, 900000L,
Expose all libc features (__DARWIN_C_FULL).)
+ AC_DEFINE(USE_POSIX_SPAWN_FOR_TESTS, 1,
+ [defined if we use posix_spawn in test program])
;;
*)
;;
diff --git a/tests/random.c b/tests/random.c
index 22927a61..6d581750 100644
--- a/tests/random.c
+++ b/tests/random.c
@@ -505,6 +505,65 @@ check_drbg_reinit (void)
}
+#ifdef USE_POSIX_SPAWN_FOR_TESTS
+#include <spawn.h>
+extern char **environ;
+
+static void
+run_all_rng_tests (const char *program)
+{
+ static const char *options[][2] = {
+ { "--early-rng-check", NULL },
+ { "--early-rng-check", "--prefer-standard-rng" },
+ { "--early-rng-check", "--prefer-fips-rng" },
+ { "--early-rng-check", "--prefer-system-rng" },
+ { "--prefer-standard-rng", NULL },
+ { "--prefer-fips-rng", NULL },
+ { "--prefer-system-rng", NULL },
+ { NULL, NULL }
+ };
+ int idx;
+ char *argv[8];
+
+ for (idx=0; options[idx][0]; idx++)
+ {
+ int i;
+ pid_t pid;
+ int status;
+
+ if (verbose)
+ info ("now running with options '%s%s%s'\n",
+ options[idx][0],
+ options[idx][1] ? " " : "",
+ options[idx][1] ? options[idx][1] : "");
+
+ i = 0;
+ argv[i++] = xstrdup (program);
+ argv[i++] = xstrdup ("--in-recursion");
+ argv[i++] = xstrdup ("--verbose");
+ argv[i++] = xstrdup ("--debug");
+ argv[i++] = xstrdup ("--progress");
+ argv[i++] = xstrdup (options[idx][0]);
+ if (options[idx][1])
+ argv[i++] = xstrdup (options[idx][1]);
+ argv[i++] = NULL;
+
+ if (posix_spawn (&pid, program, NULL, NULL, argv, environ))
+ die ("spawning '%s' failed\n", program);
+
+ if (waitpid (pid, &status, 0) < 0)
+ die ("waitpid for '%s' failed\n", program);
+
+ if (WIFEXITED (status) && WEXITSTATUS (status))
+ die ("running '%s' failed with %d\n", program, WEXITSTATUS (status));
+ else if (!WIFEXITED (status))
+ die ("running '%s' failed\n", program);
+
+ while (i)
+ xfree (argv[--i]);
+ }
+}
+#else
/* Because we want to check initialization behaviour, we need to
fork/exec this program with several command line arguments. We use
system, so that these tests work also on Windows. */
@@ -559,6 +618,7 @@ run_all_rng_tests (const char *program)
free (cmdline);
}
+#endif
static void