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:10:02 +0900
commit16e855d49ca26432218a7be7416f193de1c31878 (patch)
tree4efd3d5337eb6c96ab1793741ba3c5b22ba189d6
parente5eb3eca3c7a2637424f45e26f676998fd93cbbf (diff)
downloadlibgcrypt-16e855d49ca26432218a7be7416f193de1c31878.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. -- Cherry-pick master commit of: 9769b40b54cf010a0c41c4ab05a7a88e17d70613 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 d89cf925..f60c3f56 100644
--- a/configure.ac
+++ b/configure.ac
@@ -272,6 +272,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 2f48323f..12ed81d0 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