Added some dbServer unit tests

This commit is contained in:
Andrew Johnson
2017-07-23 23:30:04 -05:00
parent c2d22ed925
commit 17e6060d16
4 changed files with 143 additions and 2 deletions
+4
View File
@@ -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
+6 -2
View File
@@ -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
+131
View File
@@ -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 <anj@aps.anl.gov>
*/
#include <string.h>
#include "dbServer.h"
#include <epicsUnitTest.h>
#include <testMain.h>
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();
}
+2
View File
@@ -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);