diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-05-25 09:19:56 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-05-25 12:37:39 -0700 |
commit | 682cc4e678aceff32dea2a84b6e5147bdf5a20a7 (patch) | |
tree | fc99f97c4f973b85fd74badd9d06d075a8df32f1 /tests | |
parent | 01e57974abc6e78daed8a6f012a832ebd6d67ac0 (diff) | |
download | gnulib-682cc4e678aceff32dea2a84b6e5147bdf5a20a7.tar.gz |
getentropy, getrandom: new modules
* MODULES.html.sh (func_all_modules):
* lib/unistd.in.h (getentropy, getrandom):
* m4/unistd_h.m4 (gl_UNISTD_H, gl_UNISTD_H_DEFAULTS):
* modules/unistd (unistd.h):
Add support for getentropy, getrandom.
* doc/glibc-functions/getentropy.texi (getentropy):
* doc/glibc-functions/getrandom.texi (getrandom):
These are now fixed on some platforms.
* lib/getentropy.c, lib/getrandom.c, lib/sys_random.in.h:
* m4/getentropy.m4, m4/getrandom.m4:
* modules/getentropy, modules/getentropy-tests:
* modules/getrandom, modules/getrandom-tests:
* tests/test-getentropy.c, tests/test-getrandom.c:
New files.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-getentropy.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test-getentropy.c b/tests/test-getentropy.c new file mode 100644 index 0000000000..845c5dcaf0 --- /dev/null +++ b/tests/test-getentropy.c @@ -0,0 +1,43 @@ +/* Test the getentropy function. + Copyright 2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#include <config.h> + +#include <unistd.h> + +#include <string.h> + +#include "signature.h" +SIGNATURE_CHECK (getentropy, int, (void *, size_t)); + +#include "macros.h" + +char empty_buf[256]; +char buf[256]; + +int +main (int argc, char *argv[]) +{ + /* If this test fails, there's something wrong with the setup anyway. */ + ASSERT (getentropy (buf, sizeof buf) == 0); + + /* This test fails with probability 2**-2048. (Run it again if so. :-) */ + ASSERT (memcmp (buf, empty_buf, sizeof buf) != 0); + + return 0; +} |