1
/* $Id: uri_test.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#define THIS_FILE "uri_test.c"
27
#define ALPHANUM "abcdefghijklmnopqrstuvwxyz" \
28
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
30
#define MARK "-_.!~*'()"
31
#define USER_CHAR ALPHANUM MARK "&=+$,;?/"
32
#define PASS_CHAR ALPHANUM MARK "&=+$,"
33
#define PARAM_CHAR ALPHANUM MARK "[]/:&+$"
35
#define POOL_SIZE 8000
36
#if defined(PJ_DEBUG) && PJ_DEBUG!=0
37
# define LOOP_COUNT 10000
39
# define LOOP_COUNT 40000
41
#define AVERAGE_URL_LEN 80
42
#define THREAD_COUNT 4
46
pj_highprec_t parse_len, print_len, cmp_len;
47
pj_timestamp parse_time, print_time, cmp_time;
51
/* URI creator functions. */
52
static pjsip_uri *create_uri0( pj_pool_t *pool );
53
static pjsip_uri *create_uri1( pj_pool_t *pool );
54
static pjsip_uri *create_uri2( pj_pool_t *pool );
55
static pjsip_uri *create_uri3( pj_pool_t *pool );
56
static pjsip_uri *create_uri4( pj_pool_t *pool );
57
static pjsip_uri *create_uri5( pj_pool_t *pool );
58
static pjsip_uri *create_uri6( pj_pool_t *pool );
59
static pjsip_uri *create_uri7( pj_pool_t *pool );
60
static pjsip_uri *create_uri8( pj_pool_t *pool );
61
static pjsip_uri *create_uri9( pj_pool_t *pool );
62
static pjsip_uri *create_uri10( pj_pool_t *pool );
63
static pjsip_uri *create_uri11( pj_pool_t *pool );
64
static pjsip_uri *create_uri12( pj_pool_t *pool );
65
static pjsip_uri *create_uri13( pj_pool_t *pool );
66
static pjsip_uri *create_uri14( pj_pool_t *pool );
67
static pjsip_uri *create_uri15( pj_pool_t *pool );
68
static pjsip_uri *create_uri16( pj_pool_t *pool );
69
static pjsip_uri *create_uri17( pj_pool_t *pool );
70
static pjsip_uri *create_uri25( pj_pool_t *pool );
71
static pjsip_uri *create_uri26( pj_pool_t *pool );
72
static pjsip_uri *create_uri27( pj_pool_t *pool );
73
static pjsip_uri *create_uri28( pj_pool_t *pool );
74
static pjsip_uri *create_uri29( pj_pool_t *pool );
75
static pjsip_uri *create_uri30( pj_pool_t *pool );
76
static pjsip_uri *create_uri31( pj_pool_t *pool );
77
static pjsip_uri *create_uri32( pj_pool_t *pool );
78
static pjsip_uri *create_uri33( pj_pool_t *pool );
79
static pjsip_uri *create_uri34( pj_pool_t *pool );
80
static pjsip_uri *create_uri35( pj_pool_t *pool );
81
static pjsip_uri *create_uri36( pj_pool_t *pool );
82
static pjsip_uri *create_uri37( pj_pool_t *pool );
83
static pjsip_uri *create_uri38( pj_pool_t *pool );
84
static pjsip_uri *create_dummy( pj_pool_t *pool );
86
#define ERR_NOT_EQUAL -1001
87
#define ERR_SYNTAX_ERR -1002
92
char str[PJSIP_MAX_URL_SIZE];
93
pjsip_uri *(*creator)(pj_pool_t *pool);
105
"sip:user@localhost",
110
"sip:user:password@localhost:5060",
113
/* Port is specified should not match unspecified port. */
115
"sip:localhost:5060",
119
/* All recognized parameters. */
121
"sip:localhost;transport=tcp;user=ip;ttl=255;lr;maddr=127.0.0.1;method=ACK",
125
/* Params mixed with other params and header params. */
127
"sip:localhost;pickup=hurry;user=phone;message=I%20am%20sorry"
128
"?Subject=Hello%20There&Server=SIP%20Server",
144
/* Name address with display name and SIPS scheme with some redundant
148
" Power Administrator <sips:localhost>",
154
" \"User\" <sip:user@localhost:5071>",
158
/* Escaped sequence in display name (display=Strange User\"\\\"). */
160
" \"Strange User\\\"\\\\\\\"\" <sip:localhost>",
164
/* Errorneous escaping in display name. */
166
" \"Rogue User\\\" <sip:localhost>",
170
/* Dangling quote in display name, but that should be OK. */
172
"Strange User\" <sip:localhost>",
176
/* Special characters in parameter value must be quoted. */
178
"sip:localhost;pvalue=\"hello world\"",
182
/* Excercise strange character sets allowed in display, user, password,
186
"This is -. !% *_+`'~ me <sip:a19A&=+$,;?/%2c:%40a&Zz=+$,@"
187
"my_proxy09.MY-domain.com:9801>",
191
/* Another excercise to the allowed character sets to the hostname. */
193
"sip:" ALPHANUM "-_.com",
197
/* Another excercise to the allowed character sets to the username
201
"sip:" USER_CHAR ":" PASS_CHAR "@host",
205
/* Excercise to the pname and pvalue, and mixup of other-param
206
* between 'recognized' params.
209
"sip:host;user=ip;" PARAM_CHAR "%21=" PARAM_CHAR "%21"
210
";lr;other=1;transport=sctp;other2",
214
/* 18: This should trigger syntax error. */
220
/* 19: Syntax error: whitespace after scheme. */
226
/* 20: Syntax error: whitespace before hostname. */
232
/* 21: Syntax error: invalid port. */
238
/* 22: Syntax error: no host. */
244
/* 23: Syntax error: no user/host. */
250
/* 24: Syntax error: empty string. */
256
/* 25: Simple tel: URI with global context */
258
"tel:+1-201-555-0123",
260
"tel:+1-201-555-0123"
263
/* 26: Simple tel: URI with local context */
265
"tel:7042;phone-context=example.com",
267
"tel:7042;phone-context=example.com"
270
/* 27: Simple tel: URI with local context */
272
"tel:863-1234;phone-context=+1-914-555",
274
"tel:863-1234;phone-context=+1-914-555"
277
/* 28: Comparison between local and global number */
284
/* 29: tel: with some visual chars and spaces */
286
"tel:(44).1234-*#+Deaf",
288
"tel:(44).1234-*#+Deaf"
291
/* 30: isub parameters */
293
"tel:+1;isub=/:@&$,-_.!~*'()[]/:&$aA1%21+=",
295
"tel:+1;isub=/:@&$,-_.!~*'()[]/:&$aA1!+%3d"
298
/* 31: extension number parsing and encoding */
305
/* 32: context parameter parsing and encoding */
307
"tel:911;phone-context=+1-911",
309
"tel:911;phone-context=+1-911"
312
/* 33: case-insensitive comparison */
314
"tel:911;phone-context=emergency.example.com",
316
"tel:911;phone-context=emergency.example.com"
319
/* 34: parameter only appears in one URL */
321
"tel:911;p1=p1;p2=p2",
323
"tel:911;p1=p1;p2=p2"
326
/* 35: IPv6 in host and maddr parameter */
328
"sip:user@[::1];maddr=[::01]",
330
"sip:user@[::1];maddr=[::01]"
333
/* 36: IPv6 in host and maddr, without username */
335
"sip:[::1];maddr=[::01]",
337
"sip:[::1];maddr=[::01]"
340
/* 37: Non-ASCII UTF-8 in display name, with quote */
342
"\"\xC0\x81\" <sip:localhost>",
344
"\"\xC0\x81\" <sip:localhost>"
347
/* 38: Non-ASCII UTF-8 in display name, without quote */
349
"\xC0\x81 <sip:localhost>",
351
"\"\xC0\x81\" <sip:localhost>"
356
static pjsip_uri *create_uri0(pj_pool_t *pool)
358
/* "sip:localhost" */
359
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
361
pj_strdup2(pool, &url->host, "localhost");
362
return (pjsip_uri*)url;
365
static pjsip_uri *create_uri1(pj_pool_t *pool)
367
/* "sip:user@localhost" */
368
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
370
pj_strdup2( pool, &url->user, "user");
371
pj_strdup2( pool, &url->host, "localhost");
373
return (pjsip_uri*) url;
376
static pjsip_uri *create_uri2(pj_pool_t *pool)
378
/* "sip:user:password@localhost:5060" */
379
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
381
pj_strdup2( pool, &url->user, "user");
382
pj_strdup2( pool, &url->passwd, "password");
383
pj_strdup2( pool, &url->host, "localhost");
386
return (pjsip_uri*) url;
389
static pjsip_uri *create_uri3(pj_pool_t *pool)
391
/* Like: "sip:localhost:5060", but without the port. */
392
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
394
pj_strdup2(pool, &url->host, "localhost");
395
return (pjsip_uri*)url;
398
static pjsip_uri *create_uri4(pj_pool_t *pool)
400
/* "sip:localhost;transport=tcp;user=ip;ttl=255;lr;maddr=127.0.0.1;method=ACK" */
401
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
403
pj_strdup2(pool, &url->host, "localhost");
404
pj_strdup2(pool, &url->transport_param, "tcp");
405
pj_strdup2(pool, &url->user_param, "ip");
406
url->ttl_param = 255;
408
pj_strdup2(pool, &url->maddr_param, "127.0.0.1");
409
pj_strdup2(pool, &url->method_param, "ACK");
411
return (pjsip_uri*)url;
414
#define param_add(list,pname,pvalue) \
416
pjsip_param *param; \
417
param=PJ_POOL_ALLOC_T(pool, pjsip_param); \
418
param->name = pj_str(pname); \
419
param->value = pj_str(pvalue); \
420
pj_list_insert_before(&list, param); \
423
static pjsip_uri *create_uri5(pj_pool_t *pool)
425
/* "sip:localhost;pickup=hurry;user=phone;message=I%20am%20sorry"
426
"?Subject=Hello%20There&Server=SIP%20Server"
428
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
430
pj_strdup2(pool, &url->host, "localhost");
431
pj_strdup2(pool, &url->user_param, "phone");
433
//pj_strdup2(pool, &url->other_param, ";pickup=hurry;message=I%20am%20sorry");
434
param_add(url->other_param, "pickup", "hurry");
435
param_add(url->other_param, "message", "I am sorry");
437
//pj_strdup2(pool, &url->header_param, "?Subject=Hello%20There&Server=SIP%20Server");
438
param_add(url->header_param, "Subject", "Hello There");
439
param_add(url->header_param, "Server", "SIP Server");
440
return (pjsip_uri*)url;
444
static pjsip_uri *create_uri6(pj_pool_t *pool)
446
/* "sips:localhost" */
447
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 1);
449
pj_strdup2(pool, &url->host, "localhost");
450
return (pjsip_uri*)url;
453
static pjsip_uri *create_uri7(pj_pool_t *pool)
455
/* "<sip:localhost>" */
456
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
459
url = pjsip_sip_uri_create(pool, 0);
460
name_addr->uri = (pjsip_uri*) url;
462
pj_strdup2(pool, &url->host, "localhost");
463
return (pjsip_uri*)name_addr;
466
static pjsip_uri *create_uri8(pj_pool_t *pool)
468
/* " Power Administrator <sips:localhost>" */
469
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
472
url = pjsip_sip_uri_create(pool, 1);
473
name_addr->uri = (pjsip_uri*) url;
475
pj_strdup2(pool, &name_addr->display, "Power Administrator");
476
pj_strdup2(pool, &url->host, "localhost");
477
return (pjsip_uri*)name_addr;
480
static pjsip_uri *create_uri9(pj_pool_t *pool)
482
/* " \"User\" <sip:user@localhost:5071>" */
483
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
486
url = pjsip_sip_uri_create(pool, 0);
487
name_addr->uri = (pjsip_uri*) url;
489
pj_strdup2(pool, &name_addr->display, "User");
490
pj_strdup2(pool, &url->user, "user");
491
pj_strdup2(pool, &url->host, "localhost");
493
return (pjsip_uri*)name_addr;
496
static pjsip_uri *create_uri10(pj_pool_t *pool)
498
/* " \"Strange User\\\"\\\\\\\"\" <sip:localhost>" */
499
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
502
url = pjsip_sip_uri_create(pool, 0);
503
name_addr->uri = (pjsip_uri*) url;
505
pj_strdup2(pool, &name_addr->display, "Strange User\\\"\\\\\\\"");
506
pj_strdup2(pool, &url->host, "localhost");
507
return (pjsip_uri*)name_addr;
510
static pjsip_uri *create_uri11(pj_pool_t *pool)
512
/* " \"Rogue User\\\" <sip:localhost>" */
513
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
516
url = pjsip_sip_uri_create(pool, 0);
517
name_addr->uri = (pjsip_uri*) url;
519
pj_strdup2(pool, &name_addr->display, "Rogue User\\");
520
pj_strdup2(pool, &url->host, "localhost");
521
return (pjsip_uri*)name_addr;
524
static pjsip_uri *create_uri12(pj_pool_t *pool)
526
/* "Strange User\" <sip:localhost>" */
527
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
530
url = pjsip_sip_uri_create(pool, 0);
531
name_addr->uri = (pjsip_uri*) url;
533
pj_strdup2(pool, &name_addr->display, "Strange User\"");
534
pj_strdup2(pool, &url->host, "localhost");
535
return (pjsip_uri*)name_addr;
538
static pjsip_uri *create_uri13(pj_pool_t *pool)
540
/* "sip:localhost;pvalue=\"hello world\"" */
542
url = pjsip_sip_uri_create(pool, 0);
543
pj_strdup2(pool, &url->host, "localhost");
544
//pj_strdup2(pool, &url->other_param, ";pvalue=\"hello world\"");
545
param_add(url->other_param, "pvalue", "\"hello world\"");
546
return (pjsip_uri*)url;
549
static pjsip_uri *create_uri14(pj_pool_t *pool)
551
/* "This is -. !% *_+`'~ me <sip:a19A&=+$,;?/%2c:%40a&Zz=+$,@my_proxy09.my-domain.com:9801>" */
552
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
555
url = pjsip_sip_uri_create(pool, 0);
556
name_addr->uri = (pjsip_uri*) url;
558
pj_strdup2(pool, &name_addr->display, "This is -. !% *_+`'~ me");
559
pj_strdup2(pool, &url->user, "a19A&=+$,;?/,");
560
pj_strdup2(pool, &url->passwd, "@a&Zz=+$,");
561
pj_strdup2(pool, &url->host, "my_proxy09.MY-domain.com");
563
return (pjsip_uri*)name_addr;
566
static pjsip_uri *create_uri15(pj_pool_t *pool)
568
/* "sip:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.com" */
570
url = pjsip_sip_uri_create(pool, 0);
571
pj_strdup2(pool, &url->host, ALPHANUM "-_.com");
572
return (pjsip_uri*)url;
575
static pjsip_uri *create_uri16(pj_pool_t *pool)
577
/* "sip:" USER_CHAR ":" PASS_CHAR "@host" */
579
url = pjsip_sip_uri_create(pool, 0);
580
pj_strdup2(pool, &url->user, USER_CHAR);
581
pj_strdup2(pool, &url->passwd, PASS_CHAR);
582
pj_strdup2(pool, &url->host, "host");
583
return (pjsip_uri*)url;
586
static pjsip_uri *create_uri17(pj_pool_t *pool)
588
/* "sip:host;user=ip;" PARAM_CHAR "%21=" PARAM_CHAR "%21;lr;other=1;transport=sctp;other2" */
590
url = pjsip_sip_uri_create(pool, 0);
591
pj_strdup2(pool, &url->host, "host");
592
pj_strdup2(pool, &url->user_param, "ip");
593
pj_strdup2(pool, &url->transport_param, "sctp");
594
param_add(url->other_param, PARAM_CHAR "!", PARAM_CHAR "!");
595
param_add(url->other_param, "other", "1");
596
param_add(url->other_param, "other2", "");
598
return (pjsip_uri*)url;
602
static pjsip_uri *create_uri25(pj_pool_t *pool)
604
/* "tel:+1-201-555-0123" */
605
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
607
uri->number = pj_str("+1-201-555-0123");
608
return (pjsip_uri*)uri;
611
static pjsip_uri *create_uri26(pj_pool_t *pool)
613
/* tel:7042;phone-context=example.com */
614
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
616
uri->number = pj_str("7042");
617
uri->context = pj_str("example.com");
618
return (pjsip_uri*)uri;
621
static pjsip_uri *create_uri27(pj_pool_t *pool)
623
/* "tel:863-1234;phone-context=+1-914-555" */
624
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
626
uri->number = pj_str("863-1234");
627
uri->context = pj_str("+1-914-555");
628
return (pjsip_uri*)uri;
632
static pjsip_uri *create_uri28(pj_pool_t *pool)
634
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
636
uri->number = pj_str("1");
637
return (pjsip_uri*)uri;
640
/* "tel:(44).1234-*#+Deaf" */
641
static pjsip_uri *create_uri29(pj_pool_t *pool)
643
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
645
uri->number = pj_str("(44).1234-*#+Deaf");
646
return (pjsip_uri*)uri;
649
/* "tel:+1;isub=/:@&$,-_.!~*'()[]/:&$aA1%21+=" */
650
static pjsip_uri *create_uri30(pj_pool_t *pool)
652
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
654
uri->number = pj_str("+1");
655
uri->isub_param = pj_str("/:@&$,-_.!~*'()[]/:&$aA1!+=");
656
return (pjsip_uri*)uri;
659
/* "tel:+1;ext=+123" */
660
static pjsip_uri *create_uri31(pj_pool_t *pool)
662
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
664
uri->number = pj_str("+1");
665
uri->ext_param = pj_str("+123");
666
return (pjsip_uri*)uri;
669
/* "tel:911;phone-context=+1-911" */
670
static pjsip_uri *create_uri32(pj_pool_t *pool)
672
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
674
uri->number = pj_str("911");
675
uri->context = pj_str("+1-911");
676
return (pjsip_uri*)uri;
679
/* "tel:911;phone-context=emergency.example.com" */
680
static pjsip_uri *create_uri33(pj_pool_t *pool)
682
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
684
uri->number = pj_str("911");
685
uri->context = pj_str("EMERGENCY.EXAMPLE.COM");
686
return (pjsip_uri*)uri;
689
/* "tel:911;p1=p1;p2=p2" */
690
static pjsip_uri *create_uri34(pj_pool_t *pool)
692
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
695
uri->number = pj_str("911");
697
p = PJ_POOL_ALLOC_T(pool, pjsip_param);
698
p->name = p->value = pj_str("p1");
699
pj_list_insert_before(&uri->other_param, p);
701
return (pjsip_uri*)uri;
704
/* "sip:user@[::1];maddr=[::01]" */
705
static pjsip_uri *create_uri35( pj_pool_t *pool )
708
url = pjsip_sip_uri_create(pool, 0);
709
url->user = pj_str("user");
710
url->host = pj_str("::1");
711
url->maddr_param = pj_str("::01");
712
return (pjsip_uri*)url;
715
/* "sip:[::1];maddr=[::01]" */
716
static pjsip_uri *create_uri36( pj_pool_t *pool )
719
url = pjsip_sip_uri_create(pool, 0);
720
url->host = pj_str("::1");
721
url->maddr_param = pj_str("::01");
722
return (pjsip_uri*)url;
726
/* "\"\xC0\x81\" <sip:localhost>" */
727
static pjsip_uri *create_uri37( pj_pool_t *pool )
729
pjsip_name_addr *name;
732
name = pjsip_name_addr_create(pool);
733
name->display = pj_str("\xC0\x81");
735
url = pjsip_sip_uri_create(pool, 0);
736
url->host = pj_str("localhost");
738
name->uri = (pjsip_uri*)url;
740
return (pjsip_uri*)name;
744
/* "\xC0\x81 <sip:localhost>" */
745
static pjsip_uri *create_uri38( pj_pool_t *pool )
747
pjsip_name_addr *name;
750
name = pjsip_name_addr_create(pool);
751
name->display = pj_str("\xC0\x81");
753
url = pjsip_sip_uri_create(pool, 0);
754
url->host = pj_str("localhost");
756
name->uri = (pjsip_uri*)url;
758
return (pjsip_uri*)name;
762
static pjsip_uri *create_dummy(pj_pool_t *pool)
768
/*****************************************************************************/
771
* Test one test entry.
773
static pj_status_t do_uri_test(pj_pool_t *pool, struct uri_test *entry)
778
pjsip_uri *parsed_uri, *ref_uri;
779
pj_str_t s1 = {NULL, 0}, s2 = {NULL, 0};
783
entry->len = pj_ansi_strlen(entry->str);
785
#if defined(PJSIP_UNESCAPE_IN_PLACE) && PJSIP_UNESCAPE_IN_PLACE!=0
786
input = pj_pool_alloc(pool, entry->len + 1);
787
pj_memcpy(input, entry->str, entry->len);
788
input[entry->len] = '\0';
793
/* Parse URI text. */
794
pj_get_timestamp(&t1);
795
var.parse_len = var.parse_len + entry->len;
796
parsed_uri = pjsip_parse_uri(pool, input, entry->len, 0);
798
/* Parsing failed. If the entry says that this is expected, then
801
status = entry->status==ERR_SYNTAX_ERR ? PJ_SUCCESS : -10;
803
PJ_LOG(3,(THIS_FILE, " uri parse error!\n"
809
pj_get_timestamp(&t2);
810
pj_sub_timestamp(&t2, &t1);
811
pj_add_timestamp(&var.parse_time, &t2);
813
/* Create the reference URI. */
814
ref_uri = entry->creator(pool);
816
/* Print both URI. */
817
s1.ptr = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
818
s2.ptr = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
820
pj_get_timestamp(&t1);
821
len = pjsip_uri_print( PJSIP_URI_IN_OTHER, parsed_uri, s1.ptr, PJSIP_MAX_URL_SIZE);
829
var.print_len = var.print_len + len;
830
pj_get_timestamp(&t2);
831
pj_sub_timestamp(&t2, &t1);
832
pj_add_timestamp(&var.print_time, &t2);
834
len = pjsip_uri_print( PJSIP_URI_IN_OTHER, ref_uri, s2.ptr, PJSIP_MAX_URL_SIZE);
842
/* Full comparison of parsed URI with reference URI. */
843
pj_get_timestamp(&t1);
844
status = pjsip_uri_cmp(PJSIP_URI_IN_OTHER, parsed_uri, ref_uri);
846
/* Not equal. See if this is the expected status. */
847
status = entry->status==ERR_NOT_EQUAL ? PJ_SUCCESS : -40;
849
PJ_LOG(3,(THIS_FILE, " uri comparison mismatch, status=%d:\n"
852
status, s1.ptr, s2.ptr));
857
/* Equal. See if this is the expected status. */
858
status = entry->status==PJ_SUCCESS ? PJ_SUCCESS : -50;
859
if (status != PJ_SUCCESS) {
864
var.cmp_len = var.cmp_len + len;
865
pj_get_timestamp(&t2);
866
pj_sub_timestamp(&t2, &t1);
867
pj_add_timestamp(&var.cmp_time, &t2);
870
if (entry->printed) {
871
if (pj_strcmp2(&s1, entry->printed) != 0) {
873
PJ_LOG(3,(THIS_FILE, " uri print mismatch:\n"
876
s1.ptr, entry->printed));
880
if (pj_strcmp(&s1, &s2) != 0) {
882
PJ_LOG(3,(THIS_FILE, " uri print mismatch:\n"
895
static int simple_uri_test(void)
901
PJ_LOG(3,(THIS_FILE, " simple test"));
902
for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) {
903
pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE);
904
status = do_uri_test(pool, &uri_test_array[i]);
905
pjsip_endpt_release_pool(endpt, pool);
906
if (status != PJ_SUCCESS) {
907
PJ_LOG(3,(THIS_FILE, " error %d when testing entry %d",
916
#if INCLUDE_BENCHMARKS
917
static int uri_benchmark(unsigned *p_parse, unsigned *p_print, unsigned *p_cmp)
920
pj_status_t status = PJ_SUCCESS;
923
pj_highprec_t avg_parse, avg_print, avg_cmp, kbytes;
925
pj_bzero(&var, sizeof(var));
927
zero.u32.hi = zero.u32.lo = 0;
929
var.parse_len = var.print_len = var.cmp_len = 0;
930
var.parse_time.u32.hi = var.parse_time.u32.lo = 0;
931
var.print_time.u32.hi = var.print_time.u32.lo = 0;
932
var.cmp_time.u32.hi = var.cmp_time.u32.lo = 0;
933
for (loop=0; loop<LOOP_COUNT; ++loop) {
934
for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) {
936
pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE);
937
status = do_uri_test(pool, &uri_test_array[i]);
938
pjsip_endpt_release_pool(endpt, pool);
939
if (status != PJ_SUCCESS) {
940
PJ_LOG(3,(THIS_FILE, " error %d when testing entry %d",
942
pjsip_endpt_release_pool(endpt, pool);
948
kbytes = var.parse_len;
949
pj_highprec_mod(kbytes, 1000000);
950
pj_highprec_div(kbytes, 100000);
951
elapsed = pj_elapsed_time(&zero, &var.parse_time);
952
avg_parse = pj_elapsed_usec(&zero, &var.parse_time);
953
pj_highprec_mul(avg_parse, AVERAGE_URL_LEN);
954
pj_highprec_div(avg_parse, var.parse_len);
957
avg_parse = 1000000 / avg_parse;
960
" %u.%u MB of urls parsed in %d.%03ds (avg=%d urls/sec)",
961
(unsigned)(var.parse_len/1000000), (unsigned)kbytes,
962
elapsed.sec, elapsed.msec,
963
(unsigned)avg_parse));
965
*p_parse = (unsigned)avg_parse;
967
kbytes = var.print_len;
968
pj_highprec_mod(kbytes, 1000000);
969
pj_highprec_div(kbytes, 100000);
970
elapsed = pj_elapsed_time(&zero, &var.print_time);
971
avg_print = pj_elapsed_usec(&zero, &var.print_time);
972
pj_highprec_mul(avg_print, AVERAGE_URL_LEN);
973
pj_highprec_div(avg_print, var.parse_len);
976
avg_print = 1000000 / avg_print;
979
" %u.%u MB of urls printed in %d.%03ds (avg=%d urls/sec)",
980
(unsigned)(var.print_len/1000000), (unsigned)kbytes,
981
elapsed.sec, elapsed.msec,
982
(unsigned)avg_print));
984
*p_print = (unsigned)avg_print;
986
kbytes = var.cmp_len;
987
pj_highprec_mod(kbytes, 1000000);
988
pj_highprec_div(kbytes, 100000);
989
elapsed = pj_elapsed_time(&zero, &var.cmp_time);
990
avg_cmp = pj_elapsed_usec(&zero, &var.cmp_time);
991
pj_highprec_mul(avg_cmp, AVERAGE_URL_LEN);
992
pj_highprec_div(avg_cmp, var.cmp_len);
995
avg_cmp = 1000000 / avg_cmp;
998
" %u.%u MB of urls compared in %d.%03ds (avg=%d urls/sec)",
999
(unsigned)(var.cmp_len/1000000), (unsigned)kbytes,
1000
elapsed.sec, elapsed.msec,
1001
(unsigned)avg_cmp));
1003
*p_cmp = (unsigned)avg_cmp;
1008
#endif /* INCLUDE_BENCHMARKS */
1010
/*****************************************************************************/
1014
enum { COUNT = 1, DETECT=0, PARSE=1, PRINT=2 };
1020
unsigned i, max, avg_len;
1024
status = simple_uri_test();
1025
if (status != PJ_SUCCESS)
1028
#if INCLUDE_BENCHMARKS
1029
for (i=0; i<COUNT; ++i) {
1030
PJ_LOG(3,(THIS_FILE, " benchmarking (%d of %d)...", i+1, COUNT));
1031
status = uri_benchmark(&run[i].parse, &run[i].print, &run[i].cmp);
1032
if (status != PJ_SUCCESS)
1036
/* Calculate average URI length */
1037
for (i=0, avg_len=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) {
1038
avg_len += uri_test_array[i].len;
1040
avg_len /= PJ_ARRAY_SIZE(uri_test_array);
1044
* Print maximum parse/sec
1046
for (i=0, max=0; i<COUNT; ++i)
1047
if (run[i].parse > max) max = run[i].parse;
1049
PJ_LOG(3,("", " Maximum URI parse/sec=%u", max));
1051
pj_ansi_sprintf(desc, "Number of SIP/TEL URIs that can be <B>parsed</B> with "
1052
"<tt>pjsip_parse_uri()</tt> per second "
1053
"(tested with %d URI set, with average length of "
1055
(int)PJ_ARRAY_SIZE(uri_test_array), avg_len);
1057
report_ival("uri-parse-per-sec", max, "URI/sec", desc);
1059
/* URI parsing bandwidth */
1060
report_ival("uri-parse-bandwidth-mb", avg_len*max/1000000, "MB/sec",
1061
"URI parsing bandwidth in megabytes (number of megabytes "
1062
"worth of URI that can be parsed per second)");
1065
/* Print maximum print/sec */
1066
for (i=0, max=0; i<COUNT; ++i)
1067
if (run[i].print > max) max = run[i].print;
1069
PJ_LOG(3,("", " Maximum URI print/sec=%u", max));
1071
pj_ansi_sprintf(desc, "Number of SIP/TEL URIs that can be <B>printed</B> with "
1072
"<tt>pjsip_uri_print()</tt> per second "
1073
"(tested with %d URI set, with average length of "
1075
(int)PJ_ARRAY_SIZE(uri_test_array), avg_len);
1077
report_ival("uri-print-per-sec", max, "URI/sec", desc);
1079
/* Print maximum detect/sec */
1080
for (i=0, max=0; i<COUNT; ++i)
1081
if (run[i].cmp > max) max = run[i].cmp;
1083
PJ_LOG(3,("", " Maximum URI comparison/sec=%u", max));
1085
pj_ansi_sprintf(desc, "Number of SIP/TEL URIs that can be <B>compared</B> with "
1086
"<tt>pjsip_uri_cmp()</tt> per second "
1087
"(tested with %d URI set, with average length of "
1089
(int)PJ_ARRAY_SIZE(uri_test_array), avg_len);
1091
report_ival("uri-cmp-per-sec", max, "URI/sec", desc);
1093
#endif /* INCLUDE_BENCHMARKS */