aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-05 17:57:02 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-05 17:57:02 +0000
commit8e4c75f917ce5aa92eb0b39eef44aaffac3a0a27 (patch)
treeb85846925fd25a2a87e7e1dc397d4844d0eb2049 /src
parent65f3c726359d3c60c760b3c116ec7c5ab97f5e5d (diff)
downloadgnunet-8e4c75f917ce5aa92eb0b39eef44aaffac3a0a27.tar.gz
gnunet-8e4c75f917ce5aa92eb0b39eef44aaffac3a0a27.zip
-draft of new low-level testing API
Diffstat (limited to 'src')
-rw-r--r--src/include/Makefile.am1
-rw-r--r--src/include/gnunet_testing_lib-new.h247
-rw-r--r--src/testing/Makefile.am13
-rw-r--r--src/testing/testing_new.c255
4 files changed, 515 insertions, 1 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 115eb51d7..582ef5629 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -77,6 +77,7 @@ gnunetinclude_HEADERS = \
77 gnunet_strings_lib.h \ 77 gnunet_strings_lib.h \
78 gnunet_testbed_service.h \ 78 gnunet_testbed_service.h \
79 gnunet_testing_lib.h \ 79 gnunet_testing_lib.h \
80 gnunet_testing_lib-new.h \
80 gnunet_time_lib.h \ 81 gnunet_time_lib.h \
81 gnunet_transport_service.h \ 82 gnunet_transport_service.h \
82 gnunet_transport_plugin.h \ 83 gnunet_transport_plugin.h \
diff --git a/src/include/gnunet_testing_lib-new.h b/src/include/gnunet_testing_lib-new.h
new file mode 100644
index 000000000..0943d6d06
--- /dev/null
+++ b/src/include/gnunet_testing_lib-new.h
@@ -0,0 +1,247 @@
1/*
2 This file is part of GNUnet
3 (C) 2008, 2009, 2012 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 3, 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 include/gnunet_testing_lib-new.h
23 * @brief convenience API for writing testcases for GNUnet;
24 * can start/stop one or more peers on a system;
25 * testing is responsible for managing private keys,
26 * ports and paths; it is a low-level library that
27 * does not support higher-level functions such as
28 * P2P connection, topology management or distributed
29 * testbed maintenance (those are in gnunet_testbed_service.h)
30 * @author Christian Grothoff
31 */
32
33#ifndef GNUNET_TESTING_LIB_NEW_H
34#define GNUNET_TESTING_LIB_NEW_H
35
36#include "gnunet_util_lib.h"
37#include "gnunet_statistics_service.h"
38
39#ifdef __cplusplus
40extern "C"
41{
42#if 0 /* keep Emacsens' auto-indent happy */
43}
44#endif
45#endif
46
47
48/**
49 * Handle for a system on which GNUnet peers are executed;
50 * a system is used for reserving unique paths and ports.
51 */
52struct GNUNET_TESTING_System;
53
54
55/**
56 * Handle for a GNUnet peer controlled by testing.
57 */
58struct GNUNET_TESTING_Peer;
59
60
61/**
62 * Create a system handle. There must only be one system
63 * handle per operating system.
64 *
65 * @param tmppath prefix path to use for all service homes
66 * @param controller hostname of the controlling host,
67 * service configurations are modified to allow
68 * control connections from this host; can be NULL
69 * @return handle to this system, NULL on error
70 */
71struct GNUNET_TESTING_System *
72GNUNET_TESTING_system_create (const char *tmppath,
73 const char *controller);
74
75
76/**
77 * Free system resources.
78 *
79 * @param system system to be freed
80 */
81void
82GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system);
83
84
85/**
86 * Testing includes a number of pre-created hostkeys for
87 * faster peer startup. This function can be used to
88 * access the n-th key of those pre-created hostkeys; note
89 * that these keys are ONLY useful for testing and not
90 * secure as the private keys are part of the public
91 * GNUnet source code.
92 *
93 * This is primarily a helper function used internally
94 * by 'GNUNET_TESTING_peer_configure'.
95 *
96 * @param key_number desired pre-created hostkey to obtain
97 * @param filename where to store the hostkey (file will
98 * be created, or overwritten if it already exists)
99 * @param id set to the peer's identity (hash of the public
100 * key; can be NULL
101 * @return GNUNET_SYSERR on error (not enough keys)
102 */
103int
104GNUNET_TESTING_hostkey_get (uint32_t key_number,
105 const char *filename,
106 struct GNUNET_PeerIdentity *id);
107
108
109
110/**
111 * Create a new configuration using the given configuration
112 * as a template; ports and paths will be modified to select
113 * available ports on the local system. If we run
114 * out of "*port" numbers, return SYSERR.
115 *
116 * This is primarily a helper function used internally
117 * by 'GNUNET_TESTING_peer_configure'.
118 *
119 * @param system system to use to coordinate resource usage
120 * @param cfg template configuration to update
121 * @return GNUNET_OK on success, GNUNET_SYSERR on error
122 */
123int
124GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
125 struct GNUNET_CONFIGURATION_Handle *cfg);
126
127
128/**
129 * Configure a GNUnet peer. GNUnet must be installed on the local
130 * system and available in the PATH.
131 *
132 * @param system system to use to coordinate resource usage
133 * @param cfg configuration to use; will be UPDATED (to reflect needed
134 * changes in port numbers and paths)
135 * @param key_number number of the hostkey to use for the peer
136 * @param id identifier for the daemon, will be set, can be NULL
137 * @param emsg set to error message (set to NULL on success), can be NULL
138 * @return handle to the peer, NULL on error
139 */
140struct GNUNET_TESTING_Peer *
141GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
142 struct GNUNET_CONFIGURATION_Handle *cfg,
143 uint32_t key_number,
144 struct GNUNET_PeerIdentity *id,
145 char **emsg);
146
147
148/**
149 * Start the peer.
150 *
151 * @param peer peer to start
152 * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer already running)
153 */
154int
155GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer);
156
157
158/**
159 * Stop the peer.
160 *
161 * @param peer peer to stop
162 * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running)
163 */
164int
165GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer);
166
167
168/**
169 * Destroy the peer. Releases resources locked during peer configuration.
170 * If the peer is still running, it will be stopped AND a warning will be
171 * printed (users of the API should stop the peer explicitly first).
172 *
173 * @param peer peer to destroy
174 */
175void
176GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer);
177
178
179/**
180 * Signature of the 'main' function for a (single-peer) testcase that
181 * is run using 'GNUNET_TESTING_peer_run'.
182 *
183 * @param cls closure
184 * @param cfg configuration of the peer that was started
185 */
186typedef void (*GNUNET_TESTING_TestMain)(void *cls,
187 const struct GNUNET_CONFIGURATION_Handle *cfg);
188
189
190/**
191 * Start a single peer and run a test using the testing library.
192 * Starts a peer using the given configuration and then invokes the
193 * given callback. This function ALSO initializes the scheduler loop
194 * and should thus be called directly from "main". The testcase
195 * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'.
196 *
197 * @param tmppath path for storing temporary data for the test
198 * @param cfgfilename name of the configuration file to use;
199 * use NULL to only run with defaults
200 * @param tm main function of the testcase
201 * @param tm_cls closure for 'tm'
202 * @return 0 on success, 1 on error
203 */
204int
205GNUNET_TESTING_peer_run (const char *tmppath,
206 const char *cfgfilename,
207 GNUNET_TESTING_TestMain tm,
208 void *tm_cls);
209
210
211
212/**
213 * Start a single service (no ARM, except of course if the given
214 * service name is 'arm') and run a test using the testing library.
215 * Starts a service using the given configuration and then invokes the
216 * given callback. This function ALSO initializes the scheduler loop
217 * and should thus be called directly from "main". The testcase
218 * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'.
219 *
220 * This function is useful if the testcase is for a single service
221 * and if that service doesn't itself depend on other services.
222 *
223 * @param tmppath path for storing temporary data for the test
224 * @param service_name name of the service to run
225 * @param cfgfilename name of the configuration file to use;
226 * use NULL to only run with defaults
227 * @param tm main function of the testcase
228 * @param tm_cls closure for 'tm'
229 * @return 0 on success, 1 on error
230 */
231int
232GNUNET_TESTING_service_run (const char *tmppath,
233 const char *service_name,
234 const char *cfgfilename,
235 GNUNET_TESTING_TestMain tm,
236 void *tm_cls);
237
238
239
240#if 0 /* keep Emacsens' auto-indent happy */
241{
242#endif
243#ifdef __cplusplus
244}
245#endif
246
247#endif
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 4f6f90c4d..7c0f289c9 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -34,7 +34,8 @@ if HAVE_EXPENSIVE_TESTS
34endif 34endif
35 35
36lib_LTLIBRARIES = \ 36lib_LTLIBRARIES = \
37 libgnunettesting.la 37 libgnunettesting.la \
38 libgnunettesting_new.la
38 39
39libgnunettesting_la_SOURCES = \ 40libgnunettesting_la_SOURCES = \
40 helper.c \ 41 helper.c \
@@ -52,6 +53,16 @@ libgnunettesting_la_LDFLAGS = \
52 $(GN_LIB_LDFLAGS) \ 53 $(GN_LIB_LDFLAGS) \
53 -version-info 0:1:0 54 -version-info 0:1:0
54 55
56
57libgnunettesting_new_la_SOURCES = \
58 testing_new.c
59libgnunettesting_new_la_LIBADD = \
60 $(top_builddir)/src/util/libgnunetutil.la
61libgnunettesting_new_la_LDFLAGS = \
62 $(GN_LIB_LDFLAGS) \
63 -version-info 0:1:0
64
65
55bin_PROGRAMS = \ 66bin_PROGRAMS = \
56 gnunet-testing 67 gnunet-testing
57 68
diff --git a/src/testing/testing_new.c b/src/testing/testing_new.c
new file mode 100644
index 000000000..cc341e037
--- /dev/null
+++ b/src/testing/testing_new.c
@@ -0,0 +1,255 @@
1/*
2 This file is part of GNUnet
3 (C) 2008, 2009, 2012 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 3, 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_new.c
23 * @brief convenience API for writing testcases for GNUnet
24 * Many testcases need to start and stop a peer/service
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 (or internal use of the testbed).
29 * @author Christian Grothoff
30 *
31 */
32#include "platform.h"
33#include "gnunet_testing_lib-new.h"
34
35
36/**
37 * Handle for a system on which GNUnet peers are executed;
38 * a system is used for reserving unique paths and ports.
39 */
40struct GNUNET_TESTING_System
41{
42};
43
44
45/**
46 * Handle for a GNUnet peer controlled by testing.
47 */
48struct GNUNET_TESTING_Peer
49{
50};
51
52
53/**
54 * Create a system handle. There must only be one system
55 * handle per operating system.
56 *
57 * @param tmppath prefix path to use for all service homes
58 * @param controller hostname of the controlling host,
59 * service configurations are modified to allow
60 * control connections from this host; can be NULL
61 * @return handle to this system, NULL on error
62 */
63struct GNUNET_TESTING_System *
64GNUNET_TESTING_system_create (const char *tmppath,
65 const char *controller)
66{
67 GNUNET_break (0);
68 return NULL;
69}
70
71
72/**
73 * Free system resources.
74 *
75 * @param system system to be freed
76 */
77void
78GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system)
79{
80 GNUNET_break (0);
81}
82
83
84/**
85 * Testing includes a number of pre-created hostkeys for
86 * faster peer startup. This function can be used to
87 * access the n-th key of those pre-created hostkeys; note
88 * that these keys are ONLY useful for testing and not
89 * secure as the private keys are part of the public
90 * GNUnet source code.
91 *
92 * This is primarily a helper function used internally
93 * by 'GNUNET_TESTING_peer_configure'.
94 *
95 * @param key_number desired pre-created hostkey to obtain
96 * @param filename where to store the hostkey (file will
97 * be created, or overwritten if it already exists)
98 * @param id set to the peer's identity (hash of the public
99 * key; can be NULL
100 * @return GNUNET_SYSERR on error (not enough keys)
101 */
102int
103GNUNET_TESTING_hostkey_get (uint32_t key_number,
104 const char *filename,
105 struct GNUNET_PeerIdentity *id)
106{
107 GNUNET_break (0);
108 return GNUNET_SYSERR;
109}
110
111
112/**
113 * Create a new configuration using the given configuration
114 * as a template; ports and paths will be modified to select
115 * available ports on the local system. If we run
116 * out of "*port" numbers, return SYSERR.
117 *
118 * This is primarily a helper function used internally
119 * by 'GNUNET_TESTING_peer_configure'.
120 *
121 * @param system system to use to coordinate resource usage
122 * @param cfg template configuration to update
123 * @return GNUNET_OK on success, GNUNET_SYSERR on error
124 */
125int
126GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
127 struct GNUNET_CONFIGURATION_Handle *cfg);
128
129
130/**
131 * Configure a GNUnet peer. GNUnet must be installed on the local
132 * system and available in the PATH.
133 *
134 * @param system system to use to coordinate resource usage
135 * @param cfg configuration to use; will be UPDATED (to reflect needed
136 * changes in port numbers and paths)
137 * @param key_number number of the hostkey to use for the peer
138 * @param id identifier for the daemon, will be set, can be NULL
139 * @param emsg set to error message (set to NULL on success), can be NULL
140 * @return handle to the peer, NULL on error
141 */
142struct GNUNET_TESTING_Peer *
143GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
144 struct GNUNET_CONFIGURATION_Handle *cfg,
145 uint32_t key_number,
146 struct GNUNET_PeerIdentity *id,
147 char **emsg)
148{
149 GNUNET_break (0);
150 return NULL;
151}
152
153
154/**
155 * Start the peer.
156 *
157 * @param peer peer to start
158 * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer already running)
159 */
160int
161GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
162{
163 GNUNET_break (0);
164 return GNUNET_SYSERR;
165}
166
167
168/**
169 * Stop the peer.
170 *
171 * @param peer peer to stop
172 * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running)
173 */
174int
175GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
176{
177 GNUNET_break (0);
178 return GNUNET_SYSERR;
179}
180
181
182/**
183 * Destroy the peer. Releases resources locked during peer configuration.
184 * If the peer is still running, it will be stopped AND a warning will be
185 * printed (users of the API should stop the peer explicitly first).
186 *
187 * @param peer peer to destroy
188 */
189void
190GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
191{
192 GNUNET_break (0);
193}
194
195
196
197/**
198 * Start a single peer and run a test using the testing library.
199 * Starts a peer using the given configuration and then invokes the
200 * given callback. This function ALSO initializes the scheduler loop
201 * and should thus be called directly from "main". The testcase
202 * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'.
203 *
204 * @param tmppath path for storing temporary data for the test
205 * @param cfgfilename name of the configuration file to use;
206 * use NULL to only run with defaults
207 * @param tm main function of the testcase
208 * @param tm_cls closure for 'tm'
209 * @return 0 on success, 1 on error
210 */
211int
212GNUNET_TESTING_peer_run (const char *tmppath,
213 const char *cfgfilename,
214 GNUNET_TESTING_TestMain tm,
215 void *tm_cls)
216{
217 return GNUNET_TESTING_service_run (tmppath, "arm",
218 cfgfilename, tm, tm_cls);
219}
220
221
222
223/**
224 * Start a single service (no ARM, except of course if the given
225 * service name is 'arm') and run a test using the testing library.
226 * Starts a service using the given configuration and then invokes the
227 * given callback. This function ALSO initializes the scheduler loop
228 * and should thus be called directly from "main". The testcase
229 * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'.
230 *
231 * This function is useful if the testcase is for a single service
232 * and if that service doesn't itself depend on other services.
233 *
234 * @param tmppath path for storing temporary data for the test
235 * @param service_name name of the service to run
236 * @param cfgfilename name of the configuration file to use;
237 * use NULL to only run with defaults
238 * @param tm main function of the testcase
239 * @param tm_cls closure for 'tm'
240 * @return 0 on success, 1 on error
241 */
242int
243GNUNET_TESTING_service_run (const char *tmppath,
244 const char *service_name,
245 const char *cfgfilename,
246 GNUNET_TESTING_TestMain tm,
247 void *tm_cls)
248{
249 GNUNET_break (0);
250 return 1;
251}
252
253
254
255/* end of testing_new.c */