2 * @file test_frescan_bwres_robjs_timedwait.c
4 * @brief test for the basic behaviour of timedwait
11 * Daniel Sangorrin <daniel.sangorrin@unican.es>
15 * This file contains a basic test for the frescan_reply_objects module.
16 * The main thread allocates a reply object, creates a thread and waits
17 * on the reply object until the thread signals it. Then it waits again, but
18 * as the thread only signals the reply one time, this tima a timeout will be
23 * See the COPYING file in the FNA's root directory
27 #include <stdio.h> /* for printf */
28 #include <assert.h> /* for assert */
29 #include <unistd.h> /* for sleep */
30 #include "fosa_threads_and_signals.h" /* for fosa_thread_xxx */
31 #include "fosa_clocks_and_timers.h" /* for fosa_clock_get_time */
32 #include "frescan_bwres_robjs.h"
36 static void *thread_code(void *arg);
42 fosa_thread_attr_t th_attr;
46 printf("TEST REPLY OBJECTS\n");
48 err = fosa_thread_set_prio(fosa_thread_self(), CEILING - 2);
51 err = frescan_bwres_robjs_init(CEILING);
54 err = frescan_bwres_robjs_alloc(&id, CEILING);
57 err = fosa_thread_attr_init(&th_attr);
60 err = fosa_thread_attr_set_prio(&th_attr, CEILING - 1);
63 err = fosa_thread_create (&tid, &th_attr, thread_code, (void *) id);
66 err = fosa_thread_attr_destroy(&th_attr);
69 err = fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &now);
72 printf("wait: %d sec %d nsec\n", now.tv_sec, now.tv_nsec);
74 now.tv_sec = now.tv_sec + 2;
75 err = frescan_bwres_robjs_timedwait(id, &now);
78 err = fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &now);
81 printf("wait again: %d sec %d nsec\n", now.tv_sec, now.tv_nsec);
83 now.tv_sec = now.tv_sec + 2;
84 err = frescan_bwres_robjs_timedwait(id, &now);
85 assert (err == FRESCAN_ETIMEDOUT);
87 printf("timeout!: %d sec %d nsec\n", now.tv_sec, now.tv_nsec);
89 err = frescan_bwres_robjs_free(id);
92 printf("TEST [OK!]\n");
97 static void *thread_code(void *arg)
100 frescan_robj_id_t reply = (frescan_robj_id_t)arg;
102 printf("Thread signaling\n");
103 err = frescan_bwres_robjs_signal(reply);
106 printf("Thread terminating\n");