Avoid "warning: $as_echo_n is obsolete" from autoconf 2.69c.
[gnulib.git] / tests / test-getentropy.c
blob8659b6dbd060724bf8bdd81d706cda9e7a82051d
1 /* Test the getentropy function.
2 Copyright 2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Paul Eggert. */
19 #include <config.h>
21 #include <unistd.h>
23 #include <string.h>
25 #include "signature.h"
26 SIGNATURE_CHECK (getentropy, int, (void *, size_t));
28 #include "macros.h"
30 char empty_buf[256];
31 char buf[256];
33 int
34 main (int argc, char *argv[])
36 /* If this test fails, there's something wrong with the setup anyway. */
37 ASSERT (getentropy (buf, sizeof buf) == 0);
39 /* This test fails with probability 2**-2048. (Run it again if so. :-) */
40 ASSERT (memcmp (buf, empty_buf, sizeof buf) != 0);
42 /* It is very unlikely that two calls to getentropy produce the same
43 results. */
45 char buf1[8];
46 char buf2[8];
48 ASSERT (getentropy (buf1, sizeof (buf1)) == 0);
49 ASSERT (getentropy (buf2, sizeof (buf2)) == 0);
50 ASSERT (memcmp (buf1, buf2, sizeof (buf1)) != 0);
53 return 0;