mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2026-10-24 00:48:56 +03:00
Done through
sed -e 's/memcmp \([(][^()]*[)]\) != 0/!memeq \1/g' \
-e 's/memcmp \([(][^()]*[(][^()]*[)][^()]*[)]\) != 0/!memeq \1/g'
* tests/**/*.[hc]: Use !memeq instead of memcmp ... != 0.
* modules/*-tests (Dependencies): Add memeq.
55 lines
1.5 KiB
C
55 lines
1.5 KiB
C
/* Test the getentropy function.
|
|
Copyright 2020-2026 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 (!memeq (buf, empty_buf, sizeof buf));
|
|
|
|
/* 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 (!memeq (buf1, buf2, sizeof (buf1)));
|
|
}
|
|
|
|
return test_exit_status;
|
|
}
|