diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-19 13:33:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-19 13:33:19 +0000 |
commit | 15f55fea6e6d2d1656e345eab131887efbd937b4 (patch) | |
tree | 4f73dcb99b65afaaec412b4a2969771497a6f876 /src/namestore/test_namestore_api_zone_to_name.c | |
parent | 0f084973d63c46217d25e6660fba56755f26e6bb (diff) | |
download | gnunet-15f55fea6e6d2d1656e345eab131887efbd937b4.tar.gz gnunet-15f55fea6e6d2d1656e345eab131887efbd937b4.zip |
-fixing IO-error bug in namestore tests on buildbots, simplifying testcases by using new testing API, eliminating dead code
Diffstat (limited to 'src/namestore/test_namestore_api_zone_to_name.c')
-rw-r--r-- | src/namestore/test_namestore_api_zone_to_name.c | 134 |
1 files changed, 32 insertions, 102 deletions
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c index 6efbaf534..e5db28165 100644 --- a/src/namestore/test_namestore_api_zone_to_name.c +++ b/src/namestore/test_namestore_api_zone_to_name.c | |||
@@ -24,63 +24,41 @@ | |||
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_common.h" | 25 | #include "gnunet_common.h" |
26 | #include "gnunet_namestore_service.h" | 26 | #include "gnunet_namestore_service.h" |
27 | #include "gnunet_testing_lib-new.h" | ||
27 | #include "namestore.h" | 28 | #include "namestore.h" |
28 | #include "gnunet_signatures.h" | 29 | #include "gnunet_signatures.h" |
29 | 30 | ||
30 | #define VERBOSE GNUNET_NO | ||
31 | |||
32 | #define RECORDS 5 | 31 | #define RECORDS 5 |
32 | |||
33 | #define TEST_RECORD_TYPE 1234 | 33 | #define TEST_RECORD_TYPE 1234 |
34 | |||
34 | #define TEST_RECORD_DATALEN 123 | 35 | #define TEST_RECORD_DATALEN 123 |
36 | |||
35 | #define TEST_RECORD_DATA 'a' | 37 | #define TEST_RECORD_DATA 'a' |
36 | 38 | ||
37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 39 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
38 | 40 | ||
41 | |||
39 | static struct GNUNET_NAMESTORE_Handle * nsh; | 42 | static struct GNUNET_NAMESTORE_Handle * nsh; |
40 | 43 | ||
41 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | 44 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; |
42 | static struct GNUNET_OS_Process *arm; | ||
43 | 45 | ||
44 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | 46 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; |
47 | |||
45 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 48 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
46 | 49 | ||
47 | struct GNUNET_TIME_Absolute expire; | 50 | static struct GNUNET_TIME_Absolute expire; |
48 | 51 | ||
49 | static struct GNUNET_CRYPTO_ShortHashCode s_zone; | 52 | static struct GNUNET_CRYPTO_ShortHashCode s_zone; |
53 | |||
50 | static struct GNUNET_CRYPTO_ShortHashCode s_zone_value; | 54 | static struct GNUNET_CRYPTO_ShortHashCode s_zone_value; |
51 | 55 | ||
52 | char * s_name; | 56 | static char * s_name; |
53 | 57 | ||
54 | struct GNUNET_NAMESTORE_RecordData *s_rd; | 58 | static struct GNUNET_CRYPTO_RsaSignature *s_signature; |
55 | struct GNUNET_CRYPTO_RsaSignature *s_signature; | ||
56 | 59 | ||
57 | static int res; | 60 | static int res; |
58 | 61 | ||
59 | static void | ||
60 | start_arm (const char *cfgname) | ||
61 | { | ||
62 | arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
63 | "gnunet-service-arm", "-c", cfgname, | ||
64 | #if VERBOSE_PEERS | ||
65 | "-L", "DEBUG", | ||
66 | #else | ||
67 | "-L", "ERROR", | ||
68 | #endif | ||
69 | NULL); | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | stop_arm () | ||
74 | { | ||
75 | if (NULL != arm) | ||
76 | { | ||
77 | if (0 != GNUNET_OS_process_kill (arm, SIGTERM)) | ||
78 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
79 | GNUNET_OS_process_wait (arm); | ||
80 | GNUNET_OS_process_destroy (arm); | ||
81 | arm = NULL; | ||
82 | } | ||
83 | } | ||
84 | 62 | ||
85 | /** | 63 | /** |
86 | * Re-establish the connection to the service. | 64 | * Re-establish the connection to the service. |
@@ -94,14 +72,9 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
94 | if (nsh != NULL) | 72 | if (nsh != NULL) |
95 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 73 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
96 | nsh = NULL; | 74 | nsh = NULL; |
97 | |||
98 | if (privkey != NULL) | 75 | if (privkey != NULL) |
99 | GNUNET_CRYPTO_rsa_key_free (privkey); | 76 | GNUNET_CRYPTO_rsa_key_free (privkey); |
100 | privkey = NULL; | 77 | privkey = NULL; |
101 | |||
102 | if (NULL != arm) | ||
103 | stop_arm(); | ||
104 | |||
105 | res = 1; | 78 | res = 1; |
106 | } | 79 | } |
107 | 80 | ||
@@ -114,26 +87,23 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
114 | GNUNET_SCHEDULER_cancel (endbadly_task); | 87 | GNUNET_SCHEDULER_cancel (endbadly_task); |
115 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 88 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; |
116 | } | 89 | } |
117 | |||
118 | if (privkey != NULL) | 90 | if (privkey != NULL) |
119 | GNUNET_CRYPTO_rsa_key_free (privkey); | 91 | GNUNET_CRYPTO_rsa_key_free (privkey); |
120 | privkey = NULL; | 92 | privkey = NULL; |
121 | |||
122 | if (nsh != NULL) | 93 | if (nsh != NULL) |
123 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); | 94 | GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); |
124 | nsh = NULL; | 95 | nsh = NULL; |
125 | |||
126 | if (NULL != arm) | ||
127 | stop_arm(); | ||
128 | } | 96 | } |
129 | 97 | ||
130 | void zone_to_name_proc (void *cls, | 98 | |
131 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 99 | static void |
132 | struct GNUNET_TIME_Absolute expire, | 100 | zone_to_name_proc (void *cls, |
133 | const char *n, | 101 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
134 | unsigned int rd_count, | 102 | struct GNUNET_TIME_Absolute expire, |
135 | const struct GNUNET_NAMESTORE_RecordData *rd, | 103 | const char *n, |
136 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 104 | unsigned int rd_count, |
105 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
106 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
137 | { | 107 | { |
138 | int fail = GNUNET_NO; | 108 | int fail = GNUNET_NO; |
139 | 109 | ||
@@ -169,26 +139,7 @@ void zone_to_name_proc (void *cls, | |||
169 | } | 139 | } |
170 | 140 | ||
171 | 141 | ||
172 | void | 142 | static void |
173 | delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
174 | { | ||
175 | char *afsdir; | ||
176 | |||
177 | if (GNUNET_OK == | ||
178 | GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", | ||
179 | "FILENAME", &afsdir)) | ||
180 | { | ||
181 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
182 | if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) | ||
183 | if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) | ||
184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); | ||
185 | GNUNET_free (afsdir); | ||
186 | } | ||
187 | |||
188 | } | ||
189 | |||
190 | |||
191 | void | ||
192 | put_cont (void *cls, int32_t success, const char *emsg) | 143 | put_cont (void *cls, int32_t success, const char *emsg) |
193 | { | 144 | { |
194 | char *name = cls; | 145 | char *name = cls; |
@@ -209,16 +160,13 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
209 | } | 160 | } |
210 | } | 161 | } |
211 | 162 | ||
163 | |||
212 | static void | 164 | static void |
213 | run (void *cls, char *const *args, const char *cfgfile, | 165 | run (void *cls, |
214 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 166 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
215 | { | 167 | { |
216 | delete_existing_db(cfg); | ||
217 | |||
218 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); | 168 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); |
219 | GNUNET_asprintf(&s_name, "dummy"); | 169 | GNUNET_asprintf(&s_name, "dummy"); |
220 | |||
221 | |||
222 | /* load privat key */ | 170 | /* load privat key */ |
223 | char *hostkey_file; | 171 | char *hostkey_file; |
224 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, | 172 | GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, |
@@ -241,10 +189,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
241 | rd.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); | 189 | rd.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); |
242 | rd.data = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_ShortHashCode)); | 190 | rd.data = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_ShortHashCode)); |
243 | memcpy ((char *) rd.data, &s_zone_value, sizeof (struct GNUNET_CRYPTO_ShortHashCode)); | 191 | memcpy ((char *) rd.data, &s_zone_value, sizeof (struct GNUNET_CRYPTO_ShortHashCode)); |
244 | |||
245 | start_arm (cfgfile); | ||
246 | GNUNET_assert (arm != NULL); | ||
247 | |||
248 | nsh = GNUNET_NAMESTORE_connect (cfg); | 192 | nsh = GNUNET_NAMESTORE_connect (cfg); |
249 | GNUNET_break (NULL != nsh); | 193 | GNUNET_break (NULL != nsh); |
250 | 194 | ||
@@ -255,34 +199,20 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
255 | GNUNET_free ((void *) rd.data); | 199 | GNUNET_free ((void *) rd.data); |
256 | } | 200 | } |
257 | 201 | ||
258 | static int | ||
259 | check () | ||
260 | { | ||
261 | static char *const argv[] = { "test-namestore-api", | ||
262 | "-c", | ||
263 | "test_namestore_api.conf", | ||
264 | #if VERBOSE | ||
265 | "-L", "DEBUG", | ||
266 | #endif | ||
267 | NULL | ||
268 | }; | ||
269 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
270 | GNUNET_GETOPT_OPTION_END | ||
271 | }; | ||
272 | 202 | ||
273 | res = 1; | ||
274 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-namestore-api", | ||
275 | "nohelp", options, &run, &res); | ||
276 | return res; | ||
277 | } | ||
278 | 203 | ||
279 | int | 204 | int |
280 | main (int argc, char *argv[]) | 205 | main (int argc, char *argv[]) |
281 | { | 206 | { |
282 | int ret; | 207 | res = 1; |
283 | 208 | if (0 != | |
284 | ret = check (); | 209 | GNUNET_TESTING_service_run ("test-namestore-api-zone-to-name", |
285 | return ret; | 210 | "namestore", |
211 | "test_namestore_api.conf", | ||
212 | &run, | ||
213 | NULL)) | ||
214 | return 1; | ||
215 | return res; | ||
286 | } | 216 | } |
287 | 217 | ||
288 | /* end of test_namestore_api.c */ | 218 | /* end of test_namestore_api_zone_to_name.c */ |