Hi,
I noticed that "stime01" test let system-clock be faster than right time.
"stime01.c" is going to set system-clock by calling "stime()" function
with "new_time" variable.
It gets "curr_time" by "time()" function, and sets "curr_time + 10sec"
in "new_time".
But after the test, It doesn't restore system-clock.
Therefore, system-clock is set faster than right time about 10 seconds
after "stime01" test.
If this test is repeated many times, the system-clock advances for the
number of test times.
And, if system is rebooted, hardware-clock will be wrong.
How about following patch?
============
--- stime01.c.org 2009-03-23 22:36:07.000000000 +0900
+++ stime01.c 2010-02-05 14:02:59.000000000 +0900
@@ -70,6 +70,7 @@
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
+#include <sys/time.h>
#include <time.h>
#include <string.h>
#include <sys/stat.h>
@@ -83,6 +84,7 @@
char *TCID = "stime01"; /* Test program identifier. */
int TST_TOTAL = 1; /* Total number of test cases. */
extern int Tst_count; /* Test Case counter for tst_* routines */
+struct timeval first_tv; /* system's current time in micro-seconds */
time_t curr_time; /* system's current time in seconds */
time_t new_time; /* system's new time */
time_t tloc; /* argument var. for time() */
@@ -193,6 +195,11 @@
/* Get the system's new time */
new_time = curr_time + INCR_TIME;
+
+ /* Get the current time in microsecond */
+ if (gettimeofday(&first_tv, NULL) != 0)
+ tst_brkm(TBROK, cleanup,
+ "gettimeofday() failed to get current time,
errno=%d", errno);
} /* End setup() */
/*
@@ -202,6 +209,10 @@
*/
void cleanup()
{
+ /* restore current time */
+ if (settimeofday(&first_tv, NULL) != 0)
+ tst_brkm(TBROK, cleanup,
+ "settimeofday() failed to restore current time,
errno=%d", errno);
/*
* print timing stats if that option was specified.
* print errno log if that option was specified.
============
We should consider that "test time" must be added in the "current time".
But the test time is so short that we can ignore it.
I repeated "for" block of stime() and time() 10,000 times, but it
needed less than 1 second.
Thank you--
-Tomonori Mitani
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list