From 0722f461c5f8fce18802c9c4f4bf384d440e0c1f Mon Sep 17 00:00:00 2001 From: Ari Koivula Date: Fri, 13 Nov 2015 22:56:00 +0200 Subject: [PATCH] Fix compiling tests on mac The mac version of KVZ_GET_TIME macro has many statements, which prevented it being used inside a for loop statement. Added brackets to all versions to prevent this issue arising in the future. Fixes #115. --- src/threads.h | 4 ++-- tests/speed_tests.c | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/threads.h b/src/threads.h index e9dcfb3f..a50f6d91 100644 --- a/src/threads.h +++ b/src/threads.h @@ -44,7 +44,7 @@ (clock_t)->tv_nsec = mts.tv_nsec; \ } #else -#define KVZ_GET_TIME(clock_t) clock_gettime(CLOCK_MONOTONIC, (clock_t)) +#define KVZ_GET_TIME(clock_t) { clock_gettime(CLOCK_MONOTONIC, (clock_t)); } #endif #define KVZ_CLOCK_T_AS_DOUBLE(ts) ((double)((ts).tv_sec) + (double)((ts).tv_nsec) / (double)1000000000L) @@ -59,7 +59,7 @@ #include #define KVZ_CLOCK_T struct _FILETIME -#define KVZ_GET_TIME(clock_t) GetSystemTimeAsFileTime(clock_t) +#define KVZ_GET_TIME(clock_t) { GetSystemTimeAsFileTime(clock_t); } // _FILETIME has 32bit low and high part of 64bit 100ns resolution timestamp (since 12:00 AM January 1, 1601) #define KVZ_CLOCK_T_AS_DOUBLE(ts) ((double)(((uint64_t)(ts).dwHighDateTime)<<32 | (uint64_t)(ts).dwLowDateTime) / (double)10000000L) #define KVZ_CLOCK_T_DIFF(start, stop) ((double)((((uint64_t)(stop).dwHighDateTime)<<32 | (uint64_t)(stop).dwLowDateTime) - \ diff --git a/tests/speed_tests.c b/tests/speed_tests.c index 9e4fcf70..1043d488 100644 --- a/tests/speed_tests.c +++ b/tests/speed_tests.c @@ -106,7 +106,7 @@ TEST test_intra_speed(const int width) // Loop until time allocated for test has passed. for (unsigned i = 0; test_end > KVZ_CLOCK_T_AS_DOUBLE(clock_now); - ++i, KVZ_GET_TIME(&clock_now)) + ++i) { int test = i % NUM_TESTS; uint64_t sum = 0; @@ -123,6 +123,7 @@ TEST test_intra_speed(const int width) } ASSERT(sum > 0); + KVZ_GET_TIME(&clock_now) } sprintf(test_env.msg, "%.3fM x %s:%s", @@ -144,7 +145,7 @@ TEST test_inter_speed(const int width) // Loop until time allocated for test has passed. for (unsigned i = 0; test_end > KVZ_CLOCK_T_AS_DOUBLE(clock_now); - ++i, KVZ_GET_TIME(&clock_now)) + ++i) { int test = i % NUM_TESTS; uint64_t sum = 0; @@ -166,6 +167,7 @@ TEST test_inter_speed(const int width) } } ASSERT(sum > 0); + KVZ_GET_TIME(&clock_now) } sprintf(test_env.msg, "%.3fM x %s(%ix%i):%s", @@ -196,7 +198,7 @@ TEST dct_speed(const int width) // Loop until time allocated for test has passed. for (unsigned i = 0; test_end > KVZ_CLOCK_T_AS_DOUBLE(clock_now); - ++i, KVZ_GET_TIME(&clock_now)) + ++i) { int test = i % NUM_TESTS; uint64_t sum = 0; @@ -216,6 +218,7 @@ TEST dct_speed(const int width) } ASSERT(sum > 0); + KVZ_GET_TIME(&clock_now) } sprintf(test_env.msg, "%.3fM x %s:%s",