diff --git a/modules/libcom/test/Makefile b/modules/libcom/test/Makefile index f2e495a90..27577f012 100755 --- a/modules/libcom/test/Makefile +++ b/modules/libcom/test/Makefile @@ -241,6 +241,11 @@ TESTS += yajlTest endif endif +TESTPROD_HOST += iocshTest +iocshTest_SRCS += iocshTest.cpp +TESTS += iocshTest +TESTFILES += $(wildcard ../iocshTest*.cmd) + # The testHarness runs all the test programs in a known working order. testHarness_SRCS += epicsRunLibComTests.c @@ -300,3 +305,6 @@ endif endif include $(TOP)/configure/RULES + +rtemsTestData.c : $(TESTFILES) $(TOOLS)/epicsMakeMemFs.pl + $(PERL) $(TOOLS)/epicsMakeMemFs.pl $@ epicsRtemsFSImage $(TESTFILES) diff --git a/modules/libcom/test/iocshTest.cpp b/modules/libcom/test/iocshTest.cpp new file mode 100644 index 000000000..1216ed579 --- /dev/null +++ b/modules/libcom/test/iocshTest.cpp @@ -0,0 +1,131 @@ +/*************************************************************************\ +* Copyright (c) 2019 Michael Davidsaver +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +namespace { +void findTestData() +{ + const char *locations[] = { + ".", + "..", + ".." OSI_PATH_LIST_SEPARATOR "O.Common", + "O.Common", + }; + + for(size_t i=0; i %d", expect ? "ran" : "expected error from", fname, err); +} + +void testCmd(const char *cmd, bool expect=true) +{ + testDiag("eval \"%s\"", cmd); + int err = iocshCmd(cmd); + testOk((err==0) ^ (!expect), "%s \"%s\" -> %d", expect ? "eval'd" : "expected error from", cmd, err); +} + +std::set reached; +const iocshArg positionArg0 = {"position", iocshArgString}; +const iocshArg * const positionArgs[1] = { &positionArg0 }; +const iocshFuncDef positionFuncDef = {"position",1,positionArgs}; +void positionCallFunc(const iocshArgBuf *args) +{ + testDiag("Reaching \"%s\"", args[0].sval); + reached.insert(args[0].sval); +} + +void testPosition(const std::string& pos, bool expect=true) +{ + testOk((reached.find(pos)!=reached.end()) ^ !expect, + "%sreached position %s", expect ? "" : "not ", pos.c_str()); +} + +const iocshArg assertArg0 = {"condition", iocshArgInt}; +const iocshArg * const assertArgs[1] = {&assertArg0}; +const iocshFuncDef assertFuncDef = {"assert",1,assertArgs}; +void assertCallFunc(const iocshArgBuf *args) +{ + iocshSetError(args[0].ival); +} + +} // namespace + +MAIN(iocshTest) +{ + testPlan(19); + libComRegister(); + iocshRegister(&positionFuncDef, &positionCallFunc); + iocshRegister(&assertFuncDef, &assertCallFunc); + findTestData(); + + testFile("iocshTestSuccess.cmd"); + testPosition("success"); + reached.clear(); + testPosition("success", false); + + testCmd("