Make db unit tests self contained

This commit is contained in:
Michael Davidsaver
2012-06-28 10:55:46 -04:00
parent 026307c06d
commit 39ccbeeb11
8 changed files with 176 additions and 73 deletions

View File

@@ -28,30 +28,31 @@ TESTSPEC_vxWorks = dbTestHarness.munch; epicsRunDbTests
TESTSPEC_RTEMS = dbTestHarness.boot; epicsRunDbTests
TESTPROD_HOST += dbChannelTest
dbChannelTest_SRCS += dbChannelTest.c xRecord_registerRecordDeviceDriver.cpp
dbChannelTest_SRCS += dbChannelTest.c xRecord.c
dbTestHarness_SRCS += dbChannelTest.c
OBJS_IOC_vxWorks += dbChannelTest
TESTS += dbChannelTest
TESTPROD_HOST += chfPluginTest
chfPluginTest_SRCS += chfPluginTest.c xRecord_registerRecordDeviceDriver.cpp
chfPluginTest_SRCS += chfPluginTest.c xRecord.c
dbTestHarness_SRCS += chfPluginTest.c
OBJS_IOC_vxWorks += chfPluginTest
TESTS += chfPluginTest
TESTPROD_HOST += arrShorthandTest
arrShorthandTest_SRCS += arrShorthandTest.c xRecord_registerRecordDeviceDriver.cpp
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
dbChannelTest$(DEP): $(COMMON_DIR)/xRecord.h
chfPluginTest$(DEP): $(COMMON_DIR)/xRecord.h
arrShorthandTest$(DEP): $(COMMON_DIR)/xRecord.h
dbStateTest$(DEP): $(COMMON_DIR)/xRecord.h

View File

@@ -21,6 +21,7 @@
#include "chfPlugin.h"
#include "dbStaticLib.h"
#include "dbAccessDefs.h"
#include "registry.h"
#include "epicsUnitTest.h"
#include "testMain.h"
@@ -75,22 +76,21 @@ static void testHead (char* title) {
testDiag("--------------------------------------------------------");
}
void xRecord_registerRecordDeviceDriver(struct dbBase *);
int loadTestDB(DBBASE **ppbase);
MAIN(chfPluginTest)
MAIN(arrShorthandTest)
{
dbChannel *pch;
testPlan(26);
testPlan(28);
db_init_events();
if (dbReadDatabase(&pdbbase, "xRecord.dbd", "..", NULL))
testAbort("Database description not loaded");
testHead("Set up database");
if(loadTestDB(&pdbbase))
return testDone();
xRecord_registerRecordDeviceDriver(pdbbase);
if (dbReadDatabase(&pdbbase, "dbChannelTest.db", "..", NULL))
testAbort("Test database not loaded");
testOk(!!pdbbase, "pdbbase was set");
testHead("Register plugin");
testOk(!chfPluginRegister("arr", &myPif, opts), "register fake arr plugin");
@@ -124,16 +124,8 @@ MAIN(chfPluginTest)
TESTGOOD("range with incr [s:i:e]", "[2:3:4]", 2, 3, 4);
dbFreeBase(pdbbase);
registryFree();
pdbbase=0;
return testDone();
}
#define GEN_SIZE_OFFSET
#include "xRecord.h"
#include <recSup.h>
#include <epicsExport.h>
static rset xRSET;
epicsExportAddress(rset,xRSET);

View File

