Module: xenomai-jki
Branch: queues/assorted
Commit: 164c50603d9fad92c266d0b58dee669f4fd5f1b5
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=164c50603d9fad92c266d0b58dee669f4fd5f1b5

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Sat Mar  6 08:43:32 2010 +0100

testsuite: Timed cond_wait test

---

 src/testsuite/unit/mutex-torture.c |   56 ++++++++++++++++++++++++++++++++++--
 1 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/src/testsuite/unit/mutex-torture.c 
b/src/testsuite/unit/mutex-torture.c
index ebcb882..5f84652 100644
--- a/src/testsuite/unit/mutex-torture.c
+++ b/src/testsuite/unit/mutex-torture.c
@@ -36,9 +36,10 @@
 #define COND_CREATE            7
 #define COND_SIGNAL            8
 #define COND_WAIT              9
-#define COND_DESTROY           10
-#define THREAD_DETACH          11
-#define THREAD_CREATE          12
+#define COND_TIMED_WAIT                10
+#define COND_DESTROY           11
+#define THREAD_DETACH          12
+#define THREAD_CREATE          13
 
 #define NS_PER_MS      1000000
 
@@ -246,6 +247,19 @@ int dispatch(const char *service_name, int service_type, 
int check, ...)
 #endif /* __NATIVE_SKIN__ */
                break;
 
+       case COND_TIMED_WAIT:
+               cond = va_arg(ap, cond_t *);
+               mutex = va_arg(ap, mutex_t *);
+               timeout = va_arg(ap, unsigned long long);
+#ifdef XENO_POSIX
+               clock_gettime(CLOCK_REALTIME, &ts);
+               timespec_add(&ts, timeout);
+               status = pthread_cond_timedwait(cond, mutex, &ts);
+#else /* __NATIVE_SKIN__ */
+               status = -rt_cond_wait(cond, mutex, timeout);
+#endif /* __NATIVE_SKIN__ */
+               break;
+
        case COND_DESTROY:
 #ifdef XENO_POSIX
                status = pthread_cond_destroy(va_arg(ap, pthread_cond_t *));
@@ -718,6 +732,41 @@ void recursive_condwait(void)
        dispatch("rec_condwait cond_destroy", COND_DESTROY, 1, &cond);
 }
 
+void timed_condwait(void)
+{
+       unsigned long long start, diff;
+       mutex_t mutex;
+       cond_t cond;
+       int result;
+
+       fprintf(stderr, "timed_condwait\n");
+
+       dispatch("timed_condwait mutex_init", MUTEX_CREATE, 1, &mutex);
+       dispatch("timed_condwait cond_init", COND_CREATE, 1, &cond);
+       dispatch("timed_condwait mutex_lock", MUTEX_LOCK, 1, &mutex);
+
+       start = rt_timer_tsc();
+       result = dispatch("timed_condwait cond_timed_wait", COND_TIMED_WAIT,
+                         0, &cond, &mutex, 10000000);
+       diff = rt_timer_tsc2ns(rt_timer_tsc() - start);
+
+       if (result != ETIMEDOUT) {
+               fprintf(stderr,
+                       "FAILURE: main cond_timed_wait: %i (%s)\n",
+                       result, strerror(result));
+               exit(EXIT_FAILURE);
+       }
+       if (diff < 10000000) {
+               fprintf(stderr, "FAILURE: main, waited %Ld.%03u us\n",
+                       diff / 1000, (unsigned) (diff % 1000));
+               exit(EXIT_FAILURE);
+       }
+       dispatch("simple_condwait mutex_unlock", MUTEX_UNLOCK, 1, &mutex);
+
+       dispatch("simple_condwait mutex_destroy", MUTEX_DESTROY, 1, &mutex);
+       dispatch("simple_condwait cond_destroy", COND_DESTROY, 1, &cond);
+}
+
 int main(void)
 {
 #ifdef XENO_POSIX
@@ -746,6 +795,7 @@ int main(void)
        lock_stealing();
        simple_condwait();
        recursive_condwait();
+       timed_condwait();
        fprintf(stderr, "Test OK\n");
        return 0;
 }


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

Reply via email to