Changeset 563 for pjproject/trunk/pjsip/src/test-pjsip/txdata_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/txdata_test.c
r127 r563 22 22 #include <pjlib.h> 23 23 24 25 #define THIS_FILE "txdata_test.c" 26 27 24 28 #define HFIND(msg,h,H) ((pjsip_##h##_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_##H, NULL)) 25 29 26 #define THIS_FILE "txdata_test.c" 30 #if defined(PJ_DEBUG) && PJ_DEBUG!=0 31 # define LOOP 10000 32 #else 33 # define LOOP 100000 34 #endif 27 35 28 36 … … 323 331 return 0; 324 332 } 333 334 335 336 /* 337 * This test demonstrate the bug as reported in: 338 * http://bugzilla.pjproject.net/show_bug.cgi?id=49 339 */ 340 static int gcc_test() 341 { 342 char msgbuf[512]; 343 pj_str_t target = pj_str("sip:alice@wonderland:5061;x-param=param%201" 344 "?X-Hdr-1=Header%201" 345 "&X-Empty-Hdr="); 346 pjsip_tx_data *tdata; 347 pjsip_parser_err_report err_list; 348 pjsip_msg *msg; 349 int len; 350 pj_status_t status; 351 352 PJ_LOG(3,(THIS_FILE, " header param in URI to create request")); 353 354 /* Create request with header param in target URI. */ 355 status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target, 356 &target, &target, &target, NULL, -1, 357 NULL, &tdata); 358 if (status != 0) { 359 app_perror(" error: Unable to create request", status); 360 return -200; 361 } 362 363 /* Print and parse the request. 364 * We'll check that header params are not present in 365 */ 366 len = pjsip_msg_print(tdata->msg, msgbuf, sizeof(msgbuf)); 367 if (len < 1) { 368 PJ_LOG(3,(THIS_FILE, " error: printing message")); 369 pjsip_tx_data_dec_ref(tdata); 370 return -250; 371 } 372 msgbuf[len] = '\0'; 373 374 PJ_LOG(5,(THIS_FILE, "%d bytes request created:--begin-msg--\n" 375 "%s\n" 376 "--end-msg--", len, msgbuf)); 377 378 /* Now parse the message. */ 379 pj_list_init(&err_list); 380 msg = pjsip_parse_msg( tdata->pool, msgbuf, len, &err_list); 381 if (msg == NULL) { 382 pjsip_parser_err_report *e; 383 384 PJ_LOG(3,(THIS_FILE, " error: parsing message message")); 385 386 e = err_list.next; 387 while (e != &err_list) { 388 PJ_LOG(3,(THIS_FILE, " %s in line %d col %d hname=%.*s", 389 pj_exception_id_name(e->except_code), 390 e->line, e->col+1, 391 (int)e->hname.slen, 392 e->hname.ptr)); 393 e = e->next; 394 } 395 396 pjsip_tx_data_dec_ref(tdata); 397 return -255; 398 } 399 400 pjsip_tx_data_dec_ref(tdata); 401 return 0; 402 } 403 325 404 326 405 /* This tests the request creating functions against the following … … 346 425 pjsip_sip_uri *uri; 347 426 pjsip_param *param; 427 pjsip_via_hdr *via; 428 pjsip_parser_err_report err_list; 348 429 pjsip_msg *msg; 349 430 int len; … … 361 442 } 362 443 444 /* Fill up the Via header to prevent syntax error on parsing */ 445 via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); 446 via->transport = pj_str("TCP"); 447 via->sent_by.host = pj_str("127.0.0.1"); 448 363 449 /* Print and parse the request. 364 450 * We'll check that header params are not present in … … 377 463 378 464 /* Now parse the message. */ 379 msg = pjsip_parse_msg( tdata->pool, msgbuf, len, NULL); 465 pj_list_init(&err_list); 466 msg = pjsip_parse_msg( tdata->pool, msgbuf, len, &err_list); 380 467 if (msg == NULL) { 381 app_perror(" error: parsing message message", status); 382 pjsip_tx_data_dec_ref(tdata); 383 return -250; 468 pjsip_parser_err_report *e; 469 470 PJ_LOG(3,(THIS_FILE, " error: parsing message message")); 471 472 e = err_list.next; 473 while (e != &err_list) { 474 PJ_LOG(3,(THIS_FILE, " %s in line %d col %d hname=%.*s", 475 pj_exception_id_name(e->except_code), 476 e->line, e->col+1, 477 (int)e->hname.slen, 478 e->hname.ptr)); 479 e = e->next; 480 } 481 482 pjsip_tx_data_dec_ref(tdata); 483 return -256; 384 484 } 385 485 … … 513 613 } 514 614 615 616 /* 617 * create request benchmark 618 */ 619 static int create_request_bench(pj_timestamp *p_elapsed) 620 { 621 enum { COUNT = 100 }; 622 unsigned i, j; 623 pjsip_tx_data *tdata[COUNT]; 624 pj_timestamp t1, t2, elapsed; 625 pj_status_t status; 626 627 pj_str_t str_target = pj_str("sip:someuser@someprovider.com"); 628 pj_str_t str_from = pj_str("\"Local User\" <sip:localuser@serviceprovider.com>"); 629 pj_str_t str_to = pj_str("\"Remote User\" <sip:remoteuser@serviceprovider.com>"); 630 pj_str_t str_contact = str_from; 631 632 elapsed.u64 = 0; 633 634 for (i=0; i<LOOP; i+=COUNT) { 635 pj_memset(tdata, 0, sizeof(tdata)); 636 637 pj_get_timestamp(&t1); 638 639 for (j=0; j<COUNT; ++j) { 640 status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, 641 &str_target, &str_from, &str_to, 642 &str_contact, NULL, -1, NULL, 643 &tdata[j]); 644 if (status != PJ_SUCCESS) { 645 app_perror(" error: unable to create request", status); 646 goto on_error; 647 } 648 } 649 650 pj_get_timestamp(&t2); 651 pj_sub_timestamp(&t2, &t1); 652 pj_add_timestamp(&elapsed, &t2); 653 654 for (j=0; j<COUNT; ++j) 655 pjsip_tx_data_dec_ref(tdata[j]); 656 } 657 658 p_elapsed->u64 = elapsed.u64; 659 return PJ_SUCCESS; 660 661 on_error: 662 for (i=0; i<COUNT; ++i) { 663 if (tdata[i]) 664 pjsip_tx_data_dec_ref(tdata[i]); 665 } 666 return -400; 667 } 668 669 670 671 /* 672 * create response benchmark 673 */ 674 static int create_response_bench(pj_timestamp *p_elapsed) 675 { 676 enum { COUNT = 100 }; 677 unsigned i, j; 678 pjsip_via_hdr *via; 679 pjsip_rx_data rdata; 680 pjsip_tx_data *request; 681 pjsip_tx_data *tdata[COUNT]; 682 pj_timestamp t1, t2, elapsed; 683 pj_status_t status; 684 685 /* Create the request first. */ 686 pj_str_t str_target = pj_str("sip:someuser@someprovider.com"); 687 pj_str_t str_from = pj_str("\"Local User\" <sip:localuser@serviceprovider.com>"); 688 pj_str_t str_to = pj_str("\"Remote User\" <sip:remoteuser@serviceprovider.com>"); 689 pj_str_t str_contact = str_from; 690 691 status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, 692 &str_target, &str_from, &str_to, 693 &str_contact, NULL, -1, NULL, 694 &request); 695 if (status != PJ_SUCCESS) { 696 app_perror(" error: unable to create request", status); 697 return status; 698 } 699 700 /* Create several Via headers */ 701 via = pjsip_via_hdr_create(request->pool); 702 via->sent_by.host = pj_str("192.168.0.7"); 703 via->sent_by.port = 5061; 704 via->transport = pj_str("udp"); 705 via->rport_param = 0; 706 via->branch_param = pj_str("012345678901234567890123456789"); 707 via->recvd_param = pj_str("192.168.0.7"); 708 pjsip_msg_insert_first_hdr(request->msg, pjsip_hdr_clone(request->pool, via)); 709 pjsip_msg_insert_first_hdr(request->msg, pjsip_hdr_clone(request->pool, via)); 710 pjsip_msg_insert_first_hdr(request->msg, (pjsip_hdr*)via); 711 712 713 /* Create "dummy" rdata from the tdata */ 714 pj_memset(&rdata, 0, sizeof(pjsip_rx_data)); 715 rdata.tp_info.pool = request->pool; 716 rdata.msg_info.msg = request->msg; 717 rdata.msg_info.from = pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL); 718 rdata.msg_info.to = pjsip_msg_find_hdr(request->msg, PJSIP_H_TO, NULL); 719 rdata.msg_info.cseq = pjsip_msg_find_hdr(request->msg, PJSIP_H_CSEQ, NULL); 720 rdata.msg_info.cid = pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL); 721 rdata.msg_info.via = via; 722 723 /* 724 * Now benchmark create_response 725 */ 726 elapsed.u64 = 0; 727 728 for (i=0; i<LOOP; i+=COUNT) { 729 pj_memset(tdata, 0, sizeof(tdata)); 730 731 pj_get_timestamp(&t1); 732 733 for (j=0; j<COUNT; ++j) { 734 status = pjsip_endpt_create_response(endpt, &rdata, 200, NULL, &tdata[j]); 735 if (status != PJ_SUCCESS) { 736 app_perror(" error: unable to create request", status); 737 goto on_error; 738 } 739 } 740 741 pj_get_timestamp(&t2); 742 pj_sub_timestamp(&t2, &t1); 743 pj_add_timestamp(&elapsed, &t2); 744 745 for (j=0; j<COUNT; ++j) 746 pjsip_tx_data_dec_ref(tdata[j]); 747 } 748 749 p_elapsed->u64 = elapsed.u64; 750 pjsip_tx_data_dec_ref(request); 751 return PJ_SUCCESS; 752 753 on_error: 754 for (i=0; i<COUNT; ++i) { 755 if (tdata[i]) 756 pjsip_tx_data_dec_ref(tdata[i]); 757 } 758 return -400; 759 } 760 761 515 762 int txdata_test(void) 516 763 { 764 enum { REPEAT = 4 }; 765 unsigned i, msgs; 766 pj_timestamp usec[REPEAT], min, freq; 517 767 int status; 768 769 status = pj_get_timestamp_freq(&freq); 770 if (status != PJ_SUCCESS) 771 return status; 518 772 519 773 status = core_txdata_test(); … … 521 775 return status; 522 776 777 #if INCLUDE_GCC_TEST 778 status = gcc_test(); 779 if (status != 0) 780 return status; 781 #endif 523 782 524 783 status = txdata_test_uri_params(); … … 526 785 return status; 527 786 787 788 /* 789 * Benchmark create_request() 790 */ 791 PJ_LOG(3,(THIS_FILE, " benchmarking request creation:")); 792 for (i=0; i<REPEAT; ++i) { 793 PJ_LOG(3,(THIS_FILE, " test %d of %d..", 794 i+1, REPEAT)); 795 status = create_request_bench(&usec[i]); 796 if (status != PJ_SUCCESS) 797 return status; 798 } 799 800 min.u64 = PJ_UINT64(0xFFFFFFFFFFFFFFF); 801 for (i=0; i<REPEAT; ++i) { 802 if (usec[i].u64 < min.u64) min.u64 = usec[i].u64; 803 } 804 805 msgs = (unsigned)(freq.u64 * LOOP / min.u64); 806 807 PJ_LOG(3,(THIS_FILE, " Requests created at %d requests/sec", msgs)); 808 809 report_ival("create-request-per-sec", 810 msgs, "msg/sec", 811 "Number of typical request messages that can be created " 812 "per second with <tt>pjsip_endpt_create_request()</tt>"); 813 814 815 /* 816 * Benchmark create_response() 817 */ 818 PJ_LOG(3,(THIS_FILE, " benchmarking response creation:")); 819 for (i=0; i<REPEAT; ++i) { 820 PJ_LOG(3,(THIS_FILE, " test %d of %d..", 821 i+1, REPEAT)); 822 status = create_response_bench(&usec[i]); 823 if (status != PJ_SUCCESS) 824 return status; 825 } 826 827 min.u64 = PJ_UINT64(0xFFFFFFFFFFFFFFF); 828 for (i=0; i<REPEAT; ++i) { 829 if (usec[i].u64 < min.u64) min.u64 = usec[i].u64; 830 } 831 832 msgs = (unsigned)(freq.u64 * LOOP / min.u64); 833 834 PJ_LOG(3,(THIS_FILE, " Responses created at %d responses/sec", msgs)); 835 836 report_ival("create-response-per-sec", 837 msgs, "msg/sec", 838 "Number of typical response messages that can be created " 839 "per second with <tt>pjsip_endpt_create_response()</tt>"); 840 841 528 842 return 0; 529 843 } 844
Note: See TracChangeset
for help on using the changeset viewer.