ioc/db/test: extend dbCaLinkTest to check CAC get operation
This commit is contained in:
@@ -90,10 +90,11 @@ TESTFILES += ../dbCaStatsTest.db
|
||||
|
||||
TESTPROD_HOST += dbCaLinkTest
|
||||
dbCaLinkTest_SRCS += dbCaLinkTest.c
|
||||
dbCaLinkTest_SRCS += dbCACTest.cpp
|
||||
dbCaLinkTest_SRCS += dbTestIoc_registerRecordDeviceDriver.cpp
|
||||
testHarness_SRCS += dbCaLinkTest.c
|
||||
TESTS += dbCaLinkTest
|
||||
TESTFILES += ../dbCaLinkTest1.db
|
||||
TESTFILES += ../dbCaLinkTest1.db ../dbCaLinkTest2.db ../dbCaLinkTest3.db
|
||||
|
||||
scanIoTest_DBD += menuScan.dbd
|
||||
TESTPROD_HOST += scanIoTest
|
||||
|
||||
82
src/ioc/db/test/dbCACTest.cpp
Normal file
82
src/ioc/db/test/dbCACTest.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*************************************************************************\
|
||||
* Copyright (c) 2015 Brookhaven Science Assoc. as operator of Brookhaven
|
||||
* National Laboratory.
|
||||
* EPICS BASE is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
/*
|
||||
* Part of dbCaLinkTest, compiled seperately to avoid
|
||||
* dbAccess.h vs. db_access.h conflicts
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <epicsEvent.h>
|
||||
|
||||
#include "epicsUnitTest.h"
|
||||
|
||||
#include "cadef.h"
|
||||
|
||||
#define testECA(OP) if((OP)!=ECA_NORMAL) {testAbort("%s", #OP);} else {testPass("%s", #OP);}
|
||||
|
||||
void putgetarray(chid chanid, double first, size_t count)
|
||||
{
|
||||
testDiag("putgetarray(%f,%u)", first, (unsigned)count);
|
||||
|
||||
std::vector<double> buf(count);
|
||||
for(size_t i=0; i<count ;i++)
|
||||
buf[i] = first + i*1.0;
|
||||
|
||||
testDiag("Put");
|
||||
|
||||
testECA(ca_array_put(DBR_DOUBLE, count, chanid, &buf[0]));
|
||||
|
||||
testECA(ca_pend_io(1.0));
|
||||
|
||||
testDiag("Get");
|
||||
|
||||
std::vector<double> buf2(count);
|
||||
|
||||
testECA(ca_array_get(DBR_DOUBLE, count, chanid, &buf2[0]));
|
||||
|
||||
testECA(ca_pend_io(1.0));
|
||||
|
||||
for(size_t i=0; i<count ;i++)
|
||||
testOk(buf[i]==buf2[i], "%f == %f", buf[i], buf2[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct CATestContext
|
||||
{
|
||||
CATestContext()
|
||||
{
|
||||
if(ca_context_create(ca_enable_preemptive_callback)!=ECA_NORMAL)
|
||||
throw std::runtime_error("Failed to create CA context");
|
||||
}
|
||||
~CATestContext()
|
||||
{
|
||||
ca_context_destroy();
|
||||
}
|
||||
};
|
||||
|
||||
extern "C"
|
||||
void dbCaLinkTest_testCAC(void)
|
||||
{
|
||||
try {
|
||||
CATestContext ctxt;
|
||||
chid chanid = 0;
|
||||
testECA(ca_create_channel("target1", NULL, NULL, 0, &chanid));
|
||||
testECA(ca_pend_io(1.0));
|
||||
putgetarray(chanid, 1.0, 1);
|
||||
putgetarray(chanid, 2.0, 2);
|
||||
putgetarray(chanid, 5.0, 5);
|
||||
|
||||
testECA(ca_clear_channel(chanid));
|
||||
}catch(std::exception& e){
|
||||
testAbort("Unexpected exception in testCAC: %s", e.what());
|
||||
}
|
||||
}
|
||||
@@ -538,9 +538,52 @@ static void testreTargetTypeChange(void)
|
||||
free(buftarg2);
|
||||
}
|
||||
|
||||
void dbCaLinkTest_testCAC(void);
|
||||
|
||||
static void testCAC(void)
|
||||
{
|
||||
arrRecord *psrc, *ptarg1, *ptarg2;
|
||||
double *bufsrc, *buftarg1;
|
||||
epicsInt32 *buftarg2;
|
||||
|
||||
testDiag("Check local CA through libca");
|
||||
testdbPrepare();
|
||||
|
||||
testdbReadDatabase("dbTestIoc.dbd", NULL, NULL);
|
||||
|
||||
dbTestIoc_registerRecordDeviceDriver(pdbbase);
|
||||
|
||||
testdbReadDatabase("dbCaLinkTest3.db", NULL, "NELM=5,TARGET=target1 CP");
|
||||
|
||||
psrc = (arrRecord*)testdbRecordPtr("source");
|
||||
ptarg1= (arrRecord*)testdbRecordPtr("target1");
|
||||
ptarg2= (arrRecord*)testdbRecordPtr("target2");
|
||||
|
||||
eltc(0);
|
||||
testIocInitOk();
|
||||
eltc(1);
|
||||
|
||||
bufsrc = psrc->bptr;
|
||||
buftarg1= ptarg1->bptr;
|
||||
buftarg2= ptarg2->bptr;
|
||||
|
||||
dbCaLinkTest_testCAC();
|
||||
|
||||
testIocShutdownOk();
|
||||
|
||||
testdbCleanup();
|
||||
|
||||
/* records don't cleanup after themselves
|
||||
* so do here to silence valgrind
|
||||
*/
|
||||
free(bufsrc);
|
||||
free(buftarg1);
|
||||
free(buftarg2);
|
||||
}
|
||||
|
||||
MAIN(dbCaLinkTest)
|
||||
{
|
||||
testPlan(62);
|
||||
testPlan(85);
|
||||
testNativeLink();
|
||||
testStringLink();
|
||||
testCP();
|
||||
@@ -549,5 +592,6 @@ MAIN(dbCaLinkTest)
|
||||
testArrayLink(1,10);
|
||||
testArrayLink(10,10);
|
||||
testreTargetTypeChange();
|
||||
testCAC();
|
||||
return testDone();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user