aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/test_conversation_api_twocalls.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-12-16 15:54:38 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-12-16 15:54:38 +0000
commit66fb60a6f01e8686ad9843daed8652b4331cde6f (patch)
tree1c5a780748650ef3e2926447668d056c9c7abb92 /src/conversation/test_conversation_api_twocalls.c
parent86feb72d269389e0289042907e1f9abbb70a442a (diff)
downloadgnunet-66fb60a6f01e8686ad9843daed8652b4331cde6f.tar.gz
gnunet-66fb60a6f01e8686ad9843daed8652b4331cde6f.zip
- handle logging clutter properly
- make testcase tighter
Diffstat (limited to 'src/conversation/test_conversation_api_twocalls.c')
-rw-r--r--src/conversation/test_conversation_api_twocalls.c79
1 files changed, 44 insertions, 35 deletions
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c
index d290dd6ef..266dc608e 100644
--- a/src/conversation/test_conversation_api_twocalls.c
+++ b/src/conversation/test_conversation_api_twocalls.c
@@ -39,7 +39,11 @@
39 39
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25) 40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25)
41 41
42static int ok = 1; 42#define LOG(kind,...) \
43 GNUNET_log (kind, __VA_ARGS__)
44
45#define LOG_DEBUG(...) \
46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
43 47
44static const struct GNUNET_CONFIGURATION_Handle *cfg; 48static const struct GNUNET_CONFIGURATION_Handle *cfg;
45 49
@@ -86,12 +90,24 @@ static const char *caller2 = "caller2";
86 */ 90 */
87static const char *phone0 = "phone"; 91static const char *phone0 = "phone";
88 92
93
89#define CALLER1 &caller1 94#define CALLER1 &caller1
90#define CALLER2 &caller2 95#define CALLER2 &caller2
91#define PHONE0 &phone0 96#define PHONE0 &phone0
92 97
93#define CLS_STR(caller) (*((char **)caller)) 98#define CLS_STR(caller) (*((char **)caller))
94 99
100
101/**
102 * Did caller1 call finish successfully
103 */
104static int call1_finished;
105
106/**
107 * Did caller2 call finish successfully
108 */
109static int call2_finished;
110
95struct MicContext 111struct MicContext
96{ 112{
97 GNUNET_MICROPHONE_RecordedDataCallback rdc; 113 GNUNET_MICROPHONE_RecordedDataCallback rdc;
@@ -100,7 +116,6 @@ struct MicContext
100 116
101 GNUNET_SCHEDULER_TaskIdentifier call_task; 117 GNUNET_SCHEDULER_TaskIdentifier call_task;
102 118
103 char sym;
104}; 119};
105 120
106static struct MicContext call1_mic_ctx; 121static struct MicContext call1_mic_ctx;
@@ -117,7 +132,6 @@ phone_send (void *cls,
117 GNUNET_assert (NULL != phone_rdc); 132 GNUNET_assert (NULL != phone_rdc);
118 GNUNET_snprintf (buf, sizeof (buf), "phone"); 133 GNUNET_snprintf (buf, sizeof (buf), "phone");
119 phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf); 134 phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf);
120 fprintf (stderr, "+");
121 phone_task = GNUNET_SCHEDULER_add_delayed (FREQ, 135 phone_task = GNUNET_SCHEDULER_add_delayed (FREQ,
122 &phone_send, NULL); 136 &phone_send, NULL);
123} 137}
@@ -133,7 +147,6 @@ call_send (void *cls,
133 GNUNET_assert (NULL != mc->rdc); 147 GNUNET_assert (NULL != mc->rdc);
134 GNUNET_snprintf (buf, sizeof (buf), "call"); 148 GNUNET_snprintf (buf, sizeof (buf), "call");
135 mc->rdc (mc->rdc_cls, strlen (buf) + 1, buf); 149 mc->rdc (mc->rdc_cls, strlen (buf) + 1, buf);
136 fprintf (stderr, "%c", mc->sym);
137 mc->call_task = GNUNET_SCHEDULER_add_delayed (FREQ, 150 mc->call_task = GNUNET_SCHEDULER_add_delayed (FREQ,
138 &call_send, mc); 151 &call_send, mc);
139} 152}
@@ -144,9 +157,8 @@ enable_speaker (void *cls)
144{ 157{
145 const char *origin = CLS_STR (cls); 158 const char *origin = CLS_STR (cls);
146 159
147 fprintf (stderr, 160 LOG_DEBUG ("Speaker %s enabled\n",
148 "Speaker %s enabled\n", 161 origin);
149 origin);
150 return GNUNET_OK; 162 return GNUNET_OK;
151} 163}
152 164
@@ -156,9 +168,8 @@ disable_speaker (void *cls)
156{ 168{
157 const char *origin = CLS_STR (cls); 169 const char *origin = CLS_STR (cls);
158 170
159 fprintf (stderr, 171 LOG_DEBUG ("Speaker %s disabled\n",
160 "Speaker %s disabled\n", 172 origin);
161 origin);
162} 173}
163 174
164 175
@@ -170,17 +181,15 @@ play (void *cls,
170 static unsigned int phone_i; 181 static unsigned int phone_i;
171 static unsigned int call_i; 182 static unsigned int call_i;
172 183
173 write (2, data, data_size);
174 if (0 == strncmp ("call", data, data_size)) 184 if (0 == strncmp ("call", data, data_size))
175 call_i++; 185 call_i++;
176 else if (0 == strncmp ("phone", data, data_size)) 186 else if (0 == strncmp ("phone", data, data_size))
177 phone_i++; 187 phone_i++;
178 else 188 else
179 { 189 {
180 fprintf (stderr, 190 LOG_DEBUG ("Received unexpected data %.*s\n",
181 "Received unexpected data %.*s\n", 191 (int) data_size,
182 (int) data_size, 192 (const char *) data);
183 (const char *) data);
184 } 193 }
185 194
186 if ( (20 < call_i) && 195 if ( (20 < call_i) &&
@@ -193,6 +202,7 @@ play (void *cls,
193 /* reset counters */ 202 /* reset counters */
194 call_i = 0; 203 call_i = 0;
195 phone_i = 0; 204 phone_i = 0;
205 call2_finished = GNUNET_YES;
196 } 206 }
197 if ( (20 < call_i) && 207 if ( (20 < call_i) &&
198 (20 < phone_i) && 208 (20 < phone_i) &&
@@ -203,6 +213,7 @@ play (void *cls,
203 call1 = NULL; 213 call1 = NULL;
204 call_i = 0; 214 call_i = 0;
205 phone_i = 0; 215 phone_i = 0;
216 call1_finished = GNUNET_YES;
206 } 217 }
207} 218}
208 219
@@ -212,7 +223,7 @@ destroy_speaker (void *cls)
212{ 223{
213 const char *origin = CLS_STR (cls); 224 const char *origin = CLS_STR (cls);
214 225
215 fprintf (stderr, "Speaker %s destroyed\n", origin); 226 LOG_DEBUG ("Speaker %s destroyed\n", origin);
216} 227}
217 228
218 229
@@ -251,9 +262,8 @@ enable_mic (void *cls,
251 const char *origin = CLS_STR (cls); 262 const char *origin = CLS_STR (cls);
252 struct MicContext *mc; 263 struct MicContext *mc;
253 264
254 fprintf (stderr, 265 LOG_DEBUG ("Mic %s enabled\n",
255 "Mic %s enabled\n", 266 origin);
256 origin);
257 if (PHONE0 == cls) 267 if (PHONE0 == cls)
258 { 268 {
259 phone_rdc = rdc; 269 phone_rdc = rdc;
@@ -263,7 +273,6 @@ enable_mic (void *cls,
263 return GNUNET_OK; 273 return GNUNET_OK;
264 } 274 }
265 mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx; 275 mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx;
266 mc->sym = (CALLER1 == cls) ? '1': '2';
267 mc->rdc = rdc; 276 mc->rdc = rdc;
268 mc->rdc_cls = rdc_cls; 277 mc->rdc_cls = rdc_cls;
269 GNUNET_break (GNUNET_SCHEDULER_NO_TASK == mc->call_task); 278 GNUNET_break (GNUNET_SCHEDULER_NO_TASK == mc->call_task);
@@ -278,9 +287,8 @@ disable_mic (void *cls)
278 const char *origin = CLS_STR (cls); 287 const char *origin = CLS_STR (cls);
279 struct MicContext *mc; 288 struct MicContext *mc;
280 289
281 fprintf (stderr, 290 LOG_DEBUG ("Mic %s disabled\n",
282 "Mic %s disabled\n", 291 origin);
283 origin);
284 if (PHONE0 == cls) 292 if (PHONE0 == cls)
285 { 293 {
286 phone_rdc = NULL; 294 phone_rdc = NULL;
@@ -302,9 +310,8 @@ destroy_mic (void *cls)
302{ 310{
303 const char *origin = CLS_STR (cls); 311 const char *origin = CLS_STR (cls);
304 312
305 fprintf (stderr, 313 LOG_DEBUG ("Mic %s destroyed\n",
306 "Mic %s destroyed\n", 314 origin);
307 origin);
308} 315}
309 316
310 317
@@ -389,7 +396,7 @@ caller_event_handler (void *cls,
389 { 396 {
390 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND: 397 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
391 case GNUNET_CONVERSATION_EC_CALLER_RESUME: 398 case GNUNET_CONVERSATION_EC_CALLER_RESUME:
392 fprintf (stderr, "Unexpected caller code: %d\n", code); 399 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected caller code: %d\n", code);
393 break; 400 break;
394 } 401 }
395} 402}
@@ -442,12 +449,11 @@ phone_event_handler (void *cls,
442 { 449 {
443 active_caller1 = NULL; 450 active_caller1 = NULL;
444 GNUNET_break (NULL == active_caller2); 451 GNUNET_break (NULL == active_caller2);
445 ok = 0;
446 GNUNET_SCHEDULER_shutdown (); 452 GNUNET_SCHEDULER_shutdown ();
447 } 453 }
448 break; 454 break;
449 default: 455 default:
450 fprintf (stderr, "Unexpected phone code: %d\n", code); 456 LOG (GNUNET_ERROR_TYPE_WARNING, "Unexpected phone code: %d\n", code);
451 break; 457 break;
452 } 458 }
453} 459}
@@ -464,22 +470,22 @@ call_event_handler (void *cls,
464 case GNUNET_CONVERSATION_EC_CALL_RINGING: 470 case GNUNET_CONVERSATION_EC_CALL_RINGING:
465 break; 471 break;
466 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: 472 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
467 fprintf (stderr, "\t Call %s picked\n", cid); 473 LOG_DEBUG ("Call %s picked\n", cid);
468 break; 474 break;
469 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: 475 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
470 fprintf (stderr, "\t Call %s GNS lookup failed \n", cid); 476 LOG_DEBUG ("Call %s GNS lookup failed \n", cid);
471 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: 477 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
472 fprintf (stderr, "\t Call %s hungup\n", cid); 478 LOG_DEBUG ("Call %s hungup\n", cid);
473 if (0 == strcmp (cid, "call1")) 479 if (0 == strcmp (cid, "call1"))
474 call1 = NULL; 480 call1 = NULL;
475 else 481 else
476 call2 = NULL; 482 call2 = NULL;
477 break; 483 break;
478 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: 484 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
479 fprintf (stderr, "\t Call %s suspended\n", cid); 485 LOG_DEBUG ("Call %s suspended\n", cid);
480 break; 486 break;
481 case GNUNET_CONVERSATION_EC_CALL_RESUMED: 487 case GNUNET_CONVERSATION_EC_CALL_RESUMED:
482 fprintf (stderr, "\t Call %s resumed\n", cid); 488 LOG_DEBUG ("Call %s resumed\n", cid);
483 break; 489 break;
484 } 490 }
485} 491}
@@ -598,11 +604,14 @@ run (void *cls,
598int 604int
599main (int argc, char *argv[]) 605main (int argc, char *argv[])
600{ 606{
607
601 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api_twocalls", 608 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api_twocalls",
602 "test_conversation.conf", 609 "test_conversation.conf",
603 &run, NULL)) 610 &run, NULL))
604 return 1; 611 return 1;
605 return ok; 612 if (call1_finished && call2_finished)
613 return 0;
614 return 1;
606} 615}
607 616
608/* end of test_conversation_api_twocalls.c */ 617/* end of test_conversation_api_twocalls.c */