* [LTP] [POSIX][PATCH] Fix bug of the test timer_create.
@ 2011-01-15 2:45 Bian Naimeng
2011-01-15 4:09 ` Garrett Cooper
0 siblings, 1 reply; 3+ messages in thread
From: Bian Naimeng @ 2011-01-15 2:45 UTC (permalink / raw)
To: Garrett Cooper; +Cc: ltp-list
CLOCK_THREAD_CPUTIME_ID and CLOCK_PROCESS_CPUTIME_ID are CPU-time clock,
so when the thread/process invokes nanosleep, these clocks will go sleeping
too.
Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com>
---
.../conformance/interfaces/timer_create/10-1.c | 36 +++++++++++++------
.../conformance/interfaces/timer_create/11-1.c | 35 +++++++++++++------
2 files changed, 48 insertions(+), 23 deletions(-)
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 27d5c1c..23a777e 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
@@ -24,9 +24,12 @@
#define SLEEPDELTA 3
#define ACCEPTABLEDELTA 1
+int caught = 0;
+
void handler(int signo)
{
printf("Caught signal\n");
+ caught = 1;
}
int main(int argc, char *argv[])
@@ -39,8 +42,8 @@ int main(int argc, char *argv[])
struct sigaction act;
timer_t tid;
struct itimerspec its;
- struct timespec ts, tsleft;
- int rc;
+ int rc, overrun = 0;
+ time_t stime = 0, etime = 0;
rc = sysconf(_SC_CPUTIME);
printf("sysconf(_SC_CPUTIME) returns: %d\n", rc);
@@ -59,9 +62,6 @@ int main(int argc, char *argv[])
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;
@@ -76,27 +76,39 @@ int main(int argc, char *argv[])
return PTS_UNRESOLVED;
}
+ if ((time_t)(-1) == time(&stime)) {
+ perror("time() 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");
- return PTS_FAIL;
+ while(!caught);
+
+ if ((time_t)(-1) == time(&etime)) {
+ perror("time() did not return success");
+ return PTS_UNRESOLVED;
+ }
+
+ if (-1 == (overrun = timer_getoverrun(tid))) {
+ perror("timer_getoverrun() did not return success");
+ return PTS_UNRESOLVED;
}
- if (abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) {
- printf("Test PASSED");
+ if (etime - stime == TIMERSEC + overrun) {
+ 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) etime - (int) stime,
TIMERSEC);
return PTS_FAIL;
}
return PTS_UNRESOLVED;
#endif
-}
\ No newline at end of file
+}
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 bd59e8f..c34b451 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
@@ -22,9 +22,12 @@
#define SLEEPDELTA 3
#define ACCEPTABLEDELTA 1
+int caught = 0;
+
void handler(int signo)
{
printf("Caught signal\n");
+ caught = 1;
}
int main(int argc, char *argv[])
@@ -38,7 +41,8 @@ int main(int argc, char *argv[])
struct sigaction act;
timer_t tid;
struct itimerspec its;
- struct timespec ts, tsleft;
+ time_t stime = 0, etime = 0;
+ int overrun = 0;
if (rc == -1) {
printf("_POSIX_THREAD_CPUTIME unsupported\n");
@@ -56,9 +60,6 @@ int main(int argc, char *argv[])
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;
@@ -73,23 +74,35 @@ int main(int argc, char *argv[])
return PTS_UNRESOLVED;
}
+ if ((time_t)(-1) == time(&stime)) {
+ perror("time() 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");
- return PTS_FAIL;
+ while(!caught);
+
+ if ((time_t)(-1) == time(&etime)) {
+ perror("time() did not return success");
+ return PTS_UNRESOLVED;
+ }
+
+ if (-1 == (overrun = timer_getoverrun(tid))) {
+ perror("timer_getoverrun() did not return success");
+ return PTS_UNRESOLVED;
}
- if (abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) {
- printf("Test PASSED");
+ if (etime - stime == TIMERSEC + overrun) {
+ 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) etime - (int) stime,
TIMERSEC);
return PTS_FAIL;
}
@@ -100,4 +113,4 @@ int main(int argc, char *argv[])
return PTS_UNSUPPORTED;
#endif
-}
\ No newline at end of file
+}
--
1.7.0.4
--
Regards
Bian Naimeng
------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [LTP] [POSIX][PATCH] Fix bug of the test timer_create.
2011-01-15 2:45 [LTP] [POSIX][PATCH] Fix bug of the test timer_create Bian Naimeng
@ 2011-01-15 4:09 ` Garrett Cooper
2011-01-16 10:17 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: Garrett Cooper @ 2011-01-15 4:09 UTC (permalink / raw)
To: Bian Naimeng; +Cc: ltp-list
On Fri, Jan 14, 2011 at 6:45 PM, Bian Naimeng <biannm@cn.fujitsu.com> wrote:
> CLOCK_THREAD_CPUTIME_ID and CLOCK_PROCESS_CPUTIME_ID are CPU-time clock,
> so when the thread/process invokes nanosleep, these clocks will go sleeping
> too.
Fixed -- thanks!
-Garrett
------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [LTP] [POSIX][PATCH] Fix bug of the test timer_create.
2011-01-15 4:09 ` Garrett Cooper
@ 2011-01-16 10:17 ` Cyril Hrubis
0 siblings, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2011-01-16 10:17 UTC (permalink / raw)
To: Garrett Cooper; +Cc: ltp-list
Hi!
> > CLOCK_THREAD_CPUTIME_ID and CLOCK_PROCESS_CPUTIME_ID are CPU-time clock,
> > so when the thread/process invokes nanosleep, these clocks will go sleeping
> > too.
I've send a sligtly better version of this patch a couple of weeks ago
and that was one of the patches I've been constantly reminding you
about.
I'm a little worried here that mixing time() that returns time since the
epoch and per process cpu timers wouldn't work on machine under load.
My patch uses only per cpu process timers so should be fine.
Could you please have a look at my version?
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-01-16 10:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-15 2:45 [LTP] [POSIX][PATCH] Fix bug of the test timer_create Bian Naimeng
2011-01-15 4:09 ` Garrett Cooper
2011-01-16 10:17 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox