Changeset 1090:8be95f757b08 in freeDiameter
- Timestamp:
- May 6, 2013, 11:29:31 AM (11 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/testmesg_stress.c
r1088 r1090 37 37 38 38 /* The number of times each operation is repeated to measure the average operation time */ 39 #define NUMBER_OF_SAMPLES 100000 39 #define DEFAULT_NUMBER_OF_SAMPLES 100000 40 41 static void display_result(int nr, struct timespec * start, struct timespec * end, char * fct, char * type, char *op) 42 { 43 long double dur = (long double)end->tv_sec + (long double)end->tv_nsec/1000000000; 44 dur -= (long double)start->tv_sec + (long double)start->tv_nsec/1000000000; 45 long double thrp = (long double)nr / dur; 46 printf("%-19s: %d %-8s %-7s in %.6LFs (%.1LFmsg/s)\n", fct, nr, type, op, dur, thrp); 47 } 48 49 40 50 41 51 /* Main test routine */ … … 45 55 struct avp * pi = NULL, *avp1, *avp2; 46 56 unsigned char * buf = NULL; 57 58 test_parameter = DEFAULT_NUMBER_OF_SAMPLES; 47 59 48 60 /* First, initialize the daemon modules */ … … 371 383 /* Test the throughput of the different functions function */ 372 384 { 373 void ** stress_array; 385 struct stress_struct { 386 struct msg * m; 387 uint8_t * b; 388 } * stress_array; 374 389 int i; 375 390 struct timespec start, end; … … 385 400 386 401 /* Create the copies of the message buffer */ 387 stress_array = calloc( NUMBER_OF_SAMPLES, sizeof(void *));402 stress_array = calloc(test_parameter, sizeof(struct stress_struct)); 388 403 CHECK( stress_array ? 1 : 0, 1); 389 404 390 for (i=0; i < NUMBER_OF_SAMPLES; i++) {405 for (i=0; i < test_parameter; i++) { 391 406 CPYBUF(); 392 stress_array[i] = buf_cpy; 393 } 407 stress_array[i].b = buf_cpy; 408 } 409 410 /* fd_msg_parse_buffer */ 394 411 395 412 CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) ); 396 413 397 414 /* Test the msg_parse_buffer function */ 398 for (i=0; i < NUMBER_OF_SAMPLES; i++) { 399 CHECK( 0, fd_msg_parse_buffer( (uint8_t **)&stress_array[i], 344, &msg) ); 400 stress_array[i] = msg; 401 } 402 403 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 404 405 { 406 long us = (end.tv_sec - start.tv_sec) * 1000000; 407 us += (end.tv_nsec - start.tv_nsec) / 1000; 408 long double thrp = (NUMBER_OF_SAMPLES * (long double)1000000) / us; 409 printf("fd_msg_bufferize : %d buffers parsed in %ldus (%.2LFmsg/s)\n", NUMBER_OF_SAMPLES, us, thrp); 410 } 411 412 415 for (i=0; i < test_parameter; i++) { 416 CHECK( 0, fd_msg_parse_buffer( &stress_array[i].b, 344, &stress_array[i].m) ); 417 } 418 419 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 420 display_result(test_parameter, &start, &end, "fd_msg_parse_buffer", "buffers", "parsed"); 421 422 /* fd_msg_parse_dict */ 413 423 414 424 CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) ); 415 425 416 426 /* Test the fd_msg_parse_dict function */ 417 for (i=0; i < NUMBER_OF_SAMPLES; i++) { 418 CHECK( 0, fd_msg_parse_dict( stress_array[i], fd_g_config->cnf_dict, NULL ) ); 419 } 420 421 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 422 423 { 424 long us = (end.tv_sec - start.tv_sec) * 1000000; 425 us += (end.tv_nsec - start.tv_nsec) / 1000; 426 long double thrp = (NUMBER_OF_SAMPLES * (long double)1000000) / us; 427 printf("fd_msg_parse_dict : %d messages parsed in %ldus (%.2LFmsg/s)\n", NUMBER_OF_SAMPLES, us, thrp); 428 } 429 430 427 for (i=0; i < test_parameter; i++) { 428 CHECK( 0, fd_msg_parse_dict( stress_array[i].m, fd_g_config->cnf_dict, NULL ) ); 429 } 430 431 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 432 display_result(test_parameter, &start, &end, "fd_msg_parse_dict", "messages", "parsed"); 433 434 435 /* fd_msg_parse_rules */ 431 436 432 437 CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) ); 433 438 434 439 /* Test the fd_msg_parse_rules function */ 435 for (i=0; i < NUMBER_OF_SAMPLES; i++) { 436 CHECK( 0, fd_msg_parse_rules( stress_array[i], fd_g_config->cnf_dict, NULL ) ); 437 } 438 439 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 440 441 { 442 long us = (end.tv_sec - start.tv_sec) * 1000000; 443 us += (end.tv_nsec - start.tv_nsec) / 1000; 444 long double thrp = (NUMBER_OF_SAMPLES * (long double)1000000) / us; 445 printf("fd_msg_parse_rules: %d messages parsed in %ldus (%.2LFmsg/s)\n", NUMBER_OF_SAMPLES, us, thrp); 446 } 447 448 440 for (i=0; i < test_parameter; i++) { 441 CHECK( 0, fd_msg_parse_rules( stress_array[i].m, fd_g_config->cnf_dict, NULL ) ); 442 } 443 444 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 445 display_result(test_parameter, &start, &end, "fd_msg_parse_rules", "messages", "parsed"); 446 447 448 /* fd_msg_new_answer_from_req (0) */ 449 450 CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) ); 451 452 /* Test the fd_msg_new_answer_from_req function */ 453 for (i=0; i < test_parameter; i++) { 454 CHECK( 0, fd_msg_new_answer_from_req( fd_g_config->cnf_dict, &stress_array[i].m, 0 ) ); 455 } 456 457 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 458 display_result(test_parameter, &start, &end, "new_answer(normal)", "messages", "created"); 459 460 /* unlink answers and go back to request messages */ 461 for (i=0; i < test_parameter; i++) { 462 struct msg * ans = stress_array[i].m; 463 CHECK( 0, fd_msg_answ_getq( ans, &stress_array[i].m ) ); 464 CHECK( 0, fd_msg_answ_detach( ans ) ); 465 fd_msg_free( ans ); 466 } 467 468 469 /* fd_msg_new_answer_from_req (MSGFL_ANSW_ERROR) */ 470 471 CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) ); 472 473 /* Test the fd_msg_new_answer_from_req function */ 474 for (i=0; i < test_parameter; i++) { 475 CHECK( 0, fd_msg_new_answer_from_req( fd_g_config->cnf_dict, &stress_array[i].m, MSGFL_ANSW_ERROR ) ); 476 } 477 478 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 479 display_result(test_parameter, &start, &end, "new_answer(error)", "messages", "created"); 480 481 /* unlink answers and go back to request messages */ 482 for (i=0; i < test_parameter; i++) { 483 struct msg * ans = stress_array[i].m; 484 CHECK( 0, fd_msg_answ_getq( ans, &stress_array[i].m ) ); 485 CHECK( 0, fd_msg_answ_detach( ans ) ); 486 fd_msg_free( ans ); 487 } 488 489 490 /* fd_msg_bufferize */ 491 492 493 CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) ); 494 495 /* Test the fd_msg_bufferize function */ 496 for (i=0; i < test_parameter; i++) { 497 size_t len = 0; 498 CHECK( 0, fd_msg_bufferize( stress_array[i].m, &stress_array[i].b, &len ) ); 499 } 500 501 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 502 display_result(test_parameter, &start, &end, "fd_msg_bufferize", "buffers", "created"); 503 504 505 /* fd_msg_free */ 449 506 450 507 CHECK( 0, clock_gettime(CLOCK_REALTIME, &start) ); 451 508 452 509 /* Free those messages */ 453 for (i=0; i < NUMBER_OF_SAMPLES; i++) { 454 fd_msg_free( stress_array[i]); 455 stress_array[i] = NULL; 456 } 457 458 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 459 460 { 461 long us = (end.tv_sec - start.tv_sec) * 1000000; 462 us += (end.tv_nsec - start.tv_nsec) / 1000; 463 long double thrp = (NUMBER_OF_SAMPLES * (long double)1000000) / us; 464 printf("fd_msg_free : %d messages freed in %ldus (%.2LFmsg/s)\n", NUMBER_OF_SAMPLES, us, thrp); 465 } 466 510 for (i=0; i < test_parameter; i++) { 511 fd_msg_free( stress_array[i].m ); 512 } 513 514 CHECK( 0, clock_gettime(CLOCK_REALTIME, &end) ); 515 display_result(test_parameter, &start, &end, "fd_msg_free", "messages", "freed"); 516 517 518 for (i=0; i < test_parameter; i++) { 519 free(stress_array[i].b); 520 } 467 521 free(stress_array); 468 522 } -
tests/tests.h
r1088 r1090 141 141 static int gnutls_debug = 0; 142 142 143 static int test_parameter = 0; 143 144 144 145 static inline void parse_cmdline(int argc, char * argv[]) { 145 146 int c; 146 147 int no_timeout = 0; 147 while ((c = getopt (argc, argv, "dqnf:F:g: ")) != -1) {148 while ((c = getopt (argc, argv, "dqnf:F:g:p:")) != -1) { 148 149 switch (c) { 149 150 case 'd': /* Increase verbosity of debug messages. */ … … 177 178 case 'g': /* Set a debug level and function for GNU TLS calls. */ 178 179 gnutls_debug = (int)atoi(optarg); 180 break; 181 182 case 'p': /* Set a debug level and function for GNU TLS calls. */ 183 test_parameter = (int)atoi(optarg); 179 184 break; 180 185
Note: See TracChangeset
for help on using the changeset viewer.