diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2015-02-09 13:39:57 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2015-02-10 15:49:30 +0100 |
commit | 62b876a0b5da8c452780fd7c3b9c1d95cede3a81 (patch) | |
tree | 06b54caf7d391f4254193cb207a2a272e5aa8d71 | |
parent | 5c864f6448d221541c1f425f3f2593061793f2da (diff) | |
download | cmocka-62b876a0b5da8c452780fd7c3b9c1d95cede3a81.tar.gz cmocka-62b876a0b5da8c452780fd7c3b9c1d95cede3a81.tar.xz cmocka-62b876a0b5da8c452780fd7c3b9c1d95cede3a81.zip |
cmocka: Check if 'struct timespec' is available.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | ConfigureChecks.cmake | 8 | ||||
-rw-r--r-- | config.h.cmake | 4 | ||||
-rw-r--r-- | src/cmocka.c | 10 |
3 files changed, 20 insertions, 2 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 761af94..7f8c11d 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -4,6 +4,7 @@ include(CheckFunctionExists) include(CheckLibraryExists) include(CheckTypeSize) include(CheckCXXSourceCompiles) +include(CheckStructHasMember) include(TestBigEndian) set(PACKAGE ${APPLICATION_NAME}) @@ -64,6 +65,9 @@ check_include_file(sys/types.h HAVE_SYS_TYPES_H) check_include_file(time.h HAVE_TIME_H) check_include_file(unistd.h HAVE_UNISTD_H) +if (HAVE_TIME_H) + check_struct_has_member("struct timespec" tv_sec "time.h" HAVE_STRUCT_TIMESPEC) +endif (HAVE_TIME_H) # FUNCTIONS check_function_exists(calloc HAVE_CALLOC) @@ -114,7 +118,7 @@ int main(void) { }" HAVE_MSVC_THREAD_LOCAL_STORAGE) endif(WIN32) -if (HAVE_TIME_H AND HAVE_CLOCK_GETTIME) +if (HAVE_TIME_H AND HAVE_STRUCT_TIMESPEC AND HAVE_CLOCK_GETTIME) set(CMAKE_REQUIRED_LIBRARIES ${RT_LIBRARY}) message(STATUS "CMAKE_REQUIRED_INCLUDES=${CMAKE_REQUIRED_INCLUDES} CMAKE_REQUIRED_LIBRARIES=${CMAKE_REQUIRED_LIBRARIES}") @@ -129,7 +133,7 @@ int main(void) { return 0; }" HAVE_CLOCK_GETTIME_REALTIME) set(CMAKE_REQUIRED_INCLUDES) -endif (HAVE_TIME_H AND HAVE_CLOCK_GETTIME) +endif () # ENDIAN if (NOT WIN32) diff --git a/config.h.cmake b/config.h.cmake index aa691d0..e657024 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -68,6 +68,10 @@ /* Define to 1 if you have the <unistd.h> header file. */ #cmakedefine HAVE_UNISTD_H 1 +/**************************** STRUCTS ****************************/ + +#cmakedefine HAVE_STRUCT_TIMESPEC 1 + /*************************** FUNCTIONS ***************************/ /* Define to 1 if you have the `calloc' function. */ diff --git a/src/cmocka.c b/src/cmocka.c index 56ac54a..9e52015 100644 --- a/src/cmocka.c +++ b/src/cmocka.c @@ -2232,6 +2232,7 @@ void cmocka_set_message_output(enum cm_message_output output) * TIME CALCULATIONS ****************************************************************************/ +#ifdef HAVE_STRUCT_TIMESPEC static struct timespec cm_tspecdiff(struct timespec time1, struct timespec time0) { @@ -2275,6 +2276,7 @@ static double cm_secdiff(struct timespec clock1, struct timespec clock0) return ret; } +#endif /* HAVE_STRUCT_TIMESPEC */ /**************************************************************************** * CMOCKA TEST RUNNER @@ -2401,6 +2403,7 @@ static int cmocka_run_group_fixture(const char *function_name, static int cmocka_run_one_tests(struct CMUnitTestState *test_state) { +#ifdef HAVE_STRUCT_TIMESPEC struct timespec start = { .tv_sec = 0, .tv_nsec = 0, @@ -2409,6 +2412,7 @@ static int cmocka_run_one_tests(struct CMUnitTestState *test_state) .tv_sec = 0, .tv_nsec = 0, }; +#endif int rc = 0; /* Run setup */ @@ -2429,7 +2433,9 @@ static int cmocka_run_one_tests(struct CMUnitTestState *test_state) } /* Run test */ +#ifdef HAVE_STRUCT_TIMESPEC CMOCKA_CLOCK_GETTIME(CLOCK_REALTIME, &start); +#endif if (rc == 0) { rc = cmocka_run_one_test_or_fixture(test_state->test->name, @@ -2451,8 +2457,12 @@ static int cmocka_run_one_tests(struct CMUnitTestState *test_state) rc = 0; } + test_state->runtime = 0.0; + +#ifdef HAVE_STRUCT_TIMESPEC CMOCKA_CLOCK_GETTIME(CLOCK_REALTIME, &finish); test_state->runtime = cm_secdiff(finish, start); +#endif /* Run teardown */ if (rc == 0 && test_state->test->teardown_func != NULL) { |