diff options
Diffstat (limited to 'tests/test-getentropy.c')
-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; +} |