diff --git a/src/ioc/db/dbServer.h b/src/ioc/db/dbServer.h index f1a48ab40..c2ebdb467 100644 --- a/src/ioc/db/dbServer.h +++ b/src/ioc/db/dbServer.h @@ -16,6 +16,10 @@ * the dbServer interface provides allow the IOC to start, pause and stop * the servers together, and to provide status and debugging information * to the IOC user/developer through a common set of commands. + * + * @todo Should dbRegisterServer() return an error status value? + * No API is provided yet for calling stats() methods. + * Nothing in the IOC calls dbStopServers(), not sure where it should go. */ #ifndef INC_dbServer_H diff --git a/src/ioc/db/test/Makefile b/src/ioc/db/test/Makefile index 37ec3da74..ff464f02a 100644 --- a/src/ioc/db/test/Makefile +++ b/src/ioc/db/test/Makefile @@ -4,7 +4,7 @@ # Copyright (c) 2002 The Regents of the University of California, as # Operator of Los Alamos National Laboratory. # EPICS BASE is distributed subject to a Software License Agreement found -# in the file LICENSE that is included with this distribution. +# in the file LICENSE that is included with this distribution. #************************************************************************* TOP=../../../.. @@ -94,6 +94,11 @@ dbStateTest_SRCS += dbStateTest.c testHarness_SRCS += dbStateTest.c TESTS += dbStateTest +TESTPROD_HOST += dbServerTest +dbServerTest_SRCS += dbServerTest.c +testHarness_SRCS += dbServerTest.c +TESTS += dbServerTest + TESTPROD_HOST += dbCaStatsTest dbCaStatsTest_SRCS += dbCaStatsTest.c dbCaStatsTest_SRCS += dbTestIoc_registerRecordDeviceDriver.cpp @@ -192,4 +197,3 @@ dbStressLock$(DEP): $(COMMON_DIR)/xRecord.h devx$(DEP): $(COMMON_DIR)/xRecord.h scanIoTest$(DEP): $(COMMON_DIR)/xRecord.h xRecord$(DEP): $(COMMON_DIR)/xRecord.h - diff --git a/src/ioc/db/test/dbServerTest.c b/src/ioc/db/test/dbServerTest.c new file mode 100644 index 000000000..6c474ecb4 --- /dev/null +++ b/src/ioc/db/test/dbServerTest.c @@ -0,0 +1,131 @@ +/*************************************************************************\ +* Copyright (c) 2017 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. + \*************************************************************************/ + +/* + * Author: Andrew Johnson + */ + +#include + +#include "dbServer.h" + +#include +#include + +enum { + NOTHING_CALLED, + REPORT_CALLED, + CLIENT_CALLED_UNKNOWN, + CLIENT_CALLED_KNOWN, + STATS_CALLED, + INIT_CALLED, + RUN_CALLED, + PAUSE_CALLED, + STOP_CALLED +} oneState; + +char *oneSim; + +void oneReport(unsigned level) +{ + oneState = REPORT_CALLED; +} + +void oneStats(unsigned *channels, unsigned *clients) +{ + oneState = STATS_CALLED; +} + +int oneClient(char *pbuf, size_t len) +{ + if (oneSim) { + strncpy(pbuf, oneSim, len); + oneState = CLIENT_CALLED_KNOWN; + oneSim = NULL; + return 0; + } + oneState = CLIENT_CALLED_UNKNOWN; + return -1; +} + +void oneInit(void) +{ + oneState = INIT_CALLED; +} + +void oneRun(void) +{ + oneState = RUN_CALLED; +} + +void onePause(void) +{ + oneState = PAUSE_CALLED; +} + +void oneStop(void) +{ + oneState = STOP_CALLED; +} + +dbServer one = { + ELLNODE_INIT, + "one", + oneReport, oneStats, oneClient, + oneInit, oneRun, onePause, oneStop +}; + +dbServer no_routines = { + ELLNODE_INIT, + "no-routines", + NULL, NULL, NULL, NULL, NULL, NULL, NULL +}; + +MAIN(dbServerTest) +{ + char name[16]; + char *theName = "The One"; + int status; + + testPlan(0); + + testDiag("Registering dbServer 'one'"); + dbRegisterServer(&one); + testOk1(oneState == NOTHING_CALLED); + + testDiag("Registering dbServer 'no-routines'"); + dbRegisterServer(&no_routines); + + dbInitServers(); + testOk(oneState == INIT_CALLED, "dbInitServers"); + + dbRunServers(); + testOk(oneState == RUN_CALLED, "dbRunServers"); + + dbPauseServers(); + testOk(oneState == PAUSE_CALLED, "dbPauseServers"); + + dbStopServers(); + testOk(oneState == STOP_CALLED, "dbStopServers"); + + dbsr(0); + testOk(oneState == REPORT_CALLED, "dbsr"); + + oneSim = NULL; + name[0] = 0; + status = dbServerClient(name, sizeof(name)); + testOk(status == -1 && name[0] == 0, + "dbServerClient mismatch"); + + oneSim = theName; + name[0] = 0; + status = dbServerClient(name, sizeof(name)); + testOk(status == 0 && strcmp(name, theName) == 0, + "dbServerClient match"); + + return testDone(); +} diff --git a/src/ioc/db/test/epicsRunDbTests.c b/src/ioc/db/test/epicsRunDbTests.c index 69f6b082e..4036268fa 100644 --- a/src/ioc/db/test/epicsRunDbTests.c +++ b/src/ioc/db/test/epicsRunDbTests.c @@ -20,6 +20,7 @@ int testdbConvert(void); int callbackTest(void); int callbackParallelTest(void); int dbStateTest(void); +int dbServerTest(void); int dbCaStatsTest(void); int dbShutdownTest(void); int dbScanTest(void); @@ -41,6 +42,7 @@ void epicsRunDbTests(void) runTest(callbackTest); runTest(callbackParallelTest); runTest(dbStateTest); + runTest(dbServerTest); runTest(dbCaStatsTest); runTest(dbShutdownTest); runTest(dbScanTest);