New src/std/link/test directory with tests for the state link type

This commit is contained in:
Andrew Johnson
2018-06-02 23:28:20 -05:00
parent 5796f717ef
commit c6c25ab43d
8 changed files with 266 additions and 2 deletions
+4 -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 = ..
@@ -72,9 +72,11 @@ std_DEPEND_DIRS = ioc libCom/RTEMS
DIRS += std/filters/test
std/filters/test_DEPEND_DIRS = std
DIRS += std/link/test
std/link/test_DEPEND_DIRS = std
DIRS += std/rec/test
std/rec/test_DEPEND_DIRS = std
include $(TOP)/configure/RULES_DIRS
+53
View File
@@ -0,0 +1,53 @@
#*************************************************************************
# Copyright (c) 2018 UChicago Argonne LLC, as Operator of Argonne
# National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in the file LICENSE that is included with this distribution.
#*************************************************************************
TOP=../../../..
include $(TOP)/configure/CONFIG
TESTLIBRARY = Recs
Recs_SRCS += ioRecord.c
Recs_LIBS += dbCore ca Com
PROD_LIBS = Recs dbRecStd dbCore ca Com
DBDDEPENDS_FILES += linkTest.dbd$(DEP)
TARGETS += $(COMMON_DIR)/linkTest.dbd
linkTest_DBD += menuGlobal.dbd
linkTest_DBD += menuConvert.dbd
linkTest_DBD += menuScan.dbd
linkTest_DBD += links.dbd
linkTest_DBD += ioRecord.dbd
TESTFILES += $(COMMON_DIR)/linkTest.dbd
testHarness_SRCS += linkTest_registerRecordDeviceDriver.cpp
TESTPROD_HOST += lnkStateTest
lnkStateTest_SRCS += lnkStateTest.c
lnkStateTest_SRCS += linkTest_registerRecordDeviceDriver.cpp
testHarness_SRCS += lnkStateTest.c
TESTFILES += ../ioRecord.db
TESTS += lnkStateTest
# epicsRunLinkTests runs all the test programs in a known working order.
testHarness_SRCS += epicsRunLinkTests.c
linkTestHarness_SRCS += $(testHarness_SRCS)
linkTestHarness_SRCS_RTEMS += rtemsTestHarness.c
PROD_vxWorks = linkTestHarness
PROD_RTEMS = linkTestHarness
TESTSPEC_vxWorks = linkTestHarness.munch; epicsRunLinkTests
TESTSPEC_RTEMS = linkTestHarness.boot; epicsRunLinkTests
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
include $(TOP)/configure/RULES
ioRecord$(DEP): $(COMMON_DIR)/ioRecord.h
lnkStateTest$(DEP): $(COMMON_DIR)/ioRecord.h
+28
View File
@@ -0,0 +1,28 @@
/*************************************************************************\
* Copyright (c) 2018 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Run filter tests as a batch.
*/
#include "epicsUnitTest.h"
#include "epicsExit.h"
#include "dbmf.h"
int lnkStateTest(void);
int lnkCalcTest(void);
void epicsRunLinkTests(void)
{
testHarness();
runTest(lnkStateTest);
dbmfFreeChunks();
epicsExit(0); /* Trigger test harness */
}
+22
View File
@@ -0,0 +1,22 @@
/*************************************************************************\
* Copyright (c) 2018 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Andrew Johnson <anj@aps.anl.gov>
*/
#include <dbAccessDefs.h>
#include <recSup.h>
#define GEN_SIZE_OFFSET
#include "ioRecord.h"
#undef GEN_SIZE_OFFSET
#include <epicsExport.h>
static rset ioRSET;
epicsExportAddress(rset,ioRSET);
+1
View File
@@ -0,0 +1 @@
record(io, io) {}
+14
View File
@@ -0,0 +1,14 @@
# This is a soft record type with both input and output links
recordtype(io) {
include "dbCommon.dbd"
field(VAL, DBF_LONG) {
prompt("Value")
}
field(INPUT, DBF_INLINK) {
prompt("Input Link")
}
field(OUTPUT, DBF_OUTLINK) {
prompt("Output Link")
}
}
+130
View File
@@ -0,0 +1,130 @@
/*************************************************************************\
* Copyright (c) 2018 Andrew Johnson
* EPICS BASE is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
#include <string.h>
#include "dbAccess.h"
#include "alarm.h"
#include "dbUnitTest.h"
#include "errlog.h"
#include "epicsThread.h"
#include "dbLink.h"
#include "dbState.h"
#include "ioRecord.h"
#include "testMain.h"
void linkTest_registerRecordDeviceDriver(struct dbBase *);
static void startTestIoc(const char *dbfile)
{
testdbPrepare();
testdbReadDatabase("linkTest.dbd", NULL, NULL);
linkTest_registerRecordDeviceDriver(pdbbase);
testdbReadDatabase(dbfile, NULL, NULL);
eltc(0);
testIocInitOk();
eltc(1);
}
static void testState()
{
dbStateId red;
ioRecord *pio;
DBLINK *pinp, *pout;
long status;
testDiag("testing lnkState");
startTestIoc("ioRecord.db");
pio = (ioRecord *) testdbRecordPtr("io");
pinp = &pio->input;
pout = &pio->output;
red = dbStateFind("red");
testOk(!red, "No state red exists");
testdbPutFieldOk("io.INPUT", DBF_STRING, "{\"state\":\"red\"}");
if (testOk1(pinp->type == JSON_LINK))
testDiag("Link was set to '%s'", pinp->value.json.string);
red = dbStateFind("red");
testOk(!!red, "state red exists");
{
epicsInt16 i16;
dbStateSet(red);
status = dbGetLink(pinp, DBF_SHORT, &i16, NULL, NULL);
testOk(!status, "dbGetLink succeeded");
testOk(i16, "Got TRUE");
testdbPutFieldOk("io.INPUT", DBF_STRING, "{\"state\":\"!red\"}");
if (testOk1(pinp->type == JSON_LINK))
testDiag("Link was set to '%s'", pinp->value.json.string);
status = dbGetLink(pinp, DBF_SHORT, &i16, NULL, NULL);
testOk(!status, "dbGetLink succeeded");
testOk(!i16, "Got FALSE");
testdbPutFieldOk("io.OUTPUT", DBF_STRING, "{\"state\":\"red\"}");
if (testOk1(pout->type == JSON_LINK))
testDiag("Link was set to '%s'", pout->value.json.string);
i16 = 0;
status = dbPutLink(pout, DBF_SHORT, &i16, 1);
testOk(!status, "dbPutLink %d succeeded", i16);
testOk(!dbStateGet(red), "state was cleared");
i16 = 0x8000;
status = dbPutLink(pout, DBF_SHORT, &i16, 1);
testOk(!status, "dbPutLink 0x%hx succeeded", i16);
testOk(dbStateGet(red), "state was set");
}
status = dbPutLink(pout, DBF_STRING, "", 1);
testOk(!status, "dbPutLink '' succeeded");
testOk(!dbStateGet(red), "state was cleared");
status = dbPutLink(pout, DBF_STRING, "FALSE", 1); /* Not really... */
testOk(!status, "dbPutLink 'FALSE' succeeded");
testOk(dbStateGet(red), "state was set");
status = dbPutLink(pout, DBF_STRING, "0", 1);
testOk(!status, "dbPutLink '0' succeeded");
testOk(!dbStateGet(red), "state was cleared");
{
epicsFloat64 f64 = 0.1;
status = dbPutLink(pout, DBF_DOUBLE, &f64, 1);
testOk(!status, "dbPutLink %g succeeded", f64);
testOk(dbStateGet(red), "state was set");
testdbPutFieldOk("io.OUTPUT", DBF_STRING, "{\"state\":\"!red\"}");
if (testOk1(pout->type == JSON_LINK))
testDiag("Link was set to '%s'", pout->value.json.string);
status = dbPutLink(pout, DBF_DOUBLE, &f64, 1);
testOk(!status, "dbPutLink %g succeeded", f64);
testOk(!dbStateGet(red), "state was cleared");
}
testIocShutdownOk();
testdbCleanup();
}
MAIN(lnkStateTest)
{
testPlan(0);
testState();
return testDone();
}
+14
View File
@@ -0,0 +1,14 @@
/*************************************************************************\
* Copyright (c) 2018 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
extern void epicsRunLinkTests(void);
int main(int argc, char **argv)
{
epicsRunLinkTests(); /* calls epicsExit(0) */
return 0;
}