Skip to content

Commit

Permalink
Fixes for timing and clang-tidy use.
Browse files Browse the repository at this point in the history
fixes mity#28 Timing calculations are wrong
fixes mity#29 TEST_CASE should evaluate as a statement (no trailing semicolon)
  • Loading branch information
gdamore committed Dec 28, 2019
1 parent 409f4ab commit 2637b96
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions include/acutest.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/*
* Portions Copyright 2019 Garrett D'Amore
*/

#ifndef ACUTEST_H__
#define ACUTEST_H__
Expand Down Expand Up @@ -178,7 +181,7 @@
* the last test case after exiting the loop), you may use TEST_CASE(NULL).
*/
#define TEST_CASE_(...) test_case__(__VA_ARGS__)
#define TEST_CASE(name) test_case__("%s", name);
#define TEST_CASE(name) test_case__("%s", name)


/* printf-like macro for outputting an extra information about a failure.
Expand Down Expand Up @@ -364,8 +367,8 @@ static jmp_buf test_abort_jmp_buf__;
static double
test_timer_diff__(LARGE_INTEGER start, LARGE_INTEGER end)
{
double duration = end.QuadPart - start.QuadPart;
duration /= test_timer_freq__.QuadPart;
double duration = (double)(end.QuadPart - start.QuadPart);
duration /= (double)test_timer_freq__.QuadPart;
return duration;
}

Expand All @@ -384,12 +387,7 @@ static jmp_buf test_abort_jmp_buf__;
test_timer_init__(void)
{
if(test_timer__ == 1)
#ifdef CLOCK_MONOTONIC_RAW
/* linux specific; not subject of NTP adjustments or adjtime() */
test_timer_id__ = CLOCK_MONOTONIC_RAW;
#else
test_timer_id__ = CLOCK_MONOTONIC;
#endif
else if(test_timer__ == 2)
test_timer_id__ = CLOCK_PROCESS_CPUTIME_ID;
}
Expand All @@ -403,11 +401,18 @@ static jmp_buf test_abort_jmp_buf__;
static double
test_timer_diff__(struct timespec start, struct timespec end)
{
return ((double) end.tv_sec +
(double) end.tv_nsec * 10e-9)
-
((double) start.tv_sec +
(double) start.tv_nsec * 10e-9);
double endns;
double startns;

endns = end.tv_sec;
endns *= 1e9;
endns += end.tv_nsec;

startns = start.tv_sec;
startns *= 1e9;
startns += start.tv_nsec;

return ((endns - startns)/ 1e9);
}

static void
Expand Down

0 comments on commit 2637b96

Please sign in to comment.