diff --git a/src/ioc/db/test/Makefile b/src/ioc/db/test/Makefile index c44226b04..2ba82c344 100644 --- a/src/ioc/db/test/Makefile +++ b/src/ioc/db/test/Makefile @@ -10,8 +10,8 @@ TOP=../../../.. include $(TOP)/configure/CONFIG -PROD_vxWorks += dbTestHarness -PROD_RTEMS += dbTestHarness +PROD_vxWorks += dbTestHarness chfPluginTest +PROD_RTEMS += dbTestHarness chfPluginTest PROD_LIBS = dbCore ca Com @@ -20,6 +20,36 @@ callbackTest_SRCS += callbackTest.c dbTestHarness_SRCS += callbackTest.c TESTS += callbackTest +TESTPROD_HOST += dbStateTest +dbStateTest_SRCS += dbStateTest.c +dbTestHarness_SRCS += dbStateTest.c +TESTS += dbStateTest + +TESTPROD_HOST += dbChannelTest +dbChannelTest_SRCS += xRecord.c +dbChannelTest_SRCS += dbChannelTest.c +dbChannelTest_SRCS += dbChannelTest_registerRecordDeviceDriver.cpp +dbTestHarness_SRCS += xRecord.c +dbTestHarness_SRCS += dbChannelTest.c +dbTestHarness_SRCS += dbChannelTest_registerRecordDeviceDriver.cpp +TESTS += dbChannelTest + +TESTPROD_HOST += chfPluginTest +chfPluginTest_SRCS += xRecord.c +chfPluginTest_SRCS += chfPluginTest.c +chfPluginTest_SRCS += chfPluginTest_registerRecordDeviceDriver.cpp +dbTestHarness_SRCS += chfPluginTest.c +dbTestHarness_SRCS += chfPluginTest_registerRecordDeviceDriver.cpp +TESTS += chfPluginTest + +TESTPROD_HOST += arrShorthandTest +arrShorthandTest_SRCS += xRecord.c +arrShorthandTest_SRCS += arrShorthandTest.c +arrShorthandTest_SRCS += arrShorthandTest_registerRecordDeviceDriver.cpp +dbTestHarness_SRCS += arrShorthandTest.c +dbTestHarness_SRCS += arrShorthandTest_registerRecordDeviceDriver.cpp +TESTS += arrShorthandTest + dbTestHarness_SRCS += epicsRunDbTests.c dbTestHarness_SRCS_RTEMS = rtemsTestHarness.c @@ -27,32 +57,9 @@ dbTestHarness_SRCS_RTEMS = rtemsTestHarness.c TESTSPEC_vxWorks = dbTestHarness.munch; epicsRunDbTests TESTSPEC_RTEMS = dbTestHarness.boot; epicsRunDbTests -TESTPROD_HOST += dbChannelTest -dbChannelTest_SRCS += dbChannelTest.c xRecord.c -dbTestHarness_SRCS += dbChannelTest.c -OBJS_IOC_vxWorks += dbChannelTest -TESTS += dbChannelTest - -TESTPROD_HOST += chfPluginTest -chfPluginTest_SRCS += chfPluginTest.c xRecord.c -dbTestHarness_SRCS += chfPluginTest.c -OBJS_IOC_vxWorks += chfPluginTest -TESTS += chfPluginTest - -TESTPROD_HOST += arrShorthandTest -arrShorthandTest_SRCS += arrShorthandTest.c xRecord.c -dbTestHarness_SRCS += arrShorthandTest.c -OBJS_IOC_vxWorks += arrShorthandTest -TESTS += arrShorthandTest - -TESTPROD_HOST += dbStateTest -dbStateTest_SRCS += dbStateTest.c -dbTestHarness_SRCS += dbStateTest.c -OBJS_IOC_vxWorks += dbStateTest -TESTS += dbStateTest - -dbTestHarness_SRCS += xRecord.c - TESTSCRIPTS_HOST += $(TESTS:%=%.t) include $(TOP)/configure/RULES + +# xRecord$(OBJ): $(COMMON_DIR)/xRecord.h +xRecord$(DEP): $(COMMON_DIR)/xRecord.h diff --git a/src/ioc/db/test/arrShorthandTest.c b/src/ioc/db/test/arrShorthandTest.c index 9957ff897..8eecb0dc3 100644 --- a/src/ioc/db/test/arrShorthandTest.c +++ b/src/ioc/db/test/arrShorthandTest.c @@ -24,6 +24,7 @@ #include "registry.h" #include "epicsUnitTest.h" #include "testMain.h" +#include "osiFileName.h" typedef struct myStruct { epicsInt32 start; @@ -76,21 +77,24 @@ static void testHead (char* title) { testDiag("--------------------------------------------------------"); } -int loadTestDB(DBBASE **ppbase); +void arrShorthandTest_registerRecordDeviceDriver(struct dbBase *); MAIN(arrShorthandTest) { dbChannel *pch; - testPlan(28); + testPlan(26); db_init_events(); - testHead("Set up database"); - if(loadTestDB(&pdbbase)) - return testDone(); + if (dbReadDatabase(&pdbbase, "arrShorthandTest.dbd", + "." OSI_PATH_LIST_SEPARATOR "..", NULL)) + testAbort("Database description not loaded"); - testOk(!!pdbbase, "pdbbase was set"); + arrShorthandTest_registerRecordDeviceDriver(pdbbase); + if (dbReadDatabase(&pdbbase, "xRecord.db", + "." OSI_PATH_LIST_SEPARATOR "..", NULL)) + testAbort("Test database not loaded"); testHead("Register plugin"); testOk(!chfPluginRegister("arr", &myPif, opts), "register fake arr plugin"); @@ -125,7 +129,7 @@ MAIN(arrShorthandTest) dbFreeBase(pdbbase); registryFree(); - pdbbase=0; + pdbbase = NULL; return testDone(); } diff --git a/src/ioc/db/test/arrShorthandTest.dbd b/src/ioc/db/test/arrShorthandTest.dbd new file mode 100644 index 000000000..7411d88b5 --- /dev/null +++ b/src/ioc/db/test/arrShorthandTest.dbd @@ -0,0 +1 @@ +include "xRecord.dbd" diff --git a/src/ioc/db/test/chfPluginTest.c b/src/ioc/db/test/chfPluginTest.c index aaffc0b7b..f8b87c81f 100644 --- a/src/ioc/db/test/chfPluginTest.c +++ b/src/ioc/db/test/chfPluginTest.c @@ -18,6 +18,7 @@ #include "registry.h" #include "epicsUnitTest.h" #include "testMain.h" +#include "osiFileName.h" #define PATTERN 0x55555555 #define TYPE_START 0xAAA @@ -470,14 +471,14 @@ static void testHead (char* title) { testDiag("--------------------------------------------------------"); } -int loadTestDB(DBBASE **ppbase); +void chfPluginTest_registerRecordDeviceDriver(struct dbBase *); MAIN(chfPluginTest) { dbChannel *pch; db_field_log *pfl; - testPlan(1353); + testPlan(1351); db_init_events(); @@ -492,10 +493,14 @@ MAIN(chfPluginTest) testOk(strcmp(chfPluginEnumString(colorEnum, 3, "-"), "-") == 0, "Enum to string: invalid index"); - testHead("Set up database"); - if(loadTestDB(&pdbbase)) - return testDone(); - testOk(!!pdbbase, "pdbbase was set"); + if (dbReadDatabase(&pdbbase, "chfPluginTest.dbd", + "." OSI_PATH_LIST_SEPARATOR "..", NULL)) + testAbort("Database description not loaded"); + + chfPluginTest_registerRecordDeviceDriver(pdbbase); + if (dbReadDatabase(&pdbbase, "xRecord.db", + "." OSI_PATH_LIST_SEPARATOR "..", NULL)) + testAbort("Test database not loaded"); testHead("Try to register buggy plugins"); testOk(!!chfPluginRegister("buggy", &myPif, brokenOpts1), @@ -825,7 +830,7 @@ MAIN(chfPluginTest) dbFreeBase(pdbbase); registryFree(); - pdbbase=0; + pdbbase = NULL; return testDone(); } diff --git a/src/ioc/db/test/chfPluginTest.dbd b/src/ioc/db/test/chfPluginTest.dbd new file mode 100644 index 000000000..7411d88b5 --- /dev/null +++ b/src/ioc/db/test/chfPluginTest.dbd @@ -0,0 +1 @@ +include "xRecord.dbd" diff --git a/src/ioc/db/test/dbChannelTest.c b/src/ioc/db/test/dbChannelTest.c index dab486b9d..6a5779f7b 100644 --- a/src/ioc/db/test/dbChannelTest.c +++ b/src/ioc/db/test/dbChannelTest.c @@ -20,6 +20,7 @@ #include "recSup.h" #include "epicsUnitTest.h" #include "testMain.h" +#include "osiFileName.h" /* Expected call bit definitions */ #define e_start 0x00000001 @@ -144,22 +145,26 @@ void c_close(chFilter *filter) } chFilterIf testIf = - { p_start, p_abort, p_end, p_null, p_boolean, p_integer, p_double, + { NULL, p_start, p_abort, p_end, p_null, p_boolean, p_integer, p_double, p_string, p_start_map, p_map_key, p_end_map, p_start_array, p_end_array, c_open, c_reg_pre, c_reg_post, c_report, c_close }; -int loadTestDB(DBBASE **ppbase); +void dbChannelTest_registerRecordDeviceDriver(struct dbBase *); MAIN(testDbChannel) /* dbChannelTest is an API routine... */ { dbChannel *pch; - testPlan(68); + testPlan(66); - if(loadTestDB(&pdbbase)) - return testDone(); + if (dbReadDatabase(&pdbbase, "dbChannelTest.dbd", + "." OSI_PATH_LIST_SEPARATOR "..", NULL)) + testAbort("Database description not loaded"); - testOk(!!pdbbase, "pdbbase was set"); + dbChannelTest_registerRecordDeviceDriver(pdbbase); + if (dbReadDatabase(&pdbbase, "xRecord.db", + "." OSI_PATH_LIST_SEPARATOR "..", NULL)) + testAbort("Test database not loaded"); r = e = 0; /* dbChannelTest() checks record and field names */ @@ -247,7 +252,7 @@ MAIN(testDbChannel) /* dbChannelTest is an API routine... */ dbFreeBase(pdbbase); registryFree(); - pdbbase=0; + pdbbase = NULL; return testDone(); } diff --git a/src/ioc/db/test/dbChannelTest.dbd b/src/ioc/db/test/dbChannelTest.dbd new file mode 100644 index 000000000..7411d88b5 --- /dev/null +++ b/src/ioc/db/test/dbChannelTest.dbd @@ -0,0 +1 @@ +include "xRecord.dbd" diff --git a/src/ioc/db/test/xRecord.c b/src/ioc/db/test/xRecord.c index a8dc1ef0d..568fbb838 100644 --- a/src/ioc/db/test/xRecord.c +++ b/src/ioc/db/test/xRecord.c @@ -1,132 +1,25 @@ - -#include -#include - -#include "epicsTypes.h" -#include "dbBase.h" -#include "devSup.h" -#include "registryCommon.h" -#include "registryRecordType.h" -#include "dbStaticLib.h" - -#include "epicsUnitTest.h" +/*************************************************************************\ +* Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* Copyright (c) 2010 Brookhaven National Laboratory. +* Copyright (c) 2010 Helmholtz-Zentrum Berlin +* fuer Materialien und Energie GmbH. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. + \*************************************************************************/ /* - * Test database initialization + * Author: Andrew Johnson + * Ralph Lange */ -/* No actual record support code is provided */ +#include "dbAccessDefs.h" +#include + +#define GEN_SIZE_OFFSET +#include "xRecord.h" + +#include + static rset xRSET; - -/* the following would normally be found in xRecord.h */ - -typedef struct xRecord { - char name[61]; /* Record Name */ - epicsInt32 val; /* Value */ -} xRecord; - -typedef enum { - xRecordNAME = 0, - xRecordVAL = 1 -} xFieldIndex; - -static int xRecordSizeOffset(dbRecordType *prt) -{ - xRecord *prec = 0; - prt->papFldDes[xRecordNAME]->size = sizeof(prec->name); - prt->papFldDes[xRecordVAL]->size = sizeof(prec->val); - prt->papFldDes[xRecordNAME]->offset = (char *)&prec->name - (char *)prec; - prt->papFldDes[xRecordVAL]->offset = (char *)&prec->val - (char *)prec; - prt->rec_size = sizeof(*prec); - return 0; -} - -/* the following would normally be found in xRecord_registerRecordDeviceDriver.cpp */ - -static const char * const recordTypeNames[] = { - "x" -}; - -static const recordTypeLocation rtl[] = { - {&xRSET, &xRecordSizeOffset} -}; - -/* the following wpuld normally be the contents of xRecord.dbd */ - -static const char xRecord_dbd[] = -"# This is a combined minimal DBD and DB file\n" -"\n" -"recordtype(x) {\n" -" field(NAME, DBF_STRING) {\n" -" prompt(\"Record Name\")\n" -" special(SPC_NOMOD)\n" -" size(61)\n" -" }\n" -" field(VAL, DBF_LONG) {\n" -" prompt(\"Value\")\n" -" }\n" -"}\n"; - -/* the following is a db file which loads a single record instance */ - -static const char recinst_db[] = "record(x, x) {}\n"; - -/* The remainder of this file is specific to the test database initialization */ - -static FILE* makefile(const char* contents) -{ - size_t len=strlen(contents); - FILE *fp=epicsTempFile(); - if(!fp) { - perror("epicsTempFile fails"); - return NULL; - } - - if(fwrite(contents, 1, len, fp)!=len){ - perror("makefile fwrite failed"); - goto fail; - } - - if(fseek(fp, 0, SEEK_SET)!=0) - goto fail; - - return fp; -fail: - fclose(fp); - return NULL; -} - -int loadTestDB(DBBASE **ppbase) -{ - FILE *fp=makefile(xRecord_dbd); - if(!fp) { - testFail("Failed to create temp xRecord.dbd"); - return -1; - } - - if(dbReadDatabaseFP(ppbase, fp, 0, 0)) { - testFail("Failed to load temp xRecord.dbd"); - goto fail; - } - /* fp closed by dbReadDatabaseFP */ - - registerRecordTypes(*ppbase, NELEMENTS(rtl), recordTypeNames, rtl); - - fp=makefile(recinst_db); - if(!fp) { - testFail("Failed to create temp xinst.db"); - return -1; - } - - if(dbReadDatabaseFP(ppbase, fp, 0, 0)) { - testFail("Failed to load temp xinst.db"); - goto fail; - } - /* fp closed by dbReadDatabaseFP */ - - testPass("Loaded test database"); - return 0; -fail: - fclose(fp); - return -1; -} +epicsExportAddress(rset,xRSET); diff --git a/src/ioc/db/test/xRecord.db b/src/ioc/db/test/xRecord.db new file mode 100644 index 000000000..a6fa08e40 --- /dev/null +++ b/src/ioc/db/test/xRecord.db @@ -0,0 +1,2 @@ +record(x, x) {} + diff --git a/src/ioc/db/test/xRecord.dbd b/src/ioc/db/test/xRecord.dbd new file mode 100644 index 000000000..4837871a4 --- /dev/null +++ b/src/ioc/db/test/xRecord.dbd @@ -0,0 +1,12 @@ +# This is a combined minimal DBD and DB file + +recordtype(x) { + field(NAME, DBF_STRING) { + prompt("Record Name") + special(SPC_NOMOD) + size(61) + } + field(VAL, DBF_LONG) { + prompt("Value") + } +}