----- "Garrett Cooper" <[email protected]> wrote:
>
> The fact that the test is using time(3) to calculate the elapsed
> period instead of clock_gettime is dubious at best, because the
> precision of time is in seconds. Maybe it should be converted to
> clock_gettime calls for improved precision?
Use clock_gettime instead of time(3), patch attached.
Another question, since POSIX.1-2008 marks gettimeofday() as obsolete
(man gettimeofday), should the usec test part be changed to
clock_getime as well?
Thanks,
Caspar
--
/---------------------------------------\
| Name: Caspar Zhang |
| Team: Kernel-QE |
| IRC: caspar @ #kernel-qe, #eng-china |
| Phone: +86-10-6260-8150 |
| Cellphone: +86-1381-073-0090 |
\---------------------------------------/
Hi all,
In my recent tests, not all desired time be equal to exact execution time,
use clock_gettime to improve precision.
Signed-off-by: Caspar Zhang <[email protected]>
--- a/testcases/kernel/syscalls/pselect/Makefile 2010-04-01 14:23:10.000000000 +0800
+++ b/testcases/kernel/syscalls/pselect/Makefile 2010-07-19 14:54:38.984482305 +0800
@@ -21,6 +21,7 @@
include $(top_srcdir)/include/mk/testcases.mk
include $(abs_srcdir)/../utils/newer_64.mk
+LDLIBS += -lpthread -lrt
%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64
include $(top_srcdir)/include/mk/generic_leaf_target.mk
--- a/testcases/kernel/syscalls/pselect/pselect01.c 2010-04-01 14:23:10.000000000 +0800
+++ b/testcases/kernel/syscalls/pselect/pselect01.c 2010-07-19 14:25:31.900419665 +0800
@@ -65,10 +65,8 @@
fd_set readfds;
struct timespec tv;
int retval;
- time_t t;
- unsigned start, end;
struct timeval tv_start, tv_end;
- int real_usec;
+ int real_usec, real_sec;
setup();
@@ -103,17 +101,20 @@
tst_resm(TINFO,
"Testing basic pselect sanity,Sleeping for %jd secs",
(intmax_t)tv.tv_sec);
- start = time(&t);
+ clock_gettime(CLOCK_REALTIME, (struct timespec *)&tv_start);
retval =
pselect(0, &readfds, NULL, NULL, (struct timespec *)&tv,
NULL);
- end = time(&t);
+ clock_gettime(CLOCK_REALTIME, (struct timespec *)&tv_end);
- if (((end - start) == total_sec) || ((end - start) == total_sec + 1))
+ /* do a rounding */
+ real_sec = (int)(0.5 + (tv_end.tv_sec - tv_start.tv_sec +
+ 1e-6 * (tv_end.tv_usec - tv_start.tv_usec)));
+ if (real_sec == total_sec)
tst_resm(TPASS, "Sleep time was correct");
else
tst_resm(TFAIL, "Sleep time was incorrect:%d != %d",
- total_sec, (end - start));
+ total_sec, real_sec);
}
#ifdef DEBUG
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list