Skip to contentSkip to conversation

fix "timer_create/10-1" and "timer_create/11-1" tests

PATCH In review Mitani 2 participants 8 messages Nov 29, 2010 – Jan 24, 2011 4 messages not in the archive

lore
Share & tools
lore

Mitani

author
#0 lore raw

PATCH 1/1 fix "timer_create/10-1" and "timer_create/11-1" tests

Hi,

"timer_create/10-1", "timer_create/11-1" failed in my system (RHEL5.5):
------------
conformance/interfaces/timer_create/6-1: execution: PASS conformance/interfaces/timer_create/10-1: execution: FAILED: Output:
nanosleep() not interrupted: Success
sysconf(_SC_CPUTIME) returns: 200112 conformance/interfaces/timer_create/11-1: execution: FAILED: Output:
nanosleep() not interrupted: Success
rc = 200112
conformance/interfaces/timer_create/8-1: execution: PASS conformance/interfaces/timer_create/14-1: execution: PASS conformance/interfaces/timer_create/3-1: execution: PASS conformance/interfaces/timer_create/1-1: execution: PASS conformance/interfaces/timer_create/4-1: execution: PASS conformance/interfaces/timer_create/9-1: execution: PASS
------------

"timer_create/10-1" failed in following line:
------------

        if (timer_create(CLOCK_PROCESS_CPUTIME_ID, &ev, &tid) != 0) {
                perror("timer_create() did not return success");
                return PTS_UNRESOLVED;
        }

        if (timer_settime(tid, 0, &its, NULL) != 0) {
                perror("timer_settime() did not return success");
                return PTS_UNRESOLVED;
        }

        if (nanosleep(&ts, &tsleft) != -1) {
                perror("nanosleep() not interrupted");			<---
failed line
                return PTS_FAIL;
        }

------------

It seems to be not able to catch timer's signal.

Manual
(http://www.kernel.org/doc/man-pages/online/pages/man2/timer_create.2.html)
says:
------------
[...]
timer_create() creates a new per-process interval timer. The ID of
the new
timer is returned in the buffer pointed to by timerid, which must be
a non-
NULL pointer. This ID is unique within the process, until the timer
is
deleted. The new timer is initially disarmed.

The clockid argument specifies the clock that the new timer uses to
measure
time. It can be specified as one of the following values:

CLOCK_REALTIME
A settable system-wide real-time clock.

CLOCK_MONOTONIC
A nonsettable monotonically increasing clock that measures
time from
some unspecified point in the past that does not change after
system
startup.

CLOCK_PROCESS_CPUTIME_ID (since Linux 2.6.12)
A clock that measures (user and system) CPU time consumed by
(all of
the threads in) the calling process.

CLOCK_THREAD_CPUTIME_ID (since Linux 2.6.12)
A clock that measures (user and system) CPU time consumed by
the
calling thread.
[...]
------------

It says that "CLOCK_REALTIME" measures "real-time clock" but "CLOCK_PROCESS_CPUTIME_ID" and "CLOCK_THREAD_CPUTIME_ID" measure "CPU time".

But "nanosleep()" doesn't count up cpu time. And "timer_settime()" cannot send signal.
"timer_create/11-1" is same.

I revised "timer_create/10-1" and "timer_create/11-1", and they succeeded.

============
---
a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c

2010-11-24 17:44:59.000000000 +0900
+++
b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c
2010-11-29 12:14:27.000000000 +0900

@@ -24,8 +24,10 @@
#define SLEEPDELTA 3
#define ACCEPTABLEDELTA 1

+int endflg = 0;
void handler(int signo)
{
+ endflg = 1;
printf("Caught signal\n");
}

@@ -81,13 +83,24 @@
return PTS_UNRESOLVED;
}

- if (nanosleep(&ts, &tsleft) != -1) {
- perror("nanosleep() not interrupted");
- return PTS_FAIL;
+ int n = 0;
+ int i = 0;
+ struct timespec ts1, ts2;
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts1);
+ while (1)
+ {
+ for (i = 0; i < 100000; i++)
+ n += i;
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts2);
+ tsleft.tv_sec = ts.tv_sec - (ts2.tv_sec - ts1.tv_sec);
+ if (tsleft.tv_sec < 0)
+ tsleft.tv_sec = 0;
+ if ((tsleft.tv_sec == 0) || (endflg == 1))
+ break;
}

if ( abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) {
- printf("Test PASSED");
+ printf("Test PASSED\n");
return PTS_PASS;
} else {
printf("Timer did not last for correct amount of time\n");
---
a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c

2010-11-24 17:44:59.000000000 +0900
+++
b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c
2010-11-29 14:19:42.000000000 +0900

@@ -22,8 +22,10 @@
#define SLEEPDELTA 3
#define ACCEPTABLEDELTA 1

+int endflg = 0;
void handler(int signo)
{
+ endflg = 1;
printf("Caught signal\n");
}

@@ -78,13 +80,24 @@
return PTS_UNRESOLVED;
}

- if (nanosleep(&ts, &tsleft) != -1) {
- perror("nanosleep() not interrupted");
- return PTS_FAIL;
+ int n = 0;
+ int i = 0;
+ struct timespec ts1, ts2;
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts1);
+ while (1)
+ {
+ for (i = 0; i < 100000; i++)
+ n += i;
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts2);
+ tsleft.tv_sec = ts.tv_sec - (ts2.tv_sec - ts1.tv_sec);
+ if (tsleft.tv_sec < 0)
+ tsleft.tv_sec = 0;
+ if ((tsleft.tv_sec == 0) || (endflg == 1))
+ break;
}

if ( abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) {
- printf("Test PASSED");
+ printf("Test PASSED\n");
return PTS_PASS;
} else {
printf("Timer did not last for correct amount of time\n");
============

Regards--

-Tomonori Mitani

testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c +17 -4
@@ -24,8 +24,10 @@
 #define SLEEPDELTA 3
 #define ACCEPTABLEDELTA 1
 
+int endflg = 0;
 void handler(int signo)
 {
+	endflg = 1;
 	printf("Caught signal\n");
 }
 
@@ -81,13 +83,24 @@
 		return PTS_UNRESOLVED;
 	}
 
-	if (nanosleep(&ts, &tsleft) != -1) {
-		perror("nanosleep() not interrupted");
-		return PTS_FAIL;
+	int n = 0;
+	int i = 0;
+	struct timespec ts1, ts2;
+	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts1);
+	while (1)
+	{
+		for (i = 0; i < 100000; i++)
+			n += i;
+		clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts2);
+		tsleft.tv_sec = ts.tv_sec - (ts2.tv_sec - ts1.tv_sec);
+		if (tsleft.tv_sec < 0)
+			tsleft.tv_sec = 0;
+		if ((tsleft.tv_sec == 0) || (endflg == 1))
+			break;
 	}
 
 	if ( abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) {
-		printf("Test PASSED");
+		printf("Test PASSED\n");
 		return PTS_PASS;
 	} else {
 		printf("Timer did not last for correct amount of time\n");
testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c +17 -4
@@ -22,8 +22,10 @@
 #define SLEEPDELTA 3
 #define ACCEPTABLEDELTA 1
 
+int endflg = 0;
 void handler(int signo)
 {
+	endflg = 1;
 	printf("Caught signal\n");
 }
 
@@ -78,13 +80,24 @@
 		return PTS_UNRESOLVED;
 	}
 
