some documentation and bugfix in testcase
[oweals/gnunet.git] / src / testing / testing.c
1 /*
2       This file is part of GNUnet
3       (C) 2008, 2009 Christian Grothoff (and other contributing authors)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 2, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * @file testing/testing.c
23  * @brief convenience API for writing testcases for GNUnet
24  *        Many testcases need to start and stop gnunetd,
25  *        and this library is supposed to make that easier
26  *        for TESTCASES.  Normal programs should always
27  *        use functions from gnunet_{util,arm}_lib.h.  This API is
28  *        ONLY for writing testcases!
29  * @author Christian Grothoff
30  */
31 #include "platform.h"
32 #include "gnunet_arm_service.h"
33 #include "gnunet_testing_lib.h"
34
35 /**
36  * Handle for a GNUnet daemon (technically a set of
37  * daemons; the handle is really for the master ARM
38  * daemon) started by the testing library.
39  */
40 struct GNUNET_TESTING_Daemon
41 {
42 };
43
44
45 /**
46  * Starts a GNUnet daemon.
47  *
48  * @param service_home directory to use as the service home directory
49  * @param transports transport services that should be loaded
50  * @param applications application services and daemons that should be started
51  * @param port_offset offset to add to all ports for all services
52  * @param hostname name of the machine where to run GNUnet
53  *        (use NULL for localhost).
54  * @param cb function to call with the result
55  * @param cb_cls closure for cb
56  */
57 void
58 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
59                              struct GNUNET_CONFIGURATION_Handle *cfg,
60                              const char *service_home,
61                              const char *transports,
62                              const char *applications,
63                              uint16_t port_offset,
64                              const char *hostname,
65                              GNUNET_TESTING_NotifyDaemonRunning cb,
66                              void *cb_cls)
67 {
68 }
69
70
71 /**
72  * Stops a GNUnet daemon.
73  *
74  * @param d the daemon that should be stopped
75  * @param cb function called once the daemon was stopped
76  * @param cb_cls closure for cb
77  */
78 void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
79                                  GNUNET_TESTING_NotifyCompletion cb,
80                                  void * cb_cls)
81 {
82 }
83
84
85 /**
86  * Establish a connection between two GNUnet daemons.
87  *
88  * @param d1 handle for the first daemon
89  * @param d2 handle for the second daemon
90  * @param cb function to call at the end
91  * @param cb_cls closure for cb
92  */
93 void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
94                                      struct GNUNET_TESTING_Daemon *d2,
95                                      GNUNET_TESTING_NotifyCompletion cb,
96                                      void *cb_cls)
97 {
98 }
99
100
101 /**
102  * Start count gnunetd processes with the same set of
103  * transports and applications.  The port numbers will
104  * be computed by adding delta each time (zero
105  * times for the first peer).
106  *
107  * @param total number of daemons to start
108  * @param service_home_prefix path to use as the prefix for the home of the services
109  * @param transports which transports should all peers use
110  * @param applications which applications should be used?
111  * @param timeout how long is this allowed to take?
112  * @param cb function to call on each daemon that was started
113  * @param cb_cls closure for cb
114  * @param cbe function to call at the end
115  * @param cbe_cls closure for cbe
116  * @param hostname where to run the peers; can be NULL (to run
117  *        everything on localhost).
118  * @param va Additional hosts can be specified using a NULL-terminated list of
119  *        varargs, hosts will then be used round-robin from that
120  *        list; va only contains anything if hostname != NULL.
121  */
122 void
123 GNUNET_TESTING_daemons_start_va (struct GNUNET_SCHEDULER_Handle *sched,
124                                  struct GNUNET_CONFIGURATION_Handle *cfg,
125                                  unsigned int total,
126                                  const char *service_home_prefix,
127                                  const char *transports,
128                                  const char *applications,
129                                  GNUNET_TESTING_NotifyDaemonRunning cb,
130                                  void *cb_cls,
131                                  GNUNET_TESTING_NotifyCompletion cbe,
132                                  void *cbe_cls,
133                                  const char *hostname,
134                                  va_list va)
135 {
136 }
137
138
139 /**
140  * Start count gnunetd processes with the same set of
141  * transports and applications.  The port numbers will
142  * be computed by adding delta each time (zero
143  * times for the first peer).
144  *
145  * @param total number of daemons to start
146  * @param service_home_prefix path to use as the prefix for the home of the services
147  * @param transports which transports should all peers use
148  * @param applications which applications should be used?
149  * @param timeout how long is this allowed to take?
150  * @param cb function to call on each daemon that was started
151  * @param cb_cls closure for cb
152  * @param cbe function to call at the end
153  * @param cbe_cls closure for cbe
154  * @param hostname where to run the peers; can be NULL (to run
155  *        everything on localhost). Additional
156  *        hosts can be specified using a NULL-terminated list of
157  *        varargs, hosts will then be used round-robin from that
158  *        list.
159  */
160 void
161 GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
162                               struct GNUNET_CONFIGURATION_Handle *cfg,
163                               unsigned int total,
164                               const char *service_home_prefix,
165                               const char *transports,
166                               const char *applications,
167                               GNUNET_TESTING_NotifyDaemonRunning cb,
168                               void *cb_cls,
169                               GNUNET_TESTING_NotifyCompletion cbe,
170                               void *cbe_cls,
171                               const char *hostname,
172                               ...)
173 {
174   va_list va;
175   
176   va_start (va, hostname);
177   GNUNET_TESTING_daemons_start_va (sched, cfg,
178                                    total, service_home_prefix,
179                                    transports, applications,
180                                    cb, cb_cls, cbe, cbe_cls, hostname,
181                                    va);
182   va_end (va);
183 }
184
185 /* end of testing.c */