maint.mk: Update system header list for #include syntax checks.
[gnulib.git] / tests / test-getentropy.c
blob288c1952ea44300011765c196ec3b9c1e4b90b2a
1 /* Test the getentropy function.
2 Copyright 2020-2024 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 test_exit_status;