Changeset 563 for pjproject/trunk/pjsip/src/test-pjsip/tsx_uac_test.c
- Timestamp:
- Jun 28, 2006 4:46:49 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/test-pjsip/tsx_uac_test.c
r555 r563 92 92 #define TEST5_RETRANSMIT_CNT 3 93 93 94 static char TARGET_URI[128]; 95 static char FROM_URI[128]; 96 static unsigned tp_flag; 97 static struct tsx_test_param *test_param; 94 98 95 99 static void tsx_user_on_tsx_state(pjsip_transaction *tsx, pjsip_event *e); … … 141 145 142 146 /* General timer entry to be used by tests. */ 143 static pj_timer_entry timer; 147 static struct my_timer 148 { 149 pj_timer_entry entry; 150 char key_buf[1024]; 151 pj_str_t tsx_key; 152 } timer; 144 153 145 154 /* … … 167 176 test_complete = -710; 168 177 } 178 179 180 /* If transport is reliable, then there must not be any 181 * retransmissions. 182 */ 183 if (tp_flag & PJSIP_TRANSPORT_RELIABLE) { 184 if (recv_count != 1) { 185 PJ_LOG(3,(THIS_FILE, 186 " error: there were %d (re)transmissions", 187 recv_count)); 188 test_complete = -715; 189 } 190 } else { 191 /* Check the number of transmissions, which must be 192 * 6 for INVITE and 10 for non-INVITE 193 */ 194 if (tsx->method.id==PJSIP_INVITE_METHOD && recv_count != 7) { 195 PJ_LOG(3,(THIS_FILE, 196 " error: there were %d (re)transmissions", 197 recv_count)); 198 test_complete = -716; 199 } else 200 if (tsx->method.id==PJSIP_OPTIONS_METHOD && recv_count != 11) { 201 PJ_LOG(3,(THIS_FILE, 202 " error: there were %d (re)transmissions", 203 recv_count)); 204 test_complete = -717; 205 } else 206 if (tsx->method.id!=PJSIP_INVITE_METHOD && 207 tsx->method.id!=PJSIP_OPTIONS_METHOD) 208 { 209 PJ_LOG(3,(THIS_FILE, " error: unexpected method")); 210 test_complete = -718; 211 } 212 } 169 213 } 170 214 … … 516 560 struct pj_timer_entry *entry) 517 561 { 518 pjsip_transaction *tsx = entry->user_data; 562 struct my_timer *m = (struct my_timer *)entry; 563 pjsip_transaction *tsx = pjsip_tsx_layer_find_tsx(&m->tsx_key, PJ_FALSE); 519 564 int status_code = entry->id; 520 565 … … 721 766 pjsip_transport_add_ref(r->res_addr.transport); 722 767 723 timer. cb = &send_response_callback;724 timer. user_data = r;725 pjsip_endpt_schedule_timer(endpt, &timer , &delay);768 timer.entry.cb = &send_response_callback; 769 timer.entry.user_data = r; 770 pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); 726 771 727 772 return PJ_TRUE; … … 769 814 rdata); 770 815 771 timer.user_data = pjsip_tsx_layer_find_tsx(&key, PJ_FALSE);772 timer. id = 301;773 timer. cb = &terminate_tsx_callback;774 775 pjsip_endpt_schedule_timer(endpt, &timer , &delay);816 pj_strcpy(&timer.tsx_key, &key); 817 timer.entry.id = 301; 818 timer.entry.cb = &terminate_tsx_callback; 819 820 pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); 776 821 } 777 822 … … 842 887 pjsip_transport_add_ref(r->res_addr.transport); 843 888 844 timer. cb = &send_response_callback;845 timer. user_data = r;846 pjsip_endpt_schedule_timer(endpt, &timer , &delay);889 timer.entry.cb = &send_response_callback; 890 timer.entry.user_data = r; 891 pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); 847 892 848 893 } else if (method->id == PJSIP_ACK_METHOD) { … … 860 905 rdata); 861 906 862 timer.user_data = pjsip_tsx_layer_find_tsx(&key, PJ_FALSE);863 timer. id = 302;864 timer. cb = &terminate_tsx_callback;865 866 pjsip_endpt_schedule_timer(endpt, &timer , &delay);907 pj_strcpy(&timer.tsx_key, &key); 908 timer.entry.id = 302; 909 timer.entry.cb = &terminate_tsx_callback; 910 911 pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); 867 912 } 868 913 … … 981 1026 pjsip_tx_data_dec_ref(tdata); 982 1027 return test_complete; 983 } 984 985 /* Allow transaction to destroy itself */ 986 flush_events(500); 1028 1029 } else { 1030 pj_time_val now; 1031 1032 /* Allow transaction to destroy itself */ 1033 flush_events(500); 1034 1035 /* Wait until test completes */ 1036 pj_gettimeofday(&now); 1037 1038 if (PJ_TIME_VAL_LT(now, timeout)) { 1039 pj_time_val interval; 1040 interval = timeout; 1041 PJ_TIME_VAL_SUB(interval, now); 1042 flush_events(PJ_TIME_VAL_MSEC(interval)); 1043 } 1044 } 987 1045 988 1046 /* Make sure transaction has been destroyed. */ … … 1053 1111 1054 1112 /* Do the test. */ 1055 status = perform_tsx_test(-500, "sip:bob@127.0.0.1;transport=loop-dgram", 1056 "sip:alice@127.0.0.1;transport=loop-dgram", 1113 status = perform_tsx_test(-500, TARGET_URI, FROM_URI, 1057 1114 TEST1_BRANCH_ID, 1058 1115 35, sub_test[i].method); … … 1094 1151 1095 1152 status = perform_tsx_test(-800, 1096 "sip:bob@unresolved-host;transport=loop-dgram", 1097 "sip:alice@127.0.0.1;transport=loop-dgram", 1098 TEST2_BRANCH_ID, 10, 1153 "sip:bob@unresolved-host", 1154 FROM_URI, TEST2_BRANCH_ID, 10, 1099 1155 &pjsip_options_method); 1100 1156 if (status != 0) … … 1106 1162 PJ_LOG(3,(THIS_FILE, " variant b: error via callback")); 1107 1163 1108 /* Set loop transport to return delayed error. */ 1109 pjsip_loop_set_failure(loop, 2, NULL); 1110 pjsip_loop_set_send_callback_delay(loop, 10, NULL); 1111 1112 status = perform_tsx_test(-800, "sip:bob@127.0.0.1;transport=loop-dgram", 1113 "sip:alice@127.0.0.1;transport=loop-dgram", 1114 TEST2_BRANCH_ID, 2, 1115 &pjsip_options_method); 1116 if (status != 0) 1117 return status; 1118 1119 /* Restore loop transport settings. */ 1120 pjsip_loop_set_failure(loop, 0, NULL); 1121 pjsip_loop_set_send_callback_delay(loop, 0, NULL); 1164 /* This only applies to "loop-dgram" transport */ 1165 if (test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { 1166 /* Set loop transport to return delayed error. */ 1167 pjsip_loop_set_failure(loop, 2, NULL); 1168 pjsip_loop_set_send_callback_delay(loop, 10, NULL); 1169 1170 status = perform_tsx_test(-800, TARGET_URI, FROM_URI, 1171 TEST2_BRANCH_ID, 2, 1172 &pjsip_options_method); 1173 if (status != 0) 1174 return status; 1175 1176 /* Restore loop transport settings. */ 1177 pjsip_loop_set_failure(loop, 0, NULL); 1178 pjsip_loop_set_send_callback_delay(loop, 0, NULL); 1179 } 1122 1180 1123 1181 return status; … … 1144 1202 1145 1203 /* Start the test. */ 1146 status = perform_tsx_test(-900, "sip:127.0.0.1;transport=loop-dgram", 1147 "sip:127.0.0.1;transport=loop-dgram", 1204 status = perform_tsx_test(-900, TARGET_URI, FROM_URI, 1148 1205 TEST3_BRANCH_ID, 2, &pjsip_options_method); 1149 1206 … … 1187 1244 1188 1245 /* Start the test. */ 1189 status = perform_tsx_test(-1000, "sip:127.0.0.1;transport=loop-dgram", 1190 "sip:127.0.0.1;transport=loop-dgram", 1246 status = perform_tsx_test(-1000, TARGET_URI, FROM_URI, 1191 1247 TEST4_BRANCH_ID, 6, &pjsip_options_method); 1192 1248 … … 1219 1275 1220 1276 /* Do the test. */ 1221 status = perform_tsx_test(-1100, "sip:bob@127.0.0.1;transport=loop-dgram", 1222 "sip:alice@127.0.0.1;transport=loop-dgram", 1277 status = perform_tsx_test(-1100, TARGET_URI, FROM_URI, 1223 1278 TEST5_BRANCH_ID, 1224 1279 6, &pjsip_options_method); … … 1250 1305 for (i=0; i<PJ_ARRAY_SIZE(delay); ++i) { 1251 1306 1252 PJ_LOG(3,(THIS_FILE, " variant %c: with %d ms transport delay", 1253 ('a'+i), delay[i])); 1254 1255 pjsip_loop_set_delay(loop, delay[i]); 1256 1257 status = perform_tsx_test(-1200, 1258 "sip:bob@127.0.0.1;transport=loop-dgram", 1259 "sip:alice@127.0.0.1;transport=loop-dgram", 1260 branch_id, 1261 10, method); 1307 if (test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { 1308 PJ_LOG(3,(THIS_FILE, " variant %c: with %d ms transport delay", 1309 ('a'+i), delay[i])); 1310 1311 pjsip_loop_set_delay(loop, delay[i]); 1312 } 1313 1314 status = perform_tsx_test(-1200, TARGET_URI, FROM_URI, 1315 branch_id, 10, method); 1262 1316 if (status != 0) 1263 1317 return status; 1318 1319 if (test_param->type != PJSIP_TRANSPORT_LOOP_DGRAM) 1320 break; 1264 1321 } 1265 1322 … … 1277 1334 ***************************************************************************** 1278 1335 */ 1279 int tsx_uac_test( void)1336 int tsx_uac_test(struct tsx_test_param *param) 1280 1337 { 1281 1338 pj_sockaddr_in addr; 1282 1339 pj_status_t status; 1340 1341 timer.tsx_key.ptr = timer.key_buf; 1342 1343 test_param = param; 1344 1345 /* Get transport flag */ 1346 tp_flag = pjsip_transport_get_flag_from_type(test_param->type); 1347 1348 pj_ansi_sprintf(TARGET_URI, "sip:bob@127.0.0.1:%d;transport=%s", 1349 param->port, param->tp_type); 1350 pj_ansi_sprintf(FROM_URI, "sip:alice@127.0.0.1:%d;transport=%s", 1351 param->port, param->tp_type); 1283 1352 1284 1353 /* Check if loop transport is configured. */ … … 1317 1386 return status; 1318 1387 1319 /* TEST4_BRANCH_ID: Transport failed after several retransmissions */ 1320 status = tsx_retransmit_fail_test(); 1321 if (status != 0) 1322 return status; 1323 1324 /* TEST5_BRANCH_ID: Terminate transaction after several retransmissions */ 1325 status = tsx_terminate_after_retransmit_test(); 1326 if (status != 0) 1327 return status; 1388 /* TEST4_BRANCH_ID: Transport failed after several retransmissions. 1389 * Only applies to loop transport. 1390 */ 1391 if (test_param->type == PJSIP_TRANSPORT_LOOP_DGRAM) { 1392 status = tsx_retransmit_fail_test(); 1393 if (status != 0) 1394 return status; 1395 } 1396 1397 /* TEST5_BRANCH_ID: Terminate transaction after several retransmissions 1398 * Only applicable to non-reliable transports. 1399 */ 1400 if ((tp_flag & PJSIP_TRANSPORT_RELIABLE) == 0) { 1401 status = tsx_terminate_after_retransmit_test(); 1402 if (status != 0) 1403 return status; 1404 } 1328 1405 1329 1406 /* TEST6_BRANCH_ID: Successfull non-invite transaction */ … … 1353 1430 return status; 1354 1431 1355 1356 1432 pjsip_transport_dec_ref(loop); 1433 flush_events(500); 1434 1435 /* Unregister modules. */ 1436 status = pjsip_endpt_unregister_module(endpt, &tsx_user); 1437 if (status != PJ_SUCCESS) { 1438 app_perror(" Error: unable to unregister module", status); 1439 return -31; 1440 } 1441 status = pjsip_endpt_unregister_module(endpt, &msg_receiver); 1442 if (status != PJ_SUCCESS) { 1443 app_perror(" Error: unable to unregister module", status); 1444 return -41; 1445 } 1446 1357 1447 return 0; 1358 1448 }
Note: See TracChangeset
for help on using the changeset viewer.