Skip to content

Commit cb0a262

Browse files
authored
Fix TEST_CASE (bogus semicolon) and time measuring (#30)
2 parents 409f4ab + 9642fcc commit cb0a262

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

include/acutest.h

+16-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* <http://github.com/mity/acutest>
44
*
55
* Copyright (c) 2013-2019 Martin Mitas
6+
* Copyright 2019 Garrett D'Amore
67
*
78
* Permission is hereby granted, free of charge, to any person obtaining a
89
* copy of this software and associated documentation files (the "Software"),
@@ -178,7 +179,7 @@
178179
* the last test case after exiting the loop), you may use TEST_CASE(NULL).
179180
*/
180181
#define TEST_CASE_(...) test_case__(__VA_ARGS__)
181-
#define TEST_CASE(name) test_case__("%s", name);
182+
#define TEST_CASE(name) test_case__("%s", name)
182183

183184

184185
/* printf-like macro for outputting an extra information about a failure.
@@ -364,8 +365,8 @@ static jmp_buf test_abort_jmp_buf__;
364365
static double
365366
test_timer_diff__(LARGE_INTEGER start, LARGE_INTEGER end)
366367
{
367-
double duration = end.QuadPart - start.QuadPart;
368-
duration /= test_timer_freq__.QuadPart;
368+
double duration = (double)(end.QuadPart - start.QuadPart);
369+
duration /= (double)test_timer_freq__.QuadPart;
369370
return duration;
370371
}
371372

@@ -384,12 +385,7 @@ static jmp_buf test_abort_jmp_buf__;
384385
test_timer_init__(void)
385386
{
386387
if(test_timer__ == 1)
387-
#ifdef CLOCK_MONOTONIC_RAW
388-
/* linux specific; not subject of NTP adjustments or adjtime() */
389-
test_timer_id__ = CLOCK_MONOTONIC_RAW;
390-
#else
391388
test_timer_id__ = CLOCK_MONOTONIC;
392-
#endif
393389
else if(test_timer__ == 2)
394390
test_timer_id__ = CLOCK_PROCESS_CPUTIME_ID;
395391
}
@@ -403,11 +399,18 @@ static jmp_buf test_abort_jmp_buf__;
403399
static double
404400
test_timer_diff__(struct timespec start, struct timespec end)
405401
{
406-
return ((double) end.tv_sec +
407-
(double) end.tv_nsec * 10e-9)
408-
-
409-
((double) start.tv_sec +
410-
(double) start.tv_nsec * 10e-9);
402+
double endns;
403+
double startns;
404+
405+
endns = end.tv_sec;
406+
endns *= 1e9;
407+
endns += end.tv_nsec;
408+
409+
startns = start.tv_sec;
410+
startns *= 1e9;
411+
startns += start.tv_nsec;
412+
413+
return ((endns - startns)/ 1e9);
411414
}
412415

413416
static void

0 commit comments

Comments
 (0)