1 //----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2009 by the FRESCOR consortium:
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
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org
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
24 // based on previous work (FSF) done in the FIRST project
26 // Copyright (C) 2005 Mälardalen University, SWEDEN
27 // Scuola Superiore S.Anna, ITALY
28 // Universidad de Cantabria, SPAIN
29 // University of York, UK
31 // This file is part of FNA (Frescor Network Adaptation)
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.
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 // -----------------------------------------------------------------------
53 * @file test_frescan_bwres_robjs_timedwait.c
55 * @brief test for the basic behaviour of timedwait
62 * Daniel Sangorrin <daniel.sangorrin@unican.es>
66 * This file contains a basic test for the frescan_reply_objects module.
67 * The main thread allocates a reply object, creates a thread and waits
68 * on the reply object until the thread signals it. Then it waits again, but
69 * as the thread only signals the reply one time, this tima a timeout will be
74 * See the COPYING file in the FNA's root directory
78 #include <stdio.h> /* for printf */
79 #include <assert.h> /* for assert */
80 #include <unistd.h> /* for sleep */
81 #include "fosa_threads_and_signals.h" /* for fosa_thread_xxx */
82 #include "fosa_clocks_and_timers.h" /* for fosa_clock_get_time */
83 #include "frescan_bwres_robjs.h"
87 static void *thread_code(void *arg);
92 frescan_bwres_robj_id_t id;
93 fosa_thread_attr_t th_attr;
97 printf("TEST REPLY OBJECTS\n");
99 err = fosa_thread_set_prio(fosa_thread_self(), CEILING - 2);
102 err = frescan_bwres_robjs_init(CEILING);
105 err = frescan_bwres_robjs_alloc(&id, CEILING);
108 err = fosa_thread_attr_init(&th_attr);
111 err = fosa_thread_attr_set_prio(&th_attr, CEILING - 1);
114 err = fosa_thread_create (&tid, &th_attr, thread_code, (void *) id);
117 err = fosa_thread_attr_destroy(&th_attr);
120 err = fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &now);
123 printf("wait: %d sec %d nsec\n", now.tv_sec, now.tv_nsec);
125 now.tv_sec = now.tv_sec + 2;
126 err = frescan_bwres_robjs_timedwait(id, &now);
129 err = fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &now);
132 printf("wait again: %d sec %d nsec\n", now.tv_sec, now.tv_nsec);
134 now.tv_sec = now.tv_sec + 2;
135 err = frescan_bwres_robjs_timedwait(id, &now);
136 assert (err == FRESCAN_ETIMEDOUT);
138 printf("timeout!: %d sec %d nsec\n", now.tv_sec, now.tv_nsec);
140 err = frescan_bwres_robjs_free(id);
143 printf("TEST [OK!]\n");
148 static void *thread_code(void *arg)
151 frescan_bwres_robj_id_t reply = (frescan_bwres_robj_id_t)arg;
153 printf("Thread signaling\n");
154 err = frescan_bwres_robjs_signal(reply);
157 printf("Thread terminating\n");