summaryrefslogtreecommitdiff
path: root/pjnath/src/pjnath-test/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'pjnath/src/pjnath-test/test.c')
-rw-r--r--pjnath/src/pjnath-test/test.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/pjnath/src/pjnath-test/test.c b/pjnath/src/pjnath-test/test.c
index 312c1ea2..2abc1696 100644
--- a/pjnath/src/pjnath-test/test.c
+++ b/pjnath/src/pjnath-test/test.c
@@ -29,6 +29,109 @@ void app_perror(const char *msg, pj_status_t rc)
PJ_LOG(1,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
}
+pj_status_t create_stun_config(pj_pool_t *pool, pj_stun_config *stun_cfg)
+{
+ pj_ioqueue_t *ioqueue;
+ pj_timer_heap_t *timer_heap;
+ pj_status_t status;
+
+ status = pj_ioqueue_create(pool, 64, &ioqueue);
+ if (status != PJ_SUCCESS) {
+ app_perror(" pj_ioqueue_create()", status);
+ return status;
+ }
+
+ status = pj_timer_heap_create(pool, 256, &timer_heap);
+ if (status != PJ_SUCCESS) {
+ app_perror(" pj_timer_heap_create()", status);
+ pj_ioqueue_destroy(ioqueue);
+ return status;
+ }
+
+ pj_stun_config_init(stun_cfg, mem, 0, ioqueue, timer_heap);
+
+ return PJ_SUCCESS;
+}
+
+void destroy_stun_config(pj_stun_config *stun_cfg)
+{
+ if (stun_cfg->timer_heap) {
+ pj_timer_heap_destroy(stun_cfg->timer_heap);
+ stun_cfg->timer_heap = NULL;
+ }
+ if (stun_cfg->ioqueue) {
+ pj_ioqueue_destroy(stun_cfg->ioqueue);
+ stun_cfg->ioqueue = NULL;
+ }
+}
+
+void poll_events(pj_stun_config *stun_cfg, unsigned msec,
+ pj_bool_t first_event_only)
+{
+ pj_time_val stop_time;
+ int count = 0;
+
+ pj_gettimeofday(&stop_time);
+ stop_time.msec += msec;
+ pj_time_val_normalize(&stop_time);
+
+ /* Process all events for the specified duration. */
+ for (;;) {
+ pj_time_val timeout = {0, 1}, now;
+ int c;
+
+ c = pj_timer_heap_poll( stun_cfg->timer_heap, NULL );
+ if (c > 0)
+ count += c;
+
+ //timeout.sec = timeout.msec = 0;
+ c = pj_ioqueue_poll( stun_cfg->ioqueue, &timeout);
+ if (c > 0)
+ count += c;
+
+ pj_gettimeofday(&now);
+ if (PJ_TIME_VAL_GTE(now, stop_time))
+ break;
+
+ if (first_event_only && count >= 0)
+ break;
+ }
+}
+
+void capture_pjlib_state(pj_stun_config *cfg, struct pjlib_state *st)
+{
+ pj_caching_pool *cp;
+
+ st->timer_cnt = pj_timer_heap_count(cfg->timer_heap);
+
+ cp = (pj_caching_pool*)mem;
+ st->pool_used_cnt = cp->used_count;
+}
+
+int check_pjlib_state(pj_stun_config *cfg,
+ const struct pjlib_state *initial_st)
+{
+ struct pjlib_state current_state;
+ int rc = 0;
+
+ capture_pjlib_state(cfg, &current_state);
+
+ if (current_state.timer_cnt > initial_st->timer_cnt) {
+ PJ_LOG(3,("", " error: possibly leaking timer"));
+ rc |= ERR_TIMER_LEAK;
+ }
+
+ if (current_state.pool_used_cnt > initial_st->pool_used_cnt) {
+ PJ_LOG(3,("", " error: possibly leaking memory"));
+ PJ_LOG(3,("", " dumping memory pool:"));
+ pj_pool_factory_dump(mem, PJ_TRUE);
+ rc |= ERR_MEMORY_LEAK;
+ }
+
+ return rc;
+}
+
+
#define DO_TEST(test) do { \
PJ_LOG(3, ("test", "Running %s...", #test)); \
rc = test; \
@@ -64,6 +167,7 @@ static int test_inner(void)
pj_dump_config();
pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
+ pjlib_util_init();
pjnath_init();
#if INCLUDE_STUN_TEST
@@ -75,6 +179,14 @@ static int test_inner(void)
DO_TEST(ice_test());
#endif
+#if INCLUDE_STUN_SOCK_TEST
+ DO_TEST(stun_sock_test());
+#endif
+
+#if INCLUDE_TURN_SOCK_TEST
+ DO_TEST(turn_sock_test());
+#endif
+
on_return:
return rc;
}