diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2013-11-18 10:23:26 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2013-11-27 11:41:43 +0100 |
commit | 4293b9ae12d07c863f882c5c0915eeccc76ed1d2 (patch) | |
tree | 7a4cde4d5c328171457336621e138cc6ac9bac7f /tests | |
parent | 5a823a9c1ac204f60e1888755dd247059f6b2fe2 (diff) | |
download | gnutls-4293b9ae12d07c863f882c5c0915eeccc76ed1d2.tar.gz |
In rng_fork test all random generators.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/rng-fork.c | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/tests/rng-fork.c b/tests/rng-fork.c index 42fc4dbbcb..5e7a8d38de 100644 --- a/tests/rng-fork.c +++ b/tests/rng-fork.c @@ -25,6 +25,7 @@ #endif #include <stdio.h> +#include <stdlib.h> #include <unistd.h> #include <sys/types.h> #if !defined(_WIN32) @@ -54,47 +55,53 @@ void doit(void) pid_t pid; int ret; FILE *fp; + unsigned i; global_init(); - pid = fork(); - if (pid == 0) { - fp = fopen(FILENAME, "w"); - if (fp == NULL) - fail("cannot open file"); - - gnutls_rnd(GNUTLS_RND_NONCE, buf1, sizeof(buf1)); - if (debug) - dump("buf1", buf1, sizeof(buf1)); - - fwrite(buf1, 1, sizeof(buf1), fp); - fclose(fp); - } else { - /* daddy */ - gnutls_rnd(GNUTLS_RND_NONCE, buf2, sizeof(buf2)); - if (debug) - dump("buf2", buf2, sizeof(buf2)); - waitpid(pid, NULL, 0); - - fp = fopen(FILENAME, "r"); - if (fp == NULL) - fail("cannot open file"); - - ret = fread(buf1, 1, sizeof(buf1), fp); - - fclose(fp); - remove(FILENAME); - - if (ret != sizeof(buf1)) { - fail("error testing the random generator.\n"); - return; - } - if (memcmp(buf1, buf2, sizeof(buf1)) == 0) { - fail("error in the random generator. Produces same valus after fork()\n"); - return; + for (i = GNUTLS_RND_NONCE; i <= GNUTLS_RND_KEY; i++) { + pid = fork(); + if (pid == 0) { + fp = fopen(FILENAME, "w"); + if (fp == NULL) + fail("cannot open file"); + + gnutls_rnd(i, buf1, sizeof(buf1)); + if (debug) + dump("buf1", buf1, sizeof(buf1)); + + fwrite(buf1, 1, sizeof(buf1), fp); + fclose(fp); + gnutls_global_deinit(); + exit(0); + } else { + /* daddy */ + gnutls_rnd(i, buf2, sizeof(buf2)); + if (debug) + dump("buf2", buf2, sizeof(buf2)); + waitpid(pid, NULL, 0); + + fp = fopen(FILENAME, "r"); + if (fp == NULL) + fail("cannot open file"); + + ret = fread(buf1, 1, sizeof(buf1), fp); + + fclose(fp); + remove(FILENAME); + + if (ret != sizeof(buf1)) { + fail("error testing the random generator (%u).\n", i); + return; + } + + if (memcmp(buf1, buf2, sizeof(buf1)) == 0) { + fail("error in the random generator (%u). Produces same valus after fork()\n", i); + return; + } + if (debug) + success("success\n"); } - if (debug) - success("success\n"); } gnutls_global_deinit(); |