Module: xenomai-3
Branch: arm64
Commit: a675f686d9a0b97a4cf397b11a6362787ee8a471
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=a675f686d9a0b97a4cf397b11a6362787ee8a471

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Fri Oct  2 23:06:14 2015 +0200

smokey/posix-cond: add testcase for autoinit

---

 testsuite/smokey/posix-cond/posix-cond.c |   53 ++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/testsuite/smokey/posix-cond/posix-cond.c 
b/testsuite/smokey/posix-cond/posix-cond.c
index 5429d1f..6c9a458 100644
--- a/testsuite/smokey/posix-cond/posix-cond.c
+++ b/testsuite/smokey/posix-cond/posix-cond.c
@@ -204,6 +204,35 @@ static void *cond_signaler(void *cookie)
        return NULL;
 }
 
+static void autoinit_simple_condwait(void)
+{
+       pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+       unsigned long long start;
+       pthread_mutex_t mutex;
+       struct cond_mutex cm = {
+               .mutex = &mutex,
+               .cond = &cond,
+       };
+       pthread_t cond_signaler_tid;
+
+       smokey_trace("%s", __func__);
+
+       check("mutex_init", mutex_init(&mutex, PTHREAD_MUTEX_DEFAULT, 0), 0);
+       check("mutex_lock", mutex_lock(&mutex), 0);
+       check("thread_spawn",
+             thread_spawn(&cond_signaler_tid, 2, cond_signaler, &cm), 0);
+       thread_msleep(11);
+
+       start = timer_get_tsc();
+       check("cond_wait", cond_wait(&cond, &mutex, 0), 0);
+       check_sleep("cond_wait", start);
+       thread_msleep(10);
+       check("mutex_unlock", mutex_unlock(&mutex), 0);
+       check("thread_join", thread_join(cond_signaler_tid), 0);
+       check("mutex_destroy", mutex_destroy(&mutex), 0);
+       check("cond_destroy", cond_destroy(&cond), 0);
+}
+
 static void simple_condwait(void)
 {
        unsigned long long start;
@@ -257,6 +286,28 @@ static void relative_condwait(void)
        check("cond_destroy", cond_destroy(&cond), 0);
 }
 
+static void autoinit_absolute_condwait(void)
+{
+       pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+       unsigned long long start;
+       pthread_mutex_t mutex;
+
+       smokey_trace("%s", __func__);
+
+       check("mutex_init", mutex_init(&mutex, PTHREAD_MUTEX_DEFAULT, 0), 0);
+       check("mutex_lock", mutex_lock(&mutex), 0);
+
+       start = timer_get_tsc();
+       check("cond_wait",
+             cond_wait_until(&cond, &mutex, timer_read() + 10 * NS_PER_MS),
+             -ETIMEDOUT);
+       check_sleep("cond_wait", start);
+
+       check("mutex_unlock", mutex_unlock(&mutex), 0);
+       check("mutex_destroy", mutex_destroy(&mutex), 0);
+       check("cond_destroy", cond_destroy(&cond), 0);
+}
+
 static void absolute_condwait(void)
 {
        unsigned long long start;
@@ -633,8 +684,10 @@ int run_posix_cond(struct smokey_test *t, int argc, char 
*const argv[])
        sparam.sched_priority = 2;
        pthread_setschedparam(pthread_self(), SCHED_FIFO, &sparam);
 
+       autoinit_simple_condwait();
        simple_condwait();
        relative_condwait();
+       autoinit_absolute_condwait();
        absolute_condwait();
        sig_norestart_condwait();
        sig_restart_condwait();


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to