]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - tests/tests_frescan/test_frescan_bwres_robjs_wait.c
ba3916697e8fe7e93c7bdbe043fabedcef0845e7
[frescor/fna.git] / tests / tests_frescan / test_frescan_bwres_robjs_wait.c
1 /*!
2  * @file test_frescan_bwres_robjs_wait.c
3  *
4  * @brief test for the basic behaviour of reply objects
5  *
6  * @version 0.01
7  *
8  * @date 1-Apr-2008
9  *
10  * @author
11  *      Daniel Sangorrin <daniel.sangorrin@unican.es>
12  *
13  * @comments
14  *
15  * This file contains a basic test for the frescan_bwres_robjs module.
16  * The main thread allocates a reply object, creates a thread and waits
17  * on the reply object until the thread signals it.
18  *
19  * @license
20  *
21  * See the COPYING file in the FNA's root directory
22  *
23  */
24
25 #include <stdio.h>  /* for printf */
26 #include <assert.h> /* for assert */
27 #include <unistd.h> /* for sleep */
28 #include "fosa_threads_and_signals.h" /* for fosa_thread_xxx */
29 #include "frescan_bwres_robjs.h"
30
31 #define CEILING 10
32
33 static void *thread_code(void *arg);
34
35 int main()
36 {
37         int err;
38         frescan_bwres_robj_id_t id;
39         fosa_thread_attr_t th_attr;
40         fosa_thread_id_t tid;
41
42         printf("TEST REPLY OBJECTS\n");
43
44         err = fosa_thread_set_prio(fosa_thread_self(), CEILING - 1);
45         assert(err == 0);
46
47         err = frescan_bwres_robjs_init(CEILING);
48         assert(err == 0);
49
50         err = frescan_bwres_robjs_alloc(&id, CEILING);
51         assert(err == 0);
52
53         err = fosa_thread_attr_init(&th_attr);
54         assert(err == 0);
55
56         err = fosa_thread_attr_set_prio(&th_attr, CEILING - 1);
57         assert(err == 0);
58
59         err = fosa_thread_create (&tid, &th_attr, thread_code, (void *) id);
60         assert(err == 0);
61
62         err = fosa_thread_attr_destroy(&th_attr);
63         assert(err == 0);
64
65         err = frescan_bwres_robjs_wait(id);
66         assert(err == 0);
67         printf("signal received\n");
68
69         err = frescan_bwres_robjs_free(id);
70         assert(err == 0);
71
72         printf("TEST [OK!]\n");
73
74         return 0;
75 }
76
77 static void *thread_code(void *arg)
78 {
79         int err;
80         frescan_bwres_robj_id_t reply = (frescan_bwres_robj_id_t)arg;
81
82         printf("Thread executing\n");
83         sleep(2);
84
85         printf("Thread signaling\n");
86         err = frescan_bwres_robjs_signal(reply);
87         assert(err == 0);
88
89         printf("Thread terminating\n");
90         return NULL;
91 }