aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/peerinfo/Makefile.am2
-rwxr-xr-xsrc/peerinfo/perf_peerinfo_api.c75
-rw-r--r--src/peerinfo/test_peerinfo_api.c79
3 files changed, 36 insertions, 120 deletions
diff --git a/src/peerinfo/Makefile.am b/src/peerinfo/Makefile.am
index 7ded60a9d..192391d88 100644
--- a/src/peerinfo/Makefile.am
+++ b/src/peerinfo/Makefile.am
@@ -57,6 +57,7 @@ test_peerinfo_api_SOURCES = \
57test_peerinfo_api_LDADD = \ 57test_peerinfo_api_LDADD = \
58 $(top_builddir)/src/hello/libgnunethello.la \ 58 $(top_builddir)/src/hello/libgnunethello.la \
59 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ 59 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
60 $(top_builddir)/src/testing/libgnunettesting.la \
60 $(top_builddir)/src/util/libgnunetutil.la 61 $(top_builddir)/src/util/libgnunetutil.la
61 62
62perf_peerinfo_api_SOURCES = \ 63perf_peerinfo_api_SOURCES = \
@@ -64,6 +65,7 @@ perf_peerinfo_api_SOURCES = \
64perf_peerinfo_api_LDADD = \ 65perf_peerinfo_api_LDADD = \
65 $(top_builddir)/src/hello/libgnunethello.la \ 66 $(top_builddir)/src/hello/libgnunethello.la \
66 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ 67 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
68 $(top_builddir)/src/testing/libgnunettesting.la \
67 $(top_builddir)/src/util/libgnunetutil.la 69 $(top_builddir)/src/util/libgnunetutil.la
68 70
69EXTRA_DIST = \ 71EXTRA_DIST = \
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c
index 34888fada..a1e309d64 100755
--- a/src/peerinfo/perf_peerinfo_api.c
+++ b/src/peerinfo/perf_peerinfo_api.c
@@ -19,18 +19,16 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file peerinfo/test_peerinfo_hammer.c 22 * @file peerinfo/perf_peerinfo_api.c
23 * @brief testcase for peerinfo_api.c, hopefully hammer the peerinfo service 23 * @brief testcase for peerinfo_api.c, hopefully hammer the peerinfo service
24 * @author Nathan Evans 24 * @author Nathan Evans
25 */ 25 */
26 26
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_hello_lib.h" 28#include "gnunet_hello_lib.h"
29#include "gnunet_getopt_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_os_lib.h" 30#include "gnunet_testing_lib-new.h"
31#include "gnunet_peerinfo_service.h" 31#include "gnunet_peerinfo_service.h"
32#include "gnunet_program_lib.h"
33#include "gnunet_time_lib.h"
34#include "peerinfo.h" 32#include "peerinfo.h"
35#include <gauger.h> 33#include <gauger.h>
36 34
@@ -38,8 +36,6 @@
38 36
39#define NUM_REQUESTS 5000 37#define NUM_REQUESTS 5000
40 38
41static const struct GNUNET_CONFIGURATION_Handle *cfg;
42
43static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS]; 39static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS];
44 40
45static struct GNUNET_PEERINFO_Handle *h; 41static struct GNUNET_PEERINFO_Handle *h;
@@ -112,12 +108,11 @@ process (void *cls, const struct GNUNET_PeerIdentity *peer,
112 108
113 109
114static void 110static void
115run (void *cls, char *const *args, const char *cfgfile, 111run (void *cls,
116 const struct GNUNET_CONFIGURATION_Handle *c) 112 const struct GNUNET_CONFIGURATION_Handle *cfg)
117{ 113{
118 size_t i; 114 size_t i;
119 115
120 cfg = c;
121 h = GNUNET_PEERINFO_connect (cfg); 116 h = GNUNET_PEERINFO_connect (cfg);
122 GNUNET_assert (h != NULL); 117 GNUNET_assert (h != NULL);
123 for (i = 0; i < NUM_REQUESTS; i++) 118 for (i = 0; i < NUM_REQUESTS; i++)
@@ -130,61 +125,19 @@ run (void *cls, char *const *args, const char *cfgfile,
130 } 125 }
131} 126}
132 127
133static int
134check ()
135{
136 int ok = 0;
137
138 char *const argv[] = { "perf-peerinfo-api",
139 "-c",
140 "test_peerinfo_api_data.conf",
141 "-L", "ERROR",
142 NULL
143 };
144#if START_SERVICE
145 struct GNUNET_OS_Process *proc;
146
147 struct GNUNET_GETOPT_CommandLineOption options[] = {
148 GNUNET_GETOPT_OPTION_END
149 };
150 proc =
151 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-peerinfo",
152 "gnunet-service-peerinfo",
153 "-L", "ERROR",
154 "-c", "test_peerinfo_api_data.conf", NULL);
155#endif
156 GNUNET_assert (NULL != proc);
157 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
158 "perf-peerinfo-api", "nohelp", options, &run, &ok);
159 FPRINTF (stderr, "Received %u/%u calls before timeout\n", numpeers,
160 NUM_REQUESTS * NUM_REQUESTS / 2);
161 GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s");
162#if START_SERVICE
163 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
164 {
165 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
166 ok = 1;
167 }
168 GNUNET_OS_process_wait (proc);
169 GNUNET_OS_process_destroy (proc);
170 proc = NULL;
171#endif
172 return ok;
173}
174
175 128
176int 129int
177main (int argc, char *argv[]) 130main (int argc, char *argv[])
178{ 131{
179 int ret = 0; 132 if (0 != GNUNET_TESTING_service_run ("perf-gnunet-peerinfo",
180 133 "peerinfo",
181 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo"); 134 "test_peerinfo_api_data.conf",
182 GNUNET_log_setup ("perf_peerinfo_api", 135 &run, NULL))
183 "ERROR", 136 return 1;
184 NULL); 137 FPRINTF (stderr, "Received %u/%u calls before timeout\n", numpeers,
185 ret = check (); 138 NUM_REQUESTS * NUM_REQUESTS / 2);
186 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo"); 139 GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s");
187 return ret; 140 return 0;
188} 141}
189 142
190/* end of perf_peerinfo_api.c */ 143/* end of perf_peerinfo_api.c */
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c
index e66878ea6..0bd5ef707 100644
--- a/src/peerinfo/test_peerinfo_api.c
+++ b/src/peerinfo/test_peerinfo_api.c
@@ -26,24 +26,22 @@
26 * TODO: 26 * TODO:
27 * - test merging of HELLOs (add same peer twice...) 27 * - test merging of HELLOs (add same peer twice...)
28 */ 28 */
29
30#include "platform.h" 29#include "platform.h"
31#include "gnunet_hello_lib.h" 30#include "gnunet_hello_lib.h"
32#include "gnunet_getopt_lib.h" 31#include "gnunet_util_lib.h"
33#include "gnunet_os_lib.h"
34#include "gnunet_peerinfo_service.h" 32#include "gnunet_peerinfo_service.h"
35#include "gnunet_program_lib.h" 33#include "gnunet_testing_lib-new.h"
36#include "gnunet_time_lib.h"
37#include "peerinfo.h" 34#include "peerinfo.h"
38 35
39static const struct GNUNET_CONFIGURATION_Handle *cfg;
40
41static struct GNUNET_PEERINFO_IteratorContext *ic; 36static struct GNUNET_PEERINFO_IteratorContext *ic;
42 37
43static struct GNUNET_PEERINFO_Handle *h; 38static struct GNUNET_PEERINFO_Handle *h;
44 39
45static unsigned int retries; 40static unsigned int retries;
46 41
42static int global_ret;
43
44
47static int 45static int
48check_it (void *cls, const struct GNUNET_HELLO_Address *address, 46check_it (void *cls, const struct GNUNET_HELLO_Address *address,
49 struct GNUNET_TIME_Absolute expiration) 47 struct GNUNET_TIME_Absolute expiration)
@@ -106,7 +104,6 @@ static void
106process (void *cls, const struct GNUNET_PeerIdentity *peer, 104process (void *cls, const struct GNUNET_PeerIdentity *peer,
107 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 105 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
108{ 106{
109 int *ok = cls;
110 unsigned int agc; 107 unsigned int agc;
111 108
112 if (err_msg != NULL) 109 if (err_msg != NULL)
@@ -118,7 +115,7 @@ process (void *cls, const struct GNUNET_PeerIdentity *peer,
118 if (peer == NULL) 115 if (peer == NULL)
119 { 116 {
120 ic = NULL; 117 ic = NULL;
121 if ((3 == *ok) && (retries < 50)) 118 if ((3 == global_ret) && (retries < 50))
122 { 119 {
123 /* try again */ 120 /* try again */
124 retries++; 121 retries++;
@@ -130,30 +127,29 @@ process (void *cls, const struct GNUNET_PeerIdentity *peer,
130 return; 127 return;
131 } 128 }
132 GNUNET_assert (peer == NULL); 129 GNUNET_assert (peer == NULL);
133 GNUNET_assert (2 == *ok); 130 GNUNET_assert (2 == global_ret);
134 GNUNET_PEERINFO_disconnect (h); 131 GNUNET_PEERINFO_disconnect (h);
135 h = NULL; 132 h = NULL;
136 *ok = 0; 133 global_ret = 0;
137 return; 134 return;
138 } 135 }
139 if (hello != NULL) 136 if (hello != NULL)
140 { 137 {
141 GNUNET_assert (3 == *ok); 138 GNUNET_assert (3 == global_ret);
142 agc = 3; 139 agc = 3;
143 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc); 140 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc);
144 GNUNET_assert (agc == 0); 141 GNUNET_assert (agc == 0);
145 *ok = 2; 142 global_ret = 2;
146 } 143 }
147} 144}
148 145
149 146
150static void 147static void
151run (void *cls, char *const *args, const char *cfgfile, 148run (void *cls,
152 const struct GNUNET_CONFIGURATION_Handle *c) 149 const struct GNUNET_CONFIGURATION_Handle *cfg)
153{ 150{
154 cfg = c;
155 h = GNUNET_PEERINFO_connect (cfg); 151 h = GNUNET_PEERINFO_connect (cfg);
156 GNUNET_assert (h != NULL); 152 GNUNET_assert (NULL != h);
157 add_peer (); 153 add_peer ();
158 ic = GNUNET_PEERINFO_iterate (h, NULL, 154 ic = GNUNET_PEERINFO_iterate (h, NULL,
159 GNUNET_TIME_relative_multiply 155 GNUNET_TIME_relative_multiply
@@ -161,51 +157,16 @@ run (void *cls, char *const *args, const char *cfgfile,
161} 157}
162 158
163 159
164static int
165check ()
166{
167 int ok = 3;
168 struct GNUNET_OS_Process *proc;
169
170 char *const argv[] = { "test-peerinfo-api",
171 "-c",
172 "test_peerinfo_api_data.conf",
173 NULL
174 };
175 struct GNUNET_GETOPT_CommandLineOption options[] = {
176 GNUNET_GETOPT_OPTION_END
177 };
178 proc =
179 GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-peerinfo",
180 "gnunet-service-peerinfo",
181 "-c", "test_peerinfo_api_data.conf", NULL);
182 GNUNET_assert (NULL != proc);
183 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
184 "test-peerinfo-api", "nohelp", options, &run, &ok);
185 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
186 {
187 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
188 ok = 1;
189 }
190 GNUNET_OS_process_wait (proc);
191 GNUNET_OS_process_destroy (proc);
192 proc = NULL;
193 return ok;
194}
195
196
197int 160int
198main (int argc, char *argv[]) 161main (int argc, char *argv[])
199{ 162{
200 int ret = 0; 163 global_ret = 3;
201 164 if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerinfo",
202 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo"); 165 "peerinfo",
203 GNUNET_log_setup ("test_peerinfo_api", 166 "test_peerinfo_api_data.conf",
204 "WARNING", 167 &run, NULL))
205 NULL); 168 return 1;
206 ret = check (); 169 return global_ret;
207 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo");
208 return ret;
209} 170}
210 171
211/* end of test_peerinfo_api.c */ 172/* end of test_peerinfo_api.c */