Changeset 563 for pjproject/trunk/pjsip/src/test-pjsip/test.c
- Timestamp:
- Jun 28, 2006 4:46:49 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/test-pjsip/test.c
r555 r563 34 34 } while (0) 35 35 36 #define DO_TSX_TEST(test, param) \ 37 do { \ 38 PJ_LOG(3, (THIS_FILE, "Running %s(%s)...", #test, (param)->tp_type)); \ 39 rc = test(param); \ 40 PJ_LOG(3, (THIS_FILE, \ 41 "%s(%d)", \ 42 (rc ? "..ERROR" : "..success"), rc)); \ 43 if (rc!=0) goto on_return; \ 44 } while (0) 36 45 37 46 38 47 pjsip_endpoint *endpt; 39 48 int log_level = 3; 49 50 static pj_oshandle_t fd_report; 51 const char *system_name = "Unknown"; 52 static char buf[1024]; 40 53 41 54 void app_perror(const char *msg, pj_status_t rc) … … 76 89 } 77 90 91 static pj_status_t init_report(void) 92 { 93 char tmp[80]; 94 pj_time_val timestamp; 95 pj_parsed_time date_time; 96 pj_ssize_t len; 97 pj_status_t status; 98 99 pj_ansi_sprintf(tmp, "pjsip-static-bench-%s-%s.htm", PJ_OS_NAME, PJ_CC_NAME); 100 101 status = pj_file_open(NULL, tmp, PJ_O_WRONLY, &fd_report); 102 if (status != PJ_SUCCESS) 103 return status; 104 105 /* Title */ 106 len = pj_ansi_sprintf(buf, "<HTML>\n" 107 " <HEAD>\n" 108 " <TITLE>PJSIP %s (%s) - Static Benchmark</TITLE>\n" 109 " </HEAD>\n" 110 "<BODY>\n" 111 "\n", 112 PJ_VERSION, 113 (PJ_DEBUG ? "Debug" : "Release")); 114 pj_file_write(fd_report, buf, &len); 115 116 117 /* Title */ 118 len = pj_ansi_sprintf(buf, "<H1>PJSIP %s (%s) - Static Benchmark</H1>\n", 119 PJ_VERSION, 120 (PJ_DEBUG ? "Debug" : "Release")); 121 pj_file_write(fd_report, buf, &len); 122 123 len = pj_ansi_sprintf(buf, "<P>Below is the benchmark result generated " 124 "by <b>test-pjsip</b> program. The program " 125 "is single-threaded only.</P>\n"); 126 pj_file_write(fd_report, buf, &len); 127 128 129 /* Write table heading */ 130 len = pj_ansi_sprintf(buf, "<TABLE border=\"1\" cellpadding=\"4\">\n" 131 " <TR><TD bgColor=\"aqua\" align=\"center\">Variable</TD>\n" 132 " <TD bgColor=\"aqua\" align=\"center\">Value</TD>\n" 133 " <TD bgColor=\"aqua\" align=\"center\">Description</TD>\n" 134 " </TR>\n"); 135 pj_file_write(fd_report, buf, &len); 136 137 138 /* Write version */ 139 report_sval("version", PJ_VERSION, "", "PJLIB/PJSIP version"); 140 141 142 /* Debug or release */ 143 report_sval("build-type", (PJ_DEBUG ? "Debug" : "Release"), "", "Build type"); 144 145 146 /* Write timestamp */ 147 pj_gettimeofday(×tamp); 148 report_ival("timestamp", timestamp.sec, "", "System timestamp of the test"); 149 150 151 /* Write time of day */ 152 pj_time_decode(×tamp, &date_time); 153 len = pj_ansi_sprintf(tmp, "%04d-%02d-%02d %02d:%02d:%02d", 154 date_time.year, date_time.mon+1, date_time.day, 155 date_time.hour, date_time.min, date_time.sec); 156 report_sval("date-time", tmp, "", "Date/time of the test"); 157 158 159 /* Write System */ 160 report_sval("system", system_name, "", "System description"); 161 162 163 /* Write OS type */ 164 report_sval("os-family", PJ_OS_NAME, "", "Operating system family"); 165 166 167 /* Write CC name */ 168 len = pj_ansi_sprintf(tmp, "%s-%d.%d.%d", PJ_CC_NAME, 169 PJ_CC_VER_1, PJ_CC_VER_2, PJ_CC_VER_2); 170 report_sval("cc-name", tmp, "", "Compiler name and version"); 171 172 173 return PJ_SUCCESS; 174 } 175 176 void report_sval(const char *name, const char* value, const char *valname, 177 const char *desc) 178 { 179 pj_ssize_t len; 180 181 len = pj_ansi_sprintf(buf, " <TR><TD><TT>%s</TT></TD>\n" 182 " <TD align=\"right\"><B>%s %s</B></TD>\n" 183 " <TD>%s</TD>\n" 184 " </TR>\n", 185 name, value, valname, desc); 186 pj_file_write(fd_report, buf, &len); 187 } 188 189 190 void report_ival(const char *name, int value, const char *valname, 191 const char *desc) 192 { 193 pj_ssize_t len; 194 195 len = pj_ansi_sprintf(buf, " <TR><TD><TT>%s</TT></TD>\n" 196 " <TD align=\"right\"><B>%d %s</B></TD>\n" 197 " <TD>%s</TD>\n" 198 " </TR>\n", 199 name, value, valname, desc); 200 pj_file_write(fd_report, buf, &len); 201 202 } 203 204 static void close_report(void) 205 { 206 pj_ssize_t len; 207 208 if (fd_report) { 209 len = pj_ansi_sprintf(buf, "</TABLE>\n</BODY>\n</HTML>\n"); 210 pj_file_write(fd_report, buf, &len); 211 212 pj_file_close(fd_report); 213 } 214 } 215 216 78 217 int test_main(void) 79 218 { … … 81 220 pj_caching_pool caching_pool; 82 221 const char *filename; 222 unsigned i, tsx_test_cnt=0; 223 struct tsx_test_param tsx_test[10]; 224 pj_status_t status; 225 pjsip_transport *tp; 226 pjsip_tpfactory *tpfactory; 83 227 int line; 84 228 … … 93 237 return rc; 94 238 } 239 240 status = init_report(); 241 if (status != PJ_SUCCESS) 242 return status; 95 243 96 244 pj_dump_config(); … … 125 273 goto on_return; 126 274 } 275 tsx_test[tsx_test_cnt].port = 5060; 276 tsx_test[tsx_test_cnt].tp_type = "loop-dgram"; 277 tsx_test[tsx_test_cnt].type = PJSIP_TRANSPORT_LOOP_DGRAM; 278 ++tsx_test_cnt; 279 127 280 128 281 #if INCLUDE_URI_TEST … … 139 292 #endif 140 293 294 #if INCLUDE_TSX_BENCH 295 DO_TEST(tsx_bench()); 296 #endif 297 141 298 #if INCLUDE_UDP_TEST 142 299 DO_TEST(transport_udp_test()); … … 147 304 #endif 148 305 306 #if INCLUDE_TCP_TEST 307 DO_TEST(transport_tcp_test()); 308 #endif 309 310 149 311 #if INCLUDE_TSX_TEST 150 DO_TEST(tsx_basic_test()); 151 DO_TEST(tsx_uac_test()); 152 DO_TEST(tsx_uas_test()); 312 status = pjsip_udp_transport_start(endpt, NULL, NULL, 1, &tp); 313 if (status == PJ_SUCCESS) { 314 tsx_test[tsx_test_cnt].port = tp->local_name.port; 315 tsx_test[tsx_test_cnt].tp_type = "udp"; 316 tsx_test[tsx_test_cnt].type = PJSIP_TRANSPORT_UDP; 317 ++tsx_test_cnt; 318 } 319 320 status = pjsip_tcp_transport_start(endpt, NULL, 1, &tpfactory); 321 if (status == PJ_SUCCESS) { 322 tsx_test[tsx_test_cnt].port = tpfactory->addr_name.port; 323 tsx_test[tsx_test_cnt].tp_type = "tcp"; 324 tsx_test[tsx_test_cnt].type = PJSIP_TRANSPORT_TCP; 325 ++tsx_test_cnt; 326 } else { 327 app_perror("Unable to create TCP", status); 328 rc = -4; 329 goto on_return; 330 } 331 332 333 for (i=0; i<tsx_test_cnt; ++i) { 334 DO_TSX_TEST(tsx_basic_test, &tsx_test[i]); 335 DO_TSX_TEST(tsx_uac_test, &tsx_test[i]); 336 DO_TSX_TEST(tsx_uas_test, &tsx_test[i]); 337 } 153 338 #endif 154 339 155 340 156 341 on_return: 157 342 flush_events(500); 158 343 pjsip_endpt_destroy(endpt); 159 344 pj_caching_pool_destroy(&caching_pool); … … 170 355 PJ_LOG(3,(THIS_FILE, "Test completed with error(s)")); 171 356 357 report_ival("test-status", rc, "", "Overall test status/result (0==success)"); 358 close_report(); 172 359 return rc; 173 360 }
Note: See TracChangeset
for help on using the changeset viewer.