|
13 | 13 | #include <stdarg.h> |
14 | 14 | #include <wchar.h> |
15 | 15 | #include <time.h> |
16 | | -#include <sys/time.h> |
17 | 16 |
|
18 | 17 | /* required for sandboxing */ |
19 | 18 | #include <sys/types.h> |
@@ -251,41 +250,70 @@ clar_report_all(void) |
251 | 250 | } |
252 | 251 | } |
253 | 252 |
|
| 253 | +#ifdef WIN32 |
| 254 | +# define clar_time DWORD |
| 255 | + |
| 256 | +static void clar_time_now(clar_time *out) |
| 257 | +{ |
| 258 | + *out = GetTickCount(); |
| 259 | +} |
| 260 | + |
| 261 | +static double clar_time_diff(clar_time *start, clar_time *end) |
| 262 | +{ |
| 263 | + return ((double)*end - (double)*start) / 1000; |
| 264 | +} |
| 265 | +#else |
| 266 | +# include <sys/time.h> |
| 267 | + |
| 268 | +# define clar_time struct timeval |
| 269 | + |
| 270 | +static void clar_time_now(clar_time *out) |
| 271 | +{ |
| 272 | + struct timezone tz; |
| 273 | + |
| 274 | + gettimeofday(out, &tz); |
| 275 | +} |
| 276 | + |
| 277 | +static double clar_time_diff(clar_time *start, clar_time *end) |
| 278 | +{ |
| 279 | + return ((double)end->tv_sec + (double)end->tv_usec / 1.0E6) - |
| 280 | + ((double)start->tv_sec + (double)start->tv_usec / 1.0E6); |
| 281 | +} |
| 282 | +#endif |
| 283 | + |
254 | 284 | static void |
255 | 285 | clar_run_test( |
256 | 286 | const struct clar_suite *suite, |
257 | 287 | const struct clar_func *test, |
258 | 288 | const struct clar_func *initialize, |
259 | 289 | const struct clar_func *cleanup) |
260 | 290 | { |
261 | | - struct timeval start, end; |
262 | | - struct timezone tz; |
| 291 | + clar_time start, end; |
263 | 292 |
|
264 | 293 | _clar.trampoline_enabled = 1; |
265 | 294 |
|
266 | 295 | CL_TRACE(CL_TRACE__TEST__BEGIN); |
267 | 296 |
|
| 297 | + _clar.last_report->start = time(NULL); |
| 298 | + clar_time_now(&start); |
| 299 | + |
268 | 300 | if (setjmp(_clar.trampoline) == 0) { |
269 | 301 | if (initialize->ptr != NULL) |
270 | 302 | initialize->ptr(); |
271 | 303 |
|
272 | | - _clar.last_report->start = time(NULL); |
273 | | - gettimeofday(&start, &tz); |
274 | | - |
275 | 304 | CL_TRACE(CL_TRACE__TEST__RUN_BEGIN); |
276 | 305 | test->ptr(); |
277 | 306 | CL_TRACE(CL_TRACE__TEST__RUN_END); |
278 | 307 | } |
279 | 308 |
|
280 | | - gettimeofday(&end, &tz); |
| 309 | + clar_time_now(&end); |
281 | 310 |
|
282 | 311 | _clar.trampoline_enabled = 0; |
283 | 312 |
|
284 | 313 | if (_clar.last_report->status == CL_TEST_NOTRUN) |
285 | 314 | _clar.last_report->status = CL_TEST_OK; |
286 | 315 |
|
287 | | - _clar.last_report->elapsed = ((double)end.tv_sec + (double)end.tv_usec / 1.0E6) - |
288 | | - ((double)start.tv_sec + (double)start.tv_usec / 1.0E6); |
| 316 | + _clar.last_report->elapsed = clar_time_diff(&start, &end); |
289 | 317 |
|
290 | 318 | if (_clar.local_cleanup != NULL) |
291 | 319 | _clar.local_cleanup(_clar.local_cleanup_payload); |
|
0 commit comments