[Xenomai-git] Gilles Chanteperdrix : regression: add clock_settime test

2014-06-01 Thread git repository hosting
Module: xenomai-gch
Branch: for-forge
Commit: 5fbfaeb911cc590a82f5b713d1231e20ec86a6be
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=5fbfaeb911cc590a82f5b713d1231e20ec86a6be

Author: Gilles Chanteperdrix 
Date:   Sun Jun  1 19:05:24 2014 +0200

regression: add clock_settime test

(bootstrap needed)

---

 testsuite/regression/posix/Makefile.am |1 +
 testsuite/regression/posix/clock_settime.c |  224 
 2 files changed, 225 insertions(+)

diff --git a/testsuite/regression/posix/Makefile.am 
b/testsuite/regression/posix/Makefile.am
index 1a534a0..f975984 100644
--- a/testsuite/regression/posix/Makefile.am
+++ b/testsuite/regression/posix/Makefile.am
@@ -5,6 +5,7 @@ CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
 noinst_HEADERS = check.h
 
 test_PROGRAMS = \
+   clock_settime \
leaks \
mq_select \
timerfd
diff --git a/testsuite/regression/posix/clock_settime.c 
b/testsuite/regression/posix/clock_settime.c
new file mode 100644
index 000..5168ea1
--- /dev/null
+++ b/testsuite/regression/posix/clock_settime.c
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2014 Gilles Chanteperdrix 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#undef NDEBUG
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include "check.h"
+
+static void clock_increase_before_oneshot_timer_first_tick(void)
+{
+   unsigned long long ticks;
+   struct itimerspec timer;
+   struct timespec now;
+   int t;
+
+   check_unix(t = timerfd_create(CLOCK_REALTIME, 0));
+   check_unix(clock_gettime(CLOCK_REALTIME, &now));
+   timer.it_value = now;
+   timer.it_value.tv_sec++;
+   timer.it_interval.tv_sec = 0;
+   timer.it_interval.tv_nsec = 0;
+   check_unix(timerfd_settime(t, TFD_TIMER_ABSTIME, &timer, NULL));
+   now.tv_sec += 5;
+   check_unix(clock_settime(CLOCK_REALTIME, &now));
+   check_unix(clock_gettime(CLOCK_MONOTONIC, &now));
+   check_unix(read(t, &ticks, sizeof(ticks)));
+   assert(ticks == 1);
+   timer.it_value = now;
+   check_unix(clock_gettime(CLOCK_MONOTONIC, &now));
+   assert(now.tv_sec * 10ULL + now.tv_nsec -
+   (timer.it_value.tv_sec * 10ULL + timer.it_value.tv_nsec)
+   < 10);
+   check_unix(close(t));
+}
+
+static void clock_increase_before_periodic_timer_first_tick(void)
+{
+   unsigned long long ticks;
+   struct itimerspec timer;
+   struct timespec now;
+   int t;
+
+   check_unix(t = timerfd_create(CLOCK_REALTIME, 0));
+   check_unix(clock_gettime(CLOCK_REALTIME, &now));
+   timer.it_value = now;
+   timer.it_value.tv_sec++;
+   timer.it_interval.tv_sec = 1;
+   timer.it_interval.tv_nsec = 0;
+   check_unix(timerfd_settime(t, TFD_TIMER_ABSTIME, &timer, NULL));
+   now.tv_sec += 5;
+   check_unix(clock_settime(CLOCK_REALTIME, &now));
+   check_unix(clock_gettime(CLOCK_MONOTONIC, &now));
+   check_unix(read(t, &ticks, sizeof(ticks)));
+   assert(ticks == 5);
+   timer.it_value = now;
+   check_unix(clock_gettime(CLOCK_MONOTONIC, &now));
+   assert(now.tv_sec * 10ULL + now.tv_nsec -
+   (timer.it_value.tv_sec * 10ULL + timer.it_value.tv_nsec)
+   < 10);
+   check_unix(read(t, &ticks, sizeof(ticks)));
+   assert(ticks == 1);
+   check_unix(close(t));
+}
+
+static void clock_increase_after_periodic_timer_first_tick(void)
+{
+   unsigned long long ticks;
+   struct itimerspec timer;
+   struct timespec now;
+   int t;
+
+   check_unix(t = timerfd_create(CLOCK_REALTIME, 0));
+   check_unix(clock_gettime(CLOCK_REALTIME, &now));
+   timer.it_value = now;
+   timer.it_value.tv_sec++;
+   timer.it_interval.tv_sec = 1;
+   timer.it_interval.tv_nsec = 0;
+   check_unix(timerfd_setti

[Xenomai-git] Gilles Chanteperdrix : regression: add clock_settime test

2014-06-01 Thread git repository hosting
Module: xenomai-gch
Branch: for-forge
Commit: db641276a3c238d1aa30097626e36d698844c679
URL:
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=db641276a3c238d1aa30097626e36d698844c679

Author: Gilles Chanteperdrix 
Date:   Sun Jun  1 19:05:24 2014 +0200

regression: add clock_settime test

(bootstrap needed)

---

 testsuite/regression/posix/Makefile.am |1 +
 testsuite/regression/posix/clock_settime.c |  224 
 2 files changed, 225 insertions(+)

diff --git a/testsuite/regression/posix/Makefile.am 
b/testsuite/regression/posix/Makefile.am
index 1a534a0..f975984 100644
--- a/testsuite/regression/posix/Makefile.am
+++ b/testsuite/regression/posix/Makefile.am
@@ -5,6 +5,7 @@ CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC)
 noinst_HEADERS = check.h
 
 test_PROGRAMS = \
+   clock_settime \
leaks \
mq_select \
timerfd
diff --git a/testsuite/regression/posix/clock_settime.c 
b/testsuite/regression/posix/clock_settime.c
new file mode 100644
index 000..5168ea1
--- /dev/null
+++ b/testsuite/regression/posix/clock_settime.c
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2014 Gilles Chanteperdrix 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#undef NDEBUG
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include "check.h"
+
+static void clock_increase_before_oneshot_timer_first_tick(void)
+{
+   unsigned long long ticks;
+   struct itimerspec timer;
+   struct timespec now;
+   int t;
+
+   check_unix(t = timerfd_create(CLOCK_REALTIME, 0));
+   check_unix(clock_gettime(CLOCK_REALTIME, &now));
+   timer.it_value = now;
+   timer.it_value.tv_sec++;
+   timer.it_interval.tv_sec = 0;
+   timer.it_interval.tv_nsec = 0;
+   check_unix(timerfd_settime(t, TFD_TIMER_ABSTIME, &timer, NULL));
+   now.tv_sec += 5;
+   check_unix(clock_settime(CLOCK_REALTIME, &now));
+   check_unix(clock_gettime(CLOCK_MONOTONIC, &now));
+   check_unix(read(t, &ticks, sizeof(ticks)));
+   assert(ticks == 1);
+   timer.it_value = now;
+   check_unix(clock_gettime(CLOCK_MONOTONIC, &now));
+   assert(now.tv_sec * 10ULL + now.tv_nsec -
+   (timer.it_value.tv_sec * 10ULL + timer.it_value.tv_nsec)
+   < 10);
+   check_unix(close(t));
+}
+
+static void clock_increase_before_periodic_timer_first_tick(void)
+{
+   unsigned long long ticks;
+   struct itimerspec timer;
+   struct timespec now;
+   int t;
+
+   check_unix(t = timerfd_create(CLOCK_REALTIME, 0));
+   check_unix(clock_gettime(CLOCK_REALTIME, &now));
+   timer.it_value = now;
+   timer.it_value.tv_sec++;
+   timer.it_interval.tv_sec = 1;
+   timer.it_interval.tv_nsec = 0;
+   check_unix(timerfd_settime(t, TFD_TIMER_ABSTIME, &timer, NULL));
+   now.tv_sec += 5;
+   check_unix(clock_settime(CLOCK_REALTIME, &now));
+   check_unix(clock_gettime(CLOCK_MONOTONIC, &now));
+   check_unix(read(t, &ticks, sizeof(ticks)));
+   assert(ticks == 5);
+   timer.it_value = now;
+   check_unix(clock_gettime(CLOCK_MONOTONIC, &now));
+   assert(now.tv_sec * 10ULL + now.tv_nsec -
+   (timer.it_value.tv_sec * 10ULL + timer.it_value.tv_nsec)
+   < 10);
+   check_unix(read(t, &ticks, sizeof(ticks)));
+   assert(ticks == 1);
+   check_unix(close(t));
+}
+
+static void clock_increase_after_periodic_timer_first_tick(void)
+{
+   unsigned long long ticks;
+   struct itimerspec timer;
+   struct timespec now;
+   int t;
+
+   check_unix(t = timerfd_create(CLOCK_REALTIME, 0));
+   check_unix(clock_gettime(CLOCK_REALTIME, &now));
+   timer.it_value = now;
+   timer.it_value.tv_sec++;
+   timer.it_interval.tv_sec = 1;
+   timer.it_interval.tv_nsec = 0;
+   check_unix(timerfd_setti