]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - tests/tests_frescan/test_frescan_bwres_robjs_wait.c
Do not enter unnecessary subdirectories
[frescor/frsh-forb.git] / tests / tests_frescan / test_frescan_bwres_robjs_wait.c
1 //----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2009 by the FRESCOR consortium:
3 //
4 //    Universidad de Cantabria,              SPAIN
5 //    University of York,                    UK
6 //    Scuola Superiore Sant'Anna,            ITALY
7 //    Kaiserslautern University,             GERMANY
8 //    Univ. Politecnica  Valencia,           SPAIN
9 //    Czech Technical University in Prague,  CZECH REPUBLIC
10 //    ENEA                                   SWEDEN
11 //    Thales Communication S.A.              FRANCE
12 //    Visual Tools S.A.                      SPAIN
13 //    Rapita Systems Ltd                     UK
14 //    Evidence                               ITALY
15 //
16 //    See http://www.frescor.org
17 //
18 //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
19 //        in part by the European Union Sixth Framework Programme
20 //        The European Union is not liable of any use that may be
21 //        made of this code.
22 //
23 //
24 //  based on previous work (FSF) done in the FIRST project
25 //
26 //   Copyright (C) 2005  Mälardalen University, SWEDEN
27 //                       Scuola Superiore S.Anna, ITALY
28 //                       Universidad de Cantabria, SPAIN
29 //                       University of York, UK
30 //
31 // This file is part of FNA (Frescor Network Adaptation)
32 //
33 // FNA is free software; you can redistribute it and/or modify it
34 // under terms of the GNU General Public License as published by the
35 // Free Software Foundation; either version 2, or (at your option) any
36 // later version.  FNA is distributed in the hope that it will be
37 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
38 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 // General Public License for more details. You should have received a
40 // copy of the GNU General Public License along with FNA; see file
41 // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
42 // Cambridge, MA 02139, USA.
43 //
44 // As a special exception, including FNA header files in a file,
45 // instantiating FNA generics or templates, or linking other files
46 // with FNA objects to produce an executable application, does not
47 // by itself cause the resulting executable application to be covered
48 // by the GNU General Public License. This exception does not
49 // however invalidate any other reasons why the executable file might be
50 // covered by the GNU Public License.
51 // -----------------------------------------------------------------------
52 /*!
53  * @file test_frescan_bwres_robjs_wait.c
54  *
55  * @brief test for the basic behaviour of reply objects
56  *
57  * @version 0.01
58  *
59  * @date 1-Apr-2008
60  *
61  * @author
62  *      Daniel Sangorrin <daniel.sangorrin@unican.es>
63  *
64  * @comments
65  *
66  * This file contains a basic test for the frescan_bwres_robjs module.
67  * The main thread allocates a reply object, creates a thread and waits
68  * on the reply object until the thread signals it.
69  *
70  * @license
71  *
72  * See the COPYING file in the FNA's root directory
73  *
74  */
75
76 #include <stdio.h>  /* for printf */
77 #include <assert.h> /* for assert */
78 #include <unistd.h> /* for sleep */
79 #include "fosa_threads_and_signals.h" /* for fosa_thread_xxx */
80 #include "frescan_bwres_robjs.h"
81
82 #define CEILING 10
83
84 static void *thread_code(void *arg);
85
86 int main()
87 {
88         int err;
89         frescan_bwres_robj_id_t id;
90         fosa_thread_attr_t th_attr;
91         fosa_thread_id_t tid;
92
93         printf("TEST REPLY OBJECTS\n");
94
95         err = fosa_thread_set_prio(fosa_thread_self(), CEILING - 1);
96         assert(err == 0);
97
98         err = frescan_bwres_robjs_init(CEILING);
99         assert(err == 0);
100
101         err = frescan_bwres_robjs_alloc(&id, CEILING);
102         assert(err == 0);
103
104         err = fosa_thread_attr_init(&th_attr);
105         assert(err == 0);
106
107         err = fosa_thread_attr_set_prio(&th_attr, CEILING - 1);
108         assert(err == 0);
109
110         err = fosa_thread_create (&tid, &th_attr, thread_code, (void *) id);
111         assert(err == 0);
112
113         err = fosa_thread_attr_destroy(&th_attr);
114         assert(err == 0);
115
116         err = frescan_bwres_robjs_wait(id);
117         assert(err == 0);
118         printf("signal received\n");
119
120         err = frescan_bwres_robjs_free(id);
121         assert(err == 0);
122
123         printf("TEST [OK!]\n");
124
125         return 0;
126 }
127
128 static void *thread_code(void *arg)
129 {
130         int err;
131         frescan_bwres_robj_id_t reply = (frescan_bwres_robj_id_t)arg;
132
133         printf("Thread executing\n");
134         sleep(2);
135
136         printf("Thread signaling\n");
137         err = frescan_bwres_robjs_signal(reply);
138         assert(err == 0);
139
140         printf("Thread terminating\n");
141         return NULL;
142 }