1: #ifndef lint
   2: static char *RCSid = "$Source: /usr/users/louie/ntp/RCS/test.c,v $ $Revision: 3.4.1.4 $ $Date: 89/05/18 18:37:39 $";
   3: #endif
   4: 
   5: /*
   6:  * $Log:	test.c,v $
   7:  * Revision 3.4.1.4  89/05/18  18:37:39  louie
   8:  * Add test for GENERIC_UNS_BUG to test.c
   9:  *
  10:  * Revision 3.4.1.3  89/04/07  19:10:41  louie
  11:  * Add check for SUN_FLT_BUG problem in test.c
  12:  *
  13:  * Revision 3.4.1.2  89/03/31  16:39:19  louie
  14:  * Bug fix for VAX_COMPILER_FLT_BUG test, start of test for Sun problem.
  15:  *
  16:  * Revision 3.4.1.1  89/03/22  18:32:26  louie
  17:  * patch3: Use new RCS headers.
  18:  *
  19:  * Revision 3.4  89/03/17  18:37:32  louie
  20:  * Latest test release.
  21:  *
  22:  * Revision 3.3  89/03/15  14:20:16  louie
  23:  * New baseline for next release.
  24:  *
  25:  * Revision 3.2.1.1  89/03/15  14:11:08  louie
  26:  * Add in kludge for old VAX pcc compiler bug that incorrectly converts unsigned
  27:  * longs to doubles.  This enables the ntest program to run when
  28:  * VAX_COMPILER_FLT_BUG is defined on those systems.
  29:  *
  30:  * Revision 3.2  89/03/07  18:30:16  louie
  31:  * New version of UNIX NTP daemon based on the 6 March 1989 draft of the new
  32:  * NTP protocol spec.  This module has mostly cosmetic changes.
  33:  *
  34:  * Revision 3.1.1.1  89/02/15  08:49:34  louie
  35:  * *** empty log message ***
  36:  *
  37:  *
  38:  * Revision 3.1  89/01/30  14:43:19  louie
  39:  * Second UNIX NTP test release.
  40:  *
  41:  * Revision 3.0  88/12/12  16:01:37  louie
  42:  * Test release of new UNIX NTP software.  This version should conform to the
  43:  * revised NTP protocol specification.
  44:  *
  45:  */
  46: 
  47: #include <stdio.h>
  48: #include <sys/param.h>
  49: #include <sys/types.h>
  50: #include <sys/time.h>
  51: #include <sys/socket.h>
  52: #include <netinet/in.h>
  53: #include <netinet/in_systm.h>
  54: #include <netinet/ip.h>
  55: #include <netinet/udp.h>
  56: #include <netdb.h>
  57: #include <sys/ioctl.h>
  58: #include <signal.h>
  59: #include <errno.h>
  60: #include <syslog.h>
  61: 
  62: #include "ntp.h"
  63: 
  64: #define TRUE    1
  65: #define FALSE   0
  66: 
  67: int test1(), test2(), test3(), test4();
  68: 
  69: double value[8] = {5.1, -5.1, 1.5, -1.5, 0.5, -0.5, -0.05, 0.0};
  70: main(argc, argv)
  71:     int argc;
  72:     char **argv;
  73: {
  74:     if (argc > 1 && strcmp(argv[1], "-v") == 0) {
  75:         exit(test1(1)
  76:              + test2(1)
  77:              + test3(1)
  78:              + test4(1));
  79:     } else {
  80:         if (test3(0))
  81:             exit(3);
  82:         if (test4(0))
  83:             exit(4);
  84:     }
  85:     exit(0);
  86: }
  87: 
  88: 
  89: test1()
  90: {
  91:     int i;
  92:     double l_fixed_to_double();
  93:     struct l_fixedpt sample;
  94:     double s_fixed_to_double();
  95:     struct s_fixedpt s_sample;
  96: 
  97:     for (i = 0; i < 8; i++) {
  98:         printf(" %4.2f ", value[i]);
  99:         double_to_l_fixed(&sample, value[i]);
 100:         printf(" x%8X.%8X ", sample.int_part, sample.fraction);
 101: #if 0
 102:         printf(" %4.2f", l_fixed_to_double(&sample));
 103: #endif
 104:         printf("\t");
 105:         double_to_s_fixed(&s_sample, value[i]);
 106:         printf(" x%4x.%4x ", s_sample.int_part, s_sample.fraction);
 107:         printf(" %4.2f\n", s_fixed_to_double(&s_sample));
 108:     }
 109:     return 0;
 110: }
 111: 
 112: test2()
 113: {
 114:     struct timeval tp;
 115:     struct l_fixedpt time_lm;
 116: 
 117:     (void)gettimeofday(&tp, (struct timezone *) 0);
 118:     tstamp(&time_lm, &tp);
 119: 
 120:     printf("tv_sec:  %d tv_usec:  %d \n", tp.tv_sec, tp.tv_usec);
 121:     printf("intpart: %lu fraction: %lu \n",
 122:            ntohl(time_lm.int_part), ntohl(time_lm.fraction));
 123:     printf("intpart: %lX fraction: %lX \n",
 124:            ntohl(time_lm.int_part), ntohl(time_lm.fraction));
 125:     return 0;
 126: }
 127: 
 128: test3(v)
 129:     int v;
 130: {
 131:     u_long ul = 0x80000001;
 132:     double dbl;
 133: 
 134: #ifdef  GENERIC_UNS_BUG
 135:     /*
 136: 	 *  Hopefully, we can avoid the unsigned issue altogether.  Make sure
 137: 	 *  that the high-order (sign) bit is zero, and fiddle from there
 138: 	 */
 139:     dbl = (long)((ul >> 1) & 0x7fffffff);
 140:     dbl *= 2.0;
 141:     if (ul & 1)
 142:         dbl += 1.0;
 143: #else
 144:     dbl = ul;
 145: #ifdef  VAX_COMPILER_FLT_BUG
 146:     if (dbl < 0.0) dbl += 4.294967296e9;
 147: #endif
 148: #endif
 149:     if (dbl != 2147483649.0) {
 150:         printf("test3 fails: can't convert from unsigned long to float\n");
 151:         printf("             (%lu != %15g)\n", ul, dbl);
 152:         printf(
 153:   "Try defining VAX_COMPILER_FLT_BUG or GENERIC_UNS_BUG in the Makefile.\n");
 154:         return 1;
 155:     } else {
 156:         if (v)
 157:             printf("test3 passes\n");
 158:         return 0;
 159:     }
 160: }
 161: 
 162: test4(v)
 163:     int v;
 164: {
 165:     double dbl = 1024.0 * 1024.0 * 1024.0;  /* 2^30 */
 166: #ifdef SUN_FLT_BUG
 167:     long l = 1.5 * dbl;
 168:     u_long ul = (l<<1);
 169: #else
 170:     u_long ul = 3.0 * dbl;          /* between 2^31 and 2^32 */
 171: #endif
 172:     if (v)
 173:         printf("test4: 3.0*1024.0*1024.0*1024.0 = 0x%08lx\n", ul);
 174: 
 175:     if (ul != 0xc0000000) {
 176:         printf("test4 fails:\n");
 177:         printf("Can't convert unsigned long to double.\n");
 178:         printf("Try defining SUN_FLT_BUG in the Makefile\n");
 179:         return 1;
 180:     } else {
 181:         if (v)
 182:             printf("test4 passes\n");
 183:             return 0;
 184:     }
 185: }

Defined functions

main defined in line 70; never used
test1 defined in line 89; used 2 times
test2 defined in line 112; used 2 times
test3 defined in line 128; used 3 times
test4 defined in line 162; used 3 times

Defined variables

RCSid defined in line 2; never used
value defined in line 69; used 3 times

Defined macros

FALSE defined in line 65; never used
TRUE defined in line 64; never used
Last modified: 1989-07-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3493
Valid CSS Valid XHTML 1.0 Strict