]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/tests/discovery.c
Fixed a bug in discovery test
[frescor/forb.git] / src / tests / discovery.c
1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                 */
4 /*                                                                        */
5 /*   Universidad de Cantabria,              SPAIN                         */
6 /*   University of York,                    UK                            */
7 /*   Scuola Superiore Sant'Anna,            ITALY                         */
8 /*   Kaiserslautern University,             GERMANY                       */
9 /*   Univ. Politécnica  Valencia,           SPAIN                        */
10 /*   Czech Technical University in Prague,  CZECH REPUBLIC                */
11 /*   ENEA                                   SWEDEN                        */
12 /*   Thales Communication S.A.              FRANCE                        */
13 /*   Visual Tools S.A.                      SPAIN                         */
14 /*   Rapita Systems Ltd                     UK                            */
15 /*   Evidence                               ITALY                         */
16 /*                                                                        */
17 /*   See http://www.frescor.org for a link to partners' websites          */
18 /*                                                                        */
19 /*          FRESCOR project (FP6/2005/IST/5-034026) is funded             */
20 /*       in part by the European Union Sixth Framework Programme          */
21 /*       The European Union is not liable of any use that may be          */
22 /*       made of this code.                                               */
23 /*                                                                        */
24 /*                                                                        */
25 /*  This file is part of FORB (Frescor Object Request Broker)             */
26 /*                                                                        */
27 /* FORB is free software; you can redistribute it and/or modify it        */
28 /* under terms of the GNU General Public License as published by the      */
29 /* Free Software Foundation; either version 2, or (at your option) any    */
30 /* later version.  FORB is distributed in the hope that it will be        */
31 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
32 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
33 /* General Public License for more details. You should have received a    */
34 /* copy of the GNU General Public License along with FORB; see file       */
35 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
36 /* Cambridge, MA 02139, USA.                                              */
37 /*                                                                        */
38 /* As a special exception, including FORB header files in a file,         */
39 /* instantiating FORB generics or templates, or linking other files       */
40 /* with FORB objects to produce an executable application, does not       */
41 /* by itself cause the resulting executable application to be covered     */
42 /* by the GNU General Public License. This exception does not             */
43 /* however invalidate any other reasons why the executable file might be  */
44 /* covered by the GNU Public License.                                     */
45 /**************************************************************************/
46
47 /**
48  * @file   discovery.c
49  * @author Michal Sojka <sojkam1@fel.cvut.cz>
50  * @date   Sun Oct 12 19:05:27 2008
51  * 
52  * @brief  Test for correctness of peer discovery protocol
53  * 
54  * Multiple FORB obejcts are created and it is tested whether every
55  * FORB automatically discovers the other FORBs.
56  */
57
58 #include <stdbool.h>
59 #include <forb.h>
60 #include <forb/object.h>
61 #include <forb/forb-internal.h>
62 #include <forb/config.h>
63 #include <unistd.h>
64 #include "../proto.h"
65 #include <error.h>
66 #include <fosa.h>
67
68 #define NUM_ORBS 5
69
70 #ifndef CONFIG_FORB_PROTO_UNIX
71 #error This test should only work with UNIX protocol enabled.
72 #endif
73
74 int main(int argc, char *argv[])
75 {
76         forb_orb orb[NUM_ORBS];
77         int i;
78         bool all_peers_found = true;
79         fosa_abs_time_t timeout;
80
81         for (i=0; i<NUM_ORBS; i++) {
82                 orb[i] = forb_init(&argc, &argv, NULL);
83                 if (!orb[i]) {
84                         error(1, errno, "Orb no. %d was not created\n", i);
85                 }
86         }
87
88         fosa_clock_get_time(FOSA_CLOCK_ABSOLUTE, &timeout);
89         timeout = fosa_abs_time_incr(timeout,
90                                      fosa_msec_to_rel_time(1000));
91
92         /* Check whether all the peers are found */
93         for (i=0; i<NUM_ORBS && all_peers_found; i++) {
94                 int j;
95                 forb_peer_t *peer;
96                 for (j=0; j<NUM_ORBS && all_peers_found; j++) {
97                         if (i==j) continue;
98                         peer = forb_peer_find_timed(forb_data(orb[i]),
99                                                     &forb_data(orb[j])->server_id,
100                                                     &timeout);
101
102                         all_peers_found &= (peer != NULL);
103                         if (!all_peers_found) {
104                                 char id[100];
105                                 error(1, 0, "Peer %d (%s) was not discovered on node %d",
106                                       j, forb_uuid_to_string(id,
107                                                              (forb_uuid_t*)&forb_data(orb[i])->server_id.uuid,
108                                                              sizeof(id)),
109                                       i);
110                         }
111                 }
112         }
113
114         return 0;
115 }