X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Ftest-timeval.c;h=99a600b21baf8b1304a26341cdc0c54ec64bcdfc;hb=96fc46e8fdafd6467906e11e0fb493e2b78f2fb5;hp=3b39b4117963452bc8d370b25e374bcab43a6b66;hpb=40f0707cd9d105203c2b8b97a955b57aca426f13;p=openvswitch diff --git a/tests/test-timeval.c b/tests/test-timeval.c index 3b39b411..99a600b2 100644 --- a/tests/test-timeval.c +++ b/tests/test-timeval.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -47,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 @@ -68,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; } } @@ -86,7 +93,6 @@ main(int argc, char *argv[]) { proctitle_init(argc, argv); set_program_name(argv[0]); - time_init(); if (argc != 2) { usage(); @@ -95,7 +101,7 @@ main(int argc, char *argv[]) } else if (!strcmp(argv[1], "daemon")) { /* Test that time still advances even in a daemon. This is an * interesting test because fork() cancels the interval timer. */ - char cwd[1024]; + char cwd[1024], *pidfile; FILE *success; assert(getcwd(cwd, sizeof cwd) == cwd); @@ -104,7 +110,9 @@ main(int argc, char *argv[]) /* Daemonize, with a pidfile in the current directory. */ set_detach(); - set_pidfile(xasprintf("%s/test-timeval.pid", cwd)); + pidfile = xasprintf("%s/test-timeval.pid", cwd); + set_pidfile(pidfile); + free(pidfile); set_no_chdir(); daemonize();