* [LTP] [PATCH] fix "timer_create/10-1" and "timer_create/11-1" tests
@ 2010-11-29 6:21 Mitani
2010-12-10 14:49 ` Cyril Hrubis
0 siblings, 1 reply; 9+ messages in thread
From: Mitani @ 2010-11-29 6:21 UTC (permalink / raw)
To: ltp-list; +Cc: 當座 健市
[-- Attachment #1: Type: text/plain, Size: 5337 bytes --]
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.
Signed-off-by: Tomonori Mitani <mitani@ryobi.co.jp>
============
---
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
[-- Attachment #2: timer_create.patch --]
[-- Type: application/octet-stream, Size: 2356 bytes --]
--- 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");
[-- Attachment #3: Type: text/plain, Size: 402 bytes --]
------------------------------------------------------------------------------
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
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [LTP] [PATCH] fix "timer_create/10-1" and "timer_create/11-1" tests 2010-11-29 6:21 [LTP] [PATCH] fix "timer_create/10-1" and "timer_create/11-1" tests Mitani @ 2010-12-10 14:49 ` Cyril Hrubis [not found] ` <AANLkTimmkmk_H+AzYOGau6fr_BHChOCif7n=FOu2F14R@mail.gmail.com> 0 siblings, 1 reply; 9+ messages in thread From: Cyril Hrubis @ 2010-12-10 14:49 UTC (permalink / raw) To: Mitani; +Cc: ltp-list, ?$BaD:B ?$B7r;T [-- Attachment #1: Type: text/plain, Size: 407 bytes --] 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. Signed-off-by: Cyril Hrubis chrubis@suse.cz -- Cyril Hrubis chrubis@suse.cz [-- Attachment #2: timer_create_II.patch --] [-- Type: text/x-patch, Size: 6090 bytes --] diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c index 56ffbbd..3553f20 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c @@ -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; } diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c index 83e87e4..b703a16 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c @@ -19,26 +19,30 @@ #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[]) { - int rc; - rc = sysconf(_SC_THREAD_CPUTIME); - printf("rc = %d\n", rc); - -#if _POSIX_THREAD_CPUTIME != -1 +#if _POSIX_THREAD_CPUTIME == -1 + printf("_POSIX_THREAD_CPUTIME unsupported\n"); + return PTS_UNSUPPORTED; +#else struct sigevent ev; struct sigaction act; timer_t tid; struct itimerspec its; - struct timespec ts, tsleft; + struct timespec tstart, tstop; + int rc; + + rc = sysconf(_SC_THREAD_CPUTIME); + printf("sysconf(_SC_THREAD_CPUTIME) returns: %d\n", rc); if (rc == -1) { printf("_POSIX_THREAD_CPUTIME unsupported\n"); @@ -48,21 +52,19 @@ int main(int argc, char *argv[]) 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; @@ -73,31 +75,38 @@ 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; } return PTS_UNRESOLVED; -#else - printf("_POSIX_THREAD_CPUTIME unsupported\n"); - return PTS_UNSUPPORTED; #endif - } [-- Attachment #3: Type: text/plain, Size: 79 bytes --] ------------------------------------------------------------------------------ [-- Attachment #4: Type: text/plain, Size: 155 bytes --] _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply related [flat|nested] 9+ messages in thread
[parent not found: <AANLkTimmkmk_H+AzYOGau6fr_BHChOCif7n=FOu2F14R@mail.gmail.com>]
[parent not found: <AANLkTi=MnLYAt+Qdn9-_Pv8rze=Jcgy5c3n7r08UMthP@mail.gmail.com>]
* Re: [LTP] [PATCH] fix "timer_create/10-1" and "timer_create/11-1" tests [not found] ` <AANLkTi=MnLYAt+Qdn9-_Pv8rze=Jcgy5c3n7r08UMthP@mail.gmail.com> @ 2010-12-13 18:06 ` Cyril Hrubis 0 siblings, 0 replies; 9+ messages in thread From: Cyril Hrubis @ 2010-12-13 18:06 UTC (permalink / raw) To: Garrett Cooper; +Cc: ltp-list, ?$BaD:B ?$B7r, T, Mitani Hi! > 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 -- Cyril Hrubis chrubis@suse.cz ------------------------------------------------------------------------------ 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 Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH] fix "timer_create/10-1" and "timer_create/11-1" tests [not found] ` <AANLkTimmkmk_H+AzYOGau6fr_BHChOCif7n=FOu2F14R@mail.gmail.com> [not found] ` <AANLkTi=MnLYAt+Qdn9-_Pv8rze=Jcgy5c3n7r08UMthP@mail.gmail.com> @ 2010-12-13 18:53 ` Cyril Hrubis 2010-12-30 14:47 ` Cyril Hrubis 2011-01-06 15:25 ` Cyril Hrubis 1 sibling, 2 replies; 9+ messages in thread From: Cyril Hrubis @ 2010-12-13 18:53 UTC (permalink / raw) To: Garrett Cooper; +Cc: ltp-list, ?$BaD:B ?$B7r, T, Mitani [-- Attachment #1: Type: text/plain, Size: 1719 bytes --] 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. > > 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. > > [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 Signed-off-by: Cyril Hrubis <chrubis@suse.cz> -- Cyril Hrubis chrubis@suse.cz [-- Attachment #2: timer_create_III.patch --] [-- Type: text/x-patch, Size: 6357 bytes --] diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c index 56ffbbd..3e105f9 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c @@ -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 diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c index 83e87e4..0f7704f 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c @@ -19,26 +19,30 @@ #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[]) { - int rc; - rc = sysconf(_SC_THREAD_CPUTIME); - printf("rc = %d\n", rc); - -#if _POSIX_THREAD_CPUTIME != -1 +#if _POSIX_THREAD_CPUTIME == -1 + printf("_POSIX_THREAD_CPUTIME unsupported\n"); + return PTS_UNSUPPORTED; +#else struct sigevent ev; struct sigaction act; timer_t tid; struct itimerspec its; - struct timespec ts, tsleft; + struct timespec tstart, tstop; + int rc; + + rc = sysconf(_SC_THREAD_CPUTIME); + printf("sysconf(_SC_THREAD_CPUTIME) returns: %d\n", rc); if (rc == -1) { printf("_POSIX_THREAD_CPUTIME unsupported\n"); @@ -48,21 +52,19 @@ int main(int argc, char *argv[]) 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; @@ -73,31 +75,38 @@ int main(int argc, char *argv[]) return PTS_UNRESOLVED; } + if (clock_gettime(CLOCK_THREAD_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_THREAD_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; } return PTS_UNRESOLVED; -#else - printf("_POSIX_THREAD_CPUTIME unsupported\n"); - return PTS_UNSUPPORTED; #endif - } [-- Attachment #3: Type: text/plain, Size: 290 bytes --] ------------------------------------------------------------------------------ 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 [-- Attachment #4: Type: text/plain, Size: 155 bytes --] _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH] fix "timer_create/10-1" and "timer_create/11-1" tests 2010-12-13 18:53 ` Cyril Hrubis @ 2010-12-30 14:47 ` Cyril Hrubis 2011-01-06 15:25 ` Cyril Hrubis 1 sibling, 0 replies; 9+ messages in thread From: Cyril Hrubis @ 2010-12-30 14:47 UTC (permalink / raw) To: Garrett Cooper; +Cc: ltp-list, ?$BaD:B ?$B7r, T, Mitani Hi! ping. -- Cyril Hrubis chrubis@suse.cz ------------------------------------------------------------------------------ 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 Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH] fix "timer_create/10-1" and "timer_create/11-1" tests 2010-12-13 18:53 ` Cyril Hrubis 2010-12-30 14:47 ` Cyril Hrubis @ 2011-01-06 15:25 ` Cyril Hrubis [not found] ` <AANLkTi=YcasSVsYCX7gmkt2m7uBDBf3u=XvAAn=x3vSy@mail.gmail.com> 1 sibling, 1 reply; 9+ messages in thread From: Cyril Hrubis @ 2011-01-06 15:25 UTC (permalink / raw) To: Garrett Cooper; +Cc: ltp-list, ?$BaD:B ?$B7r, T, Mitani Hi! Garrett could you, pretty please, review/commit the patch. -- Cyril Hrubis chrubis@suse.cz ------------------------------------------------------------------------------ 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 Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <AANLkTi=YcasSVsYCX7gmkt2m7uBDBf3u=XvAAn=x3vSy@mail.gmail.com>]
* Re: [LTP] [PATCH] fix "timer_create/10-1" and "timer_create/11-1" tests [not found] ` <AANLkTi=YcasSVsYCX7gmkt2m7uBDBf3u=XvAAn=x3vSy@mail.gmail.com> @ 2011-01-16 14:09 ` Cyril Hrubis [not found] ` <AANLkTi=DyeO5E7MWR=SbB=N24PafZwmQFqS6d2mhbZiL@mail.gmail.com> 0 siblings, 1 reply; 9+ messages in thread From: Cyril Hrubis @ 2011-01-16 14:09 UTC (permalink / raw) To: Garrett Cooper; +Cc: ltp-list, ?$BaD:B ?$B7r, T, Mitani [-- Attachment #1: Type: text/plain, Size: 957 bytes --] Hi! > > Hi! > > Garrett could you, pretty please, review/commit the patch. > > Just for future reference: > > 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. Signed-off-by: Cyril Hrubis <chrubis@suse.cz> -- Cyril Hrubis chrubis@suse.cz [-- Attachment #2: timer_create_fix.patch --] [-- Type: text/x-patch, Size: 4643 bytes --] diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c index 199c2bb..0cdc456 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/10-1.c @@ -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 } diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c index 2e0cf09..d193bf5 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_create/11-1.c @@ -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 } [-- Attachment #3: Type: text/plain, Size: 372 bytes --] ------------------------------------------------------------------------------ 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 [-- Attachment #4: Type: text/plain, Size: 155 bytes --] _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply related [flat|nested] 9+ messages in thread
[parent not found: <AANLkTi=DyeO5E7MWR=SbB=N24PafZwmQFqS6d2mhbZiL@mail.gmail.com>]
* Re: [LTP] [PATCH] fix "timer_create/10-1" and "timer_create/11-1" tests [not found] ` <AANLkTi=DyeO5E7MWR=SbB=N24PafZwmQFqS6d2mhbZiL@mail.gmail.com> @ 2011-01-24 16:59 ` Cyril Hrubis 0 siblings, 0 replies; 9+ messages in thread From: Cyril Hrubis @ 2011-01-24 16:59 UTC (permalink / raw) To: Garrett Cooper; +Cc: ltp-list, ?$BaD:B ?$B7r, T, Mitani Hi! > > 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. -- Cyril Hrubis chrubis@suse.cz ------------------------------------------------------------------------------ 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 Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH] fix \"timer_create/10-1\" and \"timer_create/11-1\" tests @ 2010-12-07 10:08 Mitani 0 siblings, 0 replies; 9+ messages in thread From: Mitani @ 2010-12-07 10:08 UTC (permalink / raw) To: ltp-list Hi, How about my patch for "timer_create/10-1" and "11-1"? I am glad if I get some opinion. Regards-- -Tomonori Mitani ------------------------------------------------------------------------------ What happens now with your Lotus Notes apps - do you make another costly upgrade, or settle for being marooned without product support? Time to move off Lotus Notes and onto the cloud with Force.com, apps are easier to build, use, and manage than apps on traditional platforms. Sign up for the Lotus Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-01-24 16:42 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-29 6:21 [LTP] [PATCH] fix "timer_create/10-1" and "timer_create/11-1" tests Mitani
2010-12-10 14:49 ` Cyril Hrubis
[not found] ` <AANLkTimmkmk_H+AzYOGau6fr_BHChOCif7n=FOu2F14R@mail.gmail.com>
[not found] ` <AANLkTi=MnLYAt+Qdn9-_Pv8rze=Jcgy5c3n7r08UMthP@mail.gmail.com>
2010-12-13 18:06 ` Cyril Hrubis
2010-12-13 18:53 ` Cyril Hrubis
2010-12-30 14:47 ` Cyril Hrubis
2011-01-06 15:25 ` Cyril Hrubis
[not found] ` <AANLkTi=YcasSVsYCX7gmkt2m7uBDBf3u=XvAAn=x3vSy@mail.gmail.com>
2011-01-16 14:09 ` Cyril Hrubis
[not found] ` <AANLkTi=DyeO5E7MWR=SbB=N24PafZwmQFqS6d2mhbZiL@mail.gmail.com>
2011-01-24 16:59 ` Cyril Hrubis
-- strict thread matches above, loose matches on Subject: below --
2010-12-07 10:08 [LTP] [PATCH] fix \"timer_create/10-1\" and \"timer_create/11-1\" tests Mitani
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox