>From c73b331059b79e9d53c9c7ad3a905580f292d972 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 31 May 2020 20:13:27 +0200 Subject: [PATCH 2/2] getentropy: Enhance tests. * tests/test-getentropy.c (main): Add one more test. * tests/test-unistd-c++.cc: Check the signature of getentropy. --- ChangeLog | 6 ++++++ tests/test-getentropy.c | 11 +++++++++++ tests/test-unistd-c++.cc | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8f03864..fbda5ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-05-31 Bruno Haible + getentropy: Enhance tests. + * tests/test-getentropy.c (main): Add one more test. + * tests/test-unistd-c++.cc: Check the signature of getentropy. + +2020-05-31 Bruno Haible + getentropy: Work around a macOS and Solaris problem. * lib/unistd.in.h: Include , when needed for the 'getentropy' module. diff --git a/tests/test-getentropy.c b/tests/test-getentropy.c index 845c5dc..8659b6d 100644 --- a/tests/test-getentropy.c +++ b/tests/test-getentropy.c @@ -39,5 +39,16 @@ main (int argc, char *argv[]) /* This test fails with probability 2**-2048. (Run it again if so. :-) */ ASSERT (memcmp (buf, empty_buf, sizeof buf) != 0); + /* It is very unlikely that two calls to getentropy produce the same + results. */ + { + char buf1[8]; + char buf2[8]; + + ASSERT (getentropy (buf1, sizeof (buf1)) == 0); + ASSERT (getentropy (buf2, sizeof (buf2)) == 0); + ASSERT (memcmp (buf1, buf2, sizeof (buf1)) != 0); + } + return 0; } diff --git a/tests/test-unistd-c++.cc b/tests/test-unistd-c++.cc index cf8d3fc..6d4c8fb 100644 --- a/tests/test-unistd-c++.cc +++ b/tests/test-unistd-c++.cc @@ -94,6 +94,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::getdomainname, int, (char *, size_t)); SIGNATURE_CHECK (GNULIB_NAMESPACE::getdtablesize, int, (void)); #endif +#if GNULIB_TEST_GETENTROPY +SIGNATURE_CHECK (GNULIB_NAMESPACE::getentropy, int, (void *, size_t)); +#endif + #if GNULIB_TEST_GETGROUPS SIGNATURE_CHECK (GNULIB_NAMESPACE::getgroups, int, (int, gid_t *)); #endif -- 2.7.4