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 <unistd.h> /* Symbolic Constants */
0041 #include <sys/types.h> /* Primitive System Data Types */
0042 #include <errno.h> /* Errors */
0043 #include <stdio.h> /* Input/Output */
0044 #include <stdlib.h> /* General Utilities */
0045 #include <pthread.h> /* POSIX Threads */
0046
0047 #include <atmi.h>
0048 #include <ubf.h>
0049 #include <ndebug.h>
0050 #include <test.fd.h>
0051 #include <ndrstandard.h>
0052 #include <nstopwatch.h>
0053 #include <nstdutil.h>
0054
0055
0056
0057
0058 #define TEST_MIN 1
0059 #define TEST_MAX 56
0060 #define TEST_STEP 4
0061
0062
0063
0064
0065
0066
0067
0068 double M_test_array[5][TEST_MAX];
0069
0070
0071
0072
0073 void do_thread_work ( void *ptr )
0074 {
0075
0076 UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 9216);
0077 long rsplen;
0078 int i, j;
0079 int ret=EXSUCCEED;
0080 double d;
0081 double cps;
0082 double dv = 55.66;
0083 char buf[1024];
0084 char test_buf_carray[68192];
0085 char test_buf_small[1024];
0086 ndrx_stopwatch_t timer;
0087 int call_num = MAX_ASYNC_CALLS *8;
0088 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
0089 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0090 Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0091
0092
0093
0094
0095
0096 if (NULL!=ptr)
0097 {
0098 int first = EXTRUE;
0099
0100 for (j=TEST_MIN; j<TEST_MAX; j+=TEST_STEP)
0101 {
0102 int callsz = j*1024;
0103 p_ub = (UBFH *)tprealloc ((char *)p_ub, callsz+500);
0104
0105 if (EXSUCCEED!=Bchg(p_ub, T_CARRAY_FLD, 0, test_buf_carray, callsz))
0106 {
0107 NDRX_LOG(log_error, "TESTERROR: Failed to set T_CARRAY_FLD to %d", callsz);
0108 ret=EXFAIL;
0109 goto out;
0110 }
0111
0112 warmed_up:
0113 ndrx_stopwatch_reset(&timer);
0114
0115
0116 for (i=0; i<call_num; i++)
0117 {
0118
0119
0120
0121 if (EXFAIL==tpcall("ECHO", (char *)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0122 {
0123 NDRX_LOG(log_error, "TESTERROR: ECHO failed: %s", tpstrerror(tperrno));
0124 ret=EXFAIL;
0125 goto out;
0126 }
0127 }
0128
0129 if (first)
0130 {
0131 first = EXFALSE;
0132 goto warmed_up;
0133 }
0134
0135 d = (double)(sizeof(test_buf_carray)*(call_num))/(double)((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0136
0137 cps = (double)(call_num)/((double)ndrx_stopwatch_get_delta(&timer)/1000.0f);
0138
0139 printf("%dKB Performance: %d bytes in %ld (sec) = %lf bytes/sec = %lf bytes/MB sec, calls/sec = %lf\n",
0140 callsz,
0141 (int)(sizeof(test_buf_carray)*(call_num)),
0142 (long)ndrx_stopwatch_get_delta_sec(&timer),
0143 d,
0144 (d/1024)/1024,
0145 cps);
0146
0147 fflush(stdout);
0148
0149
0150
0151
0152
0153
0154
0155 M_test_array[(long)ptr][j] = cps;
0156 }
0157
0158 return;
0159 }
0160
0161
0162
0163
0164 for (i=0; i<50; i++)
0165 {
0166
0167
0168
0169 if (EXFAIL == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0170 {
0171 NDRX_LOG(log_error, "TESTERROR: TESTSV failed: %s", tpstrerror(tperrno));
0172 ret=EXFAIL;
0173 goto out;
0174 }
0175
0176
0177 if (EXFAIL==Bget(p_ub, T_DOUBLE_FLD, i, (char *)&d, 0))
0178 {
0179 NDRX_LOG(log_debug, "TESTERROR: Failed to get T_DOUBLE_FLD[%d]", i);
0180 ret=EXFAIL;
0181 goto out;
0182 }
0183
0184 if (fabs(dv - d) > 0.00001)
0185 {
0186 NDRX_LOG(log_debug, "%lf!=%lf => FAIL", dv, d);
0187 ret=EXFAIL;
0188 goto out;
0189 }
0190
0191
0192
0193
0194 }
0195
0196 NDRX_LOG(log_debug, "Do second call to timeout-server");
0197 if (EXFAIL == tpcall("TIMEOUTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0198 {
0199 NDRX_LOG(log_error, "TIMEOUTSV failed: %s", tpstrerror(tperrno));
0200 if (TPETIME!=tperrno)
0201 {
0202 NDRX_LOG(log_debug, "TESTERROR: No timeout err from TIMEOUTSV!!!");
0203 ret=EXFAIL;
0204 goto out;
0205 }
0206 }
0207 else
0208 {
0209 NDRX_LOG(log_debug, "TESTERROR: No timeout from TIMEOUTSV!!!");
0210 ret=EXFAIL;
0211 goto out;
0212 }
0213
0214
0215 NDRX_LOG(log_debug, "Do third call to timeout-server, TPNOTIME");
0216 if (EXFAIL == tpcall("TIMEOUTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0217 {
0218 NDRX_LOG(log_error, "TESTERROR: TESTSV failed: %s", tpstrerror(tperrno));
0219 ret=EXFAIL;
0220 goto out;
0221 }
0222
0223
0224
0225
0226 if (EXFAIL==tpcall("NULLSV", NULL, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0227 {
0228 NDRX_LOG(log_error, "TESTERROR: NULLSV failed: %s", tpstrerror(tperrno));
0229 ret=EXFAIL;
0230 goto out;
0231 }
0232
0233
0234
0235 p_ub = (UBFH *)tpalloc("UBF", NULL, 156000);
0236
0237 if (NULL==p_ub)
0238 {
0239 NDRX_LOG(log_error, "TESTERROR: Failed to alloc ubf: %s",
0240 tpstrerror(tperrno));
0241 EXFAIL_OUT(ret);
0242 }
0243
0244 for (i=0; i<MAX_ASYNC_CALLS+2000; i++)
0245 {
0246
0247
0248
0249 if (EXFAIL==tpcall("RETSOMEDATA", NULL, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0250 {
0251 NDRX_LOG(log_error, "TESTERROR: RETSOMEDATA failed: %s", tpstrerror(tperrno));
0252 ret=EXFAIL;
0253 goto out;
0254 }
0255
0256 if (EXFAIL==Bget(p_ub, T_STRING_2_FLD, 0, buf, NULL))
0257 {
0258 NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_2_FLD: %s", Bstrerror(Berror));
0259 ret=EXFAIL;
0260 goto out;
0261 }
0262 }
0263
0264 if (0!=strcmp(buf, "RESPONSE DATA 1"))
0265 {
0266 NDRX_LOG(log_error, "TESTERROR: Invalid response data in T_STRING_2_FLD, got [%s]", buf);
0267 ret=EXFAIL;
0268 goto out;
0269 }
0270
0271
0272 p_ub = (UBFH *)tprealloc ((char *)p_ub, 1128);
0273
0274 if (EXSUCCEED!=Bchg(p_ub, T_CARRAY_FLD, 0, test_buf_small, sizeof(test_buf_small)))
0275 {
0276 NDRX_LOG(log_error, "TESTERROR: Failed to set T_CARRAY_FLD");
0277 ret=EXFAIL;
0278 goto out;
0279 }
0280
0281 ndrx_stopwatch_reset(&timer);
0282
0283
0284 for (i=0; i<call_num; i++)
0285 {
0286
0287
0288
0289 if (EXFAIL==tpcall("ECHO", (char *)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0290 {
0291 NDRX_LOG(log_error, "TESTERROR: ECHO failed: %s", tpstrerror(tperrno));
0292 ret=EXFAIL;
0293 goto out;
0294 }
0295 }
0296
0297 d = (double)(sizeof(test_buf_small)*(call_num))/(double)ndrx_stopwatch_get_delta_sec(&timer);
0298
0299 cps = (double)(call_num)/(double)ndrx_stopwatch_get_delta_sec(&timer);
0300
0301 printf("1KB Performance: %d bytes in %ld (sec) = %lf bytes/sec = %lf bytes/MB sec, 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
0308
0309
0310
0311 p_ub = (UBFH *)tprealloc ((char *)p_ub, 9216);
0312
0313 if (EXSUCCEED!=Bchg(p_ub, T_CARRAY_FLD, 0, test_buf_carray, sizeof(test_buf_carray)))
0314 {
0315 NDRX_LOG(log_error, "TESTERROR: Failed to set T_CARRAY_FLD");
0316 ret=EXFAIL;
0317 goto out;
0318 }
0319
0320 ndrx_stopwatch_reset(&timer);
0321
0322
0323 for (i=0; i<call_num; i++)
0324 {
0325
0326
0327
0328 if (EXFAIL==tpcall("ECHO", (char *)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0329 {
0330 NDRX_LOG(log_error, "TESTERROR: ECHO failed: %s", tpstrerror(tperrno));
0331 ret=EXFAIL;
0332 goto out;
0333 }
0334 }
0335
0336 d = (double)(sizeof(test_buf_carray)*(call_num))/(double)ndrx_stopwatch_get_delta_sec(&timer);
0337
0338 cps = (double)(call_num)/(double)ndrx_stopwatch_get_delta_sec(&timer);
0339
0340 printf("8KB Performance: %d bytes in %ld (sec) = %lf bytes/sec = %lf bytes/MB sec, calls/sec = %lf\n",
0341 (int)(sizeof(test_buf_carray)*(call_num)),
0342 (long)ndrx_stopwatch_get_delta_sec(&timer),
0343 d,
0344 (d/1024)/1024,
0345 cps);
0346 out:
0347 tpterm();
0348
0349 }
0350
0351
0352
0353
0354
0355 int main(int argc, char** argv)
0356 {
0357 int j;
0358 pthread_t thread1, thread2, thread3, thread4, thread5;
0359 void *arg1 = NULL;
0360 void *arg2 = NULL;
0361 void *arg3 = NULL;
0362 void *arg4 = NULL;
0363 void *arg5 = NULL;
0364 pthread_attr_t pthread_custom_attr;
0365 pthread_attr_init(&pthread_custom_attr);
0366
0367 memset(M_test_array, 0, sizeof(M_test_array));
0368
0369 if (argc>1)
0370 {
0371 arg1 = (void *)0;
0372 arg2 = (void *)1;
0373 arg3 = (void *)2;
0374 arg4 = (void *)3;
0375 arg5 = (void *)4;
0376 }
0377
0378 ndrx_platf_stack_set(&pthread_custom_attr);
0379
0380
0381 pthread_create (&thread1, &pthread_custom_attr, (void *) &do_thread_work, arg1);
0382 pthread_create (&thread2, &pthread_custom_attr, (void *) &do_thread_work, arg2);
0383
0384 pthread_create (&thread3, &pthread_custom_attr, (void *) &do_thread_work, arg3);
0385 pthread_create (&thread4, &pthread_custom_attr, (void *) &do_thread_work, arg4);
0386 pthread_create (&thread5, &pthread_custom_attr, (void *) &do_thread_work, arg5);
0387
0388
0389
0390
0391 pthread_join(thread1, NULL);
0392 pthread_join(thread2, NULL);
0393 pthread_join(thread3, NULL);
0394 pthread_join(thread4, NULL);
0395 pthread_join(thread5, NULL);
0396
0397
0398 if (argc>1)
0399 {
0400 double sum;
0401 int i;
0402
0403 for (j=TEST_MIN; j<TEST_MAX; j+=TEST_STEP)
0404 {
0405 sum=0;
0406 for (i=0; i<5; i++)
0407 {
0408 sum+=M_test_array[i][j];
0409 }
0410 if (EXSUCCEED!=ndrx_bench_write_stats((double)j, sum))
0411 {
0412 NDRX_LOG(log_always, "Failed to write stats!");
0413 exit(EXFAIL);
0414 }
0415 }
0416 }
0417
0418 exit(0);
0419 }
0420
0421