Replacing the local implementation.
Closes #17716
char **test_argv;
int testnum;
-struct timeval tv_test_start; /* for test timing */
+struct curltime tv_test_start; /* for test timing */
int unitfail; /* for unittests */
#include <fcntl.h>
-#include "testutil.h"
#include "memdebug.h"
static CURLcode test_lib1501(char *URL)
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -99;
- struct timeval before;
- struct timeval after;
- long e;
+ struct curltime before;
+ struct curltime after;
+ timediff_t e;
timeout.tv_sec = 0;
timeout.tv_usec = 100000L; /* 100 ms */
abort_on_test_timeout_custom(HANG_TIMEOUT);
curl_mfprintf(stderr, "ping\n");
- before = tutil_tvnow();
+ before = curlx_now();
multi_perform(mhandle, &still_running);
abort_on_test_timeout_custom(HANG_TIMEOUT);
- after = tutil_tvnow();
- e = tutil_tvdiff(after, before);
- curl_mfprintf(stderr, "pong = %ld\n", e);
+ after = curlx_now();
+ e = curlx_timediff(after, before);
+ curl_mfprintf(stderr, "pong = %ld\n", (long)e);
if(e > MAX_BLOCKED_TIME_MS) {
res = CURLE_TOO_LARGE;
***************************************************************************/
#include "first.h"
-#include "testutil.h"
#include "timediff.h"
#include "memdebug.h"
CURL *curl = NULL;
CURLM *mcurl = NULL;
int still_running = 1;
- struct timeval mp_start;
+ struct curltime mp_start;
struct curl_slist *rcpt_list = NULL;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
multi_add_handle(mcurl, curl);
- mp_start = tutil_tvnow();
+ mp_start = curlx_now();
/* we start some action by calling perform right away */
curl_multi_perform(mcurl, &still_running);
rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
- if(tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) {
+ if(curlx_timediff(curlx_now(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) {
curl_mfprintf(stderr, "ABORTING TEST, since it seems "
"that it would have run forever.\n");
break;
***************************************************************************/
#include "first.h"
-#include "testutil.h"
#include "memdebug.h"
#define WAKEUP_NUM 10
int numfds;
int i;
CURLcode res = CURLE_OK;
- struct timeval time_before_wait, time_after_wait;
+ struct curltime time_before_wait, time_after_wait;
(void)URL;
/* no wakeup */
- time_before_wait = tutil_tvnow();
+ time_before_wait = curlx_now();
multi_poll(multi, NULL, 0, 1000, &numfds);
- time_after_wait = tutil_tvnow();
+ time_after_wait = curlx_now();
- if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) {
+ if(curlx_timediff(time_after_wait, time_before_wait) < 500) {
curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
__FILE__, __LINE__);
res = TEST_ERR_MAJOR_BAD;
res_multi_wakeup(multi);
- time_before_wait = tutil_tvnow();
+ time_before_wait = curlx_now();
multi_poll(multi, NULL, 0, 1000, &numfds);
- time_after_wait = tutil_tvnow();
+ time_after_wait = curlx_now();
- if(tutil_tvdiff(time_after_wait, time_before_wait) > 500) {
+ if(curlx_timediff(time_after_wait, time_before_wait) > 500) {
curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too late\n",
__FILE__, __LINE__);
res = TEST_ERR_MAJOR_BAD;
/* previous wakeup should not wake up this */
- time_before_wait = tutil_tvnow();
+ time_before_wait = curlx_now();
multi_poll(multi, NULL, 0, 1000, &numfds);
- time_after_wait = tutil_tvnow();
+ time_after_wait = curlx_now();
- if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) {
+ if(curlx_timediff(time_after_wait, time_before_wait) < 500) {
curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
__FILE__, __LINE__);
res = TEST_ERR_MAJOR_BAD;
for(i = 0; i < WAKEUP_NUM; ++i)
res_multi_wakeup(multi);
- time_before_wait = tutil_tvnow();
+ time_before_wait = curlx_now();
multi_poll(multi, NULL, 0, 1000, &numfds);
- time_after_wait = tutil_tvnow();
+ time_after_wait = curlx_now();
- if(tutil_tvdiff(time_after_wait, time_before_wait) > 500) {
+ if(curlx_timediff(time_after_wait, time_before_wait) > 500) {
curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too late\n",
__FILE__, __LINE__);
res = TEST_ERR_MAJOR_BAD;
/* Even lots of previous wakeups should not wake up this. */
- time_before_wait = tutil_tvnow();
+ time_before_wait = curlx_now();
multi_poll(multi, NULL, 0, 1000, &numfds);
- time_after_wait = tutil_tvnow();
+ time_after_wait = curlx_now();
- if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) {
+ if(curlx_timediff(time_after_wait, time_before_wait) < 500) {
curl_mfprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
__FILE__, __LINE__);
res = TEST_ERR_MAJOR_BAD;
#include <fcntl.h>
-#include "testutil.h"
#include "memdebug.h"
struct t530_Sockets {
*/
static int t530_curlTimerCallback(CURLM *multi, long timeout_ms, void *userp)
{
- struct timeval *timeout = userp;
+ struct curltime *timeout = userp;
(void)multi; /* unused */
curl_mfprintf(stderr, "CURLMOPT_TIMERFUNCTION called: %u\n", timer_calls++);
return -1;
}
if(timeout_ms != -1) {
- *timeout = tutil_tvnow();
+ *timeout = curlx_now();
timeout->tv_usec += (int)timeout_ms * 1000;
}
else {
return result;
}
-static int t530_getMicroSecondTimeout(struct timeval *timeout)
+static int t530_getMicroSecondTimeout(struct curltime *timeout)
{
- struct timeval now;
+ struct curltime now;
ssize_t result;
- now = tutil_tvnow();
+ now = curlx_now();
result = (ssize_t)((timeout->tv_sec - now.tv_sec) * 1000000 +
timeout->tv_usec - now.tv_usec);
if(result < 0)
CURL *curl = NULL; CURLM *m = NULL;
struct t530_ReadWriteSockets sockets = {{NULL, 0, 0}, {NULL, 0, 0}};
int success = 0;
- struct timeval timeout = {0};
+ struct curltime timeout = {0};
timeout.tv_sec = (time_t)-1;
/* set the limits */
#include <fcntl.h>
-#include "testutil.h"
#include "memdebug.h"
struct t582_Sockets {
*/
static int t582_curlTimerCallback(CURLM *multi, long timeout_ms, void *userp)
{
- struct timeval *timeout = userp;
+ struct curltime *timeout = userp;
(void)multi; /* unused */
if(timeout_ms != -1) {
- *timeout = tutil_tvnow();
+ *timeout = curlx_now();
timeout->tv_usec += (int)timeout_ms * 1000;
}
else {
return result;
}
-static int t582_getMicroSecondTimeout(struct timeval *timeout)
+static int t582_getMicroSecondTimeout(struct curltime *timeout)
{
- struct timeval now;
+ struct curltime now;
ssize_t result;
- now = tutil_tvnow();
+ now = curlx_now();
result = (ssize_t)((timeout->tv_sec - now.tv_sec) * 1000000 +
timeout->tv_usec - now.tv_usec);
if(result < 0)
CURLM *m = NULL;
struct t582_ReadWriteSockets sockets = {{NULL, 0, 0}, {NULL, 0, 0}};
int success = 0;
- struct timeval timeout = {0};
+ struct curltime timeout = {0};
timeout.tv_sec = (time_t)-1;
assert(test_argc >= 5);
#include "curl_setup.h"
#include <curl/curl.h>
+#include <curlx/timeval.h>
#ifdef HAVE_SYS_SELECT_H
/* since so many tests use select(), we can just as well include it here */
extern int test_argc;
extern char **test_argv;
extern int testnum;
-extern struct timeval tv_test_start; /* for test timing */
+extern struct curltime tv_test_start; /* for test timing */
extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
struct timeval *tv);
/* ---------------------------------------------------------------- */
#define start_test_timing() do { \
- tv_test_start = tutil_tvnow(); \
+ tv_test_start = curlx_now(); \
} while(0)
#define TEST_HANG_TIMEOUT 60 * 1000 /* global default */
#define exe_test_timedout(T,Y,Z) do { \
- long timediff = tutil_tvdiff(tutil_tvnow(), tv_test_start); \
+ timediff_t timediff = curlx_timediff(curlx_now(), tv_test_start); \
if(timediff > (T)) { \
curl_mfprintf(stderr, "%s:%d ABORTING TEST, since it seems " \
"that it would have run forever (%ld ms > %ld ms)\n", \
- (Y), (Z), timediff, (long) (TEST_HANG_TIMEOUT)); \
+ (Y), (Z), (long)timediff, (long)(TEST_HANG_TIMEOUT)); \
res = TEST_ERR_RUNS_FOREVER; \
} \
} while(0)
*
***************************************************************************/
#include "testtrace.h"
-#include "testutil.h"
+
+#include <curlx/timeval.h>
#include "memdebug.h"
{
struct libtest_trace_cfg *trace_cfg = userp;
const char *text;
- struct timeval tv;
char timebuf[20];
char *timestr;
- time_t secs;
(void)handle;
if(trace_cfg->tracetime) {
struct tm *now;
- tv = tutil_tvnow();
+ struct curltime tv;
+ time_t secs;
+ tv = curlx_now();
if(!known_offset) {
epoch_offset = time(NULL) - tv.tv_sec;
known_offset = 1;
#include "memdebug.h"
-#ifdef _WIN32
-
-struct timeval tutil_tvnow(void)
-{
- /*
- ** GetTickCount() is available on _all_ Windows versions from W95 up
- ** to nowadays. Returns milliseconds elapsed since last system boot,
- ** increases monotonically and wraps once 49.7 days have elapsed.
- */
- struct timeval now;
- DWORD milliseconds = GetTickCount();
- now.tv_sec = (long)(milliseconds / 1000);
- now.tv_usec = (long)((milliseconds % 1000) * 1000);
- return now;
-}
-
-#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
-
-struct timeval tutil_tvnow(void)
-{
- /*
- ** clock_gettime() is granted to be increased monotonically when the
- ** monotonic clock is queried. Time starting point is unspecified, it
- ** could be the system start-up time, the Epoch, or something else,
- ** in any case the time starting point does not change once that the
- ** system has started up.
- */
- struct timeval now;
- struct timespec tsnow;
- if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
- now.tv_sec = tsnow.tv_sec;
- now.tv_usec = (int)(tsnow.tv_nsec / 1000);
- }
- /*
- ** Even when the configure process has truly detected monotonic clock
- ** availability, it might happen that it is not actually available at
- ** run-time. When this occurs simply fallback to other time source.
- */
-#ifdef HAVE_GETTIMEOFDAY
- else
- (void)gettimeofday(&now, NULL);
-#else
- else {
- now.tv_sec = time(NULL);
- now.tv_usec = 0;
- }
-#endif
- return now;
-}
-
-#elif defined(HAVE_GETTIMEOFDAY)
-
-struct timeval tutil_tvnow(void)
-{
- /*
- ** gettimeofday() is not granted to be increased monotonically, due to
- ** clock drifting and external source time synchronization it can jump
- ** forward or backward in time.
- */
- struct timeval now;
- (void)gettimeofday(&now, NULL);
- return now;
-}
-
-#else
-
-struct timeval tutil_tvnow(void)
-{
- /*
- ** time() returns the value of time in seconds since the Epoch.
- */
- struct timeval now;
- now.tv_sec = time(NULL);
- now.tv_usec = 0;
- return now;
-}
-
-#endif
-
-/*
- * Make sure that the first argument is the more recent time, as otherwise
- * we'll get a weird negative time-diff back...
- *
- * Returns: the time difference in number of milliseconds.
- */
-long tutil_tvdiff(struct timeval newer, struct timeval older)
-{
- return (long)(newer.tv_sec-older.tv_sec)*1000+
- (long)(newer.tv_usec-older.tv_usec)/1000;
-}
-
-/*
- * Same as tutil_tvdiff but with full usec resolution.
- *
- * Returns: the time difference in seconds with subsecond resolution.
- */
-double tutil_tvdiff_secs(struct timeval newer, struct timeval older)
-{
- if(newer.tv_sec != older.tv_sec)
- return (double)(newer.tv_sec-older.tv_sec)+
- (double)(newer.tv_usec-older.tv_usec)/1000000.0;
- return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
-}
-
/* build request url */
char *tutil_suburl(const char *base, int i)
{
***************************************************************************/
#include "test.h"
-struct timeval tutil_tvnow(void);
-
-/*
- * Make sure that the first argument (t1) is the more recent time and t2 is
- * the older time, as otherwise you get a weird negative time-diff back...
- *
- * Returns: the time difference in number of milliseconds.
- */
-long tutil_tvdiff(struct timeval t1, struct timeval t2);
-
-/*
- * Same as tutil_tvdiff but with full usec resolution.
- *
- * Returns: the time difference in seconds with subsecond resolution.
- */
-double tutil_tvdiff_secs(struct timeval t1, struct timeval t2);
-
/* build request url */
char *tutil_suburl(const char *base, int i);