xref: /netbsd-src/external/bsd/ntp/dist/tests/libntp/timevalops.c (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1 /*	$NetBSD: timevalops.c,v 1.1.1.5 2016/01/08 21:21:33 christos Exp $	*/
2 
3 #include "config.h"
4 
5 //some unused features are still in the wrapper, unconverted
6 
7 #include "ntp_types.h"
8 #include "ntp_fp.h"
9 
10 #include "timevalops.h"
11 
12 #include <math.h>
13 #include "unity.h"
14 
15 
16 #define TEST_ASSERT_EQUAL_timeval(a, b) {				\
17     TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec");	\
18     TEST_ASSERT_EQUAL_MESSAGE(a.tv_usec, b.tv_usec, "Field tv_usec");	\
19 }
20 
21 
22 static u_int32 my_tick_to_tsf(u_int32 ticks);
23 static u_int32 my_tsf_to_tick(u_int32 tsf);
24 
25 
26 // that's it...
27 typedef struct {
28 	long	usec;
29 	u_int32	frac;
30 } lfpfracdata ;
31 
32 typedef int bool;
33 
34 struct timeval timeval_init( time_t hi, long lo);
35 const bool timeval_isValid(struct timeval V);
36 l_fp l_fp_init(int32 i, u_int32 f);
37 bool AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit);
38 bool AssertFpClose(const l_fp m, const l_fp n, const l_fp limit);
39 
40 void setUp(void);
41 void test_Helpers1(void);
42 void test_Normalise(void);
43 void test_SignNoFrac(void);
44 void test_SignWithFrac(void);
45 void test_CmpFracEQ(void);
46 void test_CmpFracGT(void);
47 void test_CmpFracLT(void);
48 void test_AddFullNorm(void);
49 void test_AddFullOflow1(void);
50 void test_AddUsecNorm(void);
51 void test_AddUsecOflow1(void);
52 void test_SubFullNorm(void);
53 void test_SubFullOflow(void);
54 void test_SubUsecNorm(void);
55 void test_SubUsecOflow(void);
56 void test_Neg(void);
57 void test_AbsNoFrac(void);
58 void test_AbsWithFrac(void);
59 void test_Helpers2(void);
60 void test_ToLFPbittest(void);
61 void test_ToLFPrelPos(void);
62 void test_ToLFPrelNeg(void);
63 void test_ToLFPabs(void);
64 void test_FromLFPbittest(void);
65 void test_FromLFPrelPos(void);
66 void test_FromLFPrelNeg(void);
67 void test_LFProundtrip(void);
68 void test_ToString(void);
69 
70 
71 //**********************************MY CUSTOM FUNCTIONS***********************
72 
73 
74 void
75 setUp(void)
76 {
77 	init_lib();
78 
79 	return;
80 }
81 
82 
83 struct timeval
84 timeval_init(time_t hi, long lo)
85 {
86 	struct timeval V;
87 
88 	V.tv_sec = hi;
89 	V.tv_usec = lo;
90 
91 	return V;
92 }
93 
94 
95 const bool
96 timeval_isValid(struct timeval V)
97 {
98 
99 	return V.tv_usec >= 0 && V.tv_usec < 1000000;
100 }
101 
102 
103 l_fp
104 l_fp_init(int32 i, u_int32 f)
105 {
106 	l_fp temp;
107 
108 	temp.l_i  = i;
109 	temp.l_uf = f;
110 
111 	return temp;
112 }
113 
114 
115 bool
116 AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit)
117 {
118 	struct timeval diff;
119 
120 	diff = abs_tval(sub_tval(m, n));
121 	if (cmp_tval(limit, diff) >= 0)
122 		return TRUE;
123 	else
124 	{
125 		printf("m_expr which is %ld.%lu \nand\nn_expr which is %ld.%lu\nare not close; diff=%ld.%luusec\n", m.tv_sec, m.tv_usec, n.tv_sec, n.tv_usec, diff.tv_sec, diff.tv_usec);
126 		//I don't have variables m_expr and n_expr in unity, those are command line arguments which only getst has!!!
127 
128 		return FALSE;
129 	}
130 }
131 
132 
133 bool
134 AssertFpClose(const l_fp m, const l_fp n, const l_fp limit)
135 {
136 	l_fp diff;
137 
138 	if (L_ISGEQ(&m, &n)) {
139 		diff = m;
140 		L_SUB(&diff, &n);
141 	} else {
142 		diff = n;
143 		L_SUB(&diff, &m);
144 	}
145 	if (L_ISGEQ(&limit, &diff)) {
146 		return TRUE;
147 	}
148 	else {
149 		printf("m_expr which is %s \nand\nn_expr which is %s\nare not close; diff=%susec\n", lfptoa(&m, 10), lfptoa(&n, 10), lfptoa(&diff, 10));
150 		//printf("m_expr which is %d.%d \nand\nn_expr which is %d.%d\nare not close; diff=%d.%dusec\n", m.l_uf, m.Ul_i, n.l_uf, n.Ul_i, diff.l_uf, diff.Ul_i);
151 		return FALSE;
152 	}
153 }
154 
155 
156 //---------------------------------------------------
157 
158 static const lfpfracdata fdata[] = {
159 	{      0, 0x00000000 }, {   7478, 0x01ea1405 },
160 	{  22077, 0x05a6d699 }, { 125000, 0x20000000 },
161 	{ 180326, 0x2e29d841 }, { 207979, 0x353e1c9b },
162 	{ 250000, 0x40000000 }, { 269509, 0x44fe8ab5 },
163 	{ 330441, 0x5497c808 }, { 333038, 0x5541fa76 },
164 	{ 375000, 0x60000000 }, { 394734, 0x650d4995 },
165 	{ 446327, 0x72427c7c }, { 500000, 0x80000000 },
166 	{ 517139, 0x846338b4 }, { 571953, 0x926b8306 },
167 	{ 587353, 0x965cc426 }, { 625000, 0xa0000000 },
168 	{ 692136, 0xb12fd32c }, { 750000, 0xc0000000 },
169 	{ 834068, 0xd5857aff }, { 848454, 0xd9344806 },
170 	{ 854222, 0xdaae4b02 }, { 861465, 0xdc88f862 },
171 	{ 875000, 0xe0000000 }, { 910661, 0xe921144d },
172 	{ 922162, 0xec12cf10 }, { 942190, 0xf1335d25 }
173 };
174 
175 
176 u_int32
177 my_tick_to_tsf(u_int32 ticks)
178 {
179 	// convert microseconds to l_fp fractional units, using double
180 	// precision float calculations or, if available, 64bit integer
181 	// arithmetic. This should give the precise fraction, rounded to
182 	// the nearest representation.
183 
184 #ifdef HAVE_U_INT64
185 	return (u_int32)((( ((u_int64)(ticks)) << 32) + 500000) / 1000000); //I put too much () when casting just to be safe
186 #else
187 	return (u_int32)( ((double)(ticks)) * 4294.967296 + 0.5);
188 #endif
189 	// And before you ask: if ticks >= 1000000, the result is
190 	// truncated nonsense, so don't use it out-of-bounds.
191 }
192 
193 
194 u_int32
195 my_tsf_to_tick(u_int32 tsf)
196 {
197 	// Inverse operation: converts fraction to microseconds.
198 #ifdef HAVE_U_INT64
199 	return (u_int32)( ((u_int64)(tsf) * 1000000 + 0x80000000) >> 32); //CHECK ME!!!
200 #else
201 	return (u_int32)(double(tsf) / 4294.967296 + 0.5);
202 #endif
203 	// Beware: The result might be 10^6 due to rounding!
204 }
205 
206 
207 //*******************************END OF CUSTOM FUNCTIONS*********************
208 
209 
210 // ---------------------------------------------------------------------
211 // test support stuff - part1
212 // ---------------------------------------------------------------------
213 
214 void
215 test_Helpers1(void)
216 {
217 	struct timeval x;
218 
219 	for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) {
220 		x.tv_usec = -1;
221 		TEST_ASSERT_FALSE(timeval_isValid(x));
222 		x.tv_usec = 0;
223 		TEST_ASSERT_TRUE(timeval_isValid(x));
224 		x.tv_usec = 999999;
225 		TEST_ASSERT_TRUE(timeval_isValid(x));
226 		x.tv_usec = 1000000;
227 		TEST_ASSERT_FALSE(timeval_isValid(x));
228 	}
229 
230 	return;
231 }
232 
233 
234 //----------------------------------------------------------------------
235 // test normalisation
236 //----------------------------------------------------------------------
237 
238 void
239 test_Normalise(void)
240 {
241 	long ns;
242 
243 	for (ns = -2000000000; ns <= 2000000000; ns += 10000000) {
244 		struct timeval x = timeval_init(0, ns);
245 
246 		x = normalize_tval(x);
247 		TEST_ASSERT_TRUE(timeval_isValid(x));
248 	}
249 
250 	return;
251 }
252 
253 //----------------------------------------------------------------------
254 // test classification
255 //----------------------------------------------------------------------
256 
257 void
258 test_SignNoFrac(void)
259 {
260 	int i;
261 
262 	// sign test, no fraction
263 	for (i = -4; i <= 4; ++i) {
264 		struct timeval a = timeval_init(i, 0);
265 		int	     E = (i > 0) - (i < 0);
266 		int	     r = test_tval(a);
267 
268 		TEST_ASSERT_EQUAL(E, r);
269 	}
270 
271 	return;
272 }
273 
274 
275 void
276 test_SignWithFrac(void)
277 {
278 	// sign test, with fraction
279 	int i;
280 
281 	for (i = -4; i <= 4; ++i) {
282 		struct timeval a = timeval_init(i, 10);
283 		int	     E = (i >= 0) - (i < 0);
284 		int	     r = test_tval(a);
285 
286 		TEST_ASSERT_EQUAL(E, r);
287 	}
288 
289 	return;
290 }
291 
292 //----------------------------------------------------------------------
293 // test compare
294 //----------------------------------------------------------------------
295 void
296 test_CmpFracEQ(void)
297 {
298 	int i, j;
299 
300 	// fractions are equal
301 	for (i = -4; i <= 4; ++i)
302 		for (j = -4; j <= 4; ++j) {
303 			struct timeval a = timeval_init(i, 200);
304 			struct timeval b = timeval_init(j, 200);
305 			int	     E = (i > j) - (i < j);
306 			int	     r = cmp_tval_denorm(a, b);
307 
308 			TEST_ASSERT_EQUAL(E, r);
309 		}
310 
311 	return;
312 }
313 
314 
315 void
316 test_CmpFracGT(void)
317 {
318 	// fraction a bigger fraction b
319 	int i, j;
320 
321 	for (i = -4; i <= 4; ++i)
322 		for (j = -4; j <= 4; ++j) {
323 			struct timeval a = timeval_init( i , 999800);
324 			struct timeval b = timeval_init( j , 200);
325 			int	     E = (i >= j) - (i < j);
326 			int	     r = cmp_tval_denorm(a, b);
327 
328 			TEST_ASSERT_EQUAL(E, r);
329 		}
330 
331 	return;
332 }
333 
334 
335 void
336 test_CmpFracLT(void)
337 {
338 	// fraction a less fraction b
339 	int i, j;
340 
341 	for (i = -4; i <= 4; ++i)
342 		for (j = -4; j <= 4; ++j) {
343 			struct timeval a = timeval_init(i, 200);
344 			struct timeval b = timeval_init(j, 999800);
345 			int	     E = (i > j) - (i <= j);
346 			int	     r = cmp_tval_denorm(a, b);
347 
348 			TEST_ASSERT_EQUAL(E, r);
349 		}
350 
351 	return;
352 }
353 
354 //----------------------------------------------------------------------
355 // Test addition (sum)
356 //----------------------------------------------------------------------
357 
358 void
359 test_AddFullNorm(void)
360 {
361 	int i, j;
362 
363 	for (i = -4; i <= 4; ++i)
364 		for (j = -4; j <= 4; ++j) {
365 			struct timeval a = timeval_init(i, 200);
366 			struct timeval b = timeval_init(j, 400);
367 			struct timeval E = timeval_init(i + j, 200 + 400);
368 			struct timeval c;
369 
370 			c = add_tval(a, b);
371 			TEST_ASSERT_EQUAL_timeval(E, c);
372 		}
373 
374 	return;
375 }
376 
377 
378 void
379 test_AddFullOflow1(void)
380 {
381 	int i, j;
382 
383 	for (i = -4; i <= 4; ++i)
384 		for (j = -4; j <= 4; ++j) {
385 			struct timeval a = timeval_init(i, 200);
386 			struct timeval b = timeval_init(j, 999900);
387 			struct timeval E = timeval_init(i + j + 1, 100);
388 			struct timeval c;
389 
390 			c = add_tval(a, b);
391 			TEST_ASSERT_EQUAL_timeval(E, c);
392 		}
393 
394 	return;
395 }
396 
397 
398 void
399 test_AddUsecNorm(void)
400 {
401 	int i;
402 
403 	for (i = -4; i <= 4; ++i) {
404 		struct timeval a = timeval_init(i, 200);
405 		struct timeval E = timeval_init(i, 600);
406 		struct timeval c;
407 
408 		c = add_tval_us(a, 600 - 200);
409 		TEST_ASSERT_EQUAL_timeval(E, c);
410 	}
411 
412 	return;
413 }
414 
415 
416 void
417 test_AddUsecOflow1(void)
418 {
419 	int i;
420 
421 	for (i = -4; i <= 4; ++i) {
422 		struct timeval a = timeval_init(i, 200);
423 		struct timeval E = timeval_init(i + 1, 100);
424 		struct timeval c;
425 
426 		c = add_tval_us(a, MICROSECONDS - 100);
427 		TEST_ASSERT_EQUAL_timeval(E, c);
428 	}
429 
430 	return;
431 }
432 
433 //----------------------------------------------------------------------
434 // test subtraction (difference)
435 //----------------------------------------------------------------------
436 
437 void
438 test_SubFullNorm(void)
439 {
440 	int i, j;
441 
442 	for (i = -4; i <= 4; ++i)
443 		for (j = -4; j <= 4; ++j) {
444 			struct timeval a = timeval_init(i, 600);
445 			struct timeval b = timeval_init(j, 400);
446 			struct timeval E = timeval_init(i - j, 600 - 400);
447 			struct timeval c;
448 
449 			c = sub_tval(a, b);
450 			TEST_ASSERT_EQUAL_timeval(E, c);
451 		}
452 
453 	return;
454 }
455 
456 
457 void
458 test_SubFullOflow(void)
459 {
460 	int i, j;
461 
462 	for (i = -4; i <= 4; ++i)
463 		for (j = -4; j <= 4; ++j) {
464 			struct timeval a = timeval_init(i, 100);
465 			struct timeval b = timeval_init(j, 999900);
466 			struct timeval E = timeval_init(i - j - 1, 200);
467 			struct timeval c;
468 
469 			c = sub_tval(a, b);
470 			TEST_ASSERT_EQUAL_timeval(E, c);
471 		}
472 
473 	return;
474 }
475 
476 
477 void
478 test_SubUsecNorm(void)
479 {
480 	int i = -4;
481 
482 	for (i = -4; i <= 4; ++i) {
483 		struct timeval a = timeval_init(i, 600);
484 		struct timeval E = timeval_init(i, 200);
485 		struct timeval c;
486 
487 		c = sub_tval_us(a, 600 - 200);
488 		TEST_ASSERT_EQUAL_timeval(E, c);
489 	}
490 
491 	return;
492 }
493 
494 
495 void
496 test_SubUsecOflow(void)
497 {
498 	int i = -4;
499 
500 	for (i = -4; i <= 4; ++i) {
501 		struct timeval a = timeval_init(i, 100);
502 		struct timeval E = timeval_init(i - 1, 200);
503 		struct timeval c;
504 
505 		c = sub_tval_us(a, MICROSECONDS - 100);
506 		TEST_ASSERT_EQUAL_timeval(E, c);
507 	}
508 
509 	return;
510 }
511 
512 //----------------------------------------------------------------------
513 // test negation
514 //----------------------------------------------------------------------
515 
516 void
517 test_Neg(void)
518 {
519 	int i = -4;
520 
521 	for (i = -4; i <= 4; ++i) {
522 		struct timeval a = timeval_init(i, 100);
523 		struct timeval b;
524 		struct timeval c;
525 
526 		b = neg_tval(a);
527 		c = add_tval(a, b);
528 		TEST_ASSERT_EQUAL(0, test_tval(c));
529 	}
530 
531 	return;
532 }
533 
534 //----------------------------------------------------------------------
535 // test abs value
536 //----------------------------------------------------------------------
537 
538 void
539 test_AbsNoFrac(void)
540 {
541 	int i = -4;
542 
543 	for (i = -4; i <= 4; ++i) {
544 		struct timeval a = timeval_init(i, 0);
545 		struct timeval b;
546 
547 		b = abs_tval(a);
548 		TEST_ASSERT_EQUAL((i != 0), test_tval(b));
549 	}
550 
551 	return;
552 }
553 
554 
555 void
556 test_AbsWithFrac(void)
557 {
558 	int i = -4;
559 
560 	for (i = -4; i <= 4; ++i) {
561 		struct timeval a = timeval_init(i, 100);
562 		struct timeval b;
563 
564 		b = abs_tval(a);
565 		TEST_ASSERT_EQUAL(1, test_tval(b));
566 	}
567 
568 	return;
569 }
570 
571 // ---------------------------------------------------------------------
572 // test support stuff -- part 2
573 // ---------------------------------------------------------------------
574 
575 
576 void
577 test_Helpers2(void)
578 {
579 	struct timeval limit = timeval_init(0, 2);
580 	struct timeval x, y;
581 	long i;
582 
583 	for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) {
584 		for (x.tv_usec = 1;
585 		     x.tv_usec < 1000000;
586 		     x.tv_usec += 499999) {
587 			for (i = -4; i < 5; ++i) {
588 				y = x;
589 				y.tv_usec += i;
590 				if (i >= -2 && i <= 2) {
591 					TEST_ASSERT_TRUE(AssertTimevalClose(x, y, limit));//ASSERT_PRED_FORMAT2(isClose, x, y);
592 				}
593 				else {
594 					TEST_ASSERT_FALSE(AssertTimevalClose(x, y, limit));
595 				}
596 			}
597 		}
598 	}
599 
600 	return;
601 }
602 
603 // and the global predicate instances we're using here
604 
605 //static l_fp lfpClose =  l_fp_init(0, 1); //static AssertFpClose FpClose(0, 1);
606 //static struct timeval timevalClose = timeval_init(0, 1); //static AssertTimevalClose TimevalClose(0, 1);
607 
608 //----------------------------------------------------------------------
609 // conversion to l_fp
610 //----------------------------------------------------------------------
611 
612 void
613 test_ToLFPbittest(void)
614 {
615 	l_fp lfpClose =  l_fp_init(0, 1);
616 
617 	u_int32 i = 0;
618 	for (i = 0; i < 1000000; ++i) {
619 		struct timeval a = timeval_init(1, i);
620 		l_fp E = l_fp_init(1, my_tick_to_tsf(i));
621 		l_fp r;
622 
623 		r = tval_intv_to_lfp(a);
624 		TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));	//ASSERT_PRED_FORMAT2(FpClose, E, r);
625 	}
626 
627 	return;
628 }
629 
630 
631 void
632 test_ToLFPrelPos(void)
633 {
634 	l_fp lfpClose =  l_fp_init(0, 1);
635 	int i = 0;
636 
637 	for (i = 0; i < COUNTOF(fdata); ++i) {
638 		struct timeval a = timeval_init(1, fdata[i].usec);
639 		l_fp E = l_fp_init(1, fdata[i].frac);
640 		l_fp r;
641 
642 		r = tval_intv_to_lfp(a);
643 		TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
644 	}
645 
646 	return;
647 }
648 
649 
650 void
651 test_ToLFPrelNeg(void)
652 {
653 	l_fp lfpClose =  l_fp_init(0, 1);
654 	int i = 0;
655 
656 	for (i = 0; i < COUNTOF(fdata); ++i) {
657 		struct timeval a = timeval_init(-1, fdata[i].usec);
658 		l_fp E = l_fp_init(~0, fdata[i].frac);
659 		l_fp    r;
660 
661 		r = tval_intv_to_lfp(a);
662 		TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
663 	}
664 
665 	return;
666 }
667 
668 
669 void
670 test_ToLFPabs(void)
671 {
672 	l_fp lfpClose =  l_fp_init(0, 1);
673 	int i = 0;
674 
675 	for (i = 0; i < COUNTOF(fdata); ++i) {
676 		struct timeval a = timeval_init(1, fdata[i].usec);
677 		l_fp E = l_fp_init(1 + JAN_1970, fdata[i].frac);
678 		l_fp    r;
679 
680 		r = tval_stamp_to_lfp(a);
681 		TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
682 	}
683 
684 	return;
685 }
686 
687 //----------------------------------------------------------------------
688 // conversion from l_fp
689 //----------------------------------------------------------------------
690 
691 void
692 test_FromLFPbittest(void)
693 {
694 	struct timeval timevalClose = timeval_init(0, 1);
695 	// Not *exactly* a bittest, because 2**32 tests would take a
696 	// really long time even on very fast machines! So we do test
697 	// every 1000 fractional units.
698 	u_int32 tsf = 0;
699 
700 	for (tsf = 0; tsf < ~((u_int32)(1000)); tsf += 1000) {
701 		struct timeval E = timeval_init(1, my_tsf_to_tick(tsf));
702 		l_fp a = l_fp_init(1, tsf);
703 		struct timeval r;
704 
705 		r = lfp_intv_to_tval(a);
706 		// The conversion might be off by one microsecond when
707 		// comparing to calculated value.
708 		TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
709 	}
710 
711 	return;
712 }
713 
714 
715 void
716 test_FromLFPrelPos(void)
717 {
718 	struct timeval timevalClose = timeval_init(0, 1);
719 	int i = 0;
720 
721 	for (i = 0; i < COUNTOF(fdata); ++i) {
722 		l_fp a = l_fp_init(1, fdata[i].frac);
723 		struct timeval E = timeval_init(1, fdata[i].usec);
724 		struct timeval r;
725 
726 		r = lfp_intv_to_tval(a);
727 		TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
728 	}
729 
730 	return;
731 }
732 
733 
734 void
735 test_FromLFPrelNeg(void)
736 {
737 	struct timeval timevalClose = timeval_init(0, 1);
738 	int i = 0;
739 
740 	for (i = 0; i < COUNTOF(fdata); ++i) {
741 		l_fp a = l_fp_init(~0, fdata[i].frac);
742 		struct timeval E = timeval_init(-1, fdata[i].usec);
743 		struct timeval r;
744 
745 		r = lfp_intv_to_tval(a);
746 		TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
747 	}
748 
749 	return;
750 }
751 
752 
753 // usec -> frac -> usec roundtrip, using a prime start and increment
754 void
755 test_LFProundtrip(void)
756 {
757 	int32_t t = -1;
758 	u_int32 i = 5;
759 
760 	for (t = -1; t < 2; ++t)
761 		for (i = 5; i < 1000000; i += 11) {
762 			struct timeval E = timeval_init(t, i);
763 			l_fp a;
764 			struct timeval r;
765 
766 			a = tval_intv_to_lfp(E);
767 			r = lfp_intv_to_tval(a);
768 			TEST_ASSERT_EQUAL_timeval(E, r);
769 		}
770 
771 	return;
772 }
773 
774 //----------------------------------------------------------------------
775 // string formatting
776 //----------------------------------------------------------------------
777 
778 void
779 test_ToString(void)
780 {
781 	static const struct {
782 		time_t	     sec;
783 		long	     usec;
784 		const char * repr;
785 	} data [] = {
786 		{ 0, 0,	 "0.000000" },
787 		{ 2, 0,	 "2.000000" },
788 		{-2, 0, "-2.000000" },
789 		{ 0, 1,	 "0.000001" },
790 		{ 0,-1,	"-0.000001" },
791 		{ 1,-1,	 "0.999999" },
792 		{-1, 1, "-0.999999" },
793 		{-1,-1, "-1.000001" },
794 	};
795 	int i;
796 
797 	for (i = 0; i < COUNTOF(data); ++i) {
798 		struct timeval a = timeval_init(data[i].sec, data[i].usec);
799 		const char *  E = data[i].repr;
800 		const char *  r = tvaltoa(a);
801 
802 		TEST_ASSERT_EQUAL_STRING(E, r);
803 	}
804 
805 	return;
806 }
807 
808 // -*- EOF -*-
809