Changeset 1988 for pjproject/trunk/pjnath/src/pjnath-test/test.c
- Timestamp:
- Jun 6, 2008 2:47:10 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath-test/test.c
r1877 r1988 30 30 } 31 31 32 pj_status_t create_stun_config(pj_pool_t *pool, pj_stun_config *stun_cfg) 33 { 34 pj_ioqueue_t *ioqueue; 35 pj_timer_heap_t *timer_heap; 36 pj_status_t status; 37 38 status = pj_ioqueue_create(pool, 64, &ioqueue); 39 if (status != PJ_SUCCESS) { 40 app_perror(" pj_ioqueue_create()", status); 41 return status; 42 } 43 44 status = pj_timer_heap_create(pool, 256, &timer_heap); 45 if (status != PJ_SUCCESS) { 46 app_perror(" pj_timer_heap_create()", status); 47 pj_ioqueue_destroy(ioqueue); 48 return status; 49 } 50 51 pj_stun_config_init(stun_cfg, mem, 0, ioqueue, timer_heap); 52 53 return PJ_SUCCESS; 54 } 55 56 void destroy_stun_config(pj_stun_config *stun_cfg) 57 { 58 if (stun_cfg->timer_heap) { 59 pj_timer_heap_destroy(stun_cfg->timer_heap); 60 stun_cfg->timer_heap = NULL; 61 } 62 if (stun_cfg->ioqueue) { 63 pj_ioqueue_destroy(stun_cfg->ioqueue); 64 stun_cfg->ioqueue = NULL; 65 } 66 } 67 68 void poll_events(pj_stun_config *stun_cfg, unsigned msec, 69 pj_bool_t first_event_only) 70 { 71 pj_time_val stop_time; 72 int count = 0; 73 74 pj_gettimeofday(&stop_time); 75 stop_time.msec += msec; 76 pj_time_val_normalize(&stop_time); 77 78 /* Process all events for the specified duration. */ 79 for (;;) { 80 pj_time_val timeout = {0, 1}, now; 81 int c; 82 83 c = pj_timer_heap_poll( stun_cfg->timer_heap, NULL ); 84 if (c > 0) 85 count += c; 86 87 //timeout.sec = timeout.msec = 0; 88 c = pj_ioqueue_poll( stun_cfg->ioqueue, &timeout); 89 if (c > 0) 90 count += c; 91 92 pj_gettimeofday(&now); 93 if (PJ_TIME_VAL_GTE(now, stop_time)) 94 break; 95 96 if (first_event_only && count >= 0) 97 break; 98 } 99 } 100 101 void capture_pjlib_state(pj_stun_config *cfg, struct pjlib_state *st) 102 { 103 pj_caching_pool *cp; 104 105 st->timer_cnt = pj_timer_heap_count(cfg->timer_heap); 106 107 cp = (pj_caching_pool*)mem; 108 st->pool_used_cnt = cp->used_count; 109 } 110 111 int check_pjlib_state(pj_stun_config *cfg, 112 const struct pjlib_state *initial_st) 113 { 114 struct pjlib_state current_state; 115 int rc = 0; 116 117 capture_pjlib_state(cfg, ¤t_state); 118 119 if (current_state.timer_cnt > initial_st->timer_cnt) { 120 PJ_LOG(3,("", " error: possibly leaking timer")); 121 rc |= ERR_TIMER_LEAK; 122 } 123 124 if (current_state.pool_used_cnt > initial_st->pool_used_cnt) { 125 PJ_LOG(3,("", " error: possibly leaking memory")); 126 PJ_LOG(3,("", " dumping memory pool:")); 127 pj_pool_factory_dump(mem, PJ_TRUE); 128 rc |= ERR_MEMORY_LEAK; 129 } 130 131 return rc; 132 } 133 134 32 135 #define DO_TEST(test) do { \ 33 136 PJ_LOG(3, ("test", "Running %s...", #test)); \ … … 65 168 pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 ); 66 169 170 pjlib_util_init(); 67 171 pjnath_init(); 68 172 … … 74 178 #if INCLUDE_ICE_TEST 75 179 DO_TEST(ice_test()); 180 #endif 181 182 #if INCLUDE_STUN_SOCK_TEST 183 DO_TEST(stun_sock_test()); 184 #endif 185 186 #if INCLUDE_TURN_SOCK_TEST 187 DO_TEST(turn_sock_test()); 76 188 #endif 77 189
Note: See TracChangeset
for help on using the changeset viewer.