-	if (nanosleep(&ts, &tsleft) != -1) {
-		perror("nanosleep() not interrupted");
-		return PTS_FAIL;
+	int n = 0;
+	int i = 0;
+	struct timespec ts1, ts2;
+	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts1);
+	while (1)
+	{
+		for (i = 0; i < 100000; i++)
+			n += i;
+		clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts2);
+		tsleft.tv_sec = ts.tv_sec - (ts2.tv_sec - ts1.tv_sec);
+		if (tsleft.tv_sec < 0)
+			tsleft.tv_sec = 0;
+		if ((tsleft.tv_sec == 0) || (endflg == 1))
+			break;
 	}
 
 	if ( abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) {
-		printf("Test PASSED");
+		printf("Test PASSED\n");
 		return PTS_PASS;
 	} else {
 		printf("Timer did not last for correct amount of time\n");

------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#1 lore raw

Hi!
Slightly different patch to fix these tests is attached. The code is a little cleaner but basically does the same.

The tests now do

* get cputime
* set timer
* bussy loop while signal is not catched
* get cputime
* check that two stored cpu times differ approximately by timer interval

Also some more problems are fixed.

Signature · 2 lines
Cyril Hrubis
[email protected]
testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c +30 -20
index 56ffbbd..3553f20 100644
@@ -10,8 +10,6 @@
  * Same test as 1-1.c.
  */
 
-#define _XOPEN_SOURCE 600
-
 #include <time.h>
 #include <signal.h>
 #include <stdio.h>
@@ -21,12 +19,13 @@
 
 #define SIGTOTEST SIGALRM
 #define TIMERSEC 2
-#define SLEEPDELTA 3
 #define ACCEPTABLEDELTA 1
 
-void handler(int signo)
+static int endflg = 0;
+
+static void handler(int signo)
 {
-	printf("Caught signal\n");
+	endflg = 1;
 }
 
 int main(int argc, char *argv[])
@@ -39,33 +38,33 @@ int main(int argc, char *argv[])
 	struct sigaction act;
 	timer_t tid;
 	struct itimerspec its;
-	struct timespec ts, tsleft;
+	struct timespec tstart, tstop;
 	int rc;
 
 	rc = sysconf(_SC_CPUTIME);
 	printf("sysconf(_SC_CPUTIME) returns: %d\n", rc);
-	if (rc <= 0) {
-		return PTS_UNRESOLVED;	
+
+	if (rc == -1) {
+		printf("_POSIX_CPUTIME unsupported\n");
+		return PTS_UNSUPPORTED;
 	}
-		
+
 	ev.sigev_notify = SIGEV_SIGNAL;
 	ev.sigev_signo = SIGTOTEST;
 
-	act.sa_handler=handler;
-	act.sa_flags=0;
+	act.sa_handler = handler;
+	act.sa_flags = 0;
 
 	its.it_interval.tv_sec = 0;
 	its.it_interval.tv_nsec = 0;
 	its.it_value.tv_sec = TIMERSEC;
 	its.it_value.tv_nsec = 0;
 
-	ts.tv_sec=TIMERSEC+SLEEPDELTA;
-	ts.tv_nsec=0;
-
 	if (sigemptyset(&act.sa_mask) == -1) {
 		perror("Error calling sigemptyset");
 		return PTS_UNRESOLVED;
 	}
+
 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
 		perror("Error calling sigaction");
 		return PTS_UNRESOLVED;
@@ -76,23 +75,34 @@ int main(int argc, char *argv[])
 		return PTS_UNRESOLVED;
 	}
 
+	if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tstart) != 0) {
+		perror("clock_gettime() failed");
+		return PTS_UNRESOLVED;
+	}
+
 	if (timer_settime(tid, 0, &its, NULL) != 0) {
 		perror("timer_settime() did not return success");
 		return PTS_UNRESOLVED;
 	}
 
-	if (nanosleep(&ts, &tsleft) != -1) {
-		perror("nanosleep() not interrupted");
-		return PTS_FAIL;
+	/*
+	 * We need to bussy loop here as the timer is set to wait for 2 seconds
+	 * of cputime of this process (which doesn't tick in any sleep function)
+	 */
+	while (!endflg);
+
+	if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tstop) != 0) {
+		perror("clock_gettime() failed");
+		return PTS_UNRESOLVED;
 	}
 
