1
/* $Id: uri_test.c 4210 2012-07-19 01:00:07Z ming $ */
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_uri18( pj_pool_t *pool );
71
static pjsip_uri *create_uri25( pj_pool_t *pool );
72
static pjsip_uri *create_uri26( pj_pool_t *pool );
73
static pjsip_uri *create_uri27( pj_pool_t *pool );
74
static pjsip_uri *create_uri28( pj_pool_t *pool );
75
static pjsip_uri *create_uri29( pj_pool_t *pool );
76
static pjsip_uri *create_uri30( pj_pool_t *pool );
77
static pjsip_uri *create_uri31( pj_pool_t *pool );
78
static pjsip_uri *create_uri32( pj_pool_t *pool );
79
static pjsip_uri *create_uri33( pj_pool_t *pool );
80
static pjsip_uri *create_uri34( pj_pool_t *pool );
81
static pjsip_uri *create_uri35( pj_pool_t *pool );
82
static pjsip_uri *create_uri36( pj_pool_t *pool );
83
static pjsip_uri *create_uri37( pj_pool_t *pool );
84
static pjsip_uri *create_uri38( pj_pool_t *pool );
85
static pjsip_uri *create_uri39( pj_pool_t *pool );
86
static pjsip_uri *create_dummy( pj_pool_t *pool );
88
#define ERR_NOT_EQUAL -1001
89
#define ERR_SYNTAX_ERR -1002
94
char str[PJSIP_MAX_URL_SIZE];
95
pjsip_uri *(*creator)(pj_pool_t *pool);
107
"sip:user@localhost",
112
"sip:user:password@localhost:5060",
115
/* Port is specified should not match unspecified port. */
117
"sip:localhost:5060",
121
/* All recognized parameters. */
123
"sip:localhost;transport=tcp;user=ip;ttl=255;lr;maddr=127.0.0.1;method=ACK",
127
/* Params mixed with other params and header params. */
129
"sip:localhost;pickup=hurry;user=phone;message=I%20am%20sorry"
130
"?Subject=Hello%20There&Server=SIP%20Server",
146
/* Name address with display name and SIPS scheme with some redundant
150
" Power Administrator <sips:localhost>",
156
" \"User\" <sip:user@localhost:5071>",
160
/* Escaped sequence in display name (display=Strange User\"\\\"). */
162
" \"Strange User\\\"\\\\\\\"\" <sip:localhost>",
166
/* Errorneous escaping in display name. */
168
" \"Rogue User\\\" <sip:localhost>",
172
/* Dangling quote in display name, but that should be OK. */
174
"Strange User\" <sip:localhost>",
178
/* Special characters in parameter value must be quoted. */
180
"sip:localhost;pvalue=\"hello world\"",
184
/* Excercise strange character sets allowed in display, user, password,
188
"This is -. !% *_+`'~ me <sip:a19A&=+$,;?/%2c:%40a&Zz=+$,@"
189
"my_proxy09.MY-domain.com:9801>",
193
/* Another excercise to the allowed character sets to the hostname. */
195
"sip:" ALPHANUM "-_.com",
199
/* Another excercise to the allowed character sets to the username
203
"sip:" USER_CHAR ":" PASS_CHAR "@host",
207
/* Excercise to the pname and pvalue, and mixup of other-param
208
* between 'recognized' params.
211
"sip:host;user=ip;" PARAM_CHAR "%21=" PARAM_CHAR "%21"
212
";lr;other=1;transport=sctp;other2",
216
/* 18: This should trigger syntax error. */
222
/* 19: Syntax error: whitespace after scheme. */
228
/* 20: Syntax error: whitespace before hostname. */
234
/* 21: Syntax error: invalid port. */
240
/* 22: Syntax error: no host. */
246
/* 23: Syntax error: no user/host. */
252
/* 24: Syntax error: empty string. */
258
/* 25: Simple tel: URI with global context */
260
"tel:+1-201-555-0123",
262
"tel:+1-201-555-0123"
265
/* 26: Simple tel: URI with local context */
267
"tel:7042;phone-context=example.com",
269
"tel:7042;phone-context=example.com"
272
/* 27: Simple tel: URI with local context */
274
"tel:863-1234;phone-context=+1-914-555",
276
"tel:863-1234;phone-context=+1-914-555"
279
/* 28: Comparison between local and global number */
286
/* 29: tel: with some visual chars and spaces */
288
"tel:(44).1234-*#+Deaf",
290
"tel:(44).1234-*#+Deaf"
293
/* 30: isub parameters */
295
"tel:+1;isub=/:@&$,-_.!~*'()[]/:&$aA1%21+=",
297
"tel:+1;isub=/:@&$,-_.!~*'()[]/:&$aA1!+%3d"
300
/* 31: extension number parsing and encoding */
307
/* 32: context parameter parsing and encoding */
309
"tel:911;phone-context=+1-911",
311
"tel:911;phone-context=+1-911"
314
/* 33: case-insensitive comparison */
316
"tel:911;phone-context=emergency.example.com",
318
"tel:911;phone-context=emergency.example.com"
321
/* 34: parameter only appears in one URL */
323
"tel:911;p1=p1;p2=p2",
325
"tel:911;p1=p1;p2=p2"
328
/* 35: IPv6 in host and maddr parameter */
330
"sip:user@[::1];maddr=[::01]",
332
"sip:user@[::1];maddr=[::01]"
335
/* 36: IPv6 in host and maddr, without username */
337
"sip:[::1];maddr=[::01]",
339
"sip:[::1];maddr=[::01]"
342
/* 37: Non-ASCII UTF-8 in display name, with quote */
344
"\"\xC0\x81\" <sip:localhost>",
346
"\"\xC0\x81\" <sip:localhost>"
349
/* 38: Non-ASCII UTF-8 in display name, without quote */
351
"\xC0\x81 <sip:localhost>",
353
"\"\xC0\x81\" <sip:localhost>"
356
/* Even number of backslash before end quote in display name. */
358
"\"User\\\\\" <sip:localhost>",
364
static pjsip_uri *create_uri0(pj_pool_t *pool)
366
/* "sip:localhost" */
367
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
369
pj_strdup2(pool, &url->host, "localhost");
370
return (pjsip_uri*)url;
373
static pjsip_uri *create_uri1(pj_pool_t *pool)
375
/* "sip:user@localhost" */
376
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
378
pj_strdup2( pool, &url->user, "user");
379
pj_strdup2( pool, &url->host, "localhost");
381
return (pjsip_uri*) url;
384
static pjsip_uri *create_uri2(pj_pool_t *pool)
386
/* "sip:user:password@localhost:5060" */
387
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
389
pj_strdup2( pool, &url->user, "user");
390
pj_strdup2( pool, &url->passwd, "password");
391
pj_strdup2( pool, &url->host, "localhost");
394
return (pjsip_uri*) url;
397
static pjsip_uri *create_uri3(pj_pool_t *pool)
399
/* Like: "sip:localhost:5060", but without the port. */
400
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
402
pj_strdup2(pool, &url->host, "localhost");
403
return (pjsip_uri*)url;
406
static pjsip_uri *create_uri4(pj_pool_t *pool)
408
/* "sip:localhost;transport=tcp;user=ip;ttl=255;lr;maddr=127.0.0.1;method=ACK" */
409
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
411
pj_strdup2(pool, &url->host, "localhost");
412
pj_strdup2(pool, &url->transport_param, "tcp");
413
pj_strdup2(pool, &url->user_param, "ip");
414
url->ttl_param = 255;
416
pj_strdup2(pool, &url->maddr_param, "127.0.0.1");
417
pj_strdup2(pool, &url->method_param, "ACK");
419
return (pjsip_uri*)url;
422
#define param_add(list,pname,pvalue) \
424
pjsip_param *param; \
425
param=PJ_POOL_ALLOC_T(pool, pjsip_param); \
426
param->name = pj_str(pname); \
427
param->value = pj_str(pvalue); \
428
pj_list_insert_before(&list, param); \
431
static pjsip_uri *create_uri5(pj_pool_t *pool)
433
/* "sip:localhost;pickup=hurry;user=phone;message=I%20am%20sorry"
434
"?Subject=Hello%20There&Server=SIP%20Server"
436
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 0);
438
pj_strdup2(pool, &url->host, "localhost");
439
pj_strdup2(pool, &url->user_param, "phone");
441
//pj_strdup2(pool, &url->other_param, ";pickup=hurry;message=I%20am%20sorry");
442
param_add(url->other_param, "pickup", "hurry");
443
param_add(url->other_param, "message", "I am sorry");
445
//pj_strdup2(pool, &url->header_param, "?Subject=Hello%20There&Server=SIP%20Server");
446
param_add(url->header_param, "Subject", "Hello There");
447
param_add(url->header_param, "Server", "SIP Server");
448
return (pjsip_uri*)url;
452
static pjsip_uri *create_uri6(pj_pool_t *pool)
454
/* "sips:localhost" */
455
pjsip_sip_uri *url = pjsip_sip_uri_create(pool, 1);
457
pj_strdup2(pool, &url->host, "localhost");
458
return (pjsip_uri*)url;
461
static pjsip_uri *create_uri7(pj_pool_t *pool)
463
/* "<sip:localhost>" */
464
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
467
url = pjsip_sip_uri_create(pool, 0);
468
name_addr->uri = (pjsip_uri*) url;
470
pj_strdup2(pool, &url->host, "localhost");
471
return (pjsip_uri*)name_addr;
474
static pjsip_uri *create_uri8(pj_pool_t *pool)
476
/* " Power Administrator <sips:localhost>" */
477
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
480
url = pjsip_sip_uri_create(pool, 1);
481
name_addr->uri = (pjsip_uri*) url;
483
pj_strdup2(pool, &name_addr->display, "Power Administrator");
484
pj_strdup2(pool, &url->host, "localhost");
485
return (pjsip_uri*)name_addr;
488
static pjsip_uri *create_uri9(pj_pool_t *pool)
490
/* " \"User\" <sip:user@localhost:5071>" */
491
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
494
url = pjsip_sip_uri_create(pool, 0);
495
name_addr->uri = (pjsip_uri*) url;
497
pj_strdup2(pool, &name_addr->display, "User");
498
pj_strdup2(pool, &url->user, "user");
499
pj_strdup2(pool, &url->host, "localhost");
501
return (pjsip_uri*)name_addr;
504
static pjsip_uri *create_uri10(pj_pool_t *pool)
506
/* " \"Strange User\\\"\\\\\\\"\" <sip:localhost>" */
507
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
510
url = pjsip_sip_uri_create(pool, 0);
511
name_addr->uri = (pjsip_uri*) url;
513
pj_strdup2(pool, &name_addr->display, "Strange User\\\"\\\\\\\"");
514
pj_strdup2(pool, &url->host, "localhost");
515
return (pjsip_uri*)name_addr;
518
static pjsip_uri *create_uri11(pj_pool_t *pool)
520
/* " \"Rogue User\\\" <sip:localhost>" */
521
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
524
url = pjsip_sip_uri_create(pool, 0);
525
name_addr->uri = (pjsip_uri*) url;
527
pj_strdup2(pool, &name_addr->display, "Rogue User\\");
528
pj_strdup2(pool, &url->host, "localhost");
529
return (pjsip_uri*)name_addr;
532
static pjsip_uri *create_uri12(pj_pool_t *pool)
534
/* "Strange User\" <sip:localhost>" */
535
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
538
url = pjsip_sip_uri_create(pool, 0);
539
name_addr->uri = (pjsip_uri*) url;
541
pj_strdup2(pool, &name_addr->display, "Strange User\"");
542
pj_strdup2(pool, &url->host, "localhost");
543
return (pjsip_uri*)name_addr;
546
static pjsip_uri *create_uri13(pj_pool_t *pool)
548
/* "sip:localhost;pvalue=\"hello world\"" */
550
url = pjsip_sip_uri_create(pool, 0);
551
pj_strdup2(pool, &url->host, "localhost");
552
//pj_strdup2(pool, &url->other_param, ";pvalue=\"hello world\"");
553
param_add(url->other_param, "pvalue", "\"hello world\"");
554
return (pjsip_uri*)url;
557
static pjsip_uri *create_uri14(pj_pool_t *pool)
559
/* "This is -. !% *_+`'~ me <sip:a19A&=+$,;?/%2c:%40a&Zz=+$,@my_proxy09.my-domain.com:9801>" */
560
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
563
url = pjsip_sip_uri_create(pool, 0);
564
name_addr->uri = (pjsip_uri*) url;
566
pj_strdup2(pool, &name_addr->display, "This is -. !% *_+`'~ me");
567
pj_strdup2(pool, &url->user, "a19A&=+$,;?/,");
568
pj_strdup2(pool, &url->passwd, "@a&Zz=+$,");
569
pj_strdup2(pool, &url->host, "my_proxy09.MY-domain.com");
571
return (pjsip_uri*)name_addr;
574
static pjsip_uri *create_uri15(pj_pool_t *pool)
576
/* "sip:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.com" */
578
url = pjsip_sip_uri_create(pool, 0);
579
pj_strdup2(pool, &url->host, ALPHANUM "-_.com");
580
return (pjsip_uri*)url;
583
static pjsip_uri *create_uri16(pj_pool_t *pool)
585
/* "sip:" USER_CHAR ":" PASS_CHAR "@host" */
587
url = pjsip_sip_uri_create(pool, 0);
588
pj_strdup2(pool, &url->user, USER_CHAR);
589
pj_strdup2(pool, &url->passwd, PASS_CHAR);
590
pj_strdup2(pool, &url->host, "host");
591
return (pjsip_uri*)url;
594
static pjsip_uri *create_uri17(pj_pool_t *pool)
596
/* "sip:host;user=ip;" PARAM_CHAR "%21=" PARAM_CHAR "%21;lr;other=1;transport=sctp;other2" */
598
url = pjsip_sip_uri_create(pool, 0);
599
pj_strdup2(pool, &url->host, "host");
600
pj_strdup2(pool, &url->user_param, "ip");
601
pj_strdup2(pool, &url->transport_param, "sctp");
602
param_add(url->other_param, PARAM_CHAR "!", PARAM_CHAR "!");
603
param_add(url->other_param, "other", "1");
604
param_add(url->other_param, "other2", "");
606
return (pjsip_uri*)url;
610
static pjsip_uri *create_uri25(pj_pool_t *pool)
612
/* "tel:+1-201-555-0123" */
613
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
615
uri->number = pj_str("+1-201-555-0123");
616
return (pjsip_uri*)uri;
619
static pjsip_uri *create_uri26(pj_pool_t *pool)
621
/* tel:7042;phone-context=example.com */
622
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
624
uri->number = pj_str("7042");
625
uri->context = pj_str("example.com");
626
return (pjsip_uri*)uri;
629
static pjsip_uri *create_uri27(pj_pool_t *pool)
631
/* "tel:863-1234;phone-context=+1-914-555" */
632
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
634
uri->number = pj_str("863-1234");
635
uri->context = pj_str("+1-914-555");
636
return (pjsip_uri*)uri;
640
static pjsip_uri *create_uri28(pj_pool_t *pool)
642
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
644
uri->number = pj_str("1");
645
return (pjsip_uri*)uri;
648
/* "tel:(44).1234-*#+Deaf" */
649
static pjsip_uri *create_uri29(pj_pool_t *pool)
651
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
653
uri->number = pj_str("(44).1234-*#+Deaf");
654
return (pjsip_uri*)uri;
657
/* "tel:+1;isub=/:@&$,-_.!~*'()[]/:&$aA1%21+=" */
658
static pjsip_uri *create_uri30(pj_pool_t *pool)
660
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
662
uri->number = pj_str("+1");
663
uri->isub_param = pj_str("/:@&$,-_.!~*'()[]/:&$aA1!+=");
664
return (pjsip_uri*)uri;
667
/* "tel:+1;ext=+123" */
668
static pjsip_uri *create_uri31(pj_pool_t *pool)
670
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
672
uri->number = pj_str("+1");
673
uri->ext_param = pj_str("+123");
674
return (pjsip_uri*)uri;
677
/* "tel:911;phone-context=+1-911" */
678
static pjsip_uri *create_uri32(pj_pool_t *pool)
680
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
682
uri->number = pj_str("911");
683
uri->context = pj_str("+1-911");
684
return (pjsip_uri*)uri;
687
/* "tel:911;phone-context=emergency.example.com" */
688
static pjsip_uri *create_uri33(pj_pool_t *pool)
690
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
692
uri->number = pj_str("911");
693
uri->context = pj_str("EMERGENCY.EXAMPLE.COM");
694
return (pjsip_uri*)uri;
697
/* "tel:911;p1=p1;p2=p2" */
698
static pjsip_uri *create_uri34(pj_pool_t *pool)
700
pjsip_tel_uri *uri = pjsip_tel_uri_create(pool);
703
uri->number = pj_str("911");
705
p = PJ_POOL_ALLOC_T(pool, pjsip_param);
706
p->name = p->value = pj_str("p1");
707
pj_list_insert_before(&uri->other_param, p);
709
return (pjsip_uri*)uri;
712
/* "sip:user@[::1];maddr=[::01]" */
713
static pjsip_uri *create_uri35( pj_pool_t *pool )
716
url = pjsip_sip_uri_create(pool, 0);
717
url->user = pj_str("user");
718
url->host = pj_str("::1");
719
url->maddr_param = pj_str("::01");
720
return (pjsip_uri*)url;
723
/* "sip:[::1];maddr=[::01]" */
724
static pjsip_uri *create_uri36( pj_pool_t *pool )
727
url = pjsip_sip_uri_create(pool, 0);
728
url->host = pj_str("::1");
729
url->maddr_param = pj_str("::01");
730
return (pjsip_uri*)url;
734
/* "\"\xC0\x81\" <sip:localhost>" */
735
static pjsip_uri *create_uri37( pj_pool_t *pool )
737
pjsip_name_addr *name;
740
name = pjsip_name_addr_create(pool);
741
name->display = pj_str("\xC0\x81");
743
url = pjsip_sip_uri_create(pool, 0);
744
url->host = pj_str("localhost");
746
name->uri = (pjsip_uri*)url;
748
return (pjsip_uri*)name;
752
/* "\xC0\x81 <sip:localhost>" */
753
static pjsip_uri *create_uri38( pj_pool_t *pool )
755
pjsip_name_addr *name;
758
name = pjsip_name_addr_create(pool);
759
name->display = pj_str("\xC0\x81");
761
url = pjsip_sip_uri_create(pool, 0);
762
url->host = pj_str("localhost");
764
name->uri = (pjsip_uri*)url;
766
return (pjsip_uri*)name;
770
/* "\"User\\\\\" <sip:localhost>" */
771
static pjsip_uri *create_uri39(pj_pool_t *pool)
773
pjsip_name_addr *name_addr = pjsip_name_addr_create(pool);
776
url = pjsip_sip_uri_create(pool, 0);
777
name_addr->uri = (pjsip_uri*) url;
779
pj_strdup2(pool, &name_addr->display, "User\\\\");
780
pj_strdup2(pool, &url->host, "localhost");
781
return (pjsip_uri*)name_addr;
784
static pjsip_uri *create_dummy(pj_pool_t *pool)
790
/*****************************************************************************/
793
* Test one test entry.
795
static pj_status_t do_uri_test(pj_pool_t *pool, struct uri_test *entry)
800
pjsip_uri *parsed_uri, *ref_uri;
801
pj_str_t s1 = {NULL, 0}, s2 = {NULL, 0};
805
entry->len = pj_ansi_strlen(entry->str);
807
#if defined(PJSIP_UNESCAPE_IN_PLACE) && PJSIP_UNESCAPE_IN_PLACE!=0
808
input = pj_pool_alloc(pool, entry->len + 1);
809
pj_memcpy(input, entry->str, entry->len);
810
input[entry->len] = '\0';
815
/* Parse URI text. */
816
pj_get_timestamp(&t1);
817
var.parse_len = var.parse_len + entry->len;
818
parsed_uri = pjsip_parse_uri(pool, input, entry->len, 0);
820
/* Parsing failed. If the entry says that this is expected, then
823
status = entry->status==ERR_SYNTAX_ERR ? PJ_SUCCESS : -10;
825
PJ_LOG(3,(THIS_FILE, " uri parse error!\n"
831
pj_get_timestamp(&t2);
832
pj_sub_timestamp(&t2, &t1);
833
pj_add_timestamp(&var.parse_time, &t2);
835
/* Create the reference URI. */
836
ref_uri = entry->creator(pool);
838
/* Print both URI. */
839
s1.ptr = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
840
s2.ptr = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
842
pj_get_timestamp(&t1);
843
len = pjsip_uri_print( PJSIP_URI_IN_OTHER, parsed_uri, s1.ptr, PJSIP_MAX_URL_SIZE);
851
var.print_len = var.print_len + len;
852
pj_get_timestamp(&t2);
853
pj_sub_timestamp(&t2, &t1);
854
pj_add_timestamp(&var.print_time, &t2);
856
len = pjsip_uri_print( PJSIP_URI_IN_OTHER, ref_uri, s2.ptr, PJSIP_MAX_URL_SIZE);
864
/* Full comparison of parsed URI with reference URI. */
865
pj_get_timestamp(&t1);
866
status = pjsip_uri_cmp(PJSIP_URI_IN_OTHER, parsed_uri, ref_uri);
868
/* Not equal. See if this is the expected status. */
869
status = entry->status==ERR_NOT_EQUAL ? PJ_SUCCESS : -40;
871
PJ_LOG(3,(THIS_FILE, " uri comparison mismatch, status=%d:\n"
874
status, s1.ptr, s2.ptr));
879
/* Equal. See if this is the expected status. */
880
status = entry->status==PJ_SUCCESS ? PJ_SUCCESS : -50;
881
if (status != PJ_SUCCESS) {
886
var.cmp_len = var.cmp_len + len;
887
pj_get_timestamp(&t2);
888
pj_sub_timestamp(&t2, &t1);
889
pj_add_timestamp(&var.cmp_time, &t2);
892
if (entry->printed) {
893
if (pj_strcmp2(&s1, entry->printed) != 0) {
895
PJ_LOG(3,(THIS_FILE, " uri print mismatch:\n"
898
s1.ptr, entry->printed));
902
if (pj_strcmp(&s1, &s2) != 0) {
904
PJ_LOG(3,(THIS_FILE, " uri print mismatch:\n"
917
static int simple_uri_test(void)
923
PJ_LOG(3,(THIS_FILE, " simple test"));
924
for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) {
925
pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE);
926
status = do_uri_test(pool, &uri_test_array[i]);
927
pjsip_endpt_release_pool(endpt, pool);
928
if (status != PJ_SUCCESS) {
929
PJ_LOG(3,(THIS_FILE, " error %d when testing entry %d",
938
#if INCLUDE_BENCHMARKS
939
static int uri_benchmark(unsigned *p_parse, unsigned *p_print, unsigned *p_cmp)
942
pj_status_t status = PJ_SUCCESS;
945
pj_highprec_t avg_parse, avg_print, avg_cmp, kbytes;
947
pj_bzero(&var, sizeof(var));
949
zero.u32.hi = zero.u32.lo = 0;
951
var.parse_len = var.print_len = var.cmp_len = 0;
952
var.parse_time.u32.hi = var.parse_time.u32.lo = 0;
953
var.print_time.u32.hi = var.print_time.u32.lo = 0;
954
var.cmp_time.u32.hi = var.cmp_time.u32.lo = 0;
955
for (loop=0; loop<LOOP_COUNT; ++loop) {
956
for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) {
958
pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE);
959
status = do_uri_test(pool, &uri_test_array[i]);
960
pjsip_endpt_release_pool(endpt, pool);
961
if (status != PJ_SUCCESS) {
962
PJ_LOG(3,(THIS_FILE, " error %d when testing entry %d",
964
pjsip_endpt_release_pool(endpt, pool);
970
kbytes = var.parse_len;
971
pj_highprec_mod(kbytes, 1000000);
972
pj_highprec_div(kbytes, 100000);
973
elapsed = pj_elapsed_time(&zero, &var.parse_time);
974
avg_parse = pj_elapsed_usec(&zero, &var.parse_time);
975
pj_highprec_mul(avg_parse, AVERAGE_URL_LEN);
976
pj_highprec_div(avg_parse, var.parse_len);
979
avg_parse = 1000000 / avg_parse;
982
" %u.%u MB of urls parsed in %d.%03ds (avg=%d urls/sec)",
983
(unsigned)(var.parse_len/1000000), (unsigned)kbytes,
984
elapsed.sec, elapsed.msec,
985
(unsigned)avg_parse));
987
*p_parse = (unsigned)avg_parse;
989
kbytes = var.print_len;
990
pj_highprec_mod(kbytes, 1000000);
991
pj_highprec_div(kbytes, 100000);
992
elapsed = pj_elapsed_time(&zero, &var.print_time);
993
avg_print = pj_elapsed_usec(&zero, &var.print_time);
994
pj_highprec_mul(avg_print, AVERAGE_URL_LEN);
995
pj_highprec_div(avg_print, var.parse_len);
998
avg_print = 1000000 / avg_print;
1000
PJ_LOG(3,(THIS_FILE,
1001
" %u.%u MB of urls printed in %d.%03ds (avg=%d urls/sec)",
1002
(unsigned)(var.print_len/1000000), (unsigned)kbytes,
1003
elapsed.sec, elapsed.msec,
1004
(unsigned)avg_print));
1006
*p_print = (unsigned)avg_print;
1008
kbytes = var.cmp_len;
1009
pj_highprec_mod(kbytes, 1000000);
1010
pj_highprec_div(kbytes, 100000);
1011
elapsed = pj_elapsed_time(&zero, &var.cmp_time);
1012
avg_cmp = pj_elapsed_usec(&zero, &var.cmp_time);
1013
pj_highprec_mul(avg_cmp, AVERAGE_URL_LEN);
1014
pj_highprec_div(avg_cmp, var.cmp_len);
1017
avg_cmp = 1000000 / avg_cmp;
1019
PJ_LOG(3,(THIS_FILE,
1020
" %u.%u MB of urls compared in %d.%03ds (avg=%d urls/sec)",
1021
(unsigned)(var.cmp_len/1000000), (unsigned)kbytes,
1022
elapsed.sec, elapsed.msec,
1023
(unsigned)avg_cmp));
1025
*p_cmp = (unsigned)avg_cmp;
1030
#endif /* INCLUDE_BENCHMARKS */
1032
/*****************************************************************************/
1036
enum { COUNT = 1, DETECT=0, PARSE=1, PRINT=2 };
1042
unsigned i, max, avg_len;
1046
status = simple_uri_test();
1047
if (status != PJ_SUCCESS)
1050
#if INCLUDE_BENCHMARKS
1051
for (i=0; i<COUNT; ++i) {
1052
PJ_LOG(3,(THIS_FILE, " benchmarking (%d of %d)...", i+1, COUNT));
1053
status = uri_benchmark(&run[i].parse, &run[i].print, &run[i].cmp);
1054
if (status != PJ_SUCCESS)
1058
/* Calculate average URI length */
1059
for (i=0, avg_len=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) {
1060
avg_len += uri_test_array[i].len;
1062
avg_len /= PJ_ARRAY_SIZE(uri_test_array);
1066
* Print maximum parse/sec
1068
for (i=0, max=0; i<COUNT; ++i)
1069
if (run[i].parse > max) max = run[i].parse;
1071
PJ_LOG(3,("", " Maximum URI parse/sec=%u", max));
1073
pj_ansi_sprintf(desc, "Number of SIP/TEL URIs that can be <B>parsed</B> with "
1074
"<tt>pjsip_parse_uri()</tt> per second "
1075
"(tested with %d URI set, with average length of "
1077
(int)PJ_ARRAY_SIZE(uri_test_array), avg_len);
1079
report_ival("uri-parse-per-sec", max, "URI/sec", desc);
1081
/* URI parsing bandwidth */
1082
report_ival("uri-parse-bandwidth-mb", avg_len*max/1000000, "MB/sec",
1083
"URI parsing bandwidth in megabytes (number of megabytes "
1084
"worth of URI that can be parsed per second)");
1087
/* Print maximum print/sec */
1088
for (i=0, max=0; i<COUNT; ++i)
1089
if (run[i].print > max) max = run[i].print;
1091
PJ_LOG(3,("", " Maximum URI print/sec=%u", max));
1093
pj_ansi_sprintf(desc, "Number of SIP/TEL URIs that can be <B>printed</B> with "
1094
"<tt>pjsip_uri_print()</tt> per second "
1095
"(tested with %d URI set, with average length of "
1097
(int)PJ_ARRAY_SIZE(uri_test_array), avg_len);
1099
report_ival("uri-print-per-sec", max, "URI/sec", desc);
1101
/* Print maximum detect/sec */
1102
for (i=0, max=0; i<COUNT; ++i)
1103
if (run[i].cmp > max) max = run[i].cmp;
1105
PJ_LOG(3,("", " Maximum URI comparison/sec=%u", max));
1107
pj_ansi_sprintf(desc, "Number of SIP/TEL URIs that can be <B>compared</B> with "
1108
"<tt>pjsip_uri_cmp()</tt> per second "
1109
"(tested with %d URI set, with average length of "
1111
(int)PJ_ARRAY_SIZE(uri_test_array), avg_len);
1113
report_ival("uri-cmp-per-sec", max, "URI/sec", desc);
1115
#endif /* INCLUDE_BENCHMARKS */