0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <math.h>
0039
0040 #include <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045 #include <nstopwatch.h>
0046 #include <fcntl.h>
0047 #include <unistd.h>
0048
0049 #include <nstdutil.h>
0050
0051
0052 #define _BENCHONLY
0053
0054 #define SYNC_FILE "sync.log"
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 int do_sync (void)
0065 {
0066 while (EXFAIL == access( SYNC_FILE, F_OK ) )
0067 {
0068
0069 usleep(10000);
0070 }
0071
0072 return EXSUCCEED;
0073 }
0074
0075
0076
0077
0078 int main(int argc, char** argv) {
0079
0080 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 156000);
0081 long rsplen;
0082 int i, j;
0083 int ret=EXSUCCEED;
0084 double d;
0085 double cps;
0086 double dv = 55.66;
0087 char bench_mode[16]=":0:1:8:";
0088 char buf[1024];
0089 char test_buf_carray[56*1024];
0090 char test_buf_small[1024];
0091 ndrx_stopwatch_t timer;
0092 int call_num = MAX_ASYNC_CALLS *10;
0093 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
0094 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0095 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0096
0097
0098 if (argc>1 && (argv[1][0]=='s' || argv[1][0]=='S'))
0099 {
0100 printf("syncing...\n");
0101 do_sync();
0102 }
0103
0104
0105 printf("syncing ok...\n");
0106 fflush(stdout);
0107
0108 if (argc>2)
0109 {
0110 strcpy(bench_mode, argv[2]);
0111 }
0112
0113
0114 printf("test mode [%s]\n", bench_mode);
0115 fflush(stdout);
0116
0117 for (i=0; i<50; i++)
0118 {
0119 char tmp[128];
0120 snprintf(tmp, sizeof(tmp), "HELLO FROM CLIENT %d abc", i);
0121 if (EXFAIL==CBchg(p_ub, T_CARRAY_FLD, i, tmp, 0, BFLD_STRING))
0122 {
0123 NDRX_LOG(log_debug, "Failed to get T_CARRAY_FLD[%d]", i);
0124 ret=EXFAIL;
0125 goto out;
0126 }
0127 }
0128
0129 tplogprintubf(log_error, "Carray buffer", p_ub);
0130
0131 if (strstr(bench_mode, ":0:"))
0132 {
0133 for (i=0; i<50; i++)
0134 {
0135 d=i;
0136 if (EXFAIL==Bchg(p_ub, T_DOUBLE_FLD, i, (char *)&d, 0))
0137 {
0138 NDRX_LOG(log_debug, "Failed to get T_DOUBLE_FLD[%d]", i);
0139 ret=EXFAIL;
0140 goto out;
0141 }
0142
0143 if (EXFAIL == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0144 {
0145 NDRX_LOG(log_error, "TESTSV failed: %s", tpstrerror(tperrno));
0146 ret=EXFAIL;
0147 goto out;
0148 }
0149
0150
0151 if (EXFAIL==Bget(p_ub, T_DOUBLE_FLD, i, (char *)&d, 0))
0152 {
0153 NDRX_LOG(log_debug, "Failed to get T_DOUBLE_FLD[%d]", i);
0154 ret=EXFAIL;
0155 goto out;
0156 }
0157
0158 if (fabs(i - d) > 0.00001)
0159 {
0160 NDRX_LOG(log_debug, "%lf!=%lf => FAIL", dv, d);
0161 ret=EXFAIL;
0162 goto out;
0163 }
0164
0165
0166 Bfprint(p_ub, stderr);
0167 }
0168
0169 NDRX_LOG(log_debug, "Do second call to timeout-server");
0170 if (EXFAIL == tpcall("TIMEOUTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0171 {
0172 NDRX_LOG(log_error, "TIMEOUTSV failed: %s", tpstrerror(tperrno));
0173 if (TPETIME!=tperrno)
0174 {
0175 NDRX_LOG(log_debug, "No timeout err from TIMEOUTSV!!!");
0176 ret=EXFAIL;
0177 goto out;
0178 }
0179 }
0180 else
0181 {
0182 NDRX_LOG(log_debug, "No timeout from TIMEOUTSV!!!");
0183 ret=EXFAIL;
0184 goto out;
0185 }
0186
0187
0188 NDRX_LOG(log_debug, "Do third call to timeout-server, TPNOTIME");
0189 if (EXFAIL == tpcall("TIMEOUTSV", (char *)p_ub, 0L, (char **)&p_ub,
0190 &rsplen, TPNOTIME))
0191 {
0192 NDRX_LOG(log_error, "TESTSV failed: %s", tpstrerror(tperrno));
0193 ret=EXFAIL;
0194 goto out;
0195 }
0196
0197
0198 if (EXFAIL == tpcall("SOFTTOUT", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0199 {
0200 NDRX_LOG(log_error, "SOFTTOUT failed: %s", tpstrerror(tperrno));
0201 if (TPETIME!=tperrno)
0202 {
0203 NDRX_LOG(log_debug, "No timeout err from SOFTTOUT!!!");
0204 ret=EXFAIL;
0205 goto out;
0206 }
0207 }
0208 else
0209 {
0210 NDRX_LOG(log_debug, "No timeout from SOFTTOUT!!!");
0211 ret=EXFAIL;
0212 goto out;
0213 }
0214
0215
0216
0217
0218 if (EXFAIL==tpcall("NULLSV", NULL, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0219 {
0220 NDRX_LOG(log_error, "TESTERROR: NULLSV failed: %s", tpstrerror(tperrno));
0221 ret=EXFAIL;
0222 goto out;
0223 }
0224
0225
0226
0227 p_ub = (UBFH *)tpalloc("UBF", NULL, 156000);
0228
0229 if (NULL==p_ub)
0230 {
0231 NDRX_LOG(log_error, "TESTERROR: Failed to alloc ubf: %s",
0232 tpstrerror(tperrno));
0233 EXFAIL_OUT(ret);
0234 }
0235
0236 for (i=0; i<MAX_ASYNC_CALLS+2000; i++)
0237 {
0238
0239
0240
0241 if (EXFAIL==tpcall("RETSOMEDATA", NULL, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0242 {
0243 NDRX_LOG(log_error, "TESTERROR: RETSOMEDATA failed: %s",
0244 tpstrerror(tperrno));
0245 ret=EXFAIL;
0246 goto out;
0247 }
0248
0249 if (EXFAIL==Bget(p_ub, T_STRING_2_FLD, 0, buf, NULL))
0250 {
0251 NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_2_FLD: %s",
0252 Bstrerror(Berror));
0253 ret=EXFAIL;
0254 goto out;
0255 }
0256 }
0257
0258 if (0!=strcmp(buf, "RESPONSE DATA 1"))
0259 {
0260 NDRX_LOG(log_error, "TESTERROR: Invalid response data in "
0261 "T_STRING_2_FLD, got [%s]", buf);
0262 ret=EXFAIL;
0263 goto out;
0264 }
0265 }
0266
0267
0268 if (strstr(bench_mode, ":1:"))
0269 {
0270
0271
0272 if (EXSUCCEED!=Bchg(p_ub, T_CARRAY_FLD, 0, test_buf_small, sizeof(test_buf_small)))
0273 {
0274 NDRX_LOG(log_error, "TESTERROR: Failed to set T_CARRAY_FLD: %s",
0275 Bstrerror(Berror));
0276 ret=EXFAIL;
0277 goto out;
0278 }
0279
0280 ndrx_stopwatch_reset(&timer);
0281
0282
0283 for (i=0; i<call_num; i++)
0284 {
0285
0286
0287
0288 if (EXFAIL==tpcall("ECHO", (char *)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0289 {
0290 NDRX_LOG(log_error, "TESTERROR: ECHO failed: %s", tpstrerror(tperrno));
0291 ret=EXFAIL;
0292 goto out;
0293 }
0294 }
0295
0296 d = (double)(sizeof(test_buf_small)*(call_num))/((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0297
0298 cps = (double)(call_num)/((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0299
0300 printf("1KB Performance: %d bytes in %ld (sec) = %lf bytes/sec = %lf bytes/MB sec, "
0301 "calls/sec = %lf\n",
0302 (int)(sizeof(test_buf_small)*(call_num)),
0303 (long)ndrx_stopwatch_get_delta_sec(&timer),
0304 d,
0305 (d/1024)/1024,
0306 cps);
0307 fflush(stdout);
0308 }
0309
0310
0311
0312 if (strstr(bench_mode, ":8:"))
0313 {
0314
0315 tplogprintubf(log_error, "Buffer before 8K test", p_ub);
0316
0317 if (EXSUCCEED!=Bchg(p_ub, T_CARRAY_FLD, 0, test_buf_carray, 1024*8))
0318 {
0319 NDRX_LOG(log_error, "TESTERROR: Failed to set T_CARRAY_FLD: %s",
0320 Bstrerror(Berror));
0321 ret=EXFAIL;
0322 goto out;
0323 }
0324
0325 ndrx_stopwatch_reset(&timer);
0326
0327
0328 for (i=0; i<call_num; i++)
0329 {
0330
0331
0332
0333 if (EXFAIL==tpcall("ECHO", (char *)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0334 {
0335 NDRX_LOG(log_error, "TESTERROR: ECHO failed: %s", tpstrerror(tperrno));
0336 ret=EXFAIL;
0337 goto out;
0338 }
0339 }
0340
0341 d = (double)(sizeof(test_buf_carray)*(call_num))/((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0342
0343 cps = (double)(call_num)/((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0344
0345 printf("8KB Performance: %d bytes in %ld (sec) = %lf bytes/sec = %lf bytes/MB sec, calls/sec = %lf\n",
0346 (int)(sizeof(test_buf_carray)*(call_num)),
0347 (long)ndrx_stopwatch_get_delta_sec(&timer),
0348 d,
0349 (d/1024)/1024,
0350 cps);
0351 fflush(stdout);
0352 }
0353
0354
0355
0356 if (strstr(bench_mode, ":B:"))
0357 {
0358 int bench_call_num;
0359 int first = EXTRUE;
0360
0361
0362 for (j=0; j<56; j=(j==0?1:j+4))
0363 {
0364 int callsz = j*1024;
0365 if (0==j)
0366 {
0367 callsz = 1;
0368 }
0369
0370
0371
0372
0373 if (EXSUCCEED!=Bchg(p_ub, T_CARRAY_FLD, 0, test_buf_carray, callsz))
0374 {
0375 NDRX_LOG(log_error, "TESTERROR: Failed to set T_CARRAY_FLD to %d: %s",
0376 callsz, Bstrerror(Berror));
0377 ret=EXFAIL;
0378 goto out;
0379 }
0380
0381 if (j<10)
0382 {
0383 bench_call_num = call_num*2;
0384 }
0385 else
0386 {
0387 bench_call_num = call_num;
0388 }
0389
0390 B_warmed_up:
0391 ndrx_stopwatch_reset(&timer);
0392
0393
0394 for (i=0; i<bench_call_num; i++)
0395 {
0396
0397
0398
0399 if (EXFAIL==tpcall("ECHO", (char *)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0400 {
0401 NDRX_LOG(log_error, "TESTERROR: ECHO failed: %s", tpstrerror(tperrno));
0402 ret=EXFAIL;
0403 goto out;
0404 }
0405 }
0406
0407
0408 if (first)
0409 {
0410 first = EXFALSE;
0411 goto B_warmed_up;
0412 }
0413
0414 d = (double)(sizeof(test_buf_carray)*(bench_call_num))/(double)((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0415
0416 cps = (double)(bench_call_num)/((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0417
0418 printf("%dKB Performance: %d bytes in %ld (sec) = %lf bytes/sec = %lf bytes/MB sec, calls/sec = %lf\n",
0419 callsz,
0420 (int)(sizeof(test_buf_carray)*(call_num)),
0421 (long)ndrx_stopwatch_get_delta_sec(&timer),
0422 d,
0423 (d/1024)/1024,
0424 cps);
0425
0426 fflush(stdout);
0427
0428 if (EXSUCCEED!=ndrx_bench_write_stats((double)j, cps))
0429 {
0430 NDRX_LOG(log_always, "Failed to write stats!");
0431 EXFAIL_OUT(ret);
0432 }
0433 }
0434 }
0435
0436
0437 if (strstr(bench_mode, ":b:"))
0438 {
0439 int bench_call_num;
0440 int first = EXTRUE;
0441 for (j=0; j<56; j=(j==0?1:j+4))
0442 {
0443 int callsz = j*1024;
0444 if (0==j)
0445 {
0446 callsz = 1;
0447 }
0448
0449
0450
0451 if (EXSUCCEED!=Bchg(p_ub, T_CARRAY_FLD, 0, test_buf_carray, callsz))
0452 {
0453 NDRX_LOG(log_error, "TESTERROR: Failed to set T_CARRAY_FLD to %d", callsz);
0454 ret=EXFAIL;
0455 goto out;
0456 }
0457
0458 if (j<20)
0459 {
0460 bench_call_num = call_num*5;
0461 }
0462 else
0463 {
0464 bench_call_num = call_num;
0465 }
0466
0467
0468 b_warmed_up:
0469 ndrx_stopwatch_reset(&timer);
0470
0471 for (i=0; i<bench_call_num; i++)
0472 {
0473
0474
0475
0476 if (EXFAIL==tpacall("ECHO", (char *)p_ub, 0L, TPNOTIME|TPNOREPLY))
0477 {
0478 NDRX_LOG(log_error, "TESTERROR: ECHO failed: %s", tpstrerror(tperrno));
0479 ret=EXFAIL;
0480 goto out;
0481 }
0482 }
0483
0484
0485 if (EXFAIL==tpcall("ECHO", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,
0486 TPNOTIME))
0487 {
0488 NDRX_LOG(log_error, "TESTERROR: ECHO failed: %s", tpstrerror(tperrno));
0489 ret=EXFAIL;
0490 goto out;
0491 }
0492
0493
0494 if (first)
0495 {
0496 first = EXFALSE;
0497 goto b_warmed_up;
0498 }
0499
0500
0501 d = (double)(sizeof(test_buf_carray)*(bench_call_num))/(double)((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0502
0503 cps = (double)(bench_call_num)/((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0504
0505 printf("%dKB Performance: %d bytes in %ld (sec) = %lf bytes/sec = %lf bytes/MB sec, calls/sec = %lf\n",
0506 callsz,
0507 (int)(sizeof(test_buf_carray)*(call_num)),
0508 (long)ndrx_stopwatch_get_delta_sec(&timer),
0509 d,
0510 (d/1024)/1024,
0511 cps);
0512
0513 fflush(stdout);
0514
0515 if (EXSUCCEED!=ndrx_bench_write_stats((double)j, cps))
0516 {
0517 NDRX_LOG(log_always, "Failed to write stats!");
0518 EXFAIL_OUT(ret);
0519 }
0520 }
0521 }
0522
0523 out:
0524 tpterm();
0525
0526 if (argc>1 && argv[1][0]=='S')
0527 {
0528 printf("Test finished waiting for kill..");
0529 fflush(stdout);
0530 sleep(9999999);
0531 }
0532 fprintf(stderr, "Exit with %d\n", ret);
0533
0534 return ret;
0535 }
0536
0537