aboutsummaryrefslogtreecommitdiff
path: root/test/validation/api/time/time.c
blob: 666a39b8182eefd7188d5d7f9f1f4aacf6ef4470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2015-2018 Linaro Limited
 * Copyright (c) 2019-2024 Nokia
 */

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <time.h>

#include <odp_api.h>
#include <odp/helper/odph_api.h>
#include "odp_cunit_common.h"

#define BUSY_LOOP_CNT		30000000    /* used for t > min resolution */
#define MIN_TIME_RATE		32000
#define MAX_TIME_RATE		15000000000
#define DELAY_TOLERANCE		40000000	    /* deviation for delay */
#define WAIT_SECONDS		3
#define MAX_WORKERS		32
#define TEST_ROUNDS		1024
#define TIME_SAMPLES		2
#define TIME_TOLERANCE_NS	1000000
#define TIME_TOLERANCE_CI_NS	40000000
#define TIME_TOLERANCE_1CPU_NS	40000000
#define GLOBAL_SHM_NAME		"GlobalTimeTest"
#define YEAR_IN_NS		(365 * 24 * ODP_TIME_HOUR_IN_NS)

static uint64_t local_res;
static uint64_t global_res;

typedef odp_time_t time_cb(void);
typedef uint64_t time_res_cb(void);
typedef odp_time_t time_from_ns_cb(uint64_t ns);
typedef uint64_t time_nsec_cb(void);

typedef struct {
	uint32_t num_threads;
	odp_barrier_t test_barrier;
	odp_time_t time[MAX_WORKERS + 1][TIME_SAMPLES];
	odp_queue_t queue[MAX_WORKERS];
	uint32_t num_queues;
	odp_atomic_u32_t event_count;
} global_shared_mem_t;

static global_shared_mem_t *global_mem;
static odp_instance_t *instance;

static int time_global_init(odp_instance_t *inst)
{
	odp_shm_t global_shm;
	odp_init_t init_param;
	odph_helper_options_t helper_options;
	uint32_t workers_count, max_threads;

	if (odph_options(&helper_options)) {
		ODPH_ERR("odph_options() failed\n");
		return -1;
	}

	odp_init_param_init(&init_param);
	init_param.mem_model = helper_options.mem_model;

	if (0 != odp_init_global(inst, &init_param, NULL)) {
		ODPH_ERR("odp_init_global() failed\n");
		return -1;
	}
	if (0 != odp_init_local(*inst, ODP_THREAD_CONTROL)) {
		ODPH_ERR("odp_init_local() failed\n");
		return -1;
	}

	global_shm = odp_shm_reserve(GLOBAL_SHM_NAME,
				     sizeof(global_shared_mem_t),
				     ODP_CACHE_LINE_SIZE, 0);
	if (global_shm == ODP_SHM_INVALID) {
		ODPH_ERR("Unable reserve memory for global_shm\n");
		return -1;
	}

	global_mem = odp_shm_addr(global_shm);
	memset(global_mem, 0, sizeof(global_shared_mem_t));

	global_mem->num_threads = MAX_WORKERS;

	workers_count = odp_cpumask_default_worker(NULL, 0);

	max_threads = (workers_count >= MAX_WORKERS) ?
			MAX_WORKERS : workers_count;

	if (max_threads < global_mem->num_threads) {
		printf("Requested num of threads is too large\n");
		printf("reducing from %" PRIu32 " to %" PRIu32 "\n",
		       global_mem->num_threads,
		       max_threads);
		global_mem->num_threads = max_threads;
	}

	printf("Num of threads used = %" PRIu32 "\n",
	       global_mem->num_threads);

	instance = inst;

	return 0;
}

static int time_global_term(odp_instance_t inst)
{
	odp_shm_t shm;

	shm = odp_shm_lookup(GLOBAL_SHM_NAME);
	if (0 != odp_shm_free(shm)) {
		ODPH_ERR("odp_shm_free() failed\n");
		return -1;
	}

	if (0 != odp_term_local()) {
		ODPH_ERR("odp_term_local() failed\n");
		return -1;
	}

	if (0 != odp_term_global(inst)) {
		ODPH_ERR("odp_term_global() failed\n");
		return -1;
	}

	return 0;
}

static void time_test_constants(void)
{
	uint64_t ns;

	CU_ASSERT(ODP_TIME_USEC_IN_NS == 1000);

	ns = ODP_TIME_HOUR_IN_NS;
	CU_ASSERT(ns == 60 * ODP_TIME_MIN_IN_NS);
	ns = ODP_TIME_MIN_IN_NS;
	CU_ASSERT(ns == 60 * ODP_TIME_SEC_IN_NS);
	ns = ODP_TIME_SEC_IN_NS;
	CU_ASSERT(ns == 1000 * ODP_TIME_MSEC_IN_NS);
	ns = ODP_TIME_MSEC_IN_NS;
	CU_ASSERT(ns == 1000 * ODP_TIME_USEC_IN_NS);

	ns = ODP_TIME_SEC_IN_NS / 1000;
	CU_ASSERT(ns == ODP_TIME_MSEC_IN_NS);
	ns /= 1000;
	CU_ASSERT(ns == ODP_TIME_USEC_IN_NS);
}

static void time_test_startup_time(void)
{
	odp_time_startup_t startup;
	uint64_t ns1, ns2, ns3;
	odp_time_t time;

	memset(&startup, 0, sizeof(odp_time_startup_t));

	odp_time_startup(&startup);
	ns1 = startup.global_ns;
	ns2 = odp_time_to_ns(startup.global);

	CU_ASSERT(UINT64_MAX - ns1 >= 10 * YEAR_IN_NS);
	CU_ASSERT(UINT64_MAX - ns2 >= 10 * YEAR_IN_NS);

	time = odp_time_global();
	ns3  = odp_time_to_ns(time);
	CU_ASSERT(odp_time_cmp(time, startup.global) > 0);

	time = odp_time_global_from_ns(10 * YEAR_IN_NS);
	time = odp_time_sum(startup.global, time);
	CU_ASSERT(odp_time_cmp(time, startup.global) > 0);

	printf("\n");
	printf("    Startup time in nsec: %" PRIu64 "\n", ns1);
	printf("    Startup time to nsec: %" PRIu64 "\n", ns2);
	printf("    Nsec since startup:   %" PRIu64 "\n\n", ns3 - startup.global_ns);
}

static void time_test_res(time_res_cb time_res, uint64_t *res)
{
	uint64_t rate;

	rate = time_res();
	CU_ASSERT(rate > MIN_TIME_RATE);
	CU_ASSERT(rate < MAX_TIME_RATE);

	*res = ODP_TIME_SEC_IN_NS / rate;
	if (ODP_TIME_SEC_IN_NS % rate)
		(*res)++;
}

static void time_test_local_res(void)
{
	time_test_res(odp_time_local_res, &local_res);
}

static void time_test_global_res(void)
{
	time_test_res(odp_time_global_res, &global_res);
}

/* check that related conversions come back to the same value */
static void time_test_conversion(time_from_ns_cb time_from_ns, uint64_t res)
{
	uint64_t ns1, ns2;
	odp_time_t time;
	uint64_t upper_limit, lower_limit;

	ns1 = 100;
	time = time_from_ns(ns1);

	ns2 = odp_time_to_ns(time);

	/* need to check within arithmetic tolerance that the same
	 * value in ns is returned after conversions */
	upper_limit = ns1 + res;
	lower_limit = ns1 - res;
	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));

	ns1 = 60 * 11 * ODP_TIME_SEC_IN_NS;
	time = time_from_ns(ns1);

	ns2 = odp_time_to_ns(time);

	/* need to check within arithmetic tolerance that the same
	 * value in ns is returned after conversions */
	upper_limit = ns1 + res;
	lower_limit = ns1 - res;
	CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit));

	/* test on 0 */
	ns1 = odp_time_to_ns(ODP_TIME_NULL);
	CU_ASSERT(ns1 == 0);
}

static void time_test_local_conversion(void)
{
	time_test_conversion(odp_time_local_from_ns, local_res);
}

static void time_test_global_conversion(void)
{
	time_test_conversion(odp_time_global_from_ns, global_res);
}

