aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-02-24 10:28:16 +0100
committerChristian Grothoff <christian@grothoff.org>2019-02-24 10:28:16 +0100
commit0b5dc8a620fca8dbca9c122594b70267e404859f (patch)
tree71166165545fcd77ee36bba8eaec45f7bac62da9 /src/namestore
parent4577873dccd43d132062ae3c07e316c86be6af2f (diff)
downloadgnunet-0b5dc8a620fca8dbca9c122594b70267e404859f.tar.gz
gnunet-0b5dc8a620fca8dbca9c122594b70267e404859f.zip
avoid failing hard if 'gnunetcheck' db does not exist
(or plugins cannot be loaded for other reasons)
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/Makefile.am1
-rw-r--r--src/namestore/perf_namestore_api_zone_iteration.c17
-rw-r--r--src/namestore/test_common.c89
-rw-r--r--src/namestore/test_namestore_api_lookup_nick.c9
-rw-r--r--src/namestore/test_namestore_api_lookup_private.c10
-rw-r--r--src/namestore/test_namestore_api_lookup_public.c10
-rw-r--r--src/namestore/test_namestore_api_lookup_shadow_filter.c10
-rw-r--r--src/namestore/test_namestore_api_monitoring.c10
-rw-r--r--src/namestore/test_namestore_api_store.c11
-rw-r--r--src/namestore/test_namestore_api_store_update.c10
-rw-r--r--src/namestore/test_namestore_api_zone_iteration.c16
11 files changed, 134 insertions, 59 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index c9ff763fd..ac4eebd06 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -662,6 +662,7 @@ check_SCRIPTS = \
662 test_namestore_delete.sh 662 test_namestore_delete.sh
663 663
664EXTRA_DIST = \ 664EXTRA_DIST = \
665 test_common.c \
665 test_namestore_api.conf \ 666 test_namestore_api.conf \
666 test_namestore_api_postgres.conf \ 667 test_namestore_api_postgres.conf \
667 test_namestore_api_sqlite.conf \ 668 test_namestore_api_sqlite.conf \
diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c
index 505f624df..5da958aad 100644
--- a/src/namestore/perf_namestore_api_zone_iteration.c
+++ b/src/namestore/perf_namestore_api_zone_iteration.c
@@ -276,7 +276,12 @@ put_cont (void *cls,
276{ 276{
277 (void) cls; 277 (void) cls;
278 qe = NULL; 278 qe = NULL;
279 GNUNET_assert (GNUNET_OK == success); 279 if (GNUNET_OK != success)
280 {
281 GNUNET_break (0);
282 GNUNET_SCHEDULER_shutdown ();
283 return;
284 }
280 t = GNUNET_SCHEDULER_add_now (&publish_record, 285 t = GNUNET_SCHEDULER_add_now (&publish_record,
281 NULL); 286 NULL);
282} 287}
@@ -349,6 +354,9 @@ run (void *cls,
349} 354}
350 355
351 356
357#include "test_common.c"
358
359
352int 360int
353main (int argc, 361main (int argc,
354 char *argv[]) 362 char *argv[])
@@ -356,13 +364,8 @@ main (int argc,
356 const char *plugin_name; 364 const char *plugin_name;
357 char *cfg_name; 365 char *cfg_name;
358 366
359 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 367 SETUP_CFG (plugin_name, cfg_name);
360 GNUNET_asprintf (&cfg_name,
361 "perf_namestore_api_%s.conf",
362 plugin_name);
363 res = 1; 368 res = 1;
364 GNUNET_DISK_purge_cfg_dir (cfg_name,
365 "GNUNET_TEST_HOME");
366 if (0 != 369 if (0 !=
367 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration", 370 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration",
368 cfg_name, 371 cfg_name,
diff --git a/src/namestore/test_common.c b/src/namestore/test_common.c
new file mode 100644
index 000000000..0dc6f9277
--- /dev/null
+++ b/src/namestore/test_common.c
@@ -0,0 +1,89 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2019 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19*/
20/**
21 * @file namestore/test_common.c
22 * @brief common functions for testcase setup
23 */
24
25/**
26 * test if we can load the plugin @a name.
27 */
28static int
29TNC_test_plugin (const char *cfg_name)
30{
31 char *database;
32 char *db_lib_name;
33 struct GNUNET_NAMESTORE_PluginFunctions *db;
34 struct GNUNET_CONFIGURATION_Handle *cfg;
35
36 cfg = GNUNET_CONFIGURATION_create ();
37 if (GNUNET_OK !=
38 GNUNET_CONFIGURATION_load (cfg,
39 cfg_name))
40 {
41 GNUNET_break (0);
42 GNUNET_CONFIGURATION_destroy (cfg);
43 return GNUNET_SYSERR;
44 }
45 if (GNUNET_OK !=
46 GNUNET_CONFIGURATION_get_value_string (cfg,
47 "namestore",
48 "database",
49 &database))
50 {
51 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
52 "No database backend configured\n");
53 GNUNET_CONFIGURATION_destroy (cfg);
54 return GNUNET_SYSERR;
55 }
56 GNUNET_asprintf (&db_lib_name,
57 "libgnunet_plugin_namestore_%s",
58 database);
59 db = GNUNET_PLUGIN_load (db_lib_name,
60 (void *) cfg);
61 if (NULL != db)
62 GNUNET_break (NULL ==
63 GNUNET_PLUGIN_unload (db_lib_name,
64 db));
65 GNUNET_free (db_lib_name);
66 GNUNET_CONFIGURATION_destroy (cfg);
67 if (NULL == db)
68 return GNUNET_NO;
69 return GNUNET_YES;
70}
71
72
73/**
74 * General setup logic for starting the tests. Obtains the @a
75 * plugin_name and initializes the @a cfg_name.
76 */
77#define SETUP_CFG(plugin_name,cfg_name) do { \
78 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \
79 GNUNET_asprintf (&cfg_name, \
80 "test_namestore_api_%s.conf", \
81 plugin_name); \
82 if (! TNC_test_plugin (cfg_name)) \
83 { \
84 GNUNET_free (cfg_name); \
85 return 77; \
86 } \
87 GNUNET_DISK_purge_cfg_dir (cfg_name, \
88 "GNUNET_TEST_HOME"); \
89 } while (0)
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c
index 8f2896359..1257701e9 100644
--- a/src/namestore/test_namestore_api_lookup_nick.c
+++ b/src/namestore/test_namestore_api_lookup_nick.c
@@ -306,6 +306,8 @@ run (void *cls,
306 } 306 }
307} 307}
308 308
309#include "test_common.c"
310
309 311
310int 312int
311main (int argc, char *argv[]) 313main (int argc, char *argv[])
@@ -313,12 +315,7 @@ main (int argc, char *argv[])
313 const char *plugin_name; 315 const char *plugin_name;
314 char *cfg_name; 316 char *cfg_name;
315 317
316 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 318 SETUP_CFG (plugin_name, cfg_name);
317 GNUNET_asprintf (&cfg_name,
318 "test_namestore_api_%s.conf",
319 plugin_name);
320 GNUNET_DISK_purge_cfg_dir (cfg_name,
321 "GNUNET_TEST_HOME");
322 res = 1; 319 res = 1;
323 if (0 != 320 if (0 !=
324 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick", 321 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick",
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c
index 0730db04c..2615f52c8 100644
--- a/src/namestore/test_namestore_api_lookup_private.c
+++ b/src/namestore/test_namestore_api_lookup_private.c
@@ -223,18 +223,16 @@ run (void *cls,
223} 223}
224 224
225 225
226#include "test_common.c"
227
228
226int 229int
227main (int argc, char *argv[]) 230main (int argc, char *argv[])
228{ 231{
229 const char *plugin_name; 232 const char *plugin_name;
230 char *cfg_name; 233 char *cfg_name;
231 234
232 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 235 SETUP_CFG(plugin_name, cfg_name);
233 GNUNET_asprintf (&cfg_name,
234 "test_namestore_api_%s.conf",
235 plugin_name);
236 GNUNET_DISK_purge_cfg_dir (cfg_name,
237 "GNUNET_TEST_HOME");
238 res = 1; 236 res = 1;
239 if (0 != 237 if (0 !=
240 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private", 238 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private",
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c
index 2a75d42f3..460be0a18 100644
--- a/src/namestore/test_namestore_api_lookup_public.c
+++ b/src/namestore/test_namestore_api_lookup_public.c
@@ -223,18 +223,16 @@ run (void *cls,
223} 223}
224 224
225 225
226#include "test_common.c"
227
228
226int 229int
227main (int argc, char *argv[]) 230main (int argc, char *argv[])
228{ 231{
229 const char *plugin_name; 232 const char *plugin_name;
230 char *cfg_name; 233 char *cfg_name;
231 234
232 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 235 SETUP_CFG (plugin_name, cfg_name);
233 GNUNET_asprintf (&cfg_name,
234 "test_namestore_api_%s.conf",
235 plugin_name);
236 GNUNET_DISK_purge_cfg_dir (cfg_name,
237 "GNUNET_TEST_HOME");
238 res = 1; 236 res = 1;
239 if (0 != 237 if (0 !=
240 GNUNET_TESTING_peer_run ("test-namestore-api", 238 GNUNET_TESTING_peer_run ("test-namestore-api",
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c
index 0347eafcc..3d1dbfacf 100644
--- a/src/namestore/test_namestore_api_lookup_shadow_filter.c
+++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c
@@ -333,18 +333,16 @@ run (void *cls,
333} 333}
334 334
335 335
336#include "test_common.c"
337
338
336int 339int
337main (int argc, char *argv[]) 340main (int argc, char *argv[])
338{ 341{
339 const char *plugin_name; 342 const char *plugin_name;
340 char *cfg_name; 343 char *cfg_name;
341 344
342 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 345 SETUP_CFG (plugin_name, cfg_name);
343 GNUNET_asprintf (&cfg_name,
344 "test_namestore_api_%s.conf",
345 plugin_name);
346 GNUNET_DISK_purge_cfg_dir (cfg_name,
347 "GNUNET_TEST_HOME");
348 res = 1; 346 res = 1;
349 if (0 != 347 if (0 !=
350 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter", 348 GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter",
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c
index 4aed21d86..c85ec8457 100644
--- a/src/namestore/test_namestore_api_monitoring.c
+++ b/src/namestore/test_namestore_api_monitoring.c
@@ -363,6 +363,9 @@ run (void *cls,
363} 363}
364 364
365 365
366#include "test_common.c"
367
368
366int 369int
367main (int argc, 370main (int argc,
368 char *argv[]) 371 char *argv[])
@@ -370,12 +373,7 @@ main (int argc,
370 const char *plugin_name; 373 const char *plugin_name;
371 char *cfg_name; 374 char *cfg_name;
372 375
373 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 376 SETUP_CFG (plugin_name, cfg_name);
374 GNUNET_asprintf (&cfg_name,
375 "test_namestore_api_%s.conf",
376 plugin_name);
377 GNUNET_DISK_purge_cfg_dir (cfg_name,
378 "GNUNET_TEST_HOME");
379 res = 1; 377 res = 1;
380 if (0 != 378 if (0 !=
381 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring", 379 GNUNET_TESTING_peer_run ("test-namestore-api-monitoring",
diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c
index 4fe77a2c6..0dbad8ce3 100644
--- a/src/namestore/test_namestore_api_store.c
+++ b/src/namestore/test_namestore_api_store.c
@@ -144,24 +144,21 @@ run (void *cls,
144 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 144 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
145 _("Namestore cannot store no block\n")); 145 _("Namestore cannot store no block\n"));
146 } 146 }
147
148 GNUNET_free ((void *)rd.data); 147 GNUNET_free ((void *)rd.data);
149} 148}
150 149
151 150
151#include "test_common.c"
152
153
152int 154int
153main (int argc, char *argv[]) 155main (int argc, char *argv[])
154{ 156{
155 const char *plugin_name; 157 const char *plugin_name;
156 char *cfg_name; 158 char *cfg_name;
157 159
158 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 160 SETUP_CFG (plugin_name, cfg_name);
159 GNUNET_asprintf (&cfg_name,
160 "test_namestore_api_%s.conf",
161 plugin_name);
162 res = 1; 161 res = 1;
163 GNUNET_DISK_purge_cfg_dir (cfg_name,
164 "GNUNET_TEST_HOME");
165 if (0 != 162 if (0 !=
166 GNUNET_TESTING_peer_run ("test-namestore-api", 163 GNUNET_TESTING_peer_run ("test-namestore-api",
167 cfg_name, 164 cfg_name,
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c
index aad5852e9..b1c0770ae 100644
--- a/src/namestore/test_namestore_api_store_update.c
+++ b/src/namestore/test_namestore_api_store_update.c
@@ -283,6 +283,9 @@ run (void *cls,
283} 283}
284 284
285 285
286#include "test_common.c"
287
288
286int 289int
287main (int argc, 290main (int argc,
288 char *argv[]) 291 char *argv[])
@@ -290,13 +293,8 @@ main (int argc,
290 const char *plugin_name; 293 const char *plugin_name;
291 char *cfg_name; 294 char *cfg_name;
292 295
293 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 296 SETUP_CFG (plugin_name, cfg_name);
294 GNUNET_asprintf (&cfg_name,
295 "test_namestore_api_%s.conf",
296 plugin_name);
297 res = 1; 297 res = 1;
298 GNUNET_DISK_purge_cfg_dir (cfg_name,
299 "GNUNET_TEST_HOME");
300 if (0 != 298 if (0 !=
301 GNUNET_TESTING_peer_run ("test-namestore-api-store-update", 299 GNUNET_TESTING_peer_run ("test-namestore-api-store-update",
302 cfg_name, 300 cfg_name,
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c
index d09505db1..fa641954b 100644
--- a/src/namestore/test_namestore_api_zone_iteration.c
+++ b/src/namestore/test_namestore_api_zone_iteration.c
@@ -98,9 +98,9 @@ end (void *cls)
98 GNUNET_free (privkey2); 98 GNUNET_free (privkey2);
99 privkey2 = NULL; 99 privkey2 = NULL;
100 } 100 }
101 GNUNET_free (s_name_1); 101 GNUNET_free_non_null (s_name_1);
102 GNUNET_free (s_name_2); 102 GNUNET_free_non_null (s_name_2);
103 GNUNET_free (s_name_3); 103 GNUNET_free_non_null (s_name_3);
104 if (NULL != s_rd_1) 104 if (NULL != s_rd_1)
105 { 105 {
106 GNUNET_free ((void *)s_rd_1->data); 106 GNUNET_free ((void *)s_rd_1->data);
@@ -466,18 +466,16 @@ run (void *cls,
466} 466}
467 467
468 468
469#include "test_common.c"
470
471
469int 472int
470main (int argc, char *argv[]) 473main (int argc, char *argv[])
471{ 474{
472 const char *plugin_name; 475 const char *plugin_name;
473 char *cfg_name; 476 char *cfg_name;
474 477
475 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 478 SETUP_CFG (plugin_name, cfg_name);
476 GNUNET_asprintf (&cfg_name,
477 "test_namestore_api_%s.conf",
478 plugin_name);
479 GNUNET_DISK_purge_cfg_dir (cfg_name,
480 "GNUNET_TEST_HOME");
481 res = 1; 479 res = 1;
482 if (0 != 480 if (0 !=
483 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration", 481 GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration",