summary refs log tree commit diff
path: root/rt
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2004-12-06 22:28:45 +0000
committerRoland McGrath <roland@gnu.org>2004-12-06 22:28:45 +0000
commitbc5cb1e6aaa5f50f7ec508c1f0c1d8a539da0fcd (patch)
treeec842c8e567974c466da767e2daeff0b5331bf2f /rt
parentd8f73de86a4073070f5b626dc66a330d1597df88 (diff)
downloadglibc-bc5cb1e6aaa5f50f7ec508c1f0c1d8a539da0fcd.tar.gz
glibc-bc5cb1e6aaa5f50f7ec508c1f0c1d8a539da0fcd.tar.xz
glibc-bc5cb1e6aaa5f50f7ec508c1f0c1d8a539da0fcd.zip
2004-12-06 Roland McGrath <roland@redhat.com>
	* rt/tst-timer4.c (TEST_CLOCK, TEST_CLOCK_NANOSLEEP): New macros.
	Use them throughout in place of CLOCK_REALTIME and nanosleep.
	(do_test) [TEST_CLOCK_MISSING]: Call this macro and if it returns
	non-null, punt the test with a message using the string returned.
	* rt/tst-timer5.c: New file.
	* rt/Makefile (tests): Add it.
Diffstat (limited to 'rt')
-rw-r--r--rt/Makefile2
-rw-r--r--rt/tst-timer4.c39
-rw-r--r--rt/tst-timer5.c14
3 files changed, 41 insertions, 14 deletions
diff --git a/rt/Makefile b/rt/Makefile
index 29e7f847e4..407cc99897 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -45,7 +45,7 @@ tests := tst-shm tst-clock tst-clock_nanosleep tst-timer tst-timer2 \
 	 tst-aio tst-aio64 tst-aio2 tst-aio3 tst-aio4 tst-aio5 tst-aio6 \
 	 tst-aio7 tst-mqueue1 tst-mqueue2 tst-mqueue3 tst-mqueue4 \
 	 tst-mqueue5 tst-mqueue6 tst-mqueue7 tst-mqueue8 tst-mqueue9 \
-	 tst-timer3 tst-timer4
+	 tst-timer3 tst-timer4 tst-timer5
 
 extra-libs := librt
 extra-libs-others := $(extra-libs)
diff --git a/rt/tst-timer4.c b/rt/tst-timer4.c
index bc5d14e5b7..5bec01181d 100644
--- a/rt/tst-timer4.c
+++ b/rt/tst-timer4.c
@@ -27,6 +27,10 @@
 #if _POSIX_THREADS
 # include <pthread.h>
 
+# ifndef TEST_CLOCK
+#  define TEST_CLOCK		CLOCK_REALTIME
+# endif
+
 pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
 
@@ -40,7 +44,7 @@ static void
 thr1 (union sigval sigval)
 {
   pthread_mutex_lock (&lock);
-  thr1_err = clock_gettime (CLOCK_REALTIME, &thr1_ts);
+  thr1_err = clock_gettime (TEST_CLOCK, &thr1_ts);
   if (thr1_cnt >= 5)
     {
       struct itimerspec it = { };
@@ -86,7 +90,7 @@ thr2 (union sigval sigval)
         }
     }
   pthread_mutex_lock (&lock);
-  thr2_err = clock_gettime (CLOCK_REALTIME, &thr2_ts) | err;
+  thr2_err = clock_gettime (TEST_CLOCK, &thr2_ts) | err;
   if (thr2_cnt >= 5)
     {
       struct itimerspec it = { };
@@ -110,7 +114,7 @@ sig1_handler (int sig, siginfo_t *info, void *ctx)
   if (sig != SIGRTMIN) err |= 1 << 0;
   if (info->si_signo != SIGRTMIN) err |= 1 << 1;
   if (info->si_code != SI_TIMER) err |= 1 << 2;
-  if (clock_gettime (CLOCK_REALTIME, &sig1_ts) != 0)
+  if (clock_gettime (TEST_CLOCK, &sig1_ts) != 0)
     err |= 1 << 3;
   if (sig1_cnt >= 5)
     {
@@ -134,7 +138,7 @@ sig2_handler (int sig, siginfo_t *info, void *ctx)
   if (sig != SIGRTMIN + 1) err |= 1 << 0;
   if (info->si_signo != SIGRTMIN + 1) err |= 1 << 1;
   if (info->si_code != SI_TIMER) err |= 1 << 2;
-  if (clock_gettime (CLOCK_REALTIME, &sig2_ts) != 0)
+  if (clock_gettime (TEST_CLOCK, &sig2_ts) != 0)
     err |= 1 << 3;
   if (sig2_cnt >= 5)
     {
@@ -181,8 +185,17 @@ do_test (void)
 {
   int result = 0;
 
+#ifdef TEST_CLOCK_MISSING
+  const char *missing = TEST_CLOCK_MISSING (TEST_CLOCK);
+  if (missing != NULL)
+    {
+      printf ("%s missing, skipping test\n", missing);
+      return 0;
+    }
+#endif
+
   struct timespec ts;
-  if (clock_gettime (CLOCK_REALTIME, &ts) != 0)
+  if (clock_gettime (TEST_CLOCK, &ts) != 0)
     {
       printf ("*** clock_gettime failed: %m\n");
       result = 1;
@@ -191,7 +204,7 @@ do_test (void)
     printf ("clock_gettime returned timespec = { %ld, %ld }\n",
 	    (long) ts.tv_sec, ts.tv_nsec);
 
-  if (clock_getres (CLOCK_REALTIME, &ts) != 0)
+  if (clock_getres (TEST_CLOCK, &ts) != 0)
     {
       printf ("*** clock_getres failed: %m\n");
       result = 1;
@@ -203,7 +216,7 @@ do_test (void)
   struct sigevent ev;
   memset (&ev, 0x11, sizeof (ev));
   ev.sigev_notify = SIGEV_NONE;
-  if (timer_create (CLOCK_REALTIME, &ev, &timer_none) != 0)
+  if (timer_create (TEST_CLOCK, &ev, &timer_none) != 0)
     {
       printf ("*** timer_create for timer_none failed: %m\n");
       return 1;
@@ -220,7 +233,7 @@ do_test (void)
   ev.sigev_notify = SIGEV_SIGNAL;
   ev.sigev_signo = SIGRTMIN;
   ev.sigev_value.sival_ptr = &ev;
-  if (timer_create (CLOCK_REALTIME, &ev, &timer_sig1) != 0)
+  if (timer_create (TEST_CLOCK, &ev, &timer_sig1) != 0)
     {
       printf ("*** timer_create for timer_sig1 failed: %m\n");
       return 1;
@@ -230,7 +243,7 @@ do_test (void)
   ev.sigev_notify = SIGEV_SIGNAL;
   ev.sigev_signo = SIGRTMIN + 1;
   ev.sigev_value.sival_int = 163;
-  if (timer_create (CLOCK_REALTIME, &ev, &timer_sig2) != 0)
+  if (timer_create (TEST_CLOCK, &ev, &timer_sig2) != 0)
     {
       printf ("*** timer_create for timer_sig2 failed: %m\n");
       return 1;
@@ -241,7 +254,7 @@ do_test (void)
   ev.sigev_notify_function = thr1;
   ev.sigev_notify_attributes = NULL;
   ev.sigev_value.sival_ptr = &ev;
-  if (timer_create (CLOCK_REALTIME, &ev, &timer_thr1) != 0)
+  if (timer_create (TEST_CLOCK, &ev, &timer_thr1) != 0)
     {
       printf ("*** timer_create for timer_thr1 failed: %m\n");
       return 1;
@@ -260,7 +273,7 @@ do_test (void)
   ev.sigev_notify_function = thr2;
   ev.sigev_notify_attributes = &nattr;
   ev.sigev_value.sival_int = 111;
-  if (timer_create (CLOCK_REALTIME, &ev, &timer_thr2) != 0)
+  if (timer_create (TEST_CLOCK, &ev, &timer_thr2) != 0)
     {
       printf ("*** timer_create for timer_thr2 failed: %m\n");
       return 1;
@@ -330,7 +343,7 @@ do_test (void)
 #endif
 
   struct timespec startts;
-  if (clock_gettime (CLOCK_REALTIME, &startts) != 0)
+  if (clock_gettime (TEST_CLOCK, &startts) != 0)
     {
       printf ("*** clock_gettime failed: %m\n");
       result = 1;
@@ -482,7 +495,7 @@ do_test (void)
       result = 1;
     }
 
-  if (clock_gettime (CLOCK_REALTIME, &startts) != 0)
+  if (clock_gettime (TEST_CLOCK, &startts) != 0)
     {
       printf ("*** clock_gettime failed: %m\n");
       result = 1;
diff --git a/rt/tst-timer5.c b/rt/tst-timer5.c
new file mode 100644
index 0000000000..2683021eda
--- /dev/null
+++ b/rt/tst-timer5.c
@@ -0,0 +1,14 @@
+/* Timer test using the monotonic clock.  */
+
+#include <time.h>
+#include <unistd.h>
+
+#if defined CLOCK_MONOTONIC && defined _POSIX_MONOTONIC_CLOCK
+# define TEST_CLOCK	CLOCK_MONOTONIC
+# define TEST_CLOCK_MISSING(clock) \
+  (sysconf (_SC_MONOTONIC_CLOCK) > 0 ? NULL : #clock)
+# include "tst-timer4.c"
+#else
+# define TEST_FUNCTION	0
+# include "../test-skeleton.c"
+#endif