static void time_test_monotony(void)
{
	volatile uint64_t count = 0;
	odp_time_t l_t1, l_t2, l_t3;
	odp_time_t ls_t1, ls_t2, ls_t3;
	odp_time_t g_t1, g_t2, g_t3;
	odp_time_t gs_t1, gs_t2, gs_t3;
	uint64_t l_ns1, l_ns2, l_ns3;
	uint64_t ls_ns1, ls_ns2, ls_ns3;
	uint64_t g_ns1, g_ns2, g_ns3;
	uint64_t gs_ns1, gs_ns2, gs_ns3;
	uint64_t ns1, ns2, ns3;
	uint64_t s_ns1, s_ns2, s_ns3;
	uint64_t limit;

	l_t1   = odp_time_local();
	ls_t1  = odp_time_local_strict();
	l_ns1  = odp_time_local_ns();
	ls_ns1 = odp_time_local_strict_ns();

	g_t1   = odp_time_global();
	gs_t1  = odp_time_global_strict();
	g_ns1  = odp_time_global_ns();
	gs_ns1 = odp_time_global_strict_ns();

	while (count < BUSY_LOOP_CNT) {
		count++;
	};

	l_t2   = odp_time_local();
	ls_t2  = odp_time_local_strict();
	l_ns2  = odp_time_local_ns();
	ls_ns2 = odp_time_local_strict_ns();

	g_t2   = odp_time_global();
	gs_t2  = odp_time_global_strict();
	g_ns2  = odp_time_global_ns();
	gs_ns2 = odp_time_global_strict_ns();

	count = 0;
	while (count < BUSY_LOOP_CNT) {
		count++;
	};

	l_t3   = odp_time_local();
	ls_t3  = odp_time_local_strict();
	l_ns3  = odp_time_local_ns();
	ls_ns3 = odp_time_local_strict_ns();

	g_t3   = odp_time_global();
	gs_t3  = odp_time_global_strict();
	g_ns3  = odp_time_global_ns();
	gs_ns3 = odp_time_global_strict_ns();

	/* Local time tests
	 * ---------------- */

	ns1 = odp_time_to_ns(l_t1);
	ns2 = odp_time_to_ns(l_t2);
	ns3 = odp_time_to_ns(l_t3);

	s_ns1 = odp_time_to_ns(ls_t1);
	s_ns2 = odp_time_to_ns(ls_t2);
	s_ns3 = odp_time_to_ns(ls_t3);

	/* Time should not wrap in at least 10 years from ODP start. Ignoring delay from start up
	 * and other test cases, which should be few seconds. */
	limit = 10 * YEAR_IN_NS;
	CU_ASSERT(UINT64_MAX - ns1    > limit);
	CU_ASSERT(UINT64_MAX - s_ns1  > limit);
	CU_ASSERT(UINT64_MAX - l_ns1  > limit);
	CU_ASSERT(UINT64_MAX - ls_ns1 > limit);

	/* Time stamp */
	CU_ASSERT(ns2 > ns1);
	CU_ASSERT(ns3 > ns2);

	/* Strict time stamp */
	CU_ASSERT(s_ns2 > s_ns1);
	CU_ASSERT(s_ns3 > s_ns2);

	/* Nsec time */
	CU_ASSERT(l_ns2 > l_ns1);
	CU_ASSERT(l_ns3 > l_ns2);

	/* Strict nsec time */
	CU_ASSERT(ls_ns2 > ls_ns1);
	CU_ASSERT(ls_ns3 > ls_ns2);

	/* Strict time stamp order is maintained */
	CU_ASSERT(ls_ns1 >= s_ns1);
	CU_ASSERT(ls_ns2 >= s_ns2);
	CU_ASSERT(ls_ns3 >= s_ns3);

	/* Time in nanoseconds have the same time base. Allow less than 100 msec error
	 * between time stamp converted to nsec and nsec time. */
	CU_ASSERT((ls_ns1 - s_ns1) < (100 * ODP_TIME_MSEC_IN_NS));
	CU_ASSERT((ls_ns2 - s_ns2) < (100 * ODP_TIME_MSEC_IN_NS));
	CU_ASSERT((ls_ns3 - s_ns3) < (100 * ODP_TIME_MSEC_IN_NS));

	/* Global time tests
	 * ----------------- */

	ns1 = odp_time_to_ns(g_t1);
	ns2 = odp_time_to_ns(g_t2);
	ns3 = odp_time_to_ns(g_t3);

	s_ns1 = odp_time_to_ns(gs_t1);
	s_ns2 = odp_time_to_ns(gs_t2);
	s_ns3 = odp_time_to_ns(gs_t3);

	/* Time should not wrap in at least 10 years from ODP start. Ignoring delay from start up
	 * and other test cases, which should be few seconds. */
	limit = 10 * YEAR_IN_NS;
	CU_ASSERT(UINT64_MAX - ns1    > limit);
	CU_ASSERT(UINT64_MAX - s_ns1  > limit);
	CU_ASSERT(UINT64_MAX - g_ns1  > limit);
	CU_ASSERT(UINT64_MAX - gs_ns1 > limit);

	/* Time stamp */
	CU_ASSERT(ns2 > ns1);
	CU_ASSERT(ns3 > ns2);

	/* Strict time stamp */
	CU_ASSERT(s_ns2 > s_ns1);
	CU_ASSERT(s_ns3 > s_ns2);

	/* Nsec time */
	CU_ASSERT(g_ns2 > g_ns1);
	CU_ASSERT(g_ns3 > g_ns2);

	/* Strict nsec time */
	CU_ASSERT(gs_ns2 > gs_ns1);
	CU_ASSERT(gs_ns3 > gs_ns2);

	/* Strict time stamp order is maintained */
	CU_ASSERT(gs_ns1 >= s_ns1);
	CU_ASSERT(gs_ns2 >= s_ns2);
	CU_ASSERT(gs_ns3 >= s_ns3);

	/* Time in nanoseconds have the same time base. Allow less than 100 msec error
	 * between time stamp converted to nsec and nsec time. */
	CU_ASSERT((gs_ns1 - s_ns1) < (100 * ODP_TIME_MSEC_IN_NS));
	CU_ASSERT((gs_ns2 - s_ns2) < (100 * ODP_TIME_MSEC_IN_NS));
	CU_ASSERT((gs_ns3 - s_ns3) < (100 * ODP_TIME_MSEC_IN_NS));

	/* Tight error margin cannot be used due to possible OS interrupts during the test.
	 * Record all time stamp values into the log to help debugging their relative order and
	 * accuracy. */
	printf("\n    Time stamp values in nsec:\n");
	printf("    odp_time_local():            %" PRIu64 "\n", odp_time_to_ns(l_t1));
	printf("    odp_time_local_strict():     %" PRIu64 "\n", odp_time_to_ns(ls_t1));
	printf("    odp_time_local_ns():         %" PRIu64 "\n", l_ns1);
	printf("    odp_time_local_strict_ns():  %" PRIu64 "\n", ls_ns1);
	printf("    odp_time_global():           %" PRIu64 "\n", odp_time_to_ns(g_t1));
	printf("    odp_time_global_strict():    %" PRIu64 "\n", odp_time_to_ns(gs_t1));
	printf("    odp_time_global_ns():        %" PRIu64 "\n", g_ns1);
	printf("    odp_time_global_strict_ns(): %" PRIu64 "\n\n", gs_ns1);
}

static void time_test_cmp(time_cb time_cur, time_from_ns_cb time_from_ns)
{
	/* volatile to stop optimization of busy loop */
	volatile int count = 0;
	odp_time_t t1, t2, t3;

	t1 = time_cur();

	while (count < BUSY_LOOP_CNT) {
		count++;
	};

	t2 = time_cur();

	while (count < BUSY_LOOP_CNT * 2) {
		count++;
	};

	t3 = time_cur();

	CU_ASSERT(odp_time_cmp(t2, t1) > 0);
	CU_ASSERT(odp_time_cmp(t3, t2) > 0);
	CU_ASSERT(odp_time_cmp(t3, t1) > 0);
	CU_ASSERT(odp_time_cmp(t1, t2) < 0);
	CU_ASSERT(odp_time_cmp(t2, t3) < 0);
	CU_ASSERT(odp_time_cmp(t1, t3) < 0);
	CU_ASSERT(odp_time_cmp(t1, t1) == 0);
	CU_ASSERT(odp_time_cmp(t2, t2) == 0);
	CU_ASSERT(odp_time_cmp(t3, t3) == 0);

	t2 = time_from_ns(60 * 10 * ODP_TIME_SEC_IN_NS);
	t1 = time_from_ns(3);

	CU_ASSERT(odp_time_cmp(t2, t1) > 0);
	CU_ASSERT(odp_time_cmp(t1, t2) < 0);

	t1 = time_from_ns(0);
	CU_ASSERT(odp_time_cmp(t1, ODP_TIME_NULL) == 0);
}

static void time_test_local_cmp(void)
{
	time_test_cmp(odp_time_local, odp_time_local_from_ns);
}

static void time_test_global_cmp(void)
{
	time_test_cmp(odp_time_global, odp_time_global_from_ns);
}

static void time_test_local_strict_cmp(void)
{
	time_test_cmp(odp_time_local_strict, odp_time_local_from_ns);
}

static void time_test_global_strict_cmp(void)
{
	time_test_cmp(odp_time_global_strict, odp_time_global_from_ns);
}

/* check that a time difference gives a reasonable result */
static void time_test_diff(time_cb time_cur,
			   time_from_ns_cb time_from_ns,
			   uint64_t res)
{
	/* volatile to stop optimization of busy loop */
	volatile int count = 0;
	odp_time_t diff, t1, t2;
	uint64_t ns1, ns2, ns;
	uint64_t nsdiff, diff_ns;
	uint64_t upper_limit, lower_limit;

	/* test timestamp diff */
	t1 = time_cur();

	while (count < BUSY_LOOP_CNT) {
		count++;
	};

	t2 = time_cur();
	CU_ASSERT(odp_time_cmp(t2, t1) > 0);

	diff = odp_time_diff(t2, t1);
	CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) > 0);

	diff_ns = odp_time_diff_ns(t2, t1);
	CU_ASSERT(diff_ns > 0);

	ns1 = odp_time_to_ns(t1);
	ns2 = odp_time_to_ns(t2);
	ns = ns2 - ns1;
	nsdiff = odp_time_to_ns(diff);

	upper_limit = ns + 2 * res;
	lower_limit = ns - 2 * res;
	CU_ASSERT((nsdiff <= upper_limit) && (nsdiff >= lower_limit));
	CU_ASSERT((diff_ns <= upper_limit) && (diff_ns >= lower_limit));

	/* test timestamp and interval diff */
	ns1 = 54;
	t1 = time_from_ns(ns1);
	ns = ns2 - ns1;

	diff = odp_time_diff(t2, t1);
	CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) > 0);

	diff_ns = odp_time_diff_ns(t2, t1);
	CU_ASSERT(diff_ns > 0);

	nsdiff = odp_time_to_ns(diff);

	upper_limit = ns + 2 * res;
	lower_limit = ns - 2 * res;
	CU_ASSERT((nsdiff <= upper_limit) && (nsdiff >= lower_limit));
	CU_ASSERT((diff_ns <= upper_limit) && (diff_ns >= lower_limit));

	/* test interval diff */
	ns2 = 60 * 10 * ODP_TIME_SEC_IN_NS;
	ns = ns2 - ns1;

	t2 = time_from_ns(ns2);
	diff = odp_time_diff(t2, t1);
	CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) > 0);

	diff_ns = odp_time_diff_ns(t2, t1);
	CU_ASSERT(diff_ns > 0);

	nsdiff = odp_time_to_ns(diff);

	upper_limit = ns + 2 * res;
	lower_limit = ns - 2 * res;
	CU_ASSERT((nsdiff <= upper_limit) && (nsdiff >= lower_limit));
	CU_ASSERT((diff_ns <= upper_limit) && (diff_ns >= lower_limit));

	/* same time has to diff to 0 */
	diff = odp_time_diff(t2, t2);
	CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) == 0);

	diff = odp_time_diff(t2, ODP_TIME_NULL);
	CU_ASSERT(odp_time_cmp(t2, diff) == 0);

	diff_ns = odp_time_diff_ns(t2, t2);
	CU_ASSERT(diff_ns == 0);
}

static void time_test_local_diff(void)
{
	time_test_diff(odp_time_local, odp_time_local_from_ns, local_res);
}

static void time_test_global_diff(void)
{
	time_test_diff(odp_time_global, odp_time_global_from_ns, global_res);
}

static void time_test_local_strict_diff(void)
{
	time_test_diff(odp_time_local_strict, odp_time_local_from_ns, local_res);
}

static void time_test_global_strict_diff(void)
{
	time_test_diff(odp_time_global_strict, odp_time_global_from_ns, global_res);
}

/* check that a time sum gives a reasonable result */
static void time_test_sum(time_cb time_cur,
			  time_from_ns_cb time_from_ns,
			  uint64_t res)
{
	odp_time_t sum, t1, t2;
	uint64_t nssum, ns1, ns2, ns, diff;
	uint64_t upper_limit, lower_limit;

	/* sum timestamp and interval */
	t1 = time_cur();
	ns2 = 103;
	t2 = time_from_ns(ns2);
	ns1 = odp_time_to_ns(t1);
	ns = ns1 + ns2;

	sum = odp_time_sum(t2, t1);
	CU_ASSERT(odp_time_cmp(sum, ODP_TIME_NULL) > 0);
	nssum = odp_time_to_ns(sum);

	upper_limit = ns + 2 * res;
	lower_limit = ns - 2 * res;
	CU_ASSERT((nssum <= upper_limit) && (nssum >= lower_limit));

	/* sum intervals */
	ns1 = 60 * 13 * ODP_TIME_SEC_IN_NS;
	t1 = time_from_ns(ns1);
	ns = ns1 + ns2;

	sum = odp_time_sum(t2, t1);
	CU_ASSERT(odp_time_cmp(sum, ODP_TIME_NULL) > 0);
	nssum = odp_time_to_ns(sum);

	upper_limit = ns + 2 * res;
	lower_limit = ns - 2 * res;
	CU_ASSERT((nssum <= upper_limit) && (nssum >= lower_limit));

	/* test on 0 */
	sum = odp_time_sum(t2, ODP_TIME_NULL);
	CU_ASSERT(odp_time_cmp(t2, sum) == 0);

	/* test add nsec */
	ns = ODP_TIME_SEC_IN_NS;
	upper_limit = ns + 2 * res;
	lower_limit = ns - 2 * res;

	t1 = time_cur();
	t2 = odp_time_add_ns(t1, ns);

	CU_ASSERT(odp_time_cmp(t2, t1) > 0);

	diff = odp_time_diff_ns(t2, t1);
	CU_ASSERT((diff <= upper_limit) && (diff >= lower_limit));

	t1 = ODP_TIME_NULL;
	t2 = odp_time_add_ns(t1, ns);

	CU_ASSERT(odp_time_cmp(t2, t1) > 0);

	diff = odp_time_diff_ns(t2, t1);
	CU_ASSERT((diff <= upper_limit) && (diff >= lower_limit));
}

static void time_test_local_sum(void)
{
	time_test_sum(odp_time_local, odp_time_local_from_ns, local_res);
}

static void time_test_global_sum(void)
{
	time_test_sum(odp_time_global, odp_time_global_from_ns, global_res);
}

static void time_test_local_strict_sum(void)
{
	time_test_sum(odp_time_local_strict, odp_time_local_from_ns, local_res);
}

static void time_test_global_strict_sum(void)
{
	time_test_sum(odp_time_global_strict, odp_time_global_from_ns, global_res);
}

static void time_test_wait_until(time_cb time_cur, time_from_ns_cb time_from_ns)
{
	int i;
	odp_time_t lower_limit, upper_limit;
	odp_time_t start_time, end_time, wait;
	odp_time_t second = time_from_ns(ODP_TIME_SEC_IN_NS);

	start_time = time_cur();
	wait = start_time;
	for (i = 0; i < WAIT_SECONDS; i++) {
		wait = odp_time_sum(wait, second);
		odp_time_wait_until(wait);
	}
	end_time = time_cur();

	wait = odp_time_diff(end_time, start_time);
	lower_limit = time_from_ns(WAIT_SECONDS * ODP_TIME_SEC_IN_NS -
				   DELAY_TOLERANCE);
	upper_limit = time_from_ns(WAIT_SECONDS * ODP_TIME_SEC_IN_NS +
				   DELAY_TOLERANCE);

	if (odp_time_cmp(wait, lower_limit) < 0) {
		ODPH_ERR("Exceed lower limit: wait is %" PRIu64 ", lower_limit %" PRIu64 "\n",
			 odp_time_to_ns(wait), odp_time_to_ns(lower_limit));
		CU_FAIL("Exceed lower limit\n");
	}

	if (odp_time_cmp(wait, upper_limit) > 0) {
		ODPH_ERR("Exceed upper limit: wait is %" PRIu64 ", upper_limit %" PRIu64 "\n",
			 odp_time_to_ns(wait), odp_time_to_ns(lower_limit));
		CU_FAIL("Exceed upper limit\n");
	}
}

static void time_test_local_wait_until(void)
{
	time_test_wait_until(odp_time_local, odp_time_local_from_ns);
}

static void time_test_global_wait_until(void)
{
	time_test_wait_until(odp_time_global, odp_time_global_from_ns);
}

static void time_test_wait_ns(void)
{
	int i;
	odp_time_t lower_limit, upper_limit;
	odp_time_t start_time, end_time, diff;

	start_time = odp_time_local();
	for (i = 0; i < WAIT_SECONDS; i++)
		odp_time_wait_ns(ODP_TIME_SEC_IN_NS);
	end_time = odp_time_local();

	diff = odp_time_diff(end_time, start_time);

	lower_limit = odp_time_local_from_ns(WAIT_SECONDS * ODP_TIME_SEC_IN_NS -
					     DELAY_TOLERANCE);
	upper_limit = odp_time_local_from_ns(WAIT_SECONDS * ODP_TIME_SEC_IN_NS +
					     DELAY_TOLERANCE);

	if (odp_time_cmp(diff, lower_limit) < 0) {
		ODPH_ERR("Exceed lower limit: diff is %" PRIu64 ", lower_limit %" PRIu64 "\n",
			 odp_time_to_ns(diff), odp_time_to_ns(lower_limit));
		CU_FAIL("Exceed lower limit\n");
	}

	if (odp_time_cmp(diff, upper_limit) > 0) {
		ODPH_ERR("Exceed upper limit: diff is %" PRIu64 ", upper_limit %" PRIu64 "\n",
			 odp_time_to_ns(diff), odp_time_to_ns(upper_limit));
		CU_FAIL("Exceed upper limit\n");
	}
}

/* Check that ODP time is within +-5% of system time */
static void check_time_diff(double t_odp, double t_system,
			    const char *test, int id)
{
	if (t_odp > t_system * 1.05) {
		CU_FAIL("ODP time too high");
		ODPH_ERR("ODP time too high (%s/%d): t_odp: %f, t_system: %f\n",
			 test, id, t_odp, t_system);
	}
	if (t_odp < t_system * 0.95) {
		CU_FAIL("ODP time too low");
		ODPH_ERR("ODP time too low (%s/%d): t_odp: %f, t_system: %f\n",
			 test, id, t_odp, t_system);
	}
}

static void time_test_accuracy(time_cb time_cur,
			       time_cb time_cur_strict, time_from_ns_cb time_from_ns)
{
	int i;
	odp_time_t t1[2], t2[2], wait;
	struct timespec ts1, ts2, tsdiff;
	double sec_c;
	odp_time_t sec = time_from_ns(ODP_TIME_SEC_IN_NS);

	i = clock_gettime(CLOCK_MONOTONIC, &ts1);
	CU_ASSERT(i == 0);
	t1[0] = time_cur_strict();
	t1[1] = time_cur();

	wait = odp_time_sum(t1[0], sec);
	for (i = 0; i < 5; i++) {
		odp_time_wait_until(wait);
		wait = odp_time_add_ns(wait, ODP_TIME_SEC_IN_NS);
	}

	i = clock_gettime(CLOCK_MONOTONIC, &ts2);
	CU_ASSERT(i == 0);
	t2[0] = time_cur_strict();
	t2[1] = time_cur();

	if (ts2.tv_nsec < ts1.tv_nsec) {
		tsdiff.tv_nsec = 1000000000L + ts2.tv_nsec - ts1.tv_nsec;
		tsdiff.tv_sec = ts2.tv_sec - 1 - ts1.tv_sec;
	} else {
		tsdiff.tv_nsec = ts2.tv_nsec - ts1.tv_nsec;
		tsdiff.tv_sec = ts2.tv_sec - ts1.tv_sec;
	}
	sec_c = ((double)(tsdiff.tv_nsec) / 1000000000L) + tsdiff.tv_sec;

	for (i = 0; i < 2; i++) {
		odp_time_t diff  = odp_time_diff(t2[i], t1[i]);
		double sec_t = ((double)odp_time_to_ns(diff)) / ODP_TIME_SEC_IN_NS;

		check_time_diff(sec_t, sec_c, __func__, i);
	}
}

static void time_test_local_accuracy(void)
{
	time_test_accuracy(odp_time_local, odp_time_local_strict, odp_time_local_from_ns);
}

static void time_test_global_accuracy(void)
{
	time_test_accuracy(odp_time_global, odp_time_global_strict, odp_time_global_from_ns);
}

static void time_test_accuracy_nsec(void)
{
	uint64_t t1[4], t2[4];
	struct timespec ts1, ts2, tsdiff;
	double sec_c;
	int i, ret;

	ret = clock_gettime(CLOCK_MONOTONIC, &ts1);
	CU_ASSERT(ret == 0);
	t1[0] = odp_time_global_strict_ns();
	t1[1] = odp_time_local_strict_ns();
	t1[2] = odp_time_global_ns();
	t1[3] = odp_time_local_ns();

	for (i = 0; i < 5; i++)
		odp_time_wait_ns(ODP_TIME_SEC_IN_NS);

	ret = clock_gettime(CLOCK_MONOTONIC, &ts2);
	CU_ASSERT(ret == 0);
	t2[0] = odp_time_global_strict_ns();
	t2[1] = odp_time_local_strict_ns();
	t2[2] = odp_time_global_ns();
	t2[3] = odp_time_local_ns();

	if (ts2.tv_nsec < ts1.tv_nsec) {
		tsdiff.tv_nsec = 1000000000L + ts2.tv_nsec - ts1.tv_nsec;
		tsdiff.tv_sec = ts2.tv_sec - 1 - ts1.tv_sec;
	} else {
		tsdiff.tv_nsec = ts2.tv_nsec - ts1.tv_nsec;
		tsdiff.tv_sec = ts2.tv_sec - ts1.tv_sec;
	}
	sec_c = ((double)(tsdiff.tv_nsec) / 1000000000L) + tsdiff.tv_sec;

	for (i = 0; i < 4; i++) {
		uint64_t diff  = t2[i] - t1[i];
		double sec_t = ((double)diff) / ODP_TIME_SEC_IN_NS;

		check_time_diff(sec_t, sec_c, __func__, i);
	}
}

static int time_test_global_sync_thr(void *arg ODP_UNUSED)
{
	int tid = odp_thread_id();
	odp_shm_t global_shm = odp_shm_lookup(GLOBAL_SHM_NAME);
	global_shared_mem_t *global_mem = odp_shm_addr(global_shm);

	if (!global_mem)
		return 1;

	odp_barrier_wait(&global_mem->test_barrier);
	global_mem->time[tid][0] = odp_time_global();
	odp_time_wait_ns(ODP_TIME_MSEC_IN_NS * 100);
	odp_barrier_wait(&global_mem->test_barrier);
	global_mem->time[tid][1] = odp_time_global();

	return 0;
}

static void time_test_global_sync(const int ctrl)
{
	odp_cpumask_t cpumask;
	odph_thread_common_param_t thr_common;
	odph_thread_param_t thr_param;
	odph_thread_t thread_tbl[MAX_WORKERS];
	uint64_t tolerance = odp_cunit_ci() ? TIME_TOLERANCE_CI_NS : TIME_TOLERANCE_NS;
	const int num = ctrl ? 2 : global_mem->num_threads;

	if (num < 2) {
		printf(" number of threads is less than two, test skipped. ");
		return;
	}

	odp_barrier_init(&global_mem->test_barrier, num);

	odph_thread_param_init(&thr_param);
	thr_param.start = time_test_global_sync_thr;

	odph_thread_common_param_init(&thr_common);
	thr_common.instance = *instance;

	int thr = 0;

	if (ctrl) {
		/* Test sync between one control and one worker thread. */
		int control_cpu;
		int worker_cpu;

		odp_cpumask_default_control(&cpumask, 1);
		thr_common.cpumask = &cpumask;
		thr_param.thr_type = ODP_THREAD_CONTROL;
		control_cpu = odp_cpumask_first(&cpumask);

		int r = odph_thread_create(&thread_tbl[thr++],
					   &thr_common, &thr_param, 1);
		CU_ASSERT_FATAL(r == 1);
		odp_cpumask_default_worker(&cpumask, 1);
		worker_cpu = odp_cpumask_first(&cpumask);
		if (control_cpu == worker_cpu) {
			printf(" single CPU, relaxing tolerance. ");
			tolerance = TIME_TOLERANCE_1CPU_NS;
		}
	} else {
		/* Test sync between num worker threads. */
		odp_cpumask_default_worker(&cpumask, num);
	}

	int cpu = odp_cpumask_first(&cpumask);

	while (cpu >= 0) {
		odp_cpumask_t cpumask_one;

		/*
		 * Delay for more than the tolerance, so that we notice if the
		 * thread's view of global time is affected.
		 */
		odp_time_wait_ns(tolerance * 2);

		odp_cpumask_zero(&cpumask_one);
		odp_cpumask_set(&cpumask_one, cpu);
		thr_common.cpumask = &cpumask_one;
		thr_param.thr_type = ODP_THREAD_WORKER;

		int r = odph_thread_create(&thread_tbl[thr++],
					   &thr_common, &thr_param, 1);
		CU_ASSERT_FATAL(r == 1);

		cpu = odp_cpumask_next(&cpumask, cpu);
	}

	CU_ASSERT(odph_thread_join(thread_tbl, num) == num);

	for (int s = 0; s < TIME_SAMPLES; s++) {
		int min_idx = 0, max_idx = 0;
		uint64_t min = UINT64_MAX, max = 0;
		double avg = 0;

		for (int i = 1; i < num + 1; i++) {
			uint64_t t = odp_time_to_ns(global_mem->time[i][s]);

			if (t < min) {
				min = t;
				min_idx = i;
			}
		}

		printf("\nround %d\nthread time diffs: ", s);

		for (int i = 1; i < num + 1; i++) {
			uint64_t t = odp_time_to_ns(global_mem->time[i][s]) - min;

			printf("%" PRIu64 " ", t);

			if (t > max) {
				max = t;
				max_idx = i;
			}

			avg += t;
		}

		/* The min result itself is not included in the average. */
		avg /= num - 1;
		printf("\nmin: %" PRIu64 " (tid %d)  max diff: %" PRIu64
		       " (tid %d)  avg diff: %g", min, min_idx, max, max_idx, avg);
		CU_ASSERT(max < tolerance);
	}

	printf("\n");
}

static void time_test_global_sync_workers(void)
{
	time_test_global_sync(0);
}

static void time_test_global_sync_control(void)
{
	time_test_global_sync(1);
}

static odp_queue_t select_dst_queue(int thread_id, const odp_queue_t queue[], uint32_t num)
{
	uint8_t rand_u8;
	int rand_id = 0;

	if (num == 1)
		return queue[0];

	do {
		odp_random_data(&rand_u8, 1, ODP_RANDOM_BASIC);
		rand_id = rand_u8 % num;
	} while (rand_id == thread_id);

	return queue[rand_id];
}

static int run_time_global_thread(void *arg)
{
	global_shared_mem_t *gbl = arg;
	const int thread_id = odp_thread_id();
	const odp_queue_t src_queue = gbl->queue[thread_id % gbl->num_queues];
	const odp_queue_t *queues = gbl->queue;
	const uint32_t num_queues = gbl->num_queues;
	odp_atomic_u32_t *event_count = &gbl->event_count;

	odp_barrier_wait(&gbl->test_barrier);

	while (odp_atomic_load_u32(event_count) < TEST_ROUNDS) {
		odp_time_t *ts;
		odp_time_t cur_time;
		odp_buffer_t buf;
		odp_queue_t dst_queue;
		odp_event_t ev = odp_queue_deq(src_queue);

		if (ev == ODP_EVENT_INVALID) {
			odp_cpu_pause();
			continue;
		}

		cur_time = odp_time_global();

		buf = odp_buffer_from_event(ev);
		ts = odp_buffer_addr(buf);

		CU_ASSERT(odp_time_cmp(cur_time, *ts) >= 0);

		*ts = cur_time;

		dst_queue = select_dst_queue(thread_id, queues, num_queues);

		CU_ASSERT_FATAL(odp_queue_enq(dst_queue, ev) == 0);

		odp_atomic_inc_u32(event_count);
	}
	return 0;
}

static void time_test_global_mt(void)
{
	odp_cpumask_t cpumask;
	odp_pool_t pool;
	odp_pool_param_t pool_param;
	odp_pool_capability_t pool_capa;
	odp_queue_param_t queue_param;
	odp_queue_capability_t queue_capa;
	odph_thread_t thread_tbl[MAX_WORKERS];
	odph_thread_common_param_t thr_common;
	odph_thread_param_t thr_param;
	odp_time_t cur_time;
	uint32_t i;
	int num_workers = odp_cpumask_default_worker(&cpumask, global_mem->num_threads);
	uint32_t num_events = num_workers;
	uint32_t num_queues = num_workers;

	CU_ASSERT_FATAL(odp_pool_capability(&pool_capa) == 0);
	CU_ASSERT_FATAL(odp_queue_capability(&queue_capa) == 0);

	if (pool_capa.buf.max_num && num_events > pool_capa.buf.max_num)
		num_events = pool_capa.buf.max_num;

	if (queue_capa.plain.max_size && num_events > queue_capa.plain.max_size)
		num_events = queue_capa.plain.max_size;

	if (queue_capa.plain.max_num < num_queues)
		num_queues = queue_capa.plain.max_num;
	CU_ASSERT_FATAL(num_queues > 0);

	odp_pool_param_init(&pool_param);
	pool_param.buf.size = sizeof(odp_time_t);
	pool_param.buf.num = num_events;
	pool_param.type = ODP_POOL_BUFFER;

	pool = odp_pool_create("test event pool", &pool_param);
	CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);

	odp_queue_param_init(&queue_param);
	queue_param.size = num_events;
	queue_param.type = ODP_QUEUE_TYPE_PLAIN;

	for (i = 0; i < num_queues; i++) {
		global_mem->queue[i]  = odp_queue_create(NULL, &queue_param);
		CU_ASSERT_FATAL(global_mem->queue[i] != ODP_QUEUE_INVALID);
	}
	global_mem->num_queues = num_queues;

	odp_atomic_init_u32(&global_mem->event_count, 0);

	for (i = 0; i < num_events; i++) {
		odp_time_t *ts;
		odp_buffer_t buf = odp_buffer_alloc(pool);

		if (buf == ODP_BUFFER_INVALID)
			break;

		ts = odp_buffer_addr(buf);
		*ts = odp_time_global();

		CU_ASSERT_FATAL(odp_queue_enq(global_mem->queue[i % num_queues],
					      odp_buffer_to_event(buf)) == 0);
	}
	CU_ASSERT_FATAL(i > 0);
	CU_ASSERT(i == num_events);

	odp_barrier_init(&global_mem->test_barrier, num_workers);

	odph_thread_param_init(&thr_param);
	thr_param.start    = run_time_global_thread;
	thr_param.arg      = global_mem;
	thr_param.thr_type = ODP_THREAD_WORKER;

	odph_thread_common_param_init(&thr_common);
	thr_common.instance = *instance;
	thr_common.cpumask = &cpumask;
	thr_common.share_param = 1;

	CU_ASSERT_FATAL(odph_thread_create(thread_tbl, &thr_common, &thr_param, num_workers) ==
			num_workers);

	CU_ASSERT(odph_thread_join(thread_tbl, num_workers) == num_workers);

	cur_time = odp_time_global_strict();

	for (i = 0; i < num_queues; i++) {
		odp_queue_t queue = global_mem->queue[i];

		while (1) {
			odp_buffer_t buf;
			odp_time_t *ts;
			odp_event_t ev = odp_queue_deq(queue);

			if (ev == ODP_EVENT_INVALID)
				break;

			buf = odp_buffer_from_event(ev);
			ts = odp_buffer_addr(buf);

			CU_ASSERT(odp_time_cmp(cur_time, *ts) >= 0);
			odp_buffer_free(buf);
		};

		CU_ASSERT(odp_queue_destroy(queue) == 0);
	}

	CU_ASSERT(odp_pool_destroy(pool) == 0);
}

odp_testinfo_t time_suite_time[] = {
	ODP_TEST_INFO(time_test_constants),
	ODP_TEST_INFO(time_test_startup_time),
	ODP_TEST_INFO(time_test_local_res),
	ODP_TEST_INFO(time_test_local_conversion),
	ODP_TEST_INFO(time_test_local_cmp),
	ODP_TEST_INFO(time_test_local_diff),
	ODP_TEST_INFO(time_test_local_sum),
	ODP_TEST_INFO(time_test_global_mt),
	ODP_TEST_INFO(time_test_global_res),
	ODP_TEST_INFO(time_test_global_conversion),
	ODP_TEST_INFO(time_test_global_cmp),
	ODP_TEST_INFO(time_test_global_diff),
	ODP_TEST_INFO(time_test_global_sum),
	ODP_TEST_INFO(time_test_wait_ns),
	ODP_TEST_INFO(time_test_monotony),
	ODP_TEST_INFO(time_test_local_wait_until),
	ODP_TEST_INFO(time_test_global_wait_until),
	ODP_TEST_INFO(time_test_local_accuracy),
	ODP_TEST_INFO(time_test_global_accuracy),
	ODP_TEST_INFO(time_test_accuracy_nsec),
	ODP_TEST_INFO(time_test_local_strict_diff),
	ODP_TEST_INFO(time_test_local_strict_sum),
	ODP_TEST_INFO(time_test_local_strict_cmp),
	ODP_TEST_INFO(time_test_global_strict_diff),
	ODP_TEST_INFO(time_test_global_strict_sum),
	ODP_TEST_INFO(time_test_global_strict_cmp),
	ODP_TEST_INFO(time_test_global_sync_workers),
	ODP_TEST_INFO(time_test_global_sync_control),
	ODP_TEST_INFO_NULL
};

odp_suiteinfo_t time_suites[] = {
		{"Time", NULL, NULL, time_suite_time},
		ODP_SUITE_INFO_NULL
};

int main(int argc, char *argv[])
{
	int ret;

	/* parse common options: */
	if (odp_cunit_parse_options(&argc, argv))
		return -1;

	odp_cunit_register_global_init(time_global_init);
	odp_cunit_register_global_term(time_global_term);

	ret = odp_cunit_register(time_suites);

	if (ret == 0)
		ret = odp_cunit_run();

	return ret;
}