2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <sys/param.h>
11 #include <afsconfig.h>
17 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <netinet/in_systm.h>
22 #include <netinet/ip.h>
23 #include <netinet/udp.h>
25 #include <sys/ioctl.h>
35 int test1(), test2(), test3(), test4(), test5(), test6();
37 double value[8] = {5.1, -5.1, 1.5, -1.5, 0.5, -0.5, -0.05, 0.0};
39 #include "AFS_component_version_number.c"
45 if (argc > 1 && strcmp(argv[1], "-v") == 0) {
73 double l_fixed_to_double();
74 struct l_fixedpt sample;
75 double s_fixed_to_double();
76 struct s_fixedpt s_sample;
78 for (i = 0; i < 8; i++) {
79 printf(" %4.2f ", value[i]);
80 double_to_l_fixed(&sample, value[i]);
81 printf(" x%#8X.%#8X ", sample.int_part, sample.fraction);
83 printf(" %4.2f", l_fixed_to_double(&sample));
86 double_to_s_fixed(&s_sample, value[i]);
87 printf(" x%#4X.%#4X ", s_sample.int_part, s_sample.fraction);
88 printf(" %4.2f\n", s_fixed_to_double(&s_sample));
97 struct l_fixedpt time_lm;
99 (void)gettimeofday(&tp, NULL);
100 tstamp(&time_lm, &tp);
103 printf("tv_sec: %d tv_usec: %d \n", tp.tv_sec, tp.tv_usec);
104 printf("intpart: %lu fraction: %lu \n",
105 ntohl(time_lm.int_part), ntohl(time_lm.fraction));
106 printf("intpart: %lX fraction: %lX \n",
107 ntohl(time_lm.int_part), ntohl(time_lm.fraction));
109 { extern double ul_fixed_to_double();
111 d = ul_fixed_to_double (&time_lm);
112 if (v) printf ("ul_fixed_to_double returns %f\n", d);
114 printf ("ul_ftd returned negative number\n");
118 double_to_l_fixed (&time_lm, d);
119 if (v) printf("intpart: %lX fraction: %lX \n",
120 ntohl(time_lm.int_part), ntohl(time_lm.fraction));
121 d = ul_fixed_to_double (&time_lm);
123 printf ("second ul_ftd returned negative number\n");
126 if (v) printf ("ul_fixed_to_double(double_to_l_fixed(-d)) returns %f\n", d);
128 if (v) printf("test2 passes\n");
135 afs_uint32 ul = 0x80000001;
138 #ifdef GENERIC_UNS_BUG
140 * Hopefully, we can avoid the unsigned issue altogether. Make sure
141 * that the high-order (sign) bit is zero, and fiddle from there
143 dbl = (afs_int32)((ul >> 1) & 0x7fffffff);
149 #ifdef VAX_COMPILER_FLT_BUG
150 if (dbl < 0.0) dbl += 4.294967296e9;
153 if (dbl != 2147483649.0) {
154 printf("test3 fails: can't convert from unsigned long to float\n");
155 printf(" (%lu != %15g)\n", ul, dbl);
157 "Try defining VAX_COMPILER_FLT_BUG or GENERIC_UNS_BUG in the Makefile.\n");
161 printf("test3 passes\n");
169 double dbl = 1024.0 * 1024.0 * 1024.0; /* 2^30 */
172 afs_uint32 ul = (l<<1);
174 afs_uint32 ul = 3.0 * dbl; /* between 2^31 and 2^32 */
177 printf("test4: 3.0*1024.0*1024.0*1024.0 = 0x%08x\n", ul);
179 if (ul != 0xc0000000) {
180 printf("test4 fails:\n");
181 printf("Can't convert unsigned long to double.\n");
182 printf("Try defining SUN_FLT_BUG in the Makefile\n");
186 printf("test4 passes\n");
191 /* test5 - check for sign extension of int:8 in pkt precision variable. */
197 struct ntp_peer peer;
201 memset(&peer, 0, sizeof(peer));
202 memset(&sys, 0, sizeof(sys));
204 peer.precision = pkt.precision;
205 sys.precision = pkt.precision;
206 if ((pkt.precision != -6) ||
207 (peer.precision != -6) ||
208 (sys.precision != -6)) {
209 printf ("pkt %d, peer %d, sys %d, all should be %d\n",
210 pkt.precision, peer.precision, sys.precision, -6);
214 delay += 1.0/(afs_uint32)(1L << -peer.precision)
215 + ((peer.flags&PEER_FL_REFCLOCK) ? NTP_REFMAXSKW : NTP_MAXSKW);
216 if (peer.precision < 0 && -peer.precision < sizeof(afs_int32)*NBBY)
217 delay += 1.0/(afs_uint32)(1L << -peer.precision);
218 if (v) printf ("delay is %f\n", delay);
220 if ((delay - 0.041249) > .000002) {
221 printf ("delay calculation in error: delay was %d, should be %d\n",
225 if (v) printf("test5 passes\n");
229 /* test6 - calculates the machine clock's apparent precision. */
237 #if defined(AFS_SUN_ENV) || defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV)
238 #define PRECISION -20
240 #define PRECISION -18
245 precision = MeasurePrecision(&interval);
246 if ((precision >= 0) || (-precision >= sizeof(afs_int32)*NBBY)) {
247 printf ("Couldn't measure precision\n");
250 if (precision < PRECISION) {
251 printf ("Precision (%d) seems too small (best interval measured to date: 13 usec, 10/10/94). -JPM\n", precision);
252 printf ("Make certain that the reported interval is accurate (possible), and then relax\n");
253 printf ("this check only if appropriate.\n");
258 ("precision is %d (%f) from measured interval of %d usec (%f)\n",
259 precision, 1.0 / (afs_uint32)(1L << -precision),
260 interval, interval / 1000000.0);
261 if (!code) printf ("test6 passes\n");