@@ -15,6 +15,7 @@
#include "chfPlugin.h"
#include "dbStaticLib.h"
#include "dbAccessDefs.h"
#include "registry.h"
#include "epicsUnitTest.h"
#include "testMain.h"
@@ -462,14 +463,14 @@ static void testHead (char* title) {
testDiag("--------------------------------------------------------");
}
void xRecord_registerRecordDeviceDriver(struct dbBase *);
int loadTestDB(DBBASE **ppbase);
MAIN(chfPluginTest)
{
dbChannel *pch;
db_field_log *pfl;
testPlan(1351);
testPlan(1353);
db_init_events();
@@ -484,12 +485,10 @@ MAIN(chfPluginTest)
testOk(strcmp(chfPluginEnumString(colorEnum, 3, "-"), "-") == 0,
"Enum to string: invalid index");
if (dbReadDatabase(&pdbbase, "xRecord.dbd", "..", NULL))
testAbort("Database description not loaded");
xRecord_registerRecordDeviceDriver(pdbbase);
if (dbReadDatabase(&pdbbase, "dbChannelTest.db", "..", NULL))
testAbort("Test database not loaded");
testHead("Set up database");
if(loadTestDB(&pdbbase))
return testDone();
testOk(!!pdbbase, "pdbbase was set");
testHead("Try to register buggy plugins");
testOk(!!chfPluginRegister("buggy", &myPif, brokenOpts1),
@@ -818,15 +817,8 @@ MAIN(chfPluginTest)
drop = -1;
dbFreeBase(pdbbase);
registryFree();
pdbbase=0;
return testDone();
}
#define GEN_SIZE_OFFSET
#include "xRecord.h"
#include <recSup.h>
#include <epicsExport.h>
static rset xRSET;
epicsExportAddress(rset,xRSET);

View File

@@ -16,6 +16,7 @@
#include "dbChannel.h"
#include "dbStaticLib.h"
#include "dbAccessDefs.h"
#include "registry.h"
#include "recSup.h"
#include "epicsUnitTest.h"
#include "testMain.h"
@@ -147,20 +148,18 @@ chFilterIf testIf =
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 };
void xRecord_registerRecordDeviceDriver(struct dbBase *);
int loadTestDB(DBBASE **ppbase);
MAIN(testDbChannel) /* dbChannelTest is an API routine... */
{
dbChannel *pch;
testPlan(66);
testPlan(68);
if (dbReadDatabase(&pdbbase, "xRecord.dbd", "..", NULL))
testAbort("Database description not loaded");
if(loadTestDB(&pdbbase))
return testDone();
xRecord_registerRecordDeviceDriver(pdbbase);
if (dbReadDatabase(&pdbbase, "dbChannelTest.db", "..", NULL))
testAbort("Test database not loaded");
testOk(!!pdbbase, "pdbbase was set");
r = e = 0;
/* dbChannelTest() checks record and field names */
@@ -247,15 +246,8 @@ MAIN(testDbChannel) /* dbChannelTest is an API routine... */
testOk1(!dbChannelCreate("x.{\"scalar\":{}}"));
dbFreeBase(pdbbase);
registryFree();
pdbbase=0;
return testDone();
}
#define GEN_SIZE_OFFSET
#include "xRecord.h"
#include <recSup.h>
#include <epicsExport.h>
static rset xRSET;
epicsExportAddress(rset,xRSET);

View File

@@ -1,2 +0,0 @@
record(x, x) {}

View File

@@ -17,12 +17,20 @@
#include "dbmf.h"
int callbackTest(void);
int dbStateTest(void);
int testDbChannel(void);
int chfPluginTest(void);
int arrShorthandTest(void);
void epicsRunDbTests(void)
{
testHarness();
runTest(callbackTest);
runTest(dbStateTest);
runTest(testDbChannel);
runTest(chfPluginTest);
runTest(arrShorthandTest);
dbmfFreeChunks();

132
src/ioc/db/test/xRecord.c Normal file
View File

@@ -0,0 +1,132 @@
#include <epicsStdio.h>
#include <string.h>
#include "epicsTypes.h"
#include "dbBase.h"
#include "devSup.h"
#include "registryCommon.h"
#include "registryRecordType.h"
#include "dbStaticLib.h"
#include "epicsUnitTest.h"
/*
* Test database initialization
*/
/* No actual record support code is provided */
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;
}

View File

@@ -1,12 +0,0 @@
# 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")
}
}