diff options
author | Michael Kaufmann <mail@michael-kaufmann.ch> | 2017-05-20 19:39:51 +0200 |
---|---|---|
committer | Michael Kaufmann <mail@michael-kaufmann.ch> | 2017-05-24 22:56:22 +0200 |
commit | 8ab22a74533acee61af31c48e75269822f408cb4 (patch) | |
tree | 24025f8450cf3b72eb5bf9316c1212b0a571363c /tests | |
parent | b4d87f54d60711e936fefae388d741b281eecdf0 (diff) |
time: fix type conversions and compiler warnings
Fix bugs and compiler warnings on systems with 32-bit long and
64-bit time_t.
Reviewed-by: Daniel Stenberg
Closes #1499
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libtest/lib1501.c | 25 | ||||
-rw-r--r-- | tests/libtest/lib1507.c | 21 | ||||
-rw-r--r-- | tests/libtest/lib1900.c | 5 | ||||
-rw-r--r-- | tests/libtest/lib582.c | 4 | ||||
-rw-r--r-- | tests/libtest/testutil.c | 15 | ||||
-rw-r--r-- | tests/libtest/testutil.h | 2 |
6 files changed, 14 insertions, 58 deletions
diff --git a/tests/libtest/lib1501.c b/tests/libtest/lib1501.c index cc442b529..8a6ef5172 100644 --- a/tests/libtest/lib1501.c +++ b/tests/libtest/lib1501.c @@ -31,22 +31,7 @@ /* 500 milliseconds allowed. An extreme number but lets be really conservative to allow old and slow machines to run this test too */ -#define MAX_BLOCKED_TIME_US 500000 - -/* return the number of microseconds between two time stamps */ -static int elapsed(struct timeval *before, - struct timeval *after) -{ - ssize_t result; - - result = (after->tv_sec - before->tv_sec) * 1000000 + - after->tv_usec - before->tv_usec; - if(result < 0) - result = 0; - - return curlx_sztosi(result); -} - +#define MAX_BLOCKED_TIME_MS 500 int test(char *URL) { @@ -80,7 +65,7 @@ int test(char *URL) int maxfd = -99; struct timeval before; struct timeval after; - int e; + long e; timeout.tv_sec = 0; timeout.tv_usec = 100000L; /* 100 ms */ @@ -105,10 +90,10 @@ int test(char *URL) abort_on_test_timeout(); after = tutil_tvnow(); - e = elapsed(&before, &after); - fprintf(stderr, "pong = %d\n", e); + e = tutil_tvdiff(after, before); + fprintf(stderr, "pong = %ld\n", e); - if(e > MAX_BLOCKED_TIME_US) { + if(e > MAX_BLOCKED_TIME_MS) { res = 100; break; } diff --git a/tests/libtest/lib1507.c b/tests/libtest/lib1507.c index 7ab305711..cd8500195 100644 --- a/tests/libtest/lib1507.c +++ b/tests/libtest/lib1507.c @@ -44,23 +44,6 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp) return CURL_READFUNC_ABORT; } -static struct timeval tvnow(void) -{ - /* - ** time() returns the value of time in seconds since the Epoch. - */ - struct timeval now; - now.tv_sec = (long)time(NULL); - now.tv_usec = 0; - return now; -} - -static long tvdiff(struct timeval newer, struct timeval older) -{ - return (newer.tv_sec-older.tv_sec)*1000+ - (newer.tv_usec-older.tv_usec)/1000; -} - int test(char *URL) { int res = 0; @@ -93,7 +76,7 @@ int test(char *URL) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); multi_add_handle(mcurl, curl); - mp_start = tvnow(); + mp_start = tutil_tvnow(); /* we start some action by calling perform right away */ curl_multi_perform(mcurl, &still_running); @@ -137,7 +120,7 @@ int test(char *URL) rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); - if(tvdiff(tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { + if(tutil_tvdiff(tutil_tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { fprintf(stderr, "ABORTING TEST, since it seems " "that it would have run forever.\n"); break; diff --git a/tests/libtest/lib1900.c b/tests/libtest/lib1900.c index 42c0ef1dd..b55f3b7d8 100644 --- a/tests/libtest/lib1900.c +++ b/tests/libtest/lib1900.c @@ -167,7 +167,6 @@ int test(char *URL) for(;;) { struct timeval interval; struct timeval now; - long int msnow, mslast; fd_set rd, wr, exc; int maxfd = -99; long timeout; @@ -177,9 +176,7 @@ int test(char *URL) if(handlenum < num_handles) { now = tutil_tvnow(); - msnow = now.tv_sec * 1000 + now.tv_usec / 1000; - mslast = last_handle_add.tv_sec * 1000 + last_handle_add.tv_usec / 1000; - if((msnow - mslast) >= urltime[handlenum]) { + if(tutil_tvdiff(now, last_handle_add) >= urltime[handlenum]) { fprintf(stdout, "Adding handle %d\n", handlenum); setup_handle(URL, m, handlenum); last_handle_add = now; diff --git a/tests/libtest/lib582.c b/tests/libtest/lib582.c index 1eb9b02d5..d7e4dd1bf 100644 --- a/tests/libtest/lib582.c +++ b/tests/libtest/lib582.c @@ -174,8 +174,8 @@ static int getMicroSecondTimeout(struct timeval* timeout) struct timeval now; ssize_t result; now = tutil_tvnow(); - result = (timeout->tv_sec - now.tv_sec) * 1000000 + - timeout->tv_usec - now.tv_usec; + result = (ssize_t)((timeout->tv_sec - now.tv_sec) * 1000000 + + timeout->tv_usec - now.tv_usec); if(result < 0) result = 0; diff --git a/tests/libtest/testutil.c b/tests/libtest/testutil.c index b9c43de04..f3ad0ce58 100644 --- a/tests/libtest/testutil.c +++ b/tests/libtest/testutil.c @@ -111,10 +111,11 @@ struct timeval tutil_tvnow(void) */ long tutil_tvdiff(struct timeval newer, struct timeval older) { - return (newer.tv_sec-older.tv_sec)*1000+ - (newer.tv_usec-older.tv_usec)/1000; + 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. * @@ -125,13 +126,5 @@ 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; - else - return (double)(newer.tv_usec-older.tv_usec)/1000000.0; -} - -/* return the number of seconds in the given input timeval struct */ -long tutil_tvlong(struct timeval t1) -{ - return t1.tv_sec; + return (double)(newer.tv_usec-older.tv_usec)/1000000.0; } - diff --git a/tests/libtest/testutil.h b/tests/libtest/testutil.h index 0bc5e03b7..f2aeae642 100644 --- a/tests/libtest/testutil.h +++ b/tests/libtest/testutil.h @@ -40,8 +40,6 @@ long tutil_tvdiff(struct timeval t1, struct timeval t2); */ double tutil_tvdiff_secs(struct timeval t1, struct timeval t2); -long tutil_tvlong(struct timeval t1); - #endif /* HEADER_CURL_LIBTEST_TESTUTIL_H */ |