X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-timeval.c;h=9896cf7372ff880b8af487c3819e47ee69c36c7b;hb=ea7655d9f9d38a3af7250de8ba0b89115b5f4a5e;hp=533f81aed3ff87e7e236628cb237d9ff800df591;hpb=a0bc29a541fc7dc6e20137d5558e2094d614e6ab;p=sliver-openvswitch.git diff --git a/tests/test-timeval.c b/tests/test-timeval.c index 533f81aed..9896cf737 100644 --- a/tests/test-timeval.c +++ b/tests/test-timeval.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Nicira Networks. + * Copyright (c) 2009, 2010, 2011 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ gettimeofday_in_msec(void) { struct timeval tv; - assert(!gettimeofday(&tv, NULL)); + xgettimeofday(&tv); return timeval_to_msec(&tv); } @@ -48,10 +48,11 @@ do_test(void) * setitimer()). Then ensure that, if time has really advanced by * TIME_UPDATE_INTERVAL, then time_msec() reports that it advanced. */ - long long int start_time_msec; + long long int start_time_msec, start_time_wall; long long int start_gtod; start_time_msec = time_msec(); + start_time_wall = time_wall_msec(); start_gtod = gettimeofday_in_msec(); for (;;) { /* Wait up to 1 second. Using select() to do the timeout avoids @@ -69,7 +70,12 @@ do_test(void) } if (gettimeofday_in_msec() - start_gtod >= TIME_UPDATE_INTERVAL) { - assert(time_msec() - start_time_msec >= TIME_UPDATE_INTERVAL); + /* gettimeofday() and time_msec() have different granularities in + * their time sources. Depending on the rounding used this could + * result in a slight difference, so we allow for 1 ms of slop. */ + assert(time_msec() - start_time_msec >= TIME_UPDATE_INTERVAL - 1); + assert(time_wall_msec() - start_time_wall >= + TIME_UPDATE_INTERVAL - 1); break; } } @@ -87,11 +93,16 @@ main(int argc, char *argv[]) { proctitle_init(argc, argv); set_program_name(argv[0]); - time_init(); if (argc != 2) { usage(); } else if (!strcmp(argv[1], "plain")) { + /* If we're not caching time there isn't much to test and SIGALRM won't + * be around to pull us out of the select() call, so just skip out */ + if (!CACHE_TIME) { + exit (77); + } + do_test(); } else if (!strcmp(argv[1], "daemon")) { /* Test that time still advances even in a daemon. This is an @@ -99,6 +110,10 @@ main(int argc, char *argv[]) char cwd[1024], *pidfile; FILE *success; + if (!CACHE_TIME) { + exit (77); + } + assert(getcwd(cwd, sizeof cwd) == cwd); unlink("test-timeval.success");