root/maint/gnulib/tests/test-getentropy.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Test the getentropy function.
   2    Copyright 2020-2021 Free Software Foundation, Inc.
   3 
   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.
   8 
   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.
  13 
  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/>.  */
  16 
  17 /* Written by Paul Eggert.  */
  18 
  19 #include <config.h>
  20 
  21 #include <unistd.h>
  22 
  23 #include <string.h>
  24 
  25 #include "signature.h"
  26 SIGNATURE_CHECK (getentropy, int, (void *, size_t));
  27 
  28 #include "macros.h"
  29 
  30 char empty_buf[256];
  31 char buf[256];
  32 
  33 int
  34 main (int argc, char *argv[])
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36   /* If this test fails, there's something wrong with the setup anyway.  */
  37   ASSERT (getentropy (buf, sizeof buf) == 0);
  38 
  39   /* This test fails with probability 2**-2048.  (Run it again if so. :-) */
  40   ASSERT (memcmp (buf, empty_buf, sizeof buf) != 0);
  41 
  42   /* It is very unlikely that two calls to getentropy produce the same
  43      results.  */
  44   {
  45     char buf1[8];
  46     char buf2[8];
  47 
  48     ASSERT (getentropy (buf1, sizeof (buf1)) == 0);
  49     ASSERT (getentropy (buf2, sizeof (buf2)) == 0);
  50     ASSERT (memcmp (buf1, buf2, sizeof (buf1)) != 0);
  51   }
  52 
  53   return 0;
  54 }

/* [previous][next][first][last][top][bottom][index][help] */