summaryrefslogtreecommitdiff
path: root/pjsip/src/test-pjsip
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2005-11-20 19:58:10 +0000
committerBenny Prijono <bennylp@teluu.com>2005-11-20 19:58:10 +0000
commit9f4da35e676737f830a90a18de08440cf0f6cdf9 (patch)
tree5485d610d1c65f3d0be067794c81ba02c33a1bd4 /pjsip/src/test-pjsip
parent37e8cb76f7b1f6e5dada1f8a06be4b963ee71be3 (diff)
More compliant URI parser, comparison, etc.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@64 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/test-pjsip')
-rw-r--r--pjsip/src/test-pjsip/main.c6
-rw-r--r--pjsip/src/test-pjsip/msg.c (renamed from pjsip/src/test-pjsip/parse_msg.c)117
-rw-r--r--pjsip/src/test-pjsip/test.c47
-rw-r--r--pjsip/src/test-pjsip/test.h9
-rw-r--r--pjsip/src/test-pjsip/uri.c (renamed from pjsip/src/test-pjsip/parse_uri.c)162
5 files changed, 106 insertions, 235 deletions
diff --git a/pjsip/src/test-pjsip/main.c b/pjsip/src/test-pjsip/main.c
index 75b3792e..3c819be8 100644
--- a/pjsip/src/test-pjsip/main.c
+++ b/pjsip/src/test-pjsip/main.c
@@ -16,3 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "test.h"
+
+int main(void)
+{
+ return test_main();
+}
diff --git a/pjsip/src/test-pjsip/parse_msg.c b/pjsip/src/test-pjsip/msg.c
index 94ac25ce..b546a756 100644
--- a/pjsip/src/test-pjsip/parse_msg.c
+++ b/pjsip/src/test-pjsip/msg.c
@@ -16,19 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <pjsip/sip_msg.h>
-#include <pjsip/sip_parser.h>
-#include <pj/os.h>
-#include <pj/pool.h>
-#include <pj/string.h>
-#include <stdlib.h>
-#include <stdio.h>
#include "test.h"
-
-#define ERR_SYNTAX_ERR (-2)
-#define ERR_NOT_EQUAL (-3)
-#define ERR_SYSTEM (-4)
-
+#include <pjsip_core.h>
+#include <pjlib.h>
static pjsip_msg *create_msg0(pj_pool_t *pool);
@@ -66,66 +56,31 @@ struct test_msg
}
};
-static pj_caching_pool cp;
-static pj_pool_factory *pf = &cp.factory;
static pj_uint32_t parse_len, parse_time, print_time;
-static void pool_error(pj_pool_t *pool, pj_size_t sz)
-{
- PJ_UNUSED_ARG(pool)
- PJ_UNUSED_ARG(sz)
-
- pj_assert(0);
- exit(1);
-}
-
-static const char *STATUS_STR(pj_status_t status)
-{
- switch (status) {
- case 0: return "OK";
- case ERR_SYNTAX_ERR: return "Syntax Error";
- case ERR_NOT_EQUAL: return "Not Equal";
- case ERR_SYSTEM: return "System Error";
- }
- return "???";
-}
-
-static pj_status_t test_entry( struct test_msg *entry )
+static pj_status_t test_entry( pj_pool_t *pool, struct test_msg *entry )
{
pjsip_msg *parsed_msg, *ref_msg;
- pj_pool_t *pool;
pj_status_t status = PJ_SUCCESS;
int len;
pj_str_t str1, str2;
pjsip_hdr *hdr1, *hdr2;
- pj_hr_timestamp t1, t2;
+ pj_timestamp t1, t2;
char *msgbuf;
enum { BUFLEN = 512 };
- pool = pj_pool_create( pf, "",
- PJSIP_POOL_LEN_RDATA*2, PJSIP_POOL_INC_RDATA,
- &pool_error);
-
- if (entry->len == 0) {
- entry->len = strlen(entry->msg);
- }
-
/* Parse message. */
parse_len += entry->len;
- pj_hr_gettimestamp(&t1);
+ pj_get_timestamp(&t1);
parsed_msg = pjsip_parse_msg(pool, entry->msg, entry->len, NULL);
if (parsed_msg == NULL) {
- status = ERR_SYNTAX_ERR;
+ status = -10;
goto on_return;
}
- pj_hr_gettimestamp(&t2);
+ pj_get_timestamp(&t2);
parse_time += t2.u32.lo - t1.u32.lo;
-#if IS_PROFILING
- goto print_msg;
-#endif
-
/* Create reference message. */
ref_msg = entry->creator(pool);
@@ -135,7 +90,7 @@ static pj_status_t test_entry( struct test_msg *entry )
/* Compare message type. */
if (parsed_msg->type != ref_msg->type) {
- status = ERR_NOT_EQUAL;
+ status = -20;
goto on_return;
}
@@ -145,7 +100,7 @@ static pj_status_t test_entry( struct test_msg *entry )
pjsip_method *m2 = &ref_msg->line.req.method;
if (m1->id != m2->id || pj_strcmp(&m1->name, &m2->name)) {
- status = ERR_NOT_EQUAL;
+ status = -30;
goto on_return;
}
} else {
@@ -159,26 +114,20 @@ static pj_status_t test_entry( struct test_msg *entry )
while (hdr1 != &parsed_msg->hdr && hdr2 != &ref_msg->hdr) {
len = hdr1->vptr->print_on(hdr1, str1.ptr, BUFLEN);
if (len < 1) {
- status = ERR_SYSTEM;
+ status = -40;
goto on_return;
}
str1.slen = len;
len = hdr2->vptr->print_on(hdr2, str2.ptr, BUFLEN);
if (len < 1) {
- status = ERR_SYSTEM;
+ status = -50;
goto on_return;
}
str2.slen = len;
- if (!SILENT) {
- printf("hdr1='%.*s'\n"
- "hdr2='%.*s'\n\n",
- str1.slen, str1.ptr,
- str2.slen, str2.ptr);
- }
if (pj_strcmp(&str1, &str2) != 0) {
- status = ERR_NOT_EQUAL;
+ status = -60;
goto on_return;
}
@@ -187,62 +136,42 @@ static pj_status_t test_entry( struct test_msg *entry )
}
if (hdr1 != &parsed_msg->hdr || hdr2 != &ref_msg->hdr) {
- status = ERR_NOT_EQUAL;
+ status = -70;
goto on_return;
}
/* Print message. */
-#if IS_PROFILING
-print_msg:
-#endif
msgbuf = pj_pool_alloc(pool, PJSIP_MAX_PKT_LEN);
if (msgbuf == NULL) {
- status = ERR_SYSTEM;
+ status = -80;
goto on_return;
}
- pj_hr_gettimestamp(&t1);
+ pj_get_timestamp(&t1);
len = pjsip_msg_print(parsed_msg, msgbuf, PJSIP_MAX_PKT_LEN);
if (len < 1) {
- status = ERR_SYSTEM;
+ status = -90;
goto on_return;
}
- pj_hr_gettimestamp(&t2);
+ pj_get_timestamp(&t2);
print_time += t2.u32.lo - t1.u32.lo;
status = PJ_SUCCESS;
on_return:
- pj_pool_release(pool);
return status;
}
-static void warm_up()
-{
- pj_pool_t *pool;
- pool = pj_pool_create( pf, "",
- PJSIP_POOL_LEN_RDATA*2, PJSIP_POOL_INC_RDATA,
- &pool_error);
- pj_pool_release(pool);
-}
-
-pj_status_t test_msg(void)
+pj_status_t msg_test(void)
{
pj_status_t status;
- unsigned i;
+ pj_pool_t *pool;
- pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
- warm_up();
+ pool = pjsip_endpt_create_pool(endpt, NULL, 4000, 4000);
- for (i=0; i<LOOP; ++i) {
- status = test_entry( &test_array[0] );
- }
- printf("%s\n", STATUS_STR(status));
+ status = test_entry( pool, &test_array[0] );
- printf("Total bytes: %u, parse time=%f/char, print time=%f/char\n",
- parse_len,
- parse_time*1.0/parse_len,
- print_time*1.0/parse_len);
- return PJ_SUCCESS;
+ pjsip_endpt_destroy(endpt);
+ return status;
}
/*****************************************************************************/
diff --git a/pjsip/src/test-pjsip/test.c b/pjsip/src/test-pjsip/test.c
index 4a69b582..80d08881 100644
--- a/pjsip/src/test-pjsip/test.c
+++ b/pjsip/src/test-pjsip/test.c
@@ -46,20 +46,59 @@ void app_perror(const char *msg, pj_status_t rc)
}
+pj_status_t register_static_modules(pj_size_t *count, pjsip_module **modules)
+{
+ *count = 0;
+ return PJ_SUCCESS;
+}
-
-int main()
+int test_main(void)
{
pj_status_t rc;
+ pj_caching_pool caching_pool;
+ const char *filename;
+ int line;
+
+ pj_log_set_level(3);
+ pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
+ PJ_LOG_HAS_MICRO_SEC);
if ((rc=pj_init()) != PJ_SUCCESS) {
app_perror("pj_init", rc);
+ return rc;
+ }
+
+ pj_dump_config();
+
+ pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
+
+ rc = pjsip_endpt_create(&caching_pool.factory, "endpt", &endpt);
+ if (rc != PJ_SUCCESS) {
+ app_perror("pjsip_endpt_create", rc);
+ pj_caching_pool_destroy(&caching_pool);
+ return rc;
}
- DO_TEST(parse_uri());
- DO_TEST(parse_msg());
+ PJ_LOG(3,("",""));
+
+ DO_TEST(uri_test());
on_return:
+
+ pjsip_endpt_destroy(endpt);
+ pj_caching_pool_destroy(&caching_pool);
+
+ PJ_LOG(3,("test", ""));
+
+ pj_thread_get_stack_info(pj_thread_this(), &filename, &line);
+ PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u",
+ pj_thread_get_stack_max_usage(pj_thread_this()),
+ filename, line));
+ if (rc == 0)
+ PJ_LOG(3,("test", "Looks like everything is okay!.."));
+ else
+ PJ_LOG(3,("test", "Test completed with error(s)"));
+
return 0;
}
diff --git a/pjsip/src/test-pjsip/test.h b/pjsip/src/test-pjsip/test.h
index 225c8be7..60b67c5e 100644
--- a/pjsip/src/test-pjsip/test.h
+++ b/pjsip/src/test-pjsip/test.h
@@ -21,15 +21,12 @@
#include <pjsip/sip_types.h>
-#define SILENT 1
-#define IS_PROFILING 1
-#define LOOP 2000
-
extern pjsip_endpoint *endpt;
-pj_status_t parse_uri(void);
-pj_status_t parse_msg(void);
+pj_status_t uri_test(void);
+pj_status_t msg_test(void);
+int test_main(void);
void app_perror(const char *msg, pj_status_t status);
diff --git a/pjsip/src/test-pjsip/parse_uri.c b/pjsip/src/test-pjsip/uri.c
index cfb3afd7..a61382f0 100644
--- a/pjsip/src/test-pjsip/parse_uri.c
+++ b/pjsip/src/test-pjsip/uri.c
@@ -16,17 +16,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <pjsip/sip_parser.h>
-#include <pjsip/sip_uri.h>
-#include <pj/os.h>
-#include <pj/pool.h>
-#include <pj/string.h>
-#include <stdlib.h>
-#include <stdio.h>
#include "test.h"
+#include <pjsip_core.h>
+#include <pjlib.h>
-#define ERR_SYNTAX_ERR (-2)
-#define ERR_NOT_EQUAL (-3)
#define ALPHANUM "abcdefghijklmnopqrstuvwxyz" \
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
@@ -38,18 +31,7 @@
#define POOL_SIZE 4096
-static const char *STATUS_STR(pj_status_t status)
-{
- switch (status) {
- case 0: return "OK";
- case ERR_SYNTAX_ERR: return "Syntax Error";
- case ERR_NOT_EQUAL: return "Not Equal";
- }
- return "???";
-}
-
static pj_uint32_t parse_len, parse_time, print_time;
-static pj_caching_pool cp;
/* URI creator functions. */
@@ -74,6 +56,9 @@ static pjsip_uri *create_uri18( pj_pool_t *pool );
static pjsip_uri *create_uri19( pj_pool_t *pool );
static pjsip_uri *create_dummy( pj_pool_t *pool );
+#define ERR_NOT_EQUAL -1001
+#define ERR_SYNTAX_ERR -1002
+
struct uri_test
{
pj_status_t status;
@@ -239,12 +224,7 @@ struct uri_test
ERR_SYNTAX_ERR,
"",
&create_dummy,
- },
- {
- PJ_SUCCESS,
- "",
- NULL,
- },
+ }
};
static pjsip_uri *create_uri1(pj_pool_t *pool)
@@ -476,47 +456,37 @@ static pjsip_uri *create_uri18(pj_pool_t *pool)
static pjsip_uri *create_dummy(pj_pool_t *pool)
{
- PJ_UNUSED_ARG(pool)
+ PJ_UNUSED_ARG(pool);
return NULL;
}
/*****************************************************************************/
-static void pool_error(pj_pool_t *pool, pj_size_t sz)
-{
- PJ_UNUSED_ARG(pool)
- PJ_UNUSED_ARG(sz)
-
- pj_assert(0);
- exit(1);
-}
-
/*
* Test one test entry.
*/
-static pj_status_t test_entry(struct uri_test *entry)
+static pj_status_t do_uri_test(pj_pool_t *pool, struct uri_test *entry)
{
pj_status_t status;
- pj_pool_t *pool;
int len;
pjsip_uri *parsed_uri, *ref_uri;
pj_str_t s1 = {NULL, 0}, s2 = {NULL, 0};
- pj_hr_timestamp t1, t2;
+ pj_timestamp t1, t2;
- pool = (*cp.factory.create_pool)( &cp.factory, "", POOL_SIZE, 0, &pool_error);
+ entry->len = pj_native_strlen(entry->str);
/* Parse URI text. */
- pj_hr_gettimestamp(&t1);
+ pj_get_timestamp(&t1);
parse_len += entry->len;
parsed_uri = pjsip_parse_uri(pool, entry->str, entry->len, 0);
if (!parsed_uri) {
/* Parsing failed. If the entry says that this is expected, then
* return OK.
*/
- status = entry->status==ERR_SYNTAX_ERR ? PJ_SUCCESS : ERR_SYNTAX_ERR;
+ status = entry->status==ERR_SYNTAX_ERR ? PJ_SUCCESS : -10;
goto on_return;
}
- pj_hr_gettimestamp(&t2);
+ pj_get_timestamp(&t2);
parse_time += t2.u32.lo - t1.u32.lo;
/* Create the reference URI. */
@@ -526,32 +496,32 @@ static pj_status_t test_entry(struct uri_test *entry)
s1.ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
s2.ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
- pj_hr_gettimestamp(&t1);
+ pj_get_timestamp(&t1);
len = pjsip_uri_print( PJSIP_URI_IN_OTHER, parsed_uri, s1.ptr, PJSIP_MAX_URL_SIZE);
if (len < 1) {
- status = -1;
+ status = -20;
goto on_return;
}
s1.slen = len;
len = pjsip_uri_print( PJSIP_URI_IN_OTHER, ref_uri, s2.ptr, PJSIP_MAX_URL_SIZE);
if (len < 1) {
- status = -1;
+ status = -30;
goto on_return;
}
s2.slen = len;
- pj_hr_gettimestamp(&t2);
+ pj_get_timestamp(&t2);
print_time += t2.u32.lo - t1.u32.lo;
/* Full comparison of parsed URI with reference URI. */
if (pjsip_uri_cmp(PJSIP_URI_IN_OTHER, parsed_uri, ref_uri) != 0) {
/* Not equal. See if this is the expected status. */
- status = entry->status==ERR_NOT_EQUAL ? PJ_SUCCESS : ERR_NOT_EQUAL;
+ status = entry->status==ERR_NOT_EQUAL ? PJ_SUCCESS : -40;
goto on_return;
} else {
/* Equal. See if this is the expected status. */
- status = entry->status==PJ_SUCCESS ? PJ_SUCCESS : -1;
+ status = entry->status==PJ_SUCCESS ? PJ_SUCCESS : -50;
if (status != PJ_SUCCESS) {
goto on_return;
}
@@ -560,101 +530,31 @@ static pj_status_t test_entry(struct uri_test *entry)
/* Compare text. */
if (pj_strcmp(&s1, &s2) != 0) {
/* Not equal. */
- status = ERR_NOT_EQUAL;
+ status = -60;
}
on_return:
- if (!SILENT) {
- printf("%.2d %s (expected status=%s)\n"
- " str=%s\n"
- " uri=%.*s\n"
- " ref=%.*s\n\n",
- entry-uri_test_array,
- STATUS_STR(status),
- STATUS_STR(entry->status),
- entry->str,
- (int)s1.slen, s1.ptr, (int)s2.slen, s2.ptr);
- }
-
- pj_pool_release(pool);
return status;
}
-static void warm_up(pj_pool_factory *pf)
+pj_status_t uri_test()
{
+ unsigned i;
pj_pool_t *pool;
- struct uri_test *entry;
-
- pool = pj_pool_create(pf, "", POOL_SIZE, 0, &pool_error);
- pjsip_parse_uri(pool, "sip:host", 8, 0);
- entry = &uri_test_array[0];
- while (entry->creator) {
- entry->len = strlen(entry->str);
- ++entry;
- }
- pj_pool_release(pool);
-}
-
-//#if !IS_PROFILING
-#if 1
-pj_status_t test_uri()
-{
- struct uri_test *entry;
- int i=0, err=0;
pj_status_t status;
- pj_hr_timestamp t1, t2;
- pj_uint32_t total_time;
-
- pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
- warm_up(&cp.factory);
-
- pj_hr_gettimestamp(&t1);
- for (i=0; i<LOOP; ++i) {
- entry = &uri_test_array[0];
- while (entry->creator) {
- status = test_entry(entry);
- if (status != PJ_SUCCESS) {
- ++err;
- }
- ++entry;
- }
- }
- pj_hr_gettimestamp(&t2);
- total_time = t2.u32.lo - t1.u32.lo;
-
- printf("Error=%d\n", err);
- printf("Total parse len: %u bytes\n", parse_len);
- printf("Total parse time: %u (%f/char), print time: %u (%f/char)\n",
- parse_time, parse_time*1.0/parse_len,
- print_time, print_time*1.0/parse_len);
- printf("Total time: %u (%f/char)\n", total_time, total_time*1.0/parse_len);
- return err;
-}
-
-#else
-
-pj_status_t test_uri()
-{
- struct uri_test *entry;
- unsigned i;
-
- warm_up();
- pj_caching_pool_init(&cp, 1024*1024);
- for (i=0; i<LOOP; ++i) {
- entry = &uri_test_array[0];
- while (entry->creator) {
- pj_pool_t *pool;
- pjsip_uri *uri1, *uri2;
+ pool = pjsip_endpt_create_pool(endpt, "", 4000, 4000);
- pool = pj_pool_create( &cp.factory, "", POOL_SIZE, 0, &pool_error);
- uri1 = pjsip_parse_uri(pool, entry->str, strlen(entry->str));
- pj_pool_release(pool);
- ++entry;
+ for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) {
+ status = do_uri_test(pool, &uri_test_array[i]);
+ if (status != PJ_SUCCESS) {
+ PJ_LOG(3,("uri_test", " error %d when testing entry %d",
+ status, i));
+ break;
}
}
- return 0;
+ pjsip_endpt_destroy_pool(endpt, pool);
+ return status;
}
-#endif