----- "Caspar Zhang" <[email protected]> wrote:

> ----- "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?

s/1e-6/1e-9 in the patch, my typo :-|

Thanks,
Caspar

> 
> 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?
> 


-- 
Kernel Associate Quality Engineer
Red Hat Inc. (Beijing R&D Branch)

Red Hat China R&D Branch Unit 907, North Tower C, 
  Raycom Infotech Park, No.2 Kexueyuan Nanlu, 
  Haidian District, Beijing 100190

TEL: +86-10-62608150
Web: http://www.redhat.com/
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 15:04:24.175607371 +0800
@@ -65,10 +65,9 @@
 	fd_set readfds;
 	struct timespec tv;
 	int retval;
-	time_t t;
-	unsigned start, end;
+	struct timespec tp_start, tp_end;
 	struct timeval tv_start, tv_end;
-	int real_usec;
+	int real_usec, real_sec;
 
 	setup();
 
@@ -103,17 +102,20 @@
 		tst_resm(TINFO,
 			 "Testing basic pselect sanity,Sleeping for %jd secs",
 			 (intmax_t)tv.tv_sec);
-		start = time(&t);
+		clock_gettime(CLOCK_REALTIME, &tp_start);
 		retval =
 		    pselect(0, &readfds, NULL, NULL, (struct timespec *)&tv,
 			    NULL);
-		end = time(&t);
+		clock_gettime(CLOCK_REALTIME, &tp_end);
 
-		if (((end - start) == total_sec) || ((end - start) == total_sec + 1))
+		/* do a rounding */
+		real_sec = (int)(0.5 + (tp_end.tv_sec - tp_start.tv_sec + 
+				1e-9 * (tp_end.tv_nsec - tp_start.tv_nsec)));
+		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

Reply via email to