1 //----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2007 by the FRESCOR consortium:
4 // Universidad de Cantabria, SPAIN
5 // University of York, UK
6 // Scuola Superiore Sant'Anna, ITALY
7 // Kaiserslautern University, GERMANY
8 // Univ. Politecnica Valencia, SPAIN
9 // Czech Technical University in Prague, CZECH REPUBLIC
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org
18 // The FRESCOR project (FP6/2005/IST/5-034026) is funded
19 // in part by the European Union Sixth Framework Programme
20 // The European Union is not liable of any use that may be
24 // based on previous work (FSF) done in the FIRST project
26 // Copyright (C) 2005 Mälardalen University, SWEDEN
27 // Scuola Superiore S.Anna, ITALY
28 // Universidad de Cantabria, SPAIN
29 // University of York, UK
31 // This file is part of FRSH (FRescor ScHeduler)
33 // FRSH is free software; you can redistribute it and/or modify it
34 // under terms of the GNU General Public License as published by the
35 // Free Software Foundation; either version 2, or (at your option) any
36 // later version. FRSH is distributed in the hope that it will be
37 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
38 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 // General Public License for more details. You should have received a
40 // copy of the GNU General Public License along with FRSH; see file
41 // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
42 // Cambridge, MA 02139, USA.
44 // As a special exception, including FRSH header files in a file,
45 // instantiating FRSH generics or templates, or linking other files
46 // with FRSH objects to produce an executable application, does not
47 // by itself cause the resulting executable application to be covered
48 // by the GNU General Public License. This exception does not
49 // however invalidate any other reasons why the executable file might be
50 // covered by the GNU Public License.
51 // -----------------------------------------------------------------------
54 #include <time.h> /* for timespec */
55 #include <stdio.h> /* for printf */
56 #include <string.h> /* for memcmp */
58 static int check_exact_abs_msec(fosa_abs_time_t abs_time, long msec);
59 static int check_exact_rel_msec(fosa_rel_time_t rel_time, long msec);
64 struct timespec tspec1 = {1, 500000000};
65 struct timespec tspec2 = {0, 400000000};
66 struct timespec tspec_result;
68 fosa_rel_time_t rel_time1 = fosa_msec_to_rel_time(1500);
69 fosa_rel_time_t rel_time2 = fosa_msec_to_rel_time(400);
70 fosa_rel_time_t rel_time_aux = fosa_msec_to_rel_time(1500);
71 fosa_rel_time_t rel_time_result;
73 fosa_abs_time_t abs_time1 = fosa_msec_to_abs_time(1500);
74 fosa_abs_time_t abs_time2 = fosa_msec_to_abs_time(400);
75 fosa_abs_time_t abs_time_aux = fosa_msec_to_abs_time(1500);
76 fosa_abs_time_t abs_time_result;
81 /* fosa_abs_time_incr */
82 abs_time_result = fosa_abs_time_incr(abs_time1, rel_time2);
83 assert( check_exact_abs_msec(abs_time_result, 1900) );
85 /* fosa_abs_time_decr */
86 abs_time_result = fosa_abs_time_decr(abs_time1, rel_time2);
87 assert( check_exact_abs_msec(abs_time_result, 1100) );
89 /* fosa_abs_time_decr (negative) */
90 abs_time_result = fosa_abs_time_decr(abs_time2, rel_time1);
91 // assert( check_exact_abs_msec(abs_time_result, -1100) );
93 /* fosa_abs_time_extract_interval */
94 rel_time_result = fosa_abs_time_extract_interval(abs_time2, abs_time1);
95 assert( check_exact_rel_msec(rel_time_result, 1100) );
97 /* fosa_abs_time_extract_interval (negative) */
98 rel_time_result = fosa_abs_time_extract_interval(abs_time1, abs_time2);
99 // assert( check_exact_rel_msec(rel_time_result, -1100) );
101 /* fosa_rel_time_add */
102 rel_time_result = fosa_rel_time_add(rel_time1, rel_time2);
103 assert( check_exact_rel_msec(rel_time_result, 1900) );
105 /* fosa_rel_time_decr */
106 rel_time_result = fosa_rel_time_decr(rel_time1, rel_time2);
107 assert( check_exact_rel_msec(rel_time_result, 1100) );
109 /* fosa_rel_time_decr (negative) */
110 rel_time_result = fosa_rel_time_decr(rel_time2, rel_time1);
111 // assert( check_exact_rel_msec(rel_time_result, 1100) );
113 /* fosa_abs_time_smaller */
114 test = fosa_abs_time_smaller(abs_time1, abs_time2);
115 assert(test == false);
117 test = fosa_abs_time_smaller(abs_time1, abs_time_aux);
118 assert(test == false);
120 test = fosa_abs_time_smaller(abs_time2, abs_time1);
123 /* fosa_rel_time_smaller */
124 test = fosa_rel_time_smaller(rel_time1, rel_time2);
125 assert(test == false);
127 test = fosa_rel_time_smaller(rel_time1, rel_time_aux);
128 assert(test == false);
130 test = fosa_rel_time_smaller(rel_time2, rel_time1);
133 /* fosa_abs_time_smaller_or_equal */
134 test = fosa_abs_time_smaller_or_equal(abs_time1, abs_time2);
135 assert(test == false);
137 test = fosa_abs_time_smaller_or_equal(abs_time1, abs_time_aux);
140 test = fosa_abs_time_smaller_or_equal(abs_time2, abs_time1);
143 /* fosa_rel_time_smaller_or_equal */
144 test = fosa_rel_time_smaller_or_equal(rel_time1, rel_time2);
145 assert(test == false);
147 test = fosa_rel_time_smaller_or_equal(rel_time1, rel_time_aux);
150 test = fosa_rel_time_smaller_or_equal(rel_time2, rel_time1);
153 /* fosa_msec_to_rel_time */
154 rel_time_result = fosa_msec_to_rel_time(1850);
155 assert( check_exact_rel_msec(rel_time_result, 1850) );
157 /* fosa_rel_time_to_msec */
158 numeric = fosa_rel_time_to_msec(rel_time1);
159 assert(numeric == 1500);
161 /* fosa_msec_to_abs_time */
162 abs_time_result = fosa_msec_to_rel_time(1320);
163 assert( check_exact_abs_msec(abs_time_result, 1320) );
165 /* fosa_abs_time_to_msec */
166 numeric = fosa_abs_time_to_msec(abs_time2);
167 assert(numeric == 400);
169 /* fosa_usec_to_rel_time */
170 rel_time_result = fosa_usec_to_rel_time(1850000);
171 assert( check_exact_rel_msec(rel_time_result, 1850) );
173 /* fosa_rel_time_to_usec */
174 numeric = fosa_rel_time_to_usec(rel_time1);
175 assert(numeric == 1500000);
177 /* fosa_msec_to_abs_time */
178 abs_time_result = fosa_usec_to_rel_time(1320000);
179 assert( check_exact_abs_msec(abs_time_result, 1320) );
181 /* fosa_abs_time_to_msec */
182 numeric = fosa_abs_time_to_usec(abs_time2);
183 assert(numeric == 400000);
185 /* fosa_timespec_to_rel_time */
186 struct timespec tspec_aux = {1, 750000000};
187 rel_time_result = fosa_timespec_to_rel_time(tspec_aux);
188 assert( check_exact_rel_msec(rel_time_result, 1750) );
190 /* fosa_rel_time_to_timespec */
191 tspec_result = fosa_rel_time_to_timespec(rel_time1);
192 test = memcmp(&tspec_result, &tspec1, sizeof(tspec_result) );
195 /* fosa_timespec_to_abs_time */
196 struct timespec tspec_aux_extra = {1, 200000000};
197 abs_time_result = fosa_timespec_to_abs_time(tspec_aux_extra);
198 assert( check_exact_abs_msec(abs_time_result, 1200) );
200 /* fosa_abs_time_to_timespec */
201 tspec_result = fosa_abs_time_to_timespec(abs_time2);
202 test = memcmp(&tspec_result, &tspec2, sizeof(tspec_result) );
205 printf("End of test OK!!\n");
210 // -------------------------------------------------------------
212 static int check_exact_abs_msec(fosa_abs_time_t abs_time, long msec)
214 fosa_abs_time_t time_check;
217 time_check = fosa_msec_to_abs_time(msec);
218 cmp = memcmp(&time_check, &abs_time, sizeof(time_check) );
230 // -------------------------------------------------------------
232 static int check_exact_rel_msec(fosa_rel_time_t rel_time, long msec)
234 fosa_rel_time_t time_check;
237 time_check = fosa_msec_to_rel_time(msec);
238 cmp = memcmp(&time_check, &rel_time, sizeof(time_check) );