diff --git a/src/Makefile b/src/Makefile index 3307b8786..8205a427b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -62,7 +62,7 @@ DIRS += ioc ioc_DEPEND_DIRS = libCom ca/client DIRS += ioc/db/test -ioc/db/test_DEPEND_DIRS = ioc libCom/RTEMS +ioc/db/test_DEPEND_DIRS = ioc std libCom/RTEMS DIRS += ioc/dbtemplate/test ioc/dbtemplate/test_DEPEND_DIRS = ioc diff --git a/src/ioc/db/test/Makefile b/src/ioc/db/test/Makefile index 2f428aa5b..dd149c8a0 100644 --- a/src/ioc/db/test/Makefile +++ b/src/ioc/db/test/Makefile @@ -16,6 +16,15 @@ xRec_SRCS = xRecord.c PROD_LIBS = xRec dbCore ca Com +TESTPROD_HOST += dbShutdownTest +TARGETS += $(COMMON_DIR)/dbShutdownTest.dbd +dbShutdownTest_SRCS += dbShutdownTest.c +dbShutdownTest_SRCS += dbShutdownTest_registerRecordDeviceDriver.cpp +dbShutdownTest_LIBS += $(EPICS_BASE_IOC_LIBS) +dbShutdownTest_DBD += base.dbd +TESTFILES += $(COMMON_DIR)/dbShutdownTest.dbd ../sRecord.db +TESTS += dbShutdownTest + TESTPROD_HOST += callbackTest callbackTest_SRCS += callbackTest.c testHarness_SRCS += callbackTest.c diff --git a/src/ioc/db/test/dbShutdownTest.c b/src/ioc/db/test/dbShutdownTest.c new file mode 100644 index 000000000..7d9b3862a --- /dev/null +++ b/src/ioc/db/test/dbShutdownTest.c @@ -0,0 +1,98 @@ +/*************************************************************************\ +* Copyright (c) 2013 Brookhaven National Laboratory. +* Copyright (c) 2013 ITER Organization. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. + \*************************************************************************/ + +/* + * Author: Michael Davidsaver + * Ralph Lange + */ + +#include + +#include "epicsUnitTest.h" +#include "epicsThread.h" +#include "iocInit.h" +#include "dbBase.h" +#include "dbAccess.h" +#include "registry.h" +#include "dbStaticLib.h" +#include "osiFileName.h" +#include "dbmf.h" + +#include "testMain.h" + +void dbShutdownTest_registerRecordDeviceDriver(struct dbBase *); + +static struct threadItem { + char *name; + char found; +} commonThreads[] = { + { "errlog", 0 }, + { "taskwd", 0 }, + { "timerQueue", 0 }, + { "cbLow", 0 }, + { "scanOnce", 0 }, + { NULL, 0 } +}; + +static +void findCommonThread (epicsThreadId id) { + struct threadItem *thr; + char name[32]; + + epicsThreadGetName(id, name, 32); + + for (thr = commonThreads; thr->name; thr++) { + if (strcasecmp(thr->name, name) == 0) { + thr->found = 1; + } + } +} + +static +void checkCommonThreads (void) { + struct threadItem *thr; + + for (thr = commonThreads; thr->name; thr++) { + testOk(thr->found, "Thread %s is running", thr->name); + thr->found = 0; + } +} + +static +void cycle(void) { + if (dbReadDatabase(&pdbbase, "dbShutdownTest.dbd", + "." OSI_PATH_LIST_SEPARATOR ".." OSI_PATH_LIST_SEPARATOR + "../O.Common" OSI_PATH_LIST_SEPARATOR "O.Common", NULL)) + testAbort("Database description 'dbShutdownTest.dbd' not found"); + + dbShutdownTest_registerRecordDeviceDriver(pdbbase); + if (dbReadDatabase(&pdbbase, "sRecord.db", + "." OSI_PATH_LIST_SEPARATOR "..", NULL)) + testAbort("Test database 'sRecord.db' not found"); + + testOk1(!(iocBuildNoCA() || iocRun())); + + epicsThreadMap(findCommonThread); + checkCommonThreads(); + + testOk1(iocShutdown()==0); + + dbFreeBase(pdbbase); + registryFree(); + pdbbase = NULL; + dbmfFreeChunks(); +} + +MAIN(dbShutdownTest) +{ + testPlan(14); + + cycle(); + cycle(); + + return testDone(); +} diff --git a/src/ioc/db/test/sRecord.db b/src/ioc/db/test/sRecord.db new file mode 100644 index 000000000..790a7df7c --- /dev/null +++ b/src/ioc/db/test/sRecord.db @@ -0,0 +1 @@ +record(ai, "somename") {}