Blame stdlib/tst-limits.c

Packit Service 82fcde
/* It is important that this comes first to not hide effects introduced
Packit Service 82fcde
   by other headers.  */
Packit Service 82fcde
#include <limits.h>
Packit Service 82fcde
Packit Service 82fcde
#include <inttypes.h>
Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
static long long int
Packit Service 82fcde
bitval (int bits)
Packit Service 82fcde
{
Packit Service 82fcde
  long long int val = 0;
Packit Service 82fcde
  while (bits-- > 0)
Packit Service 82fcde
    val |= 1ll << bits;
Packit Service 82fcde
  return val;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
static int
Packit Service 82fcde
do_test (void)
Packit Service 82fcde
{
Packit Service 82fcde
  int result = 0;
Packit Service 82fcde
Packit Service 82fcde
#define TEST(name, format, expected) \
Packit Service 82fcde
  printf ("%-12s expected = %-20" format "  actual = %" format "\n",	      \
Packit Service 82fcde
	  #name ":", expected, name);					      \
Packit Service 82fcde
  result |= name != expected
Packit Service 82fcde
Packit Service 82fcde
  /* The limits from ISO C99.  */
Packit Service 82fcde
Packit Service 82fcde
  /* We cannot support anything but 8-bit chars.  */
Packit Service 82fcde
  TEST (CHAR_BIT, "d", 8);
Packit Service 82fcde
  TEST (SCHAR_MIN, "d", -128);
Packit Service 82fcde
  TEST (SCHAR_MAX, "d", 127);
Packit Service 82fcde
  TEST (UCHAR_MAX, "d", 255);
Packit Service 82fcde
Packit Service 82fcde
  TEST (SHRT_MIN, "d", -(1 << (sizeof (short int) * CHAR_BIT - 1)));
Packit Service 82fcde
  TEST (SHRT_MAX, "d", (1 << (sizeof (short int) * CHAR_BIT - 1)) - 1);
Packit Service 82fcde
  TEST (USHRT_MAX, "d", (1 << sizeof (short int) * CHAR_BIT) - 1);
Packit Service 82fcde
Packit Service 82fcde
  TEST (INT_MIN, "d", (int) -bitval (sizeof (int) * CHAR_BIT - 1) - 1);
Packit Service 82fcde
  TEST (INT_MAX, "d", (int) bitval (sizeof (int) * CHAR_BIT - 1));
Packit Service 82fcde
  TEST (UINT_MAX, "u",
Packit Service 82fcde
	(unsigned int) bitval (sizeof (unsigned int) * CHAR_BIT));
Packit Service 82fcde
Packit Service 82fcde
  TEST (LONG_MIN, "ld",
Packit Service 82fcde
	(long int) -bitval (sizeof (long int) * CHAR_BIT - 1) - 1);
Packit Service 82fcde
  TEST (LONG_MAX, "ld", (long int) bitval (sizeof (long int) * CHAR_BIT - 1));
Packit Service 82fcde
  TEST (ULONG_MAX, "lu",
Packit Service 82fcde
	(unsigned long int) bitval (sizeof (unsigned long int) * CHAR_BIT));
Packit Service 82fcde
Packit Service 82fcde
  TEST (LLONG_MIN, "lld", -bitval (sizeof (long long int) * CHAR_BIT - 1) - 1);
Packit Service 82fcde
  TEST (LLONG_MAX, "lld", bitval (sizeof (long long int) * CHAR_BIT - 1));
Packit Service 82fcde
  TEST (ULLONG_MAX, "llu",
Packit Service 82fcde
	(unsigned long long int) bitval (sizeof (unsigned long long int)
Packit Service 82fcde
					 * CHAR_BIT));
Packit Service 82fcde
Packit Service 82fcde
  /* Values from POSIX and Unix.  */
Packit Service 82fcde
#ifdef PAGESIZE
Packit Service 82fcde
  TEST (PAGESIZE, "d", getpagesize ());
Packit Service 82fcde
#elif defined (PAGE_SIZE)
Packit Service 82fcde
  TEST (PAGE_SIZE, "d", getpagesize ());
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
  TEST (WORD_BIT, "d", (int) sizeof (int) * CHAR_BIT);
Packit Service 82fcde
  TEST (LONG_BIT, "d", (int) sizeof (long int) * CHAR_BIT);
Packit Service 82fcde
Packit Service 82fcde
  return result;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#define TEST_FUNCTION do_test ()
Packit Service 82fcde
#include "../test-skeleton.c"