-	if (abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) {
-		printf("Test PASSED");
+	if (abs(tstop.tv_sec - tstart.tv_sec - TIMERSEC) <= ACCEPTABLEDELTA) {
+		printf("Test PASSED\n");
 		return PTS_PASS;
 	} else {
 		printf("Timer did not last for correct amount of time\n");
 		printf("timer: %d != correct %d\n", 
-				(int) ts.tv_sec- (int) tsleft.tv_sec,
+				(int) tstop.tv_sec - tstart.tv_sec,
 				TIMERSEC);
 		return PTS_FAIL;
 	}
testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c +33 -24

111 lines not on this page · raw message

------------------------------------------------------------------------------

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Hi!

Quoted 1 line

Also, why remove _XOPEN_SOURCE? Are you sure that this is correct?

The same is defined in the Makefile as -D_XOPEN_SOURCE=600 in CFLAGS

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#5 lore raw
In reply to a message not in the archive

Hi!

Quoted 32 lines
Quoted 5 lines

Slightly different patch to fix these tests is attached. The code is a little cleaner but basically does the same.

The tests now do

Quoted 7 lines

* get cputime
* set timer
* bussy loop while signal is not catched
* get cputime
* check that two stored cpu times differ approximately by timer interval

Also some more problems are fixed.

Could you please add...

#ifdef CLOCK_PROCESS_CPUTIME_ID
/* ... */
#else
int
main(void)

{
    printf("CLOCK_PROCESS_CPUTIME_ID not supported\n");
    return PTS_UNSUPPORTED;
}

#endif

...? The constant is optional according to POSIX 2008.1:

"[CPT][Option Start] Process CPU-Time Clocks [Option End] The functionality described is optional. The functionality described is also an extension to the ISO C standard.

Quoted 8 lines

[TMR][Option Start] Timers [Option End]
The functionality described is optional. The functionality described is also an extension to the ISO C standard.

Where applicable, functions are marked with the TMR margin legend in the SYNOPSIS section. Where additional semantics apply to a function, the material is identified by use of the TMR margin legend."

Here you are.

(I also noted that previous patch was by accident using
CLOCK_PROCESS_CPUTIME_ID to get elapsed time in 11-1.c, this is fixed too)

Notable changes:

* changed tests to do a bussy loop waiting as cpu time is not counted up in any of the sleep functions

* removed printf() from signal handlers as printf() is not async-signal-safe function

* added check for optional CLOCK_PROCESS_CPUTIME_ID

* coding style cleanup

Signature · 2 lines
Cyril Hrubis
[email protected]
testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c +38 -20
index 56ffbbd..3e105f9 100644
@@ -10,8 +10,6 @@
  * Same test as 1-1.c.
  */
 
-#define _XOPEN_SOURCE 600
-
 #include <time.h>
 #include <signal.h>
 #include <stdio.h>
@@ -21,14 +19,16 @@
 
 #define SIGTOTEST SIGALRM
 #define TIMERSEC 2
-#define SLEEPDELTA 3
 #define ACCEPTABLEDELTA 1
 
-void handler(int signo)
+static int endflg = 0;
+
+static void handler(int signo)
 {
-	printf("Caught signal\n");
+	endflg = 1;
 }
 
+#ifdef CLOCK_PROCESS_CPUTIME_ID
 int main(int argc, char *argv[])
 {
 #if _POSIX_CPUTIME == -1
@@ -39,33 +39,33 @@ int main(int argc, char *argv[])
 	struct sigaction act;
 	timer_t tid;
 	struct itimerspec its;
-	struct timespec ts, tsleft;
+	struct timespec tstart, tstop;
 	int rc;
 
 	rc = sysconf(_SC_CPUTIME);
 	printf("sysconf(_SC_CPUTIME) returns: %d\n", rc);
-	if (rc <= 0) {
-		return PTS_UNRESOLVED;	
+
+	if (rc == -1) {
+		printf("_POSIX_CPUTIME unsupported\n");
+		return PTS_UNSUPPORTED;
 	}
-		
+
 	ev.sigev_notify = SIGEV_SIGNAL;
 	ev.sigev_signo = SIGTOTEST;
 
-	act.sa_handler=handler;
-	act.sa_flags=0;
+	act.sa_handler = handler;
+	act.sa_flags = 0;
 
 	its.it_interval.tv_sec = 0;
 	its.it_interval.tv_nsec = 0;
 	its.it_value.tv_sec = TIMERSEC;
 	its.it_value.tv_nsec = 0;
 
-	ts.tv_sec=TIMERSEC+SLEEPDELTA;
-	ts.tv_nsec=0;
-
 	if (sigemptyset(&act.sa_mask) == -1) {
 		perror("Error calling sigemptyset");
 		return PTS_UNRESOLVED;
 	}
+
 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
 		perror("Error calling sigaction");
 		return PTS_UNRESOLVED;
@@ -76,23 +76,34 @@ int main(int argc, char *argv[])
 		return PTS_UNRESOLVED;
 	}
 
+	if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tstart) != 0) {
+		perror("clock_gettime() failed");
+		return PTS_UNRESOLVED;
+	}
+
 	if (timer_settime(tid, 0, &its, NULL) != 0) {
 		perror("timer_settime() did not return success");
 		return PTS_UNRESOLVED;
 	}
 
-	if (nanosleep(&ts, &tsleft) != -1) {
-		perror("nanosleep() not interrupted");
-		return PTS_FAIL;
+	/*
+	 * We need to bussy loop here as the timer is set to wait for 2 seconds
+	 * of cputime of this process (which doesn't tick in any sleep function)
+	 */
+	while (!endflg);
+
+	if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tstop) != 0) {
+		perror("clock_gettime() failed");
+		return PTS_UNRESOLVED;
 	}
 
-	if (abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) {
-		printf("Test PASSED");
+	if (abs(tstop.tv_sec - tstart.tv_sec - TIMERSEC) <= ACCEPTABLEDELTA) {
+		printf("Test PASSED\n");
 		return PTS_PASS;
 	} else {
 		printf("Timer did not last for correct amount of time\n");
 		printf("timer: %d != correct %d\n", 
-				(int) ts.tv_sec- (int) tsleft.tv_sec,
+				(int) tstop.tv_sec - tstart.tv_sec,
 				TIMERSEC);
 		return PTS_FAIL;
 	}
@@ -100,3 +111,10 @@ int main(int argc, char *argv[])
 	return PTS_UNRESOLVED;
 #endif
 }
+#else
+int main(void)
+{
+	printf("CLOCK_PROCESS_CPUTIME_ID not supported\n");
+	return PTS_UNSUPPORTED;
+}
+#endif
testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c +33 -24

111 lines not on this page · raw message

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how to connect the dots, take your collaborative environment to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#6 lore raw

Hi!

ping.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#7 lore raw
In reply to Cyril Hrubis

Hi!
Garrett could you, pretty please, review/commit the patch.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

Hi!

Quoted 5 lines
Quoted 2 lines

Hi!
Garrett could you, pretty please, review/commit the patch.

Just for future reference:

Quoted 8 lines

1. All variables static to main are pre-initialized to 0 by default according to ANSI-C (see: http://en.wikipedia.org/wiki/.bss ) .
2. I removed the printf's for sysconf(_SC_CPUTIME) because it was unnecessary.
3. The sysconf call for the CLOCK_THREAD_CPUTIME_ID was wrong.
4. sysconf should always return -1 when unsupported, not 0.

Could you please provide a diff from the version I'm about ready to commit so I can determine what needs to be fixed, and why?

The outstanding problems are:

You should not call printf() from signal handler.

Misplaced whitespace after while (!caught_signal) ;

You should get rather difference on cputime timers than on system timers that count's time rather than proces cpu time.

Patch for latest git attached.

Signature · 2 lines
Cyril Hrubis
[email protected]
testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c +16 -20
index 199c2bb..0cdc456 100644
@@ -19,12 +19,12 @@
 
 #define SIGTOTEST SIGALRM
 #define TIMERSEC 2
+#define DELTA 1
 
 int caught_signal;
 
 void handler(int signo)
 {
-	printf("Caught signal\n");
 	caught_signal = 1;
 }
 
@@ -38,9 +38,8 @@ int main(int argc, char *argv[])
 	struct sigaction act;
 	timer_t tid;
 	struct itimerspec its;
-	struct timespec ts, tsleft;
-	time_t start_time, end_time;
-	int overrun_amount, rc;
+	struct timespec start_time, stop_time;
+	int rc;
 
 	rc = sysconf(_SC_CPUTIME);
 	if (rc == -1) {
@@ -69,41 +68,38 @@ int main(int argc, char *argv[])
 		return PTS_UNRESOLVED;
 	}
 
-	if (time(&start_time) == -1) {
-		perror("time failed");
-		return PTS_UNRESOLVED;
-	}
-
 	if (timer_create(CLOCK_PROCESS_CPUTIME_ID, &ev, &tid) != 0) {
 		perror("timer_create did not return success");
 		return PTS_UNRESOLVED;
 	}
-
-	if (timer_settime(tid, 0, &its, NULL) != 0) {
-		perror("timer_settime did not return success");
+	
+	if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time) == -1) {
+		perror("clock_gettime failed");
 		return PTS_UNRESOLVED;
 	}
 
-	while (!caught_signal) ;
-
-	if (time(&end_time) == -1) {
-		perror("time failed");
+	if (timer_settime(tid, 0, &its, NULL) != 0) {
+		perror("timer_settime did not return success");
 		return PTS_UNRESOLVED;
 	}
 
-	if ((overrun_amount = timer_getoverrun(tid)) == -1) {
-		perror("timer_getoverrun failed");
+	while (!caught_signal);
+	
+	if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &stop_time) == -1) {
+		perror("clock_gettime failed");
 		return PTS_UNRESOLVED;
 	}
 
-	if ((end_time - start_time) == (TIMERSEC + overrun_amount)) {
+	if (abs((stop_time.tv_sec - start_time.tv_sec) - TIMERSEC) < DELTA) {
 		printf("Test PASSED\n");
 		return PTS_PASS;
 	}
 
 	printf("Timer did not last for correct amount of time\n"
 		"timer: %d != correct %d\n",
-		(int) (end_time - start_time), TIMERSEC + overrun_amount);
+		(int) (stop_time.tv_sec - start_time.tv_sec),
+		TIMERSEC);
+	
 	return PTS_FAIL;
 #endif
 }
testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c +16 -20
index 2e0cf09..d193bf5 100644
@@ -19,12 +19,12 @@
 
 #define SIGTOTEST SIGALRM
 #define TIMERSEC 2
+#define DELTA 1
 
 int caught_signal;
 
 void handler(int signo)
 {
-	printf("Caught signal\n");
 	caught_signal = 1;
 }
 
@@ -38,9 +38,8 @@ int main(int argc, char *argv[])
 	struct sigaction act;
 	timer_t tid;
 	struct itimerspec its;
-	struct timespec ts, tsleft;
-	time_t start_time, end_time;
-	int overrun_amount, rc;
+	struct timespec start_time, stop_time;
+	int rc;
 
 	rc = sysconf(_SC_THREAD_CPUTIME);
 	if (rc == -1) {
@@ -69,41 +68,38 @@ int main(int argc, char *argv[])
 		return PTS_UNRESOLVED;
 	}
 
-	if (time(&start_time) == -1) {
-		perror("time failed");
-		return PTS_UNRESOLVED;
-	}
-
 	if (timer_create(CLOCK_THREAD_CPUTIME_ID, &ev, &tid) != 0) {
 		perror("timer_create did not return success");
 		return PTS_UNRESOLVED;
 	}
-
-	if (timer_settime(tid, 0, &its, NULL) != 0) {
-		perror("timer_settime did not return success");
+	
+	if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start_time) == -1) {
+		perror("clock_gettime failed");
 		return PTS_UNRESOLVED;
 	}
 
-	while (!caught_signal) ;
-
-	if (time(&end_time) == -1) {
-		perror("time failed");
+	if (timer_settime(tid, 0, &its, NULL) != 0) {
+		perror("timer_settime did not return success");
 		return PTS_UNRESOLVED;
 	}
 
-	if ((overrun_amount = timer_getoverrun(tid)) == -1) {
-		perror("timer_getoverrun failed");
+	while (!caught_signal);
+	
+	if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &stop_time) == -1) {
+		perror("clock_gettime failed");
 		return PTS_UNRESOLVED;
 	}
 
-	if ((end_time - start_time) == (TIMERSEC + overrun_amount)) {
+	if (abs((stop_time.tv_sec - start_time.tv_sec) - TIMERSEC) < DELTA) {
 		printf("Test PASSED\n");
 		return PTS_PASS;
 	}
 
 	printf("Timer did not last for correct amount of time\n"
 		"timer: %d != correct %d\n",
-		(int) (end_time - start_time), TIMERSEC + overrun_amount);
+		(int) (stop_time.tv_sec - start_time.tv_sec),
+		TIMERSEC);
+
 	return PTS_FAIL;
 #endif
 }

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw

Hi!

Quoted 8 lines
Quoted 1 line

Misplaced whitespace after while (!caught_signal) ;

Both of us are wrong. K&R says it should be:

while (!caught_signal)
; /* With the correct amount of indentation here of course. */

LKML always defers to K&R unless stated otherwise.

Hmm, I'm still not sure. LKML does cite the K&R but but I don't think that it's set as base coding style. And lindent script seems to format this as:

while (!caught_signal) ;

So it looks like LKML conding style just sets some boundaries and general ideas what to do and what not.

Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list