28 #define epicsAssertAuthor "Jeff Hill johill@lanl.gov" 51 typedef void tf (
ti *pItems,
unsigned iterations,
unsigned *pInlineIter );
56 static void test_pend(
65 for (i=0; i<iterations; i++) {
93 static void test_search (
102 for ( i = 0u; i < iterations; i++ ) {
116 static void test_sync_search(
119 unsigned *pInlineIter
125 for (i=0u; i<iterations; i++) {
139 static void test_free(
142 unsigned *pInlineIter
148 for (i=0u; i<iterations; i++) {
160 static void test_put(
163 unsigned *pInlineIter
170 for (pi=pItems; pi < &pItems[iterations]; pi++) {
252 static void test_get(
255 unsigned *pInlineIter
261 for (pi=pItems; pi<&pItems[iterations]; pi++) {
332 static void test_wait (
335 unsigned *pInlineIter
341 for (pi=pItems; pi<&pItems[iterations]; pi++) {
358 static void measure_get_latency (
ti *pItems,
unsigned iterations)
365 double max = DBL_MIN;
366 double min = DBL_MAX;
372 for ( pi = pItems; pi < &pItems[iterations]; pi++ ) {
397 stdDev = sqrt ( XX/iterations - mean*mean );
401 "std dev = %3.1f uS, " 404 mean * 1e6, stdDev * 1e6,
405 min * 1e6, max * 1e6 );
411 static void printSearchStat (
const ti * pi,
unsigned iterations )
416 double max = DBL_MIN;
417 double min = DBL_MAX;
421 for ( i = 0; i < iterations; i++ ) {
433 mean = X / iterations;
434 stdDev = sqrt( XX / iterations - mean * mean );
436 "Search tries per chan - " 441 mean, stdDev, min, max);
448 unsigned nBytesSent,
unsigned nBytesRecv )
456 (*pfunc) ( pItems, iterations, &inlineIter );
460 double freq = ( iterations * inlineIter ) / delay;
461 printf (
"Per Op, %8.4f uS ( %8.4f MHz )",
462 1e6 / freq, freq / 1e6 );
463 if ( pItems !=
NULL ) {
464 printf(
", %8.4f snd Mbps, %8.4f rcv Mbps\n",
465 (inlineIter*nBytesSent*CHAR_BIT)/(delay*1e6),
466 (inlineIter*nBytesRecv*CHAR_BIT)/(delay*1e6) );
477 static void test (
ti *pItems,
unsigned iterations )
479 unsigned payloadSize, dblPayloadSize;
480 unsigned nBytesSent, nBytesRecv;
489 if ( payloadSize > dblPayloadSize ) {
490 unsigned factor = payloadSize / dblPayloadSize;
492 if ( iterations > 10 * factor ) {
493 iterations /= factor;
500 printf (
"\t### async put test ###\n");
503 timeIt ( test_put, pItems, iterations,
504 nBytesSent * iterations,
505 nBytesRecv * iterations );
507 printf (
"\t### async get test ###\n");
508 nBytesSent =
sizeof (
caHdr );
510 timeIt ( test_get, pItems, iterations,
511 nBytesSent * ( iterations ),
512 nBytesRecv * ( iterations ) );
514 printf (
"\t### synch get test ###\n");
515 nBytesSent =
sizeof (
caHdr );
517 if ( iterations > 100 ) {
520 else if ( iterations > 10 ) {
523 timeIt ( test_wait, pItems, iterations,
524 nBytesSent * iterations,
525 nBytesRecv * iterations );
537 unsigned nBytesSent, nBytesRecv;
540 if ( channelCount == 0 ) {
541 printf (
"channel count was zero\n" );
545 pItemList = calloc ( channelCount,
sizeof (
ti) );
551 "Unable to initialize" );
554 printf (
"Testing with %u channels named %snnn\n",
555 channelCount, channelName );
558 printf (
"Testing with %u channels named %s\n",
559 channelCount, channelName );
562 strsize =
sizeof ( pItemList[0].
name ) - 1;
565 for ( i=0; i < channelCount; i++ ) {
567 sprintf ( pItemList[i].
name,
"%.*s%.6u",
568 (
int) (strsize - 15u), channelName, i );
571 strncpy ( pItemList[i].
name, channelName, strsize);
573 pItemList[
i].
name[strsize]=
'\0';
578 nBytesRecv += 2 *
sizeof (
caHdr);
581 printf (
"Channel Connect Test\n" );
582 printf (
"--------------------\n" );
583 timeIt ( test_search, pItemList, channelCount, nBytesSent, nBytesRecv );
584 printSearchStat ( pItemList, channelCount );
586 for ( i = 0; i < channelCount; i++ ) {
590 pItemList[
i].
pValue = malloc ( size );
595 "channel name=%s, native type=%d, native count=%u\n",
598 pItemList[0].
count );
600 printf (
"Pend Event Test\n");
601 printf (
"----------------\n" );
604 for ( i = 0; i < channelCount; i++ ) {
608 for ( j = 0; j < pItemList[
i].
count; j++ ) {
613 printf (
"DBR_FLOAT Test\n" );
614 printf (
"--------------\n" );
615 test ( pItemList, channelCount );
617 for ( i = 0; i < channelCount; i++ ) {
621 for ( j = 0; j < pItemList[
i].
count; j++ ) {
626 printf (
"DBR_DOUBLE Test\n" );
627 printf (
"---------------\n" );
628 test ( pItemList, channelCount );
631 for ( i = 0; i < channelCount; i++ ) {
635 for ( j = 0; j < pItemList[
i].
count; j++ ) {
636 sprintf ( pStrVal[j],
"%f", val );
640 printf (
"DBR_STRING Test\n" );
641 printf (
"---------------\n" );
642 test ( pItemList, channelCount );
644 for ( i = 0; i < channelCount; i++ ) {
648 for ( j = 0; j < pItemList[
i].
count; j++ ) {
653 printf (
"DBR_INT Test\n" );
654 printf (
"------------\n" );
655 test ( pItemList, channelCount );
657 printf (
"Get Latency Test\n" );
658 printf (
"----------------\n" );
659 for ( i = 0; i < channelCount; i++ ) {
661 for ( j = 0; j < pItemList[
i].
count; j++ ) {
666 measure_get_latency ( pItemList, channelCount );
668 printf (
"Free Channel Test\n" );
669 printf (
"-----------------\n" );
670 timeIt ( test_free, pItemList, channelCount, 0, 0 );
674 for ( i = 0; i < channelCount; i++ ) {
675 free ( pItemList[i].
pValue );
int epicsStdCall ca_task_exit()
const unsigned short dbr_size[LAST_BUFFER_TYPE+1]
#define assert(exp)
Declare that a condition should be true.
An EPICS-specific replacement for ANSI C's assert.
LIBCA_API unsigned long epicsStdCall ca_element_count(chid chan)
int epicsStdCall ca_pend_io(ca_real timeout)
int catime(const char *channelName, unsigned channelCount, enum appendNumberFlag appNF)
LIBCA_API short epicsStdCall ca_field_type(chid chan)
void timeIt(tf *pfunc, ti *pItems, unsigned iterations, unsigned nBytesSent, unsigned nBytesRecv)
int epicsStdCall ca_context_create(ca_preemptive_callback_select premptiveCallbackSelect)
int epicsStdCall ca_pend_event(ca_real timeout)
#define CA_MESSAGE_ALIGN(A)
LIBCA_API int epicsStdCall ca_array_put(chtype type, unsigned long count, chid chanId, const void *pValue)
int epicsStdCall ca_flush_io()
#define SEVCHK(CA_ERROR_CODE, MESSAGE_STRING)
int epicsStdCall epicsTimeGetCurrent(epicsTimeStamp *pDest)
Get current time into *pDest.
LIBCA_API int epicsStdCall ca_array_get(chtype type, unsigned long count, chid chanId, void *pValue)
epicsFloat64 dbr_double_t
LIBCA_API const char *epicsStdCall ca_name(chid chan)
void tf(ti *pItems, unsigned iterations, unsigned *pInlineIter)
epicsOldString dbr_string_t
int epicsStdCall ca_clear_channel(chid pChan)
#define ca_search(pChanName, pChanID)
EPICS time stamp, for use from C code.
#define dbr_size_n(TYPE, COUNT)
LIBCOM_API double epicsStdCall epicsTimeDiffInSeconds(const epicsTimeStamp *pLeft, const epicsTimeStamp *pRight)
Time difference between left and right in seconds.
EPICS time-stamps (epicsTimeStamp), epicsTime C++ class and C functions for handling wall-clock times...
LIBCA_API unsigned epicsStdCall ca_search_attempts(chid chan)