aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-07-24 13:48:06 +0200
committerChristian Grothoff <christian@grothoff.org>2019-07-24 13:48:06 +0200
commit98f2f7c900d0b31a0b05b06e77993a9ee7966d32 (patch)
tree739ff7068f0f570af4600b23884246a1acec1a0e
parentdaea7bb17e100621f04f1d87cfd5b475e37faad4 (diff)
downloadgnunet-98f2f7c900d0b31a0b05b06e77993a9ee7966d32.tar.gz
gnunet-98f2f7c900d0b31a0b05b06e77993a9ee7966d32.zip
add NZL
-rw-r--r--src/namestore/test_plugin_namestore.c108
1 files changed, 36 insertions, 72 deletions
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c
index b81900931..0cb99dcb9 100644
--- a/src/namestore/test_plugin_namestore.c
+++ b/src/namestore/test_plugin_namestore.c
@@ -49,12 +49,8 @@ unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api)
49{ 49{
50 char *libname; 50 char *libname;
51 51
52 GNUNET_asprintf (&libname, 52 GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name);
53 "libgnunet_plugin_namestore_%s", 53 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api));
54 plugin_name);
55 GNUNET_break (NULL ==
56 GNUNET_PLUGIN_unload (libname,
57 api));
58 GNUNET_free (libname); 54 GNUNET_free (libname);
59} 55}
60 56
@@ -72,16 +68,12 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
72 char *libname; 68 char *libname;
73 69
74 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 70 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
75 _("Loading `%s' namestore plugin\n"), 71 _ ("Loading `%s' namestore plugin\n"),
76 plugin_name); 72 plugin_name);
77 GNUNET_asprintf (&libname, 73 GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name);
78 "libgnunet_plugin_namestore_%s", 74 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void *) cfg)))
79 plugin_name);
80 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg)))
81 { 75 {
82 FPRINTF (stderr, 76 FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name);
83 "Failed to load plugin `%s'!\n",
84 plugin_name);
85 GNUNET_free (libname); 77 GNUNET_free (libname);
86 return NULL; 78 return NULL;
87 } 79 }
@@ -92,7 +84,7 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
92 84
93static void 85static void
94test_record (void *cls, 86test_record (void *cls,
95 uint64_t seq, 87 uint64_t seq,
96 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, 88 const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key,
97 const char *label, 89 const char *label,
98 unsigned int rd_count, 90 unsigned int rd_count,
@@ -104,69 +96,54 @@ test_record (void *cls,
104 char tname[64]; 96 char tname[64];
105 unsigned int trd_count = 1 + (id % 1024); 97 unsigned int trd_count = 1 + (id % 1024);
106 98
107 GNUNET_snprintf (tname, 99 GNUNET_snprintf (tname, sizeof (tname), "a%u", (unsigned int) id);
108 sizeof (tname),
109 "a%u",
110 (unsigned int) id);
111 GNUNET_assert (trd_count == rd_count); 100 GNUNET_assert (trd_count == rd_count);
112 for (unsigned int i=0;i<trd_count;i++) 101 for (unsigned int i = 0; i < trd_count; i++)
113 { 102 {
114 GNUNET_assert (rd[i].data_size == id % 10); 103 GNUNET_assert (rd[i].data_size == id % 10);
115 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10)); 104 GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10));
116 GNUNET_assert (rd[i].record_type == TEST_RECORD_TYPE); 105 GNUNET_assert (rd[i].record_type == TEST_RECORD_TYPE);
117 GNUNET_assert (rd[i].flags == 0); 106 GNUNET_assert (rd[i].flags == 0);
118 } 107 }
119 memset (&tzone_private_key, 108 memset (&tzone_private_key, (id % 241), sizeof (tzone_private_key));
120 (id % 241),
121 sizeof (tzone_private_key));
122 GNUNET_assert (0 == strcmp (label, tname)); 109 GNUNET_assert (0 == strcmp (label, tname));
123 GNUNET_assert (0 == GNUNET_memcmp (&tzone_private_key, 110 GNUNET_assert (0 == GNUNET_memcmp (&tzone_private_key, private_key));
124 private_key));
125} 111}
126 112
127 113
128static void 114static void
129get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, 115get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
130 int id)
131{ 116{
132 GNUNET_assert (GNUNET_OK == 117 GNUNET_assert (
133 nsp->iterate_records (nsp->cls, 118 GNUNET_OK ==
134 NULL, 119 nsp->iterate_records (nsp->cls, NULL, 0, 1, &test_record, &id));
135 0,
136 1,
137 &test_record,
138 &id));
139} 120}
140 121
141 122
142static void 123static void
143put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, 124put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id)
144 int id)
145{ 125{
146 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; 126 struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key;
147 char label[64]; 127 char label[64];
148 unsigned int rd_count = 1 + (id % 1024); 128 unsigned int rd_count = 1 + (id % 1024);
149 struct GNUNET_GNSRECORD_Data rd[rd_count]; 129 struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)];
150 struct GNUNET_CRYPTO_EcdsaSignature signature; 130 struct GNUNET_CRYPTO_EcdsaSignature signature;
151 131
152 GNUNET_snprintf (label, sizeof (label), 132 GNUNET_snprintf (label, sizeof (label), "a%u", (unsigned int) id);
153 "a%u", (unsigned int ) id); 133 for (unsigned int i = 0; i < rd_count; i++)
154 for (unsigned int i=0;i<rd_count;i++)
155 { 134 {
156 rd[i].data = "Hello World"; 135 rd[i].data = "Hello World";
157 rd[i].data_size = id % 10; 136 rd[i].data_size = id % 10;
158 rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us; 137 rd[i].expiration_time =
138 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us;
159 rd[i].record_type = TEST_RECORD_TYPE; 139 rd[i].record_type = TEST_RECORD_TYPE;
160 rd[i].flags = 0; 140 rd[i].flags = 0;
161 } 141 }
162 memset (&zone_private_key, (id % 241), sizeof (zone_private_key)); 142 memset (&zone_private_key, (id % 241), sizeof (zone_private_key));
163 memset (&signature, (id % 243), sizeof (signature)); 143 memset (&signature, (id % 243), sizeof (signature));
164 GNUNET_assert (GNUNET_OK == 144 GNUNET_assert (
165 nsp->store_records (nsp->cls, 145 GNUNET_OK ==
166 &zone_private_key, 146 nsp->store_records (nsp->cls, &zone_private_key, label, rd_count, rd));
167 label,
168 rd_count,
169 rd));
170} 147}
171 148
172 149
@@ -182,9 +159,10 @@ run (void *cls,
182 nsp = load_plugin (cfg); 159 nsp = load_plugin (cfg);
183 if (NULL == nsp) 160 if (NULL == nsp)
184 { 161 {
185 FPRINTF (stderr, 162 FPRINTF (
186 "%s", 163 stderr,
187 "Failed to initialize namestore. Database likely not setup, skipping test.\n"); 164 "%s",
165 "Failed to initialize namestore. Database likely not setup, skipping test.\n");
188 return; 166 return;
189 } 167 }
190 put_record (nsp, 1); 168 put_record (nsp, 1);
@@ -195,30 +173,19 @@ run (void *cls,
195 173
196 174
197int 175int
198main (int argc, 176main (int argc, char *argv[])
199 char *argv[])
200{ 177{
201 char cfg_name[PATH_MAX]; 178 char cfg_name[PATH_MAX];
202 char *const xargv[] = { 179 char *const xargv[] = {"test-plugin-namestore", "-c", cfg_name, NULL};
203 "test-plugin-namestore", 180 struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END};
204 "-c", 181
205 cfg_name, 182 GNUNET_log_setup ("test-plugin-namestore", "WARNING", NULL);
206 NULL
207 };
208 struct GNUNET_GETOPT_CommandLineOption options[] = {
209 GNUNET_GETOPT_OPTION_END
210 };
211
212 GNUNET_log_setup ("test-plugin-namestore",
213 "WARNING",
214 NULL);
215 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 183 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
216 GNUNET_snprintf (cfg_name, 184 GNUNET_snprintf (cfg_name,
217 sizeof (cfg_name), 185 sizeof (cfg_name),
218 "test_plugin_namestore_%s.conf", 186 "test_plugin_namestore_%s.conf",
219 plugin_name); 187 plugin_name);
220 GNUNET_DISK_purge_cfg_dir (cfg_name, 188 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP");
221 "GNUNET_TMP");
222 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 189 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
223 xargv, 190 xargv,
224 "test-plugin-namestore", 191 "test-plugin-namestore",
@@ -226,12 +193,9 @@ main (int argc,
226 options, 193 options,
227 &run, 194 &run,
228 NULL); 195 NULL);
229 GNUNET_DISK_purge_cfg_dir (cfg_name, 196 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TMP");
230 "GNUNET_TMP");
231 if (ok != 0) 197 if (ok != 0)
232 FPRINTF (stderr, 198 FPRINTF (stderr, "Missed some testcases: %d\n", ok);
233 "Missed some testcases: %d\n",
234 ok);
235 return ok; 199 return ok;
236} 200}
237 201