diff options
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/Makefile.am | 12 | ||||
-rw-r--r-- | src/testing/gnunet-testing-run-service.c | 6 | ||||
-rw-r--r-- | src/testing/gnunet-testing.c | 279 | ||||
-rw-r--r-- | src/testing/testing.c | 19 |
4 files changed, 301 insertions, 15 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 670b1d2e0..f680ad669 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am | |||
@@ -27,7 +27,8 @@ libgnunettesting_la_LDFLAGS = \ | |||
27 | -version-info 0:1:0 | 27 | -version-info 0:1:0 |
28 | 28 | ||
29 | bin_PROGRAMS = \ | 29 | bin_PROGRAMS = \ |
30 | gnunet-testing-run-service | 30 | gnunet-testing-run-service \ |
31 | gnunet-testing | ||
31 | 32 | ||
32 | 33 | ||
33 | gnunet_testing_run_service_SOURCES = \ | 34 | gnunet_testing_run_service_SOURCES = \ |
@@ -40,6 +41,15 @@ gnunet_testing_run_service_LDADD = \ | |||
40 | gnunet_testing_run_service_DEPENDENCIES = \ | 41 | gnunet_testing_run_service_DEPENDENCIES = \ |
41 | libgnunettesting.la | 42 | libgnunettesting.la |
42 | 43 | ||
44 | gnunet_testing_SOURCES = \ | ||
45 | gnunet-testing.c | ||
46 | gnunet_testing_LDADD = \ | ||
47 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
48 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
49 | $(GN_LIBINTL) | ||
50 | gnunet_testing_DEPENDENCIES = \ | ||
51 | libgnunettesting.la | ||
52 | |||
43 | 53 | ||
44 | check_PROGRAMS = \ | 54 | check_PROGRAMS = \ |
45 | test_testing_portreservation \ | 55 | test_testing_portreservation \ |
diff --git a/src/testing/gnunet-testing-run-service.c b/src/testing/gnunet-testing-run-service.c index 38351d75e..72415e606 100644 --- a/src/testing/gnunet-testing-run-service.c +++ b/src/testing/gnunet-testing-run-service.c | |||
@@ -34,15 +34,9 @@ | |||
34 | * This executable is intended to be used by gnunet-java, in order to reliably | 34 | * This executable is intended to be used by gnunet-java, in order to reliably |
35 | * start and stop services for test cases. | 35 | * start and stop services for test cases. |
36 | */ | 36 | */ |
37 | |||
38 | #include "platform.h" | 37 | #include "platform.h" |
39 | #include "gnunet_getopt_lib.h" | ||
40 | #include "gnunet_program_lib.h" | ||
41 | #include "gnunet_util_lib.h" | 38 | #include "gnunet_util_lib.h" |
42 | #include "gnunet_signal_lib.h" | ||
43 | #include "gnunet_testing_lib-new.h" | 39 | #include "gnunet_testing_lib-new.h" |
44 | #include "gnunet_os_lib.h" | ||
45 | |||
46 | 40 | ||
47 | #define LOG(kind,...) \ | 41 | #define LOG(kind,...) \ |
48 | GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__) | 42 | GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__) |
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c new file mode 100644 index 000000000..b7e115761 --- /dev/null +++ b/src/testing/gnunet-testing.c | |||
@@ -0,0 +1,279 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2004, 2005, 2006, 2007, 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 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_old/gnunet-testing.c | ||
23 | * @brief tool to use testing functionality from cmd line | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testing_lib-new.h" | ||
29 | |||
30 | #define HOSTKEYFILESIZE 914 | ||
31 | |||
32 | /** | ||
33 | * Final status code. | ||
34 | */ | ||
35 | static int ret; | ||
36 | |||
37 | static unsigned int create_hostkey; | ||
38 | |||
39 | static unsigned int create_cfg; | ||
40 | |||
41 | static int create_no; | ||
42 | |||
43 | static char * create_cfg_template; | ||
44 | |||
45 | static char * create_hostkey_file; | ||
46 | |||
47 | |||
48 | static int | ||
49 | create_unique_cfgs (const char * template, const unsigned int no) | ||
50 | { | ||
51 | struct GNUNET_TESTING_System *system; | ||
52 | int fail; | ||
53 | unsigned int cur; | ||
54 | char *cur_file; | ||
55 | struct GNUNET_CONFIGURATION_Handle *cfg_new; | ||
56 | struct GNUNET_CONFIGURATION_Handle *cfg_tmpl; | ||
57 | |||
58 | if (GNUNET_NO == GNUNET_DISK_file_test(template)) | ||
59 | { | ||
60 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Configuration template `%s': file not found\n", create_cfg_template); | ||
61 | return 1; | ||
62 | } | ||
63 | cfg_tmpl = GNUNET_CONFIGURATION_create(); | ||
64 | |||
65 | /* load template */ | ||
66 | if ((create_cfg_template != NULL) && (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, create_cfg_template))) | ||
67 | { | ||
68 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load template `%s'\n", create_cfg_template); | ||
69 | GNUNET_CONFIGURATION_destroy(cfg_tmpl); | ||
70 | |||
71 | return 1; | ||
72 | } | ||
73 | /* load defaults */ | ||
74 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, NULL)) | ||
75 | { | ||
76 | GNUNET_break (0); | ||
77 | return 1; | ||
78 | } | ||
79 | |||
80 | fail = GNUNET_NO; | ||
81 | system = GNUNET_TESTING_system_create ("testing", NULL /* controller */); | ||
82 | for (cur = 0; cur < no; cur++) | ||
83 | { | ||
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating configuration no. %u \n", cur); | ||
85 | if (create_cfg_template != NULL) | ||
86 | GNUNET_asprintf (&cur_file,"%04u-%s",cur, create_cfg_template); | ||
87 | else | ||
88 | GNUNET_asprintf (&cur_file,"%04u%s",cur, ".conf"); | ||
89 | |||
90 | cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl); | ||
91 | if (GNUNET_OK != | ||
92 | GNUNET_TESTING_configuration_create (system, cfg_new)) | ||
93 | { | ||
94 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not create another configuration\n"); | ||
95 | GNUNET_CONFIGURATION_destroy (cfg_new); | ||
96 | fail = GNUNET_YES; | ||
97 | break; | ||
98 | } | ||
99 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
100 | "Writing configuration no. %u to file `%s' \n", cur, cur_file); | ||
101 | if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg_new, cur_file)) | ||
102 | { | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to write configuration no. %u \n", cur); | ||
104 | fail = GNUNET_YES; | ||
105 | } | ||
106 | GNUNET_CONFIGURATION_destroy (cfg_new); | ||
107 | GNUNET_free (cur_file); | ||
108 | if (fail == GNUNET_YES) | ||
109 | break; | ||
110 | } | ||
111 | GNUNET_CONFIGURATION_destroy(cfg_tmpl); | ||
112 | GNUNET_TESTING_system_destroy (system, GNUNET_NO); | ||
113 | if (GNUNET_YES == fail) | ||
114 | return 1; | ||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | |||
119 | static int | ||
120 | create_hostkeys (const unsigned int no) | ||
121 | { | ||
122 | struct GNUNET_DISK_FileHandle *fd; | ||
123 | int cur = 0; | ||
124 | uint64_t fs; | ||
125 | uint64_t total_hostkeys; | ||
126 | char *hostkey_data; | ||
127 | char *hostkey_src_file; | ||
128 | char *hostkey_dest_file; | ||
129 | |||
130 | /* prepare hostkeys */ | ||
131 | if (create_hostkey_file == NULL) | ||
132 | hostkey_src_file = "../../contrib/testing_hostkeys.dat"; | ||
133 | else | ||
134 | { | ||
135 | hostkey_src_file = create_hostkey_file; | ||
136 | } | ||
137 | |||
138 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkey_src_file)) | ||
139 | { | ||
140 | if (create_hostkey_file == NULL) | ||
141 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not read hostkeys file, specify hostkey file with -H!\n")); | ||
142 | else | ||
143 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Specified hostkey file `%s' not found!\n"), create_hostkey_file); | ||
144 | return 1; | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | /* Check hostkey file size, read entire thing into memory */ | ||
149 | fd = GNUNET_DISK_file_open (hostkey_src_file, GNUNET_DISK_OPEN_READ, | ||
150 | GNUNET_DISK_PERM_NONE); | ||
151 | if (NULL == fd) | ||
152 | { | ||
153 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", hostkey_src_file); | ||
154 | return 1; | ||
155 | } | ||
156 | |||
157 | if (GNUNET_OK != GNUNET_DISK_file_size (hostkey_src_file, &fs, GNUNET_YES, GNUNET_YES)) | ||
158 | fs = 0; | ||
159 | |||
160 | if (0 != (fs % HOSTKEYFILESIZE)) | ||
161 | { | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
163 | "File size %llu seems incorrect for hostkeys...\n", fs); | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | total_hostkeys = fs / HOSTKEYFILESIZE; | ||
168 | hostkey_data = GNUNET_malloc_large (fs); | ||
169 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, hostkey_data, fs)); | ||
170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
171 | "Read %llu hostkeys from file\n", total_hostkeys); | ||
172 | } | ||
173 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
174 | } | ||
175 | |||
176 | while (cur < no) | ||
177 | { | ||
178 | GNUNET_asprintf (&hostkey_dest_file, "%04u-hostkey",cur); | ||
179 | GNUNET_assert (GNUNET_OK == | ||
180 | GNUNET_DISK_directory_create_for_file (hostkey_dest_file)); | ||
181 | fd = GNUNET_DISK_file_open (hostkey_dest_file, | ||
182 | GNUNET_DISK_OPEN_READWRITE | | ||
183 | GNUNET_DISK_OPEN_CREATE, | ||
184 | GNUNET_DISK_PERM_USER_READ | | ||
185 | GNUNET_DISK_PERM_USER_WRITE); | ||
186 | GNUNET_assert (fd != NULL); | ||
187 | GNUNET_assert (HOSTKEYFILESIZE == | ||
188 | GNUNET_DISK_file_write (fd, &hostkey_data[cur * HOSTKEYFILESIZE], HOSTKEYFILESIZE)); | ||
189 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
190 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
191 | "Wrote hostkey to file: `%s' \n", hostkey_dest_file); | ||
192 | GNUNET_free (hostkey_dest_file); | ||
193 | cur ++; | ||
194 | } | ||
195 | |||
196 | GNUNET_free (hostkey_data); | ||
197 | |||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | /** | ||
202 | * Main function that will be run by the scheduler. | ||
203 | * | ||
204 | * @param cls closure | ||
205 | * @param args remaining command-line arguments | ||
206 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
207 | * @param cfg configuration | ||
208 | */ | ||
209 | static void | ||
210 | run (void *cls, char *const *args, const char *cfgfile, | ||
211 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
212 | { | ||
213 | /* main code here */ | ||
214 | if (create_cfg == GNUNET_YES) | ||
215 | { | ||
216 | if (create_no > 0) | ||
217 | { | ||
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating %u configuration files based on template `%s'\n", create_no, create_cfg_template); | ||
219 | ret = create_unique_cfgs (create_cfg_template, create_no); | ||
220 | } | ||
221 | else | ||
222 | { | ||
223 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing arguments! \n"); | ||
224 | ret = 1; | ||
225 | } | ||
226 | } | ||
227 | |||
228 | if (create_hostkey == GNUNET_YES) | ||
229 | { | ||
230 | if (create_no > 0) | ||
231 | { | ||
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating %u hostkeys \n", create_no); | ||
233 | ret = create_hostkeys (create_no); | ||
234 | } | ||
235 | else | ||
236 | { | ||
237 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing arguments! \n"); | ||
238 | ret = 1; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | GNUNET_free_non_null (create_cfg_template); | ||
243 | } | ||
244 | |||
245 | |||
246 | /** | ||
247 | * The main function. | ||
248 | * | ||
249 | * @param argc number of arguments from the command line | ||
250 | * @param argv command line arguments | ||
251 | * @return 0 ok, 1 on error | ||
252 | */ | ||
253 | int | ||
254 | main (int argc, char *const *argv) | ||
255 | { | ||
256 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
257 | {'C', "cfg", NULL, gettext_noop ("create unique configuration files"), | ||
258 | GNUNET_NO, &GNUNET_GETOPT_set_one, &create_cfg}, | ||
259 | {'k', "key", NULL, gettext_noop ("create hostkey files from pre-computed hostkey list"), | ||
260 | GNUNET_NO, &GNUNET_GETOPT_set_one, &create_hostkey}, | ||
261 | {'H', "hostkeys", NULL, gettext_noop ("host key file"), | ||
262 | GNUNET_YES, &GNUNET_GETOPT_set_string, &create_hostkey_file}, | ||
263 | {'n', "number", NULL, gettext_noop ("number of unique configuration files or hostkeys to create"), | ||
264 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &create_no}, | ||
265 | {'t', "template", NULL, gettext_noop ("configuration template"), | ||
266 | GNUNET_YES, &GNUNET_GETOPT_set_string, &create_cfg_template}, | ||
267 | GNUNET_GETOPT_OPTION_END | ||
268 | }; | ||
269 | |||
270 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
271 | return 2; | ||
272 | |||
273 | return (GNUNET_OK == | ||
274 | GNUNET_PROGRAM_run (argc, argv, "gnunet-testing", | ||
275 | gettext_noop ("Command line tool to access the testing library"), options, &run, | ||
276 | NULL)) ? ret : 1; | ||
277 | } | ||
278 | |||
279 | /* end of gnunet-testing.c */ | ||
diff --git a/src/testing/testing.c b/src/testing/testing.c index fca969b19..369bd4e51 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -441,9 +441,9 @@ reserve_path (struct GNUNET_TESTING_System *system) | |||
441 | * @param key_number desired pre-created hostkey to obtain | 441 | * @param key_number desired pre-created hostkey to obtain |
442 | * @param id set to the peer's identity (hash of the public | 442 | * @param id set to the peer's identity (hash of the public |
443 | * key; if NULL, GNUNET_SYSERR is returned immediately | 443 | * key; if NULL, GNUNET_SYSERR is returned immediately |
444 | * @return GNUNET_SYSERR on error (not enough keys) | 444 | * @return NULL on error (not enough keys) |
445 | */ | 445 | */ |
446 | int | 446 | struct GNUNET_CRYPTO_RsaPrivateKey * |
447 | GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, | 447 | GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, |
448 | uint32_t key_number, | 448 | uint32_t key_number, |
449 | struct GNUNET_PeerIdentity *id) | 449 | struct GNUNET_PeerIdentity *id) |
@@ -452,12 +452,12 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, | |||
452 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; | 452 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; |
453 | 453 | ||
454 | if ((NULL == id) || (NULL == system->hostkeys_data)) | 454 | if ((NULL == id) || (NULL == system->hostkeys_data)) |
455 | return GNUNET_SYSERR; | 455 | return NULL; |
456 | if (key_number >= system->total_hostkeys) | 456 | if (key_number >= system->total_hostkeys) |
457 | { | 457 | { |
458 | LOG (GNUNET_ERROR_TYPE_ERROR, | 458 | LOG (GNUNET_ERROR_TYPE_ERROR, |
459 | _("Key number %u does not exist\n"), key_number); | 459 | _("Key number %u does not exist\n"), key_number); |
460 | return GNUNET_SYSERR; | 460 | return NULL; |
461 | } | 461 | } |
462 | private_key = GNUNET_CRYPTO_rsa_decode_key (system->hostkeys_data + | 462 | private_key = GNUNET_CRYPTO_rsa_decode_key (system->hostkeys_data + |
463 | (key_number * HOSTKEYFILESIZE), | 463 | (key_number * HOSTKEYFILESIZE), |
@@ -466,14 +466,13 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, | |||
466 | { | 466 | { |
467 | LOG (GNUNET_ERROR_TYPE_ERROR, | 467 | LOG (GNUNET_ERROR_TYPE_ERROR, |
468 | _("Error while decoding key %u\n"), key_number); | 468 | _("Error while decoding key %u\n"), key_number); |
469 | return GNUNET_SYSERR; | 469 | return NULL; |
470 | } | 470 | } |
471 | GNUNET_CRYPTO_rsa_key_get_public (private_key, &public_key); | 471 | GNUNET_CRYPTO_rsa_key_get_public (private_key, &public_key); |
472 | GNUNET_CRYPTO_hash (&public_key, | 472 | GNUNET_CRYPTO_hash (&public_key, |
473 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 473 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
474 | &(id->hashPubKey)); | 474 | &(id->hashPubKey)); |
475 | GNUNET_CRYPTO_rsa_key_free (private_key); | 475 | return private_key; |
476 | return GNUNET_OK; | ||
477 | } | 476 | } |
478 | 477 | ||
479 | 478 | ||
@@ -698,6 +697,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
698 | char hostkey_filename[128]; | 697 | char hostkey_filename[128]; |
699 | char *config_filename; | 698 | char *config_filename; |
700 | char *emsg_; | 699 | char *emsg_; |
700 | struct GNUNET_CRYPTO_RsaPrivateKey *pk; | ||
701 | 701 | ||
702 | if (NULL != emsg) | 702 | if (NULL != emsg) |
703 | *emsg = NULL; | 703 | *emsg = NULL; |
@@ -724,8 +724,9 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
724 | GNUNET_free (emsg_); | 724 | GNUNET_free (emsg_); |
725 | return NULL; | 725 | return NULL; |
726 | } | 726 | } |
727 | pk = NULL; | ||
727 | if ((NULL != id) && | 728 | if ((NULL != id) && |
728 | (GNUNET_SYSERR == GNUNET_TESTING_hostkey_get (system, key_number, id))) | 729 | (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id)))) |
729 | { | 730 | { |
730 | GNUNET_asprintf (&emsg_, | 731 | GNUNET_asprintf (&emsg_, |
731 | _("Failed to initialize hostkey for peer %u\n"), | 732 | _("Failed to initialize hostkey for peer %u\n"), |
@@ -737,6 +738,8 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, | |||
737 | GNUNET_free (emsg_); | 738 | GNUNET_free (emsg_); |
738 | return NULL; | 739 | return NULL; |
739 | } | 740 | } |
741 | if (NULL != pk) | ||
742 | GNUNET_CRYPTO_rsa_key_free (pk); | ||
740 | GNUNET_assert (GNUNET_OK == | 743 | GNUNET_assert (GNUNET_OK == |
741 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", | 744 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", |
742 | "SERVICEHOME", | 745 | "SERVICEHOME", |