added test for named soft events

This commit is contained in:
2018-02-13 13:50:19 +01:00
parent d19afc73af
commit 8a3080c16f
4 changed files with 141 additions and 0 deletions

View File

@@ -138,6 +138,19 @@ testHarness_SRCS += dbPutGetTest.db
TESTFILES += ../dbPutGetTest.db
TESTS += testPutGetTest
TARGETS += $(COMMON_DIR)/scanEventTest.dbd
DBDDEPENDS_FILES += scanEventTest.dbd$(DEP)
scanEventTest_DBD += menuGlobal.dbd
scanEventTest_DBD += menuConvert.dbd
scanEventTest_DBD += menuScan.dbd
scanEventTest_DBD += eventRecord.dbd
scanEventTest_DBD += calcRecord.dbd
TESTPROD_HOST += scanEventTest
scanEventTest_SRCS += scanEventTest.c
scanEventTest_SRCS += scanEventTest_registerRecordDeviceDriver.cpp
scanEventTest_LIBS = dbRecStd
TESTS += scanEventTest
# This runs all the test programs in a known working order:
testHarness_SRCS += epicsRunDbTests.c

View File

@@ -29,6 +29,7 @@ int testDbChannel(void);
int chfPluginTest(void);
int arrShorthandTest(void);
int recGblCheckDeadbandTest(void);
int scanEventTest(void);
void epicsRunDbTests(void)
{
@@ -47,6 +48,7 @@ void epicsRunDbTests(void)
runTest(arrShorthandTest);
runTest(recGblCheckDeadbandTest);
runTest(chfPluginTest);
runTest(scanEventTest);
dbmfFreeChunks();

View File

@@ -0,0 +1,117 @@
/*************************************************************************\
* Copyright (c) 2018 Paul Scherrer Institut
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Author: Dirk Zimoch <dirk.zimoch@psi.ch>
*/
#include <string.h>
#include "dbStaticLib.h"
#include "dbAccessDefs.h"
#include "dbUnitTest.h"
#include "testMain.h"
#include "osiFileName.h"
#include "dbScan.h"
void scanEventTest_registerRecordDeviceDriver(struct dbBase *);
/* test name to event number:
num = 0 is no event,
num > 0 is numeric event
num < 0 is string event (use same unique number for aliases)
*/
const struct {char* name; int num;} events[] = {
{"", 0},
{" ", 0},
{"0", 0},
{"0.000000", 0},
{"-0.00000", 0},
{"0.9", 0},
{"nan", 0},
{"NaN", 0},
{"-NAN", 0},
{"-inf", 0},
{"inf", 0},
{"info 1", -1},
{" info 1 ", -1},
{"-0.9", -2},
{"2", 2},
{"2.000000", 2},
{"2.5", 2},
{" 2.5 ", 2},
{"+0x02", 2},
{"-2", -3},
{"-2.000000", -4},
{"-2.5", -5},
{" -2.5 ", -5},
};
MAIN(scanEventTest)
{
unsigned int i;
int aliases[512] ;
int expected_count[512];
#define INDX(i) 256-events[i].num
testPlan(NELEMENTS(events)*2);
memset(aliases, 0, sizeof(aliases));
memset(expected_count, 0, sizeof(expected_count));
if (dbReadDatabase(&pdbbase, "scanEventTest.dbd",
"." OSI_PATH_LIST_SEPARATOR ".." OSI_PATH_LIST_SEPARATOR
"../O.Common" OSI_PATH_LIST_SEPARATOR "O.Common", NULL))
testAbort("Database description 'scanEventTest.dbd' not found");
scanEventTest_registerRecordDeviceDriver(pdbbase);
for (i = 0; i < NELEMENTS(events); i++) {
char substitutions[256];
sprintf(substitutions, "N=%d,EVENT=%s", i, events[i].name);
if (dbReadDatabase(&pdbbase, "scanEventTest.db",
"." OSI_PATH_LIST_SEPARATOR "..", substitutions))
testAbort("Error reading test database 'scanEventTest.db'");
}
testIocInitOk();
for (i = 0; i < NELEMENTS(events); i++) {
EVENTPVT pev = eventNameToHandle(events[i].name);
/* test that some names are not events (num=0) */
if (events[i].num == 0)
testOk(pev == NULL, "\"%s\" -> no event", events[i].name);
else
{
expected_count[INDX(i)]++; /* +1 for postEvent */
if (events[i].num > 0)
{
testOk(pev != NULL, "\"%s\" -> numeric event %d", events[i].name, events[i].num);
expected_count[INDX(i)]++; /* +1 for post_event */
}
else
{
/* test that some strings resolve the same event (num!=0) */
if (!aliases[INDX(i)])
{
aliases[INDX(i)] = i;
testOk(pev != NULL, "\"%s\" -> new named event", events[i].name);
}
else
{
testOk(pev == eventNameToHandle(events[aliases[INDX(i)]].name),
"\"%s\" alias for \"%s\"", events[i].name, events[aliases[INDX(i)]].name);
}
}
}
post_event(events[i].num);
postEvent(pev);
}
for (i = 0; i < NELEMENTS(events); i++) {
char pvname[100];
sprintf(pvname, "c%d", i);
testDiag("Check if %s (event \"%s\") has processed %d times", pvname, events[i].name, expected_count[INDX(i)]);
testdbGetFieldEqual(pvname, DBR_LONG, expected_count[INDX(i)]);
}
return testDone();
}

View File

@@ -0,0 +1,9 @@
record(calc, "c$(N)") {
field(SCAN, "Event")
field(EVNT, "$(EVENT)")
field(CALC, "VAL+1")
}
record(event, "e$(N)") {
field(SCAN, "Event")
field(VAL, "$(EVENT)")
}