public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* Re: [LTP] [PATCH] open_posix_testsuite: Don\'t use clock_settime() to reset a CPU-time Clock
@ 2010-12-02  0:29 Mitani
  0 siblings, 0 replies; 11+ messages in thread
From: Mitani @ 2010-12-02  0:29 UTC (permalink / raw)
  To: guijianfeng; +Cc: ltp-list

I agree the opinion of Gui. 

In my environment, the difference of clock-ID in the same way as 
Gui's opinion occurs with recent git.
"clock_getcpuclockid/2-1.c" succeeded with Gui's patch.


Thank you--

-Tomonori Mitani



------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 11+ messages in thread
* [LTP] [PATCH] open_posix_testsuite: Don't use clock_settime() to reset a CPU-time Clock
@ 2010-10-29  2:39 Gui Jianfeng
  2010-11-08  4:09 ` Gui Jianfeng
  2011-02-24  6:21 ` Gui Jianfeng
  0 siblings, 2 replies; 11+ messages in thread
From: Gui Jianfeng @ 2010-10-29  2:39 UTC (permalink / raw)
  To: Garrett Cooper; +Cc: ltp-list

This case is trying to set CPU-time clock(ID is returned by clock_getcpuclockid()) of
a specific process by calling clock_settime(). But Linux kernel doesn't allow to reset
a CPU-time clock of a specific process. Kernel returns -EPERM. So test fails.

In "IEEE Std 1003.1, 2004 Edition", It's said as following:
If _POSIX_CPUTIME is defined, implementations shall support clock ID values obtained by
invoking clock_getcpuclockid(), which represent the CPU-time clock of a given process.
Implementations shall also support the special clockid_t value CLOCK_PROCESS_CPUTIME_ID,
which represents the CPU-time clock of the calling process when invoking one of the 
clock_*() or timer_*() functions. For these clock IDs, the values returned by 
clock_gettime() and specified by clock_settime() represent the amount of execution time
of the process associated with the clock. Changing the value of a CPU-time clock via
clock_settime() shall have no effect on the behavior of the sporadic server scheduling
policy. 

So the behaviour when changing the value of a CPU-time clock via clock_settime() is
operating system specific. 

We may change the test progress to stop using clock_settime(). Now, We just make use
of clock_gettime() instead to achieve the same test purpose.

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
---
 .../interfaces/clock_getcpuclockid/2-1.c           |   67 ++++++++++----------
 1 files changed, 33 insertions(+), 34 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/2-1.c
index edeb397..52240df 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/2-1.c
@@ -23,48 +23,47 @@ int main(int argc, char *argv[])
         printf("_POSIX_CPUTIME unsupported\n");
         return PTS_UNSUPPORTED;
 #else
-	unsigned long time_to_set;	
 	clockid_t clockid_1, clockid_2;
 	struct timespec tp1, tp2;
+	int i;
 
 	if (sysconf(_SC_CPUTIME) == -1) {
 		printf("_POSIX_CPUTIME unsupported\n");
 		return PTS_UNSUPPORTED;
 	}
 
-	if (clock_getcpuclockid(getpid(), &clockid_1) != 0) {
-		printf("clock_getcpuclockid(getpid(), ) failed\n");
-		return PTS_FAIL;
-	}
-	
-	if (clock_getcpuclockid(0, &clockid_2) != 0) {
-		printf("clock_getcpuclockid(0, ) failed\n");
-		return PTS_FAIL;
-	}
+        for (i = 0; i < 10; i++) {
+                if (clock_getcpuclockid(getpid(), &clockid_1) != 0) {
+                        printf("clock_getcpuclockid(getpid(), ) failed\n");
+                        return PTS_FAIL;
+                }
 
-	/* Set clockid_1 as a random value from 1 sec to 10 sec */
-	srand((unsigned long)time(NULL));
-	time_to_set = rand() * 10.0 / RAND_MAX + 1;
-	tp1.tv_sec = time_to_set;
-	tp1.tv_nsec = 0;	 
-	if (clock_settime(clockid_1, &tp1) != 0) {
-		printf("clock_getcpuclockid() returned an invalid clockid_t: "
-			"%d\n", clockid_1);
-		return PTS_FAIL;
-	}
-	/* Get the time of clockid_2, should almost the same as clockid_1 */
-	if (clock_gettime(clockid_2, &tp2) != 0) {
-		printf("clock_getcpuclockid() returned an invalid clockid_t: "
-			"%d\n", clockid_2);
-		return PTS_FAIL;
-	}
-	if (tp1.tv_sec == tp2.tv_sec)	
-	{
-		printf("Test PASSED\n");
-		return PTS_PASS;
-	}
-	printf("Test FAILED\n");
-	return PTS_FAIL;
-	
+                if (clock_getcpuclockid(0, &clockid_2) != 0) {
+                        printf("clock_getcpuclockid(0, ) failed\n");
+                        return PTS_FAIL;
+                }
+
+                /* Get the time of clockid_1 */
+                if (clock_gettime(clockid_1, &tp1) != 0) {
+                        printf("clock_getcpuclockid() returned an invalid clockid_t: "
+                               "%d\n", clockid_1);
+                        return PTS_FAIL;
+                }
+
+                /* Get the time of clockid_2, should almost the same as clockid_1 */
+                if (clock_gettime(clockid_2, &tp2) != 0) {
+                        printf("clock_getcpuclockid() returned an invalid clockid_t: "
+                               "%d\n", clockid_2);
+                        return PTS_FAIL;
+                }
+
+                if (tp1.tv_sec != tp2.tv_sec) {
+                        printf("Test FAILED\n");
+                        return PTS_FAIL;
+                }
+        }
+
+        printf("Test PASSED\n");
+        return PTS_PASS;
 #endif
 }
-- 
1.7.0.4



------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-02-25 14:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-02  0:29 [LTP] [PATCH] open_posix_testsuite: Don\'t use clock_settime() to reset a CPU-time Clock Mitani
  -- strict thread matches above, loose matches on Subject: below --
2010-10-29  2:39 [LTP] [PATCH] open_posix_testsuite: Don't " Gui Jianfeng
2010-11-08  4:09 ` Gui Jianfeng
2010-11-08  6:02   ` Garrett Cooper
2010-11-08  6:20     ` Gui Jianfeng
2010-11-15  3:20       ` Gui Jianfeng
2010-11-18 20:29     ` Cyril Hrubis
     [not found]       ` <AANLkTimz2WBPfwCBHajqzA7Uk_72MZeTJdWB0Zbkch8B@mail.gmail.com>
     [not found]         ` <AANLkTi=YvMBmUQLSmtq8aM0+s2-X3BmRM13fSUa6a1-1@mail.gmail.com>
     [not found]           ` <4CF4CCD7.3060009@cn.fujitsu.com>
2010-12-02 12:13             ` Cyril Hrubis
2010-12-30 16:50               ` Cyril Hrubis
2011-02-24  6:21 ` Gui Jianfeng
2011-02-25 14:50   ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox