From: Bruno Haible Date: Sun, 31 May 2020 18:13:27 +0000 (+0200) Subject: getentropy: Enhance tests. X-Git-Tag: v1.0~3997 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=117dbe6ecf95c69b72a06474e1f2a1fe421ca9ed;p=gnulib.git getentropy: Enhance tests. * tests/test-getentropy.c (main): Add one more test. * tests/test-unistd-c++.cc: Check the signature of getentropy. --- diff --git a/ChangeLog b/ChangeLog index 141ed8a330..0eb0ba8e51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +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. diff --git a/tests/test-getentropy.c b/tests/test-getentropy.c index 845c5dcaf0..8659b6dbd0 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 cf8d3fc1af..6d4c8fbf13 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