From c6c25ab43d7d0ffd87077b37fbacc2b4154ae5f5 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sat, 2 Jun 2018 23:28:20 -0500 Subject: [PATCH] New src/std/link/test directory with tests for the state link type --- src/Makefile | 6 +- src/std/link/test/Makefile | 53 +++++++++++ src/std/link/test/epicsRunLinkTests.c | 28 ++++++ src/std/link/test/ioRecord.c | 22 +++++ src/std/link/test/ioRecord.db | 1 + src/std/link/test/ioRecord.dbd | 14 +++ src/std/link/test/lnkStateTest.c | 130 ++++++++++++++++++++++++++ src/std/link/test/rtemsTestHarness.c | 14 +++ 8 files changed, 266 insertions(+), 2 deletions(-) create mode 100644 src/std/link/test/Makefile create mode 100644 src/std/link/test/epicsRunLinkTests.c create mode 100644 src/std/link/test/ioRecord.c create mode 100644 src/std/link/test/ioRecord.db create mode 100644 src/std/link/test/ioRecord.dbd create mode 100644 src/std/link/test/lnkStateTest.c create mode 100644 src/std/link/test/rtemsTestHarness.c diff --git a/src/Makefile b/src/Makefile index 257099840..482e14843 100644 --- a/src/Makefile +++ b/src/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 = .. @@ -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 - diff --git a/src/std/link/test/Makefile b/src/std/link/test/Makefile new file mode 100644 index 000000000..30aec6038 --- /dev/null +++ b/src/std/link/test/Makefile @@ -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 diff --git a/src/std/link/test/epicsRunLinkTests.c b/src/std/link/test/epicsRunLinkTests.c new file mode 100644 index 000000000..2cfc7a8a0 --- /dev/null +++ b/src/std/link/test/epicsRunLinkTests.c @@ -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 */ +} diff --git a/src/std/link/test/ioRecord.c b/src/std/link/test/ioRecord.c new file mode 100644 index 000000000..1807c9171 --- /dev/null +++ b/src/std/link/test/ioRecord.c @@ -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 + */ + +#include +#include + +#define GEN_SIZE_OFFSET +#include "ioRecord.h" +#undef GEN_SIZE_OFFSET + +#include + +static rset ioRSET; +epicsExportAddress(rset,ioRSET); diff --git a/src/std/link/test/ioRecord.db b/src/std/link/test/ioRecord.db new file mode 100644 index 000000000..7a95a1025 --- /dev/null +++ b/src/std/link/test/ioRecord.db @@ -0,0 +1 @@ +record(io, io) {} diff --git a/src/std/link/test/ioRecord.dbd b/src/std/link/test/ioRecord.dbd new file mode 100644 index 000000000..efaec10a0 --- /dev/null +++ b/src/std/link/test/ioRecord.dbd @@ -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") + } +} diff --git a/src/std/link/test/lnkStateTest.c b/src/std/link/test/lnkStateTest.c new file mode 100644 index 000000000..a2d514e6b --- /dev/null +++ b/src/std/link/test/lnkStateTest.c @@ -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 + +#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(); +} diff --git a/src/std/link/test/rtemsTestHarness.c b/src/std/link/test/rtemsTestHarness.c new file mode 100644 index 000000000..7397f74d6 --- /dev/null +++ b/src/std/link/test/rtemsTestHarness.c @@ -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; +}