From: Bian Naimeng <biannm@cn.fujitsu.com>
To: Garrett Cooper <yanegomi@gmail.com>
Cc: ltp-list@lists.sourceforge.net
Subject: [LTP] [POSIX][PATCH] Fix bug of the test timer_create.
Date: Sat, 15 Jan 2011 10:45:49 +0800 [thread overview]
Message-ID: <4D310A5D.6000006@cn.fujitsu.com> (raw)
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
next reply other threads:[~2011-01-15 2:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-15 2:45 Bian Naimeng [this message]
2011-01-15 4:09 ` [LTP] [POSIX][PATCH] Fix bug of the test timer_create Garrett Cooper
2011-01-16 10:17 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D310A5D.6000006@cn.fujitsu.com \
--to=biannm@cn.fujitsu.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=yanegomi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox