diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/peerstore/Makefile.am | 23 | ||||
-rw-r--r-- | src/peerstore/plugin_peerstore_flat.c | 4 | ||||
-rw-r--r-- | src/peerstore/test_plugin_peerstore.c | 182 | ||||
-rw-r--r-- | src/peerstore/test_plugin_peerstore_flat.conf | 5 | ||||
-rw-r--r-- | src/peerstore/test_plugin_peerstore_sqlite.conf | 2 |
5 files changed, 210 insertions, 6 deletions
diff --git a/src/peerstore/Makefile.am b/src/peerstore/Makefile.am index dbb86553d..a12fdde2a 100644 --- a/src/peerstore/Makefile.am +++ b/src/peerstore/Makefile.am | |||
@@ -52,8 +52,8 @@ libgnunetpeerstore_la_LDFLAGS = \ | |||
52 | $(GN_LIB_LDFLAGS) | 52 | $(GN_LIB_LDFLAGS) |
53 | 53 | ||
54 | if HAVE_EXPERIMENTAL | 54 | if HAVE_EXPERIMENTAL |
55 | FLAT_PLUGIN = libgnunet_plugin_peerstore_flat.la | 55 | FLAT_PLUGIN = libgnunet_plugin_peerstore_flat.la |
56 | 56 | FLAT_TESTS = test_plugin_peerstore_flat | |
57 | libgnunet_plugin_peerstore_flat_la_SOURCES = \ | 57 | libgnunet_plugin_peerstore_flat_la_SOURCES = \ |
58 | plugin_peerstore_flat.c | 58 | plugin_peerstore_flat.c |
59 | libgnunet_plugin_peerstore_flat_la_LIBADD = \ | 59 | libgnunet_plugin_peerstore_flat_la_LIBADD = \ |
@@ -66,7 +66,9 @@ endif | |||
66 | 66 | ||
67 | if HAVE_SQLITE | 67 | if HAVE_SQLITE |
68 | SQLITE_PLUGIN = libgnunet_plugin_peerstore_sqlite.la | 68 | SQLITE_PLUGIN = libgnunet_plugin_peerstore_sqlite.la |
69 | 69 | if HAVE_TESTING | |
70 | SQLITE_TESTS = test_plugin_peerstore_sqlite | ||
71 | endif | ||
70 | libgnunet_plugin_peerstore_sqlite_la_SOURCES = \ | 72 | libgnunet_plugin_peerstore_sqlite_la_SOURCES = \ |
71 | plugin_peerstore_sqlite.c | 73 | plugin_peerstore_sqlite.c |
72 | libgnunet_plugin_peerstore_sqlite_la_LIBADD = \ | 74 | libgnunet_plugin_peerstore_sqlite_la_LIBADD = \ |
@@ -81,13 +83,26 @@ plugin_LTLIBRARIES = \ | |||
81 | $(SQLITE_PLUGIN) \ | 83 | $(SQLITE_PLUGIN) \ |
82 | $(FLAT_PLUGIN) | 84 | $(FLAT_PLUGIN) |
83 | 85 | ||
86 | test_plugin_peerstore_sqlite_SOURCES = \ | ||
87 | test_plugin_peerstore.c | ||
88 | test_plugin_peerstore_sqlite_LDADD = \ | ||
89 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
90 | $(top_builddir)/src/util/libgnunetutil.la | ||
91 | |||
92 | test_plugin_peerstore_flat_SOURCES = \ | ||
93 | test_plugin_peerstore.c | ||
94 | test_plugin_peerstore_flat_LDADD = \ | ||
95 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
96 | $(top_builddir)/src/util/libgnunetutil.la | ||
84 | 97 | ||
85 | check_PROGRAMS = \ | 98 | check_PROGRAMS = \ |
86 | test_peerstore_api_store \ | 99 | test_peerstore_api_store \ |
87 | test_peerstore_api_iterate \ | 100 | test_peerstore_api_iterate \ |
88 | test_peerstore_api_watch \ | 101 | test_peerstore_api_watch \ |
89 | test_peerstore_api_sync \ | 102 | test_peerstore_api_sync \ |
90 | perf_peerstore_store | 103 | perf_peerstore_store \ |
104 | $(SQLITE_TESTS) \ | ||
105 | $(FLAT_TESTS) | ||
91 | 106 | ||
92 | EXTRA_DIST = \ | 107 | EXTRA_DIST = \ |
93 | test_peerstore_api_data.conf | 108 | test_peerstore_api_data.conf |
diff --git a/src/peerstore/plugin_peerstore_flat.c b/src/peerstore/plugin_peerstore_flat.c index ba5301d09..5ffabed8f 100644 --- a/src/peerstore/plugin_peerstore_flat.c +++ b/src/peerstore/plugin_peerstore_flat.c | |||
@@ -294,10 +294,10 @@ peerstore_flat_store_record (void *cls, const char *sub_system, | |||
294 | entry->sub_system = GNUNET_strdup (sub_system); | 294 | entry->sub_system = GNUNET_strdup (sub_system); |
295 | entry->key = GNUNET_strdup (key); | 295 | entry->key = GNUNET_strdup (key); |
296 | entry->value = GNUNET_malloc (size); | 296 | entry->value = GNUNET_malloc (size); |
297 | memcpy (&entry->value, value, size); | 297 | memcpy (entry->value, value, size); |
298 | entry->value_size = size; | 298 | entry->value_size = size; |
299 | entry->peer = GNUNET_new (struct GNUNET_PeerIdentity); | 299 | entry->peer = GNUNET_new (struct GNUNET_PeerIdentity); |
300 | memcpy (&entry->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 300 | memcpy (entry->peer, peer, sizeof (struct GNUNET_PeerIdentity)); |
301 | entry->expiry = GNUNET_new (struct GNUNET_TIME_Absolute); | 301 | entry->expiry = GNUNET_new (struct GNUNET_TIME_Absolute); |
302 | entry->expiry->abs_value_us = expiry.abs_value_us; | 302 | entry->expiry->abs_value_us = expiry.abs_value_us; |
303 | 303 | ||
diff --git a/src/peerstore/test_plugin_peerstore.c b/src/peerstore/test_plugin_peerstore.c new file mode 100644 index 000000000..da78b3f75 --- /dev/null +++ b/src/peerstore/test_plugin_peerstore.c | |||
@@ -0,0 +1,182 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2015 GNUnet e.V. | ||
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., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /* | ||
21 | * @file namestore/test_plugin_namestore.c | ||
22 | * @brief Test for the namestore plugins | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "gnunet_peerstore_plugin.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | |||
30 | |||
31 | static int ok; | ||
32 | |||
33 | /** | ||
34 | * Name of plugin under test. | ||
35 | */ | ||
36 | static const char *plugin_name; | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Function called when the service shuts down. Unloads our namestore | ||
41 | * plugin. | ||
42 | * | ||
43 | * @param api api to unload | ||
44 | */ | ||
45 | static void | ||
46 | unload_plugin (struct GNUNET_PEERSTORE_PluginFunctions *api) | ||
47 | { | ||
48 | char *libname; | ||
49 | |||
50 | GNUNET_asprintf (&libname, "libgnunet_plugin_peer_%s", plugin_name); | ||
51 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); | ||
52 | GNUNET_free (libname); | ||
53 | } | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Load the namestore plugin. | ||
58 | * | ||
59 | * @param cfg configuration to pass | ||
60 | * @return NULL on error | ||
61 | */ | ||
62 | static struct GNUNET_PEERSTORE_PluginFunctions * | ||
63 | load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
64 | { | ||
65 | struct GNUNET_PEERSTORE_PluginFunctions *ret; | ||
66 | char *libname; | ||
67 | |||
68 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' peer plugin\n"), | ||
69 | plugin_name); | ||
70 | GNUNET_asprintf (&libname, "libgnunet_plugin_peerstore_%s", plugin_name); | ||
71 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg))) | ||
72 | { | ||
73 | FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name); | ||
74 | GNUNET_free (libname); | ||
75 | return NULL; | ||
76 | } | ||
77 | GNUNET_free (libname); | ||
78 | return ret; | ||
79 | } | ||
80 | |||
81 | |||
82 | static int | ||
83 | test_record (void *cls, | ||
84 | const struct GNUNET_PEERSTORE_Record *record, | ||
85 | const char *error) | ||
86 | { | ||
87 | struct GNUNET_PeerIdentity *id = cls; | ||
88 | char* testval = "test_val"; | ||
89 | |||
90 | if (NULL == record) | ||
91 | return GNUNET_NO; | ||
92 | |||
93 | GNUNET_assert (0 == memcmp (record->peer, id, sizeof (struct GNUNET_PeerIdentity))); | ||
94 | GNUNET_assert (0 == strcmp ("subsys", record->sub_system)); | ||
95 | GNUNET_assert (0 == strcmp ("key", record->key)); | ||
96 | GNUNET_assert (0 == memcmp (testval, record->value, strlen (testval))); | ||
97 | return GNUNET_YES; | ||
98 | } | ||
99 | |||
100 | |||
101 | static void | ||
102 | get_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, | ||
103 | const struct GNUNET_PeerIdentity *identity) | ||
104 | { | ||
105 | GNUNET_assert (GNUNET_OK == psp->iterate_records (psp->cls, | ||
106 | "subsys", identity, "key", &test_record, (void*)identity)); | ||
107 | } | ||
108 | |||
109 | static void | ||
110 | store_cont (void *cls, int status) | ||
111 | { | ||
112 | GNUNET_assert (GNUNET_OK == status); | ||
113 | } | ||
114 | |||
115 | static void | ||
116 | put_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, struct GNUNET_PeerIdentity *identity) | ||
117 | { | ||
118 | GNUNET_assert (GNUNET_OK == psp->store_record (psp->cls, | ||
119 | "subsys", | ||
120 | identity, | ||
121 | "key", "test_value", strlen ("test_value"), | ||
122 | GNUNET_TIME_absolute_get (), | ||
123 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
124 | &store_cont, | ||
125 | identity)); | ||
126 | } | ||
127 | |||
128 | |||
129 | static void | ||
130 | run (void *cls, char *const *args, const char *cfgfile, | ||
131 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
132 | { | ||
133 | struct GNUNET_PEERSTORE_PluginFunctions *psp; | ||
134 | struct GNUNET_PeerIdentity p1; | ||
135 | |||
136 | ok = 0; | ||
137 | psp = load_plugin (cfg); | ||
138 | if (NULL == psp) | ||
139 | { | ||
140 | FPRINTF (stderr, | ||
141 | "%s", | ||
142 | "Failed to initialize peerstore. Database likely not setup, skipping test.\n"); | ||
143 | return; | ||
144 | } | ||
145 | memset (&p1, 1, sizeof (p1)); | ||
146 | put_record (psp, &p1); | ||
147 | get_record (psp, &p1); | ||
148 | |||
149 | unload_plugin (psp); | ||
150 | } | ||
151 | |||
152 | |||
153 | int | ||
154 | main (int argc, char *argv[]) | ||
155 | { | ||
156 | char cfg_name[128]; | ||
157 | char *const xargv[] = { | ||
158 | "test-plugin-peerstore", | ||
159 | "-c", | ||
160 | cfg_name, | ||
161 | NULL | ||
162 | }; | ||
163 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
164 | GNUNET_GETOPT_OPTION_END | ||
165 | }; | ||
166 | |||
167 | //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite"); | ||
168 | GNUNET_log_setup ("test-plugin-peerstore", | ||
169 | "WARNING", | ||
170 | NULL); | ||
171 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | ||
172 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_peerstore_%s.conf", | ||
173 | plugin_name); | ||
174 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | ||
175 | "test-plugin-peerstore", "nohelp", options, &run, NULL); | ||
176 | if (ok != 0) | ||
177 | FPRINTF (stderr, "Missed some testcases: %d\n", ok); | ||
178 | //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite"); | ||
179 | return ok; | ||
180 | } | ||
181 | |||
182 | /* end of test_plugin_namestore.c */ | ||
diff --git a/src/peerstore/test_plugin_peerstore_flat.conf b/src/peerstore/test_plugin_peerstore_flat.conf new file mode 100644 index 000000000..48cc9940d --- /dev/null +++ b/src/peerstore/test_plugin_peerstore_flat.conf | |||
@@ -0,0 +1,5 @@ | |||
1 | [peerstore-flat] | ||
2 | FILENAME = /tmp/gnunet-test-plugin-namestore-flat/flatdb | ||
3 | |||
4 | [peerstore] | ||
5 | PREFIX = valgrind --log-file=/home/schanzen/dev/gnunet/src/peerstore/vg_log | ||
diff --git a/src/peerstore/test_plugin_peerstore_sqlite.conf b/src/peerstore/test_plugin_peerstore_sqlite.conf new file mode 100644 index 000000000..4d011944f --- /dev/null +++ b/src/peerstore/test_plugin_peerstore_sqlite.conf | |||
@@ -0,0 +1,2 @@ | |||
1 | [peerstore-sqlite] | ||
2 | FILENAME = /tmp/gnunet-test-plugin-peerstore-sqlite/sqlite.db | ||