Module: xenomai-2.6
Branch: master
Commit: a0d24693846df84bad19967804f46f4ee4f2e746
URL:    
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=a0d24693846df84bad19967804f46f4ee4f2e746

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sat Jan 14 16:25:36 2012 +0100

xeno-test: use monotonic time

In order to avoid LTP tests using settimeofday creating false timeout
conditions.

---

 src/testsuite/xeno-test/Makefile.am     |    1 +
 src/testsuite/xeno-test/Makefile.in     |    3 ++-
 src/testsuite/xeno-test/xeno-test-run.c |   17 +++++++++++++----
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/testsuite/xeno-test/Makefile.am 
b/src/testsuite/xeno-test/Makefile.am
index 0a55b32..7a59fcb 100644
--- a/src/testsuite/xeno-test/Makefile.am
+++ b/src/testsuite/xeno-test/Makefile.am
@@ -5,6 +5,7 @@ test_PROGRAMS = xeno-test-run
 bin_SCRIPTS = xeno-test
 
 xeno_test_run_CPPFLAGS = -DTESTDIR=\"$(testdir)\"
+xeno_test_run_LDADD = -lrt
 
 xeno-test: $(srcdir)/xeno-test.in Makefile
        sed "s,@testdir@,$(testdir)," $< > $@
diff --git a/src/testsuite/xeno-test/Makefile.in 
b/src/testsuite/xeno-test/Makefile.in
index ca53daa..ad33119 100644
--- a/src/testsuite/xeno-test/Makefile.in
+++ b/src/testsuite/xeno-test/Makefile.in
@@ -59,7 +59,7 @@ am__installdirs = "$(DESTDIR)$(testdir)" 
"$(DESTDIR)$(bindir)" \
 PROGRAMS = $(test_PROGRAMS)
 xeno_test_run_SOURCES = xeno-test-run.c
 xeno_test_run_OBJECTS = xeno_test_run-xeno-test-run.$(OBJEXT)
-xeno_test_run_LDADD = $(LDADD)
+xeno_test_run_DEPENDENCIES =
 am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
 am__vpath_adj = case $$p in \
     $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@@ -258,6 +258,7 @@ testdir = @XENO_TEST_DIR@
 test_SCRIPTS = xeno-test-run-wrapper dohell
 bin_SCRIPTS = xeno-test
 xeno_test_run_CPPFLAGS = -DTESTDIR=\"$(testdir)\"
+xeno_test_run_LDADD = -lrt
 EXTRA_DIST = $(test_SCRIPTS) xeno-test.in
 CLEANFILES = xeno-test
 all: all-am
diff --git a/src/testsuite/xeno-test/xeno-test-run.c 
b/src/testsuite/xeno-test/xeno-test-run.c
index 69d10b1..2761d64 100644
--- a/src/testsuite/xeno-test/xeno-test-run.c
+++ b/src/testsuite/xeno-test/xeno-test-run.c
@@ -10,6 +10,7 @@
 #include <signal.h>
 #include <sys/wait.h>
 #include <sys/select.h>
+#include <time.h>
 
 #define CHILD_SCRIPT  0
 #define CHILD_CHECKED 1
@@ -47,6 +48,13 @@ void handle_checked_child(struct child *child, fd_set *fds);
 void handle_script_child(struct child *child, fd_set *fds);
 void handle_load_child(struct child *child, fd_set *fds);
 
+static inline time_t mono_time(void)
+{
+       struct timespec ts;
+       clock_gettime(CLOCK_MONOTONIC, &ts);
+       return ts.tv_sec;
+}
+
 int child_initv(struct child *child, int type, char *argv[])
 {
        int pipe_in[2];
@@ -302,7 +310,7 @@ void cleanup(void)
 void termsig(int sig)
 {
        sigexit = sig;
-       sigexit_start = time(NULL);
+       sigexit_start = mono_time();
        children_kill(CHILD_ANY, SIGTERM);
        signal(sig, SIG_DFL);
 }
@@ -335,7 +343,7 @@ void copy(int from, int to)
 
 void handle_checked_child(struct child *child, fd_set *fds)
 {
-       time_t now = time(NULL);
+       time_t now = mono_time();
 
        if (FD_ISSET(child->out, fds)) {
                copy(child->out, STDOUT_FILENO);
@@ -445,7 +453,7 @@ void handle_load_child(struct child *child, fd_set *fds)
                copy(child->out, STDOUT_FILENO);
 
        if (child->dead) {
-               time_t now = time(NULL);
+               time_t now = mono_time();
 
                if (!termload_start) {
                        if (sigexit) {
@@ -506,6 +514,7 @@ void setpath(void)
                snprintf(path, path_len, TESTDIR);
 
        setenv("PATH", path, 1);
+       free(path);
 }
 
 int main(int argc, char *argv[])
@@ -612,7 +621,7 @@ int main(int argc, char *argv[])
                        child->handle(child, &in);
                }
 
-               if (sigexit_start && time(NULL) >= sigexit_start + 30) {
+               if (sigexit_start && mono_time() >= sigexit_start + 30) {
                        fail_fprintf(stderr, "timeout waiting for all "
                                     "children, sending SIGKILL\n");
                        children_kill(CHILD_ANY, SIGKILL);


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to