Changeset 111
- Timestamp:
- Jan 7, 2006 11:01:56 PM (19 years ago)
- Location:
- pjproject/trunk/pjsip/src/test-pjsip
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/test-pjsip/main.c
r106 r111 19 19 #include "test.h" 20 20 #include <stdio.h> 21 #include <string.h> 22 #include <stdlib.h> 23 24 static void usage() 25 { 26 puts("Usage: test-pjsip"); 27 puts("Options:"); 28 puts(" -i,--interractive Key input at the end."); 29 puts(" -h,--help Show this screen"); 30 puts(" -l,--log-level N Set log level (0-6)"); 31 } 21 32 22 33 int main(int argc, char *argv[]) 23 34 { 24 int retval = test_main(); 35 int interractive = 0; 36 int retval; 37 char **opt_arg; 38 39 /* Parse arguments. */ 40 opt_arg = argv+1; 41 while (*opt_arg) { 42 if (strcmp(*opt_arg, "-i") == 0 || 43 strcmp(*opt_arg, "--interractive") == 0) 44 { 45 interractive = 1; 46 } else if (strcmp(*opt_arg, "-h") == 0 || 47 strcmp(*opt_arg, "--help") == 0) 48 { 49 usage(); 50 return 1; 51 } else if (strcmp(*opt_arg, "-l") == 0 || 52 strcmp(*opt_arg, "--log-level") == 0) 53 { 54 ++opt_arg; 55 if (!opt_arg) { 56 usage(); 57 return 1; 58 } 59 log_level = atoi(*opt_arg); 60 } else { 61 usage(); 62 return 1; 63 } 64 65 ++opt_arg; 66 } 67 68 retval = test_main(); 25 69 26 70 if (argc != 1) { -
pjproject/trunk/pjsip/src/test-pjsip/test.c
r109 r111 37 37 38 38 pjsip_endpoint *endpt; 39 int log_level = 5; 39 40 40 41 void app_perror(const char *msg, pj_status_t rc) … … 82 83 int line; 83 84 84 pj_log_set_level( 5);85 pj_log_set_level(log_level); 85 86 /* 86 87 pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | -
pjproject/trunk/pjsip/src/test-pjsip/test.h
r109 r111 55 55 void flush_events(unsigned duration); 56 56 57 /* Settings. */ 58 extern int log_level; 59 57 60 #endif /* __TEST_H__ */ -
pjproject/trunk/pjsip/src/test-pjsip/tsx_uac_test.c
r109 r111 146 146 static pjsip_transport *loop; 147 147 148 /* General timer entry to be used by tests. */ 149 static pj_timer_entry timer; 150 148 151 /* 149 152 * This is the handler to receive state changed notification from the … … 304 307 pjsip_tsx_terminate(tsx, 202); 305 308 } 306 } 309 310 } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 311 312 /* Previous state must be COMPLETED. */ 313 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 314 test_complete = -7381; 315 } 316 317 } 318 319 } else if (pj_strcmp2(&tsx->branch, TEST7_BRANCH_ID)==0) { 320 /* 321 * Successfull non-INVITE transaction. 322 */ 323 if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { 324 325 /* Check prev state. */ 326 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { 327 PJ_LOG(3,(THIS_FILE, 328 " error: prev state is %s instead of %s", 329 pjsip_tsx_state_str(e->body.tsx_state.prev_state), 330 pjsip_tsx_state_str(PJSIP_TSX_STATE_PROCEEDING))); 331 test_complete = -739; 332 } 333 334 /* Status code must be 202. */ 335 if (tsx->status_code != 202) { 336 PJ_LOG(3,(THIS_FILE, 337 " error: status code is %d instead of %d", 338 tsx->status_code, 202)); 339 test_complete = -740; 340 } 341 342 /* Must have correct retransmission count. */ 343 if (tsx->retransmit_count != 0) { 344 PJ_LOG(3,(THIS_FILE, 345 " error: retransmit cnt is %d instead of %d", 346 tsx->retransmit_count, 0)); 347 test_complete = -741; 348 } 349 350 /* Must still keep last_tx */ 351 if (tsx->last_tx == NULL) { 352 PJ_LOG(3,(THIS_FILE, 353 " error: transaction lost last_tx")); 354 test_complete = -741; 355 } 356 357 if (test_complete == 0) { 358 test_complete = 1; 359 pjsip_tsx_terminate(tsx, 202); 360 } 361 362 } else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 363 364 /* Previous state must be COMPLETED. */ 365 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 366 test_complete = -742; 367 } 368 369 } 370 371 372 } else if (pj_strcmp2(&tsx->branch, TEST8_BRANCH_ID)==0) { 373 /* 374 * Failed INVITE transaction. 375 */ 376 if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { 377 378 /* Status code must be 301. */ 379 if (tsx->status_code != 301) { 380 PJ_LOG(3,(THIS_FILE, 381 " error: status code is %d instead of %d", 382 tsx->status_code, 301)); 383 test_complete = -745; 384 } 385 386 /* Must have correct retransmission count. */ 387 if (tsx->retransmit_count != 0) { 388 PJ_LOG(3,(THIS_FILE, 389 " error: retransmit cnt is %d instead of %d", 390 tsx->retransmit_count, 0)); 391 test_complete = -746; 392 } 393 394 /* Must still keep last_tx */ 395 if (tsx->last_tx == NULL) { 396 PJ_LOG(3,(THIS_FILE, 397 " error: transaction lost last_tx")); 398 test_complete = -747; 399 } 400 401 /* last_tx is ACK in this case. */ 402 if (tsx->last_tx && tsx->last_tx->msg->line.req.method.id != 403 PJSIP_ACK_METHOD) 404 { 405 PJ_LOG(3,(THIS_FILE, 406 " error: last_tx is not ACK")); 407 test_complete = -748; 408 } 409 } 410 else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 411 412 test_complete = 1; 413 414 /* Previous state must be COMPLETED. */ 415 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 416 test_complete = -750; 417 } 418 419 /* Status code must be 301. */ 420 if (tsx->status_code != 301) { 421 PJ_LOG(3,(THIS_FILE, 422 " error: status code is %d instead of %d", 423 tsx->status_code, 301)); 424 test_complete = -751; 425 } 426 427 } 428 429 430 } else if (pj_strcmp2(&tsx->branch, TEST9_BRANCH_ID)==0) { 431 /* 432 * Failed INVITE transaction with provisional response. 433 */ 434 if (tsx->state == PJSIP_TSX_STATE_COMPLETED) { 435 436 /* Previous state must be PJSIP_TSX_STATE_PROCEEDING. */ 437 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_PROCEEDING) { 438 test_complete = -760; 439 } 440 441 /* Status code must be 302. */ 442 if (tsx->status_code != 302) { 443 PJ_LOG(3,(THIS_FILE, 444 " error: status code is %d instead of %d", 445 tsx->status_code, 302)); 446 test_complete = -761; 447 } 448 449 /* Must have correct retransmission count. */ 450 if (tsx->retransmit_count != 0) { 451 PJ_LOG(3,(THIS_FILE, 452 " error: retransmit cnt is %d instead of %d", 453 tsx->retransmit_count, 0)); 454 test_complete = -762; 455 } 456 457 /* Must still keep last_tx */ 458 if (tsx->last_tx == NULL) { 459 PJ_LOG(3,(THIS_FILE, 460 " error: transaction lost last_tx")); 461 test_complete = -763; 462 } 463 464 /* last_tx is ACK in this case. */ 465 if (tsx->last_tx && tsx->last_tx->msg->line.req.method.id != 466 PJSIP_ACK_METHOD) 467 { 468 PJ_LOG(3,(THIS_FILE, 469 " error: last_tx is not ACK")); 470 test_complete = -764; 471 } 472 473 } 474 else if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 475 476 test_complete = 1; 477 478 /* Previous state must be COMPLETED. */ 479 if (e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED) { 480 test_complete = -767; 481 } 482 483 /* Status code must be 302. */ 484 if (tsx->status_code != 302) { 485 PJ_LOG(3,(THIS_FILE, 486 " error: status code is %d instead of %d", 487 tsx->status_code, 302)); 488 test_complete = -768; 489 } 490 491 } 492 307 493 } 308 494 } 495 496 /* 497 * This timer callback is called to send delayed response. 498 */ 499 struct response 500 { 501 pjsip_response_addr res_addr; 502 pjsip_tx_data *tdata; 503 }; 504 505 static void send_response_callback( pj_timer_heap_t *timer_heap, 506 struct pj_timer_entry *entry) 507 { 508 struct response *r = entry->user_data; 509 pjsip_transport *tp = r->res_addr.transport; 510 511 pjsip_endpt_send_response(endpt, &r->res_addr, r->tdata, NULL, NULL); 512 if (tp) 513 pjsip_transport_dec_ref(tp); 514 } 515 516 /* Timer callback to terminate a transaction. */ 517 static void terminate_tsx_callback( pj_timer_heap_t *timer_heap, 518 struct pj_timer_entry *entry) 519 { 520 pjsip_transaction *tsx = entry->user_data; 521 int status_code = entry->id; 522 523 if (tsx) { 524 pjsip_tsx_terminate(tsx, status_code); 525 } 526 } 527 309 528 310 529 #define DIFF(a,b) ((a<b) ? (b-a) : (a-b)) … … 439 658 if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST6_BRANCH_ID) == 0) { 440 659 /* 441 * The TEST5_BRANCH_ID test successfull non-INVITE transaction. 442 */ 443 pjsip_tx_data *tdata; 444 pjsip_response_addr res_addr; 660 * The TEST6_BRANCH_ID test successfull non-INVITE transaction. 661 */ 445 662 pj_status_t status; 446 663 … … 453 670 } 454 671 455 status = pjsip_endpt_create_response(endpt, rdata, 202, NULL, &tdata); 456 if (status != PJ_SUCCESS) { 457 app_perror(" error: unable to create response", status); 458 test_complete = -636; 459 } 460 461 status = pjsip_get_response_addr(tdata->pool, rdata, &res_addr); 462 if (status != PJ_SUCCESS) { 463 app_perror(" error: unable to get response addr", status); 464 test_complete = -637; 465 } 466 467 status = pjsip_endpt_send_response(endpt, &res_addr, tdata, NULL,NULL); 672 status = pjsip_endpt_respond_stateless(endpt, rdata, 202, NULL, 673 NULL, NULL); 468 674 if (status != PJ_SUCCESS) { 469 675 app_perror(" error: unable to send response", status); 470 test_complete = -638; 471 pjsip_tx_data_dec_ref(tdata); 676 test_complete = -636; 472 677 } 473 678 474 679 return PJ_TRUE; 680 681 682 } else 683 if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST7_BRANCH_ID) == 0) { 684 /* 685 * The TEST7_BRANCH_ID test successfull non-INVITE transaction 686 * with provisional response. 687 */ 688 pj_status_t status; 689 pjsip_response_addr res_addr; 690 struct response *r; 691 pjsip_tx_data *tdata; 692 pj_time_val delay = { 2, 0 }; 693 694 recv_count++; 695 696 if (recv_count > 1) { 697 PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", 698 recv_count)); 699 test_complete = -640; 700 return PJ_TRUE; 701 } 702 703 /* Respond with provisional response */ 704 status = pjsip_endpt_create_response(endpt, rdata, 100, NULL, &tdata); 705 pj_assert(status == PJ_SUCCESS); 706 707 status = pjsip_get_response_addr(tdata->pool, rdata, &res_addr); 708 pj_assert(status == PJ_SUCCESS); 709 710 status = pjsip_endpt_send_response(endpt, &res_addr, tdata, 711 NULL, NULL); 712 pj_assert(status == PJ_SUCCESS); 713 714 /* Create the final response. */ 715 status = pjsip_endpt_create_response(endpt, rdata, 202, NULL, &tdata); 716 pj_assert(status == PJ_SUCCESS); 717 718 /* Schedule sending final response in couple of of secs. */ 719 r = pj_pool_alloc(tdata->pool, sizeof(*r)); 720 r->res_addr = res_addr; 721 r->tdata = tdata; 722 if (r->res_addr.transport) 723 pjsip_transport_add_ref(r->res_addr.transport); 724 725 timer.cb = &send_response_callback; 726 timer.user_data = r; 727 pjsip_endpt_schedule_timer(endpt, &timer, &delay); 728 729 return PJ_TRUE; 730 731 732 } else 733 if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST8_BRANCH_ID) == 0) { 734 /* 735 * The TEST8_BRANCH_ID test failed INVITE transaction. 736 */ 737 pjsip_method *method; 738 pj_status_t status; 739 740 method = &rdata->msg_info.msg->line.req.method; 741 742 recv_count++; 743 744 if (method->id == PJSIP_INVITE_METHOD) { 745 746 if (recv_count > 1) { 747 PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", 748 recv_count)); 749 test_complete = -635; 750 } 751 752 status = pjsip_endpt_respond_stateless(endpt, rdata, 301, NULL, 753 NULL, NULL); 754 if (status != PJ_SUCCESS) { 755 app_perror(" error: unable to send response", status); 756 test_complete = -636; 757 } 758 759 } else if (method->id == PJSIP_ACK_METHOD) { 760 761 if (recv_count == 2) { 762 pj_str_t key; 763 pj_time_val delay = { 5, 0 }; 764 765 /* Schedule timer to destroy transaction after 5 seconds. 766 * This is to make sure that transaction does not 767 * retransmit ACK. 768 */ 769 pjsip_tsx_create_key(rdata->tp_info.pool, &key, 770 PJSIP_ROLE_UAC, &pjsip_invite_method, 771 rdata); 772 773 timer.user_data = pjsip_tsx_layer_find_tsx(&key, PJ_FALSE); 774 timer.id = 301; 775 timer.cb = &terminate_tsx_callback; 776 777 pjsip_endpt_schedule_timer(endpt, &timer, &delay); 778 } 779 780 if (recv_count > 2) { 781 PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", 782 recv_count)); 783 test_complete = -638; 784 } 785 786 787 } else { 788 PJ_LOG(3,(THIS_FILE," error: not expecting %s", 789 pjsip_rx_data_get_info(rdata))); 790 test_complete = -639; 791 792 } 793 794 795 } else 796 if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST9_BRANCH_ID) == 0) { 797 /* 798 * The TEST9_BRANCH_ID test failed INVITE transaction with 799 * provisional response. 800 */ 801 pjsip_method *method; 802 pj_status_t status; 803 804 method = &rdata->msg_info.msg->line.req.method; 805 806 recv_count++; 807 808 if (method->id == PJSIP_INVITE_METHOD) { 809 810 pjsip_response_addr res_addr; 811 struct response *r; 812 pjsip_tx_data *tdata; 813 pj_time_val delay = { 2, 0 }; 814 815 if (recv_count > 1) { 816 PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", 817 recv_count)); 818 test_complete = -650; 819 return PJ_TRUE; 820 } 821 822 /* Respond with provisional response */ 823 status = pjsip_endpt_create_response(endpt, rdata, 100, NULL, 824 &tdata); 825 pj_assert(status == PJ_SUCCESS); 826 827 status = pjsip_get_response_addr(tdata->pool, rdata, &res_addr); 828 pj_assert(status == PJ_SUCCESS); 829 830 status = pjsip_endpt_send_response(endpt, &res_addr, tdata, 831 NULL, NULL); 832 pj_assert(status == PJ_SUCCESS); 833 834 /* Create the final response. */ 835 status = pjsip_endpt_create_response(endpt, rdata, 302, NULL, 836 &tdata); 837 pj_assert(status == PJ_SUCCESS); 838 839 /* Schedule sending final response in couple of of secs. */ 840 r = pj_pool_alloc(tdata->pool, sizeof(*r)); 841 r->res_addr = res_addr; 842 r->tdata = tdata; 843 if (r->res_addr.transport) 844 pjsip_transport_add_ref(r->res_addr.transport); 845 846 timer.cb = &send_response_callback; 847 timer.user_data = r; 848 pjsip_endpt_schedule_timer(endpt, &timer, &delay); 849 850 } else if (method->id == PJSIP_ACK_METHOD) { 851 852 if (recv_count == 2) { 853 pj_str_t key; 854 pj_time_val delay = { 5, 0 }; 855 856 /* Schedule timer to destroy transaction after 5 seconds. 857 * This is to make sure that transaction does not 858 * retransmit ACK. 859 */ 860 pjsip_tsx_create_key(rdata->tp_info.pool, &key, 861 PJSIP_ROLE_UAC, &pjsip_invite_method, 862 rdata); 863 864 timer.user_data = pjsip_tsx_layer_find_tsx(&key, PJ_FALSE); 865 timer.id = 302; 866 timer.cb = &terminate_tsx_callback; 867 868 pjsip_endpt_schedule_timer(endpt, &timer, &delay); 869 } 870 871 if (recv_count > 2) { 872 PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", 873 recv_count)); 874 test_complete = -638; 875 } 876 877 878 } else { 879 PJ_LOG(3,(THIS_FILE," error: not expecting %s", 880 pjsip_rx_data_get_info(rdata))); 881 test_complete = -639; 882 883 } 884 885 return PJ_TRUE; 886 475 887 } 476 888 … … 827 1239 ** 828 1240 ** TEST6_BRANCH_ID: Successfull non-invite transaction 1241 ** TEST7_BRANCH_ID: Successfull non-invite transaction with provisional 1242 ** TEST8_BRANCH_ID: Failed invite transaction 1243 ** TEST9_BRANCH_ID: Failed invite transaction with provisional 829 1244 ** 830 1245 ***************************************************************************** 831 1246 */ 832 static int tsx_successfull_non_invite_test(void) 1247 static int perform_generic_test( const char *title, 1248 char *branch_id, 1249 const pjsip_method *method) 833 1250 { 834 1251 int i, status; 835 1252 unsigned delay[] = { 1, 200 }; 836 1253 837 PJ_LOG(3,(THIS_FILE, " test6: successfull non-invite transaction"));1254 PJ_LOG(3,(THIS_FILE, " test6: %s", title)); 838 1255 839 1256 /* Do the test. */ … … 848 1265 "sip:bob@127.0.0.1;transport=loop-dgram", 849 1266 "sip:alice@127.0.0.1;transport=loop-dgram", 850 TEST6_BRANCH_ID,851 2, &pjsip_options_method);1267 branch_id, 1268 10, method); 852 1269 if (status != 0) 853 1270 return status; … … 892 1309 } 893 1310 894 #if 0895 1311 /* TEST1_BRANCH_ID: Basic retransmit and timeout test. */ 896 1312 status = tsx_uac_retransmit_test(); … … 917 1333 if (status != 0) 918 1334 return status; 919 #endif920 1335 921 1336 /* TEST6_BRANCH_ID: Successfull non-invite transaction */ 922 status = tsx_successfull_non_invite_test(); 1337 status = perform_generic_test("successfull non-invite transaction", 1338 TEST6_BRANCH_ID, &pjsip_options_method); 1339 if (status != 0) 1340 return status; 1341 1342 /* TEST7_BRANCH_ID: Successfull non-invite transaction */ 1343 status = perform_generic_test("successfull non-invite transaction " 1344 "with provisional response", 1345 TEST7_BRANCH_ID, &pjsip_options_method); 1346 if (status != 0) 1347 return status; 1348 1349 /* TEST8_BRANCH_ID: Failed invite transaction */ 1350 status = perform_generic_test("failed invite transaction", 1351 TEST8_BRANCH_ID, &pjsip_invite_method); 1352 if (status != 0) 1353 return status; 1354 1355 /* TEST9_BRANCH_ID: Failed invite transaction with provisional response */ 1356 status = perform_generic_test("failed invite transaction with " 1357 "provisional response", 1358 TEST9_BRANCH_ID, &pjsip_invite_method); 923 1359 if (status != 0) 924 1360 return status;
Note: See TracChangeset
for help on using the changeset viewer.