From: Tobias Brunner Date: Fri, 16 Feb 2018 10:55:54 +0000 (+0100) Subject: appveyor: Allow events to trigger early in threading unit tests X-Git-Tag: 5.6.3dr1~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1c63a400e73679f3defb12f24e5240fbc39d5af;p=thirdparty%2Fstrongswan.git appveyor: Allow events to trigger early in threading unit tests The timed wait functions tested in the threading unit tests often but randomly trigger a bit early on AppVeyor Windows containers. We allow this if it is not earlier than 5ms. --- diff --git a/src/libstrongswan/tests/suites/test_threading.c b/src/libstrongswan/tests/suites/test_threading.c index 9a9fdd8e9e..26e60db0d4 100644 --- a/src/libstrongswan/tests/suites/test_threading.c +++ b/src/libstrongswan/tests/suites/test_threading.c @@ -1,7 +1,7 @@ /* - * Copyright (C) 2013 Tobias Brunner + * Copyright (C) 2013-2018 Tobias Brunner * Copyright (C) 2008 Martin Willi - * Hochschule fuer Technik Rapperswil + * HSR Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -27,6 +27,36 @@ #include #include +#ifdef WIN32 +/* when running on AppVeyor the wait functions seem to frequently trigger a bit + * early, allow this if the difference is within 5ms. */ +static inline void time_is_at_least(timeval_t *expected, timeval_t *actual) +{ + if (!timercmp(actual, expected, >)) + { + timeval_t diff; + + timersub(expected, actual, &diff); + if (!diff.tv_sec && diff.tv_usec <= 5000) + { + warn("allow timer event %dus too early on Windows (expected: %u.%u, " + "actual: %u.%u)", diff.tv_usec, expected->tv_sec, + expected->tv_usec, actual->tv_sec, actual->tv_usec); + return; + } + fail("expected: %u.%u, actual: %u.%u", expected->tv_sec, + expected->tv_usec, actual->tv_sec, actual->tv_usec); + } +} +#else /* WIN32 */ +static inline void time_is_at_least(timeval_t *expected, timeval_t *actual) +{ + ck_assert_msg(timercmp(actual, expected, >), "expected: %u.%u, actual: " + "%u.%u", expected->tv_sec, expected->tv_usec, actual->tv_sec, + actual->tv_usec); +} +#endif /* WIN32 */ + /******************************************************************************* * recursive mutex test */ @@ -380,8 +410,7 @@ START_TEST(test_condvar_timed) time_monotonic(&end); mutex->unlock(mutex); timersub(&end, &start, &end); - ck_assert_msg(timercmp(&end, &diff, >), "end: %u.%u, diff: %u.%u", - end.tv_sec, end.tv_usec, diff.tv_sec, diff.tv_usec); + time_is_at_least(&diff, &end); thread = thread_create(condvar_run, NULL); @@ -419,8 +448,7 @@ START_TEST(test_condvar_timed_abs) } time_monotonic(&end); mutex->unlock(mutex); - ck_assert_msg(timercmp(&end, &diff, >), "end: %u.%u, diff: %u.%u", - end.tv_sec, end.tv_usec, abso.tv_sec, abso.tv_usec); + time_is_at_least(&diff, &end); thread = thread_create(condvar_run, NULL); @@ -704,8 +732,7 @@ START_TEST(test_rwlock_condvar_timed) rwlock->unlock(rwlock); time_monotonic(&end); timersub(&end, &start, &end); - ck_assert_msg(timercmp(&end, &diff, >), "end: %u.%u, diff: %u.%u", - end.tv_sec, end.tv_usec, diff.tv_sec, diff.tv_usec); + time_is_at_least(&diff, &end); thread = thread_create(rwlock_condvar_run, NULL); @@ -743,8 +770,7 @@ START_TEST(test_rwlock_condvar_timed_abs) } rwlock->unlock(rwlock); time_monotonic(&end); - ck_assert_msg(timercmp(&end, &abso, >), "end: %u.%u, abso: %u.%u", - end.tv_sec, end.tv_usec, abso.tv_sec, abso.tv_usec); + time_is_at_least(&abso, &end); thread = thread_create(rwlock_condvar_run, NULL); @@ -866,8 +892,7 @@ START_TEST(test_semaphore_timed) ck_assert(semaphore->timed_wait(semaphore, diff.tv_usec / 1000)); time_monotonic(&end); timersub(&end, &start, &end); - ck_assert_msg(timercmp(&end, &diff, >), "end: %u.%u, diff: %u.%u", - end.tv_sec, end.tv_usec, diff.tv_sec, diff.tv_usec); + time_is_at_least(&diff, &end); thread = thread_create(semaphore_run, NULL); @@ -889,8 +914,7 @@ START_TEST(test_semaphore_timed_abs) timeradd(&start, &diff, &abso); ck_assert(semaphore->timed_wait_abs(semaphore, abso)); time_monotonic(&end); - ck_assert_msg(timercmp(&end, &abso, >), "end: %u.%u, abso: %u.%u", - end.tv_sec, end.tv_usec, abso.tv_sec, abso.tv_usec); + time_is_at_least(&abso, &end); thread = thread_create(semaphore_run, NULL);