test refactoring

This commit is contained in:
Matej Sekoranja
2014-10-31 20:08:18 +01:00
parent 5b1825a11c
commit 50c143bdec
18 changed files with 444 additions and 2124 deletions

View File

@@ -543,3 +543,352 @@ testApp/utils/testHexDump.cpp
testApp/utils/testInetAddressUtils.cpp
testApp/utils/transportRegistryTest.cpp
pvtoolsSrc/pvlist.cpp
configure/O.darwin-x86/Makefile
configure/Makefile
include/pv/baseChannelRequester.h
include/pv/beaconEmitter.h
include/pv/beaconHandler.h
include/pv/beaconServerStatusProvider.h
include/pv/blockingTCP.h
include/pv/blockingUDP.h
include/pv/caChannel.h
include/pv/caProvider.h
include/pv/channelSearchManager.h
include/pv/clientContextImpl.h
include/pv/clientFactory.h
include/pv/codec.h
include/pv/configuration.h
include/pv/hexDump.h
include/pv/inetAddressUtil.h
include/pv/introspectionRegistry.h
include/pv/likely.h
include/pv/logger.h
include/pv/namedLockPattern.h
include/pv/pvAccess.h
include/pv/pvAccessMB.h
include/pv/pvaConstants.h
include/pv/pvaVersion.h
include/pv/referenceCountingLock.h
include/pv/remote.h
include/pv/responseHandlers.h
include/pv/rpcClient.h
include/pv/rpcServer.h
include/pv/rpcService.h
include/pv/security.h
include/pv/serializationHelper.h
include/pv/serverChannelImpl.h
include/pv/serverContext.h
include/pv/simpleChannelSearchManagerImpl.h
include/pv/syncChannelFind.h
include/pv/transportRegistry.h
include/pv/wildcard.h
pvtoolsSrc/O.darwin-x86/Makefile
pvtoolsSrc/eget.cpp
pvtoolsSrc/Makefile
pvtoolsSrc/pvget.cpp
pvtoolsSrc/pvinfo.cpp
pvtoolsSrc/pvlist.cpp
pvtoolsSrc/pvput.cpp
pvtoolsSrc/pvutils.cpp
pvtoolsSrc/pvutils.h
src/ca/caChannel.cpp
src/ca/caChannel.h
src/ca/caProvider.cpp
src/ca/caProvider.h
src/ca/Makefile
src/client/Makefile
src/client/pvAccess.cpp
src/client/pvAccess.h
src/factory/ChannelAccessFactory.cpp
src/factory/Makefile
src/mb/Makefile
src/mb/pvAccessMB.cpp
src/mb/pvAccessMB.h
src/O.darwin-x86/Makefile
src/pva/clientFactory.cpp
src/pva/clientFactory.h
src/pva/Makefile
src/pva/pvaConstants.h
src/pva/pvaVersion.cpp
src/pva/pvaVersion.h
src/remote/abstractResponseHandler.cpp
src/remote/beaconHandler.cpp
src/remote/beaconHandler.h
src/remote/blockingTCP.h
src/remote/blockingTCPAcceptor.cpp
src/remote/blockingTCPConnector.cpp
src/remote/blockingUDP.h
src/remote/blockingUDPConnector.cpp
src/remote/blockingUDPTransport.cpp
src/remote/channelSearchManager.h
src/remote/codec.cpp
src/remote/codec.h
src/remote/Makefile
src/remote/remote.h
src/remote/security.cpp
src/remote/security.h
src/remote/serializationHelper.cpp
src/remote/serializationHelper.h
src/remote/simpleChannelSearchManagerImpl.cpp
src/remote/simpleChannelSearchManagerImpl.h
src/remote/transportRegistry.cpp
src/remote/transportRegistry.h
src/remoteClient/clientContextImpl.cpp
src/remoteClient/clientContextImpl.h
src/remoteClient/Makefile
src/rpcClient/Makefile
src/rpcClient/rpcClient.cpp
src/rpcClient/rpcClient.h
src/rpcService/Makefile
src/rpcService/rpcServer.cpp
src/rpcService/rpcServer.h
src/rpcService/rpcService.cpp
src/rpcService/rpcService.h
src/server/baseChannelRequester.cpp
src/server/baseChannelRequester.h
src/server/beaconEmitter.cpp
src/server/beaconEmitter.h
src/server/beaconServerStatusProvider.cpp
src/server/beaconServerStatusProvider.h
src/server/Makefile
src/server/responseHandlers.cpp
src/server/responseHandlers.h
src/server/serverChannelImpl.cpp
src/server/serverChannelImpl.h
src/server/serverContext.cpp
src/server/serverContext.h
src/utils/configuration.cpp
src/utils/configuration.h
src/utils/hexDump.cpp
src/utils/hexDump.h
src/utils/inetAddressUtil.cpp
src/utils/inetAddressUtil.h
src/utils/introspectionRegistry.cpp
src/utils/introspectionRegistry.h
src/utils/likely.h
src/utils/logger.cpp
src/utils/logger.h
src/utils/Makefile
src/utils/namedLockPattern.h
src/utils/referenceCountingLock.cpp
src/utils/referenceCountingLock.h
src/utils/wildcard.cpp
src/utils/wildcard.h
src/v3ioc/Makefile
src/v3ioc/PVAClientRegister.cpp
src/v3ioc/PVAServerRegister.cpp
src/v3ioc/syncChannelFind.h
src/Makefile
testApp/client/O.darwin-x86/Makefile
testApp/client/Makefile
testApp/client/MockClientImpl.cpp
testApp/client/testChannelAccessFactory.cpp
testApp/client/testMockClient.cpp
testApp/client/testStartStop.cpp
testApp/remote/O.darwin-x86/Makefile
testApp/remote/channelAccessIFTest.cpp
testApp/remote/channelAccessIFTest.h
testApp/remote/epicsv4Grayscale.h
testApp/remote/Makefile
testApp/remote/rpcClientExample.cpp
testApp/remote/rpcServiceExample.cpp
testApp/remote/rpcWildServiceExample.cpp
testApp/remote/syncTestRequesters.h
testApp/remote/testADCSim.cpp
testApp/remote/testBeaconEmitter.cpp
testApp/remote/testBeaconHandler.cpp
testApp/remote/testBlockingTCPClnt.cpp
testApp/remote/testBlockingTCPSrv.cpp
testApp/remote/testBlockingUDPClnt.cpp
testApp/remote/testBlockingUDPSrv.cpp
testApp/remote/testChannelAccess.cpp
testApp/remote/testChannelConnect.cpp
testApp/remote/testChannelSearchManager.cpp
testApp/remote/testCodec.cpp
testApp/remote/testGetPerformance.cpp
testApp/remote/testMonitorPerformance.cpp
testApp/remote/testNTImage.cpp
testApp/remote/testRemoteClientImpl.cpp
testApp/remote/testServer.cpp
testApp/remote/testServerContext.cpp
testApp/utils/O.darwin-x86/Makefile
testApp/utils/configurationTest.cpp
testApp/utils/introspectionRegistryTest.cpp
testApp/utils/loggerTest.cpp
testApp/utils/Makefile
testApp/utils/namedLockPatternTest.cpp
testApp/utils/testAtomicBoolean.cpp
testApp/utils/testHexDump.cpp
testApp/utils/testInetAddressUtils.cpp
testApp/utils/transportRegistryTest.cpp
testApp/Makefile
Makefile
configure/O.darwin-x86/Makefile
configure/Makefile
include/pv/baseChannelRequester.h
include/pv/beaconEmitter.h
include/pv/beaconHandler.h
include/pv/beaconServerStatusProvider.h
include/pv/blockingTCP.h
include/pv/blockingUDP.h
include/pv/caChannel.h
include/pv/caProvider.h
include/pv/channelSearchManager.h
include/pv/clientContextImpl.h
include/pv/clientFactory.h
include/pv/codec.h
include/pv/configuration.h
include/pv/hexDump.h
include/pv/inetAddressUtil.h
include/pv/introspectionRegistry.h
include/pv/likely.h
include/pv/logger.h
include/pv/namedLockPattern.h
include/pv/pvAccess.h
include/pv/pvAccessMB.h
include/pv/pvaConstants.h
include/pv/pvaVersion.h
include/pv/referenceCountingLock.h
include/pv/remote.h
include/pv/responseHandlers.h
include/pv/rpcClient.h
include/pv/rpcServer.h
include/pv/rpcService.h
include/pv/security.h
include/pv/serializationHelper.h
include/pv/serverChannelImpl.h
include/pv/serverContext.h
include/pv/simpleChannelSearchManagerImpl.h
include/pv/syncChannelFind.h
include/pv/transportRegistry.h
include/pv/wildcard.h
pvtoolsSrc/O.darwin-x86/Makefile
pvtoolsSrc/eget.cpp
pvtoolsSrc/Makefile
pvtoolsSrc/pvget.cpp
pvtoolsSrc/pvinfo.cpp
pvtoolsSrc/pvlist.cpp
pvtoolsSrc/pvput.cpp
pvtoolsSrc/pvutils.cpp
pvtoolsSrc/pvutils.h
src/ca/caChannel.cpp
src/ca/caChannel.h
src/ca/caProvider.cpp
src/ca/caProvider.h
src/ca/Makefile
src/client/Makefile
src/client/pvAccess.cpp
src/client/pvAccess.h
src/factory/ChannelAccessFactory.cpp
src/factory/Makefile
src/mb/Makefile
src/mb/pvAccessMB.cpp
src/mb/pvAccessMB.h
src/O.darwin-x86/Makefile
src/pva/clientFactory.cpp
src/pva/clientFactory.h
src/pva/Makefile
src/pva/pvaConstants.h
src/pva/pvaVersion.cpp
src/pva/pvaVersion.h
src/remote/abstractResponseHandler.cpp
src/remote/beaconHandler.cpp
src/remote/beaconHandler.h
src/remote/blockingTCP.h
src/remote/blockingTCPAcceptor.cpp
src/remote/blockingTCPConnector.cpp
src/remote/blockingUDP.h
src/remote/blockingUDPConnector.cpp
src/remote/blockingUDPTransport.cpp
src/remote/channelSearchManager.h
src/remote/codec.cpp
src/remote/codec.h
src/remote/Makefile
src/remote/remote.h
src/remote/security.cpp
src/remote/security.h
src/remote/serializationHelper.cpp
src/remote/serializationHelper.h
src/remote/simpleChannelSearchManagerImpl.cpp
src/remote/simpleChannelSearchManagerImpl.h
src/remote/transportRegistry.cpp
src/remote/transportRegistry.h
src/remoteClient/clientContextImpl.cpp
src/remoteClient/clientContextImpl.h
src/remoteClient/Makefile
src/rpcClient/Makefile
src/rpcClient/rpcClient.cpp
src/rpcClient/rpcClient.h
src/rpcService/Makefile
src/rpcService/rpcServer.cpp
src/rpcService/rpcServer.h
src/rpcService/rpcService.cpp
src/rpcService/rpcService.h
src/server/baseChannelRequester.cpp
src/server/baseChannelRequester.h
src/server/beaconEmitter.cpp
src/server/beaconEmitter.h
src/server/beaconServerStatusProvider.cpp
src/server/beaconServerStatusProvider.h
src/server/Makefile
src/server/responseHandlers.cpp
src/server/responseHandlers.h
src/server/serverChannelImpl.cpp
src/server/serverChannelImpl.h
src/server/serverContext.cpp
src/server/serverContext.h
src/utils/configuration.cpp
src/utils/configuration.h
src/utils/hexDump.cpp
src/utils/hexDump.h
src/utils/inetAddressUtil.cpp
src/utils/inetAddressUtil.h
src/utils/introspectionRegistry.cpp
src/utils/introspectionRegistry.h
src/utils/likely.h
src/utils/logger.cpp
src/utils/logger.h
src/utils/Makefile
src/utils/namedLockPattern.h
src/utils/referenceCountingLock.cpp
src/utils/referenceCountingLock.h
src/utils/wildcard.cpp
src/utils/wildcard.h
src/v3ioc/Makefile
src/v3ioc/PVAClientRegister.cpp
src/v3ioc/PVAServerRegister.cpp
src/v3ioc/syncChannelFind.h
src/Makefile
testApp/O.darwin-x86/Makefile
testApp/remote/O.darwin-x86/Makefile
testApp/remote/channelAccessIFTest.cpp
testApp/remote/channelAccessIFTest.h
testApp/remote/epicsv4Grayscale.h
testApp/remote/Makefile
testApp/remote/rpcClientExample.cpp
testApp/remote/rpcServiceExample.cpp
testApp/remote/rpcWildServiceExample.cpp
testApp/remote/syncTestRequesters.h
testApp/remote/testADCSim.cpp
testApp/remote/testChannelAccess.cpp
testApp/remote/testChannelConnect.cpp
testApp/remote/testCodec.cpp
testApp/remote/testGetPerformance.cpp
testApp/remote/testMonitorPerformance.cpp
testApp/remote/testNTImage.cpp
testApp/remote/testRemoteClientImpl.cpp
testApp/remote/testServer.cpp
testApp/remote/testServerContext.cpp
testApp/utils/O.darwin-x86/Makefile
testApp/utils/configurationTest.cpp
testApp/utils/introspectionRegistryTest.cpp
testApp/utils/loggerTest.cpp
testApp/utils/Makefile
testApp/utils/namedLockPatternTest.cpp
testApp/utils/testAtomicBoolean.cpp
testApp/utils/testHexDump.cpp
testApp/utils/testInetAddressUtils.cpp
testApp/utils/transportRegistryTest.cpp
testApp/Makefile
testApp/pvAccessAllTests.c
Makefile

View File

@@ -1,6 +1,22 @@
# Makefile for the pvAccess tests
TOP = ..
include $(TOP)/configure/CONFIG
DIRS += utils
DIRS += client
DIRS += remote
include $(TOP)/configure/RULES_DIRS
PVACCESS_TEST = $(TOP)/testApp
PROD_LIBS += pvAccess pvData pvMB Com
include $(PVACCESS_TEST)/utils/Makefile
include $(PVACCESS_TEST)/remote/Makefile
# The testHarness runs all the test programs in a known working order.
testHarness_SRCS += pvAccessAllTests.c
PROD_vxWorks = vxTestHarness
vxTestHarness_SRCS += $(testHarness_SRCS)
TESTSPEC_vxWorks = vxTestHarness.$(MUNCH_SUFFIX); pvAccessAllTests
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
include $(TOP)/configure/RULES

View File

@@ -1,20 +0,0 @@
TOP=../..
include $(TOP)/configure/CONFIG
#PROD_HOST += testChannelAccessFactory
testChannelAccessFactory_SRCS = testChannelAccessFactory.cpp
testChannelAccessFactory_LIBS = pvAccess pvData Com
#PROD_HOST += testMockClient
testMockClient_SRCS = testMockClient.cpp MockClientImpl.cpp
testMockClient_LIBS = pvAccess pvData Com
PROD_HOST += testStartStop
testStartStop_SRCS = testStartStop.cpp
testStartStop_LIBS = pvAccess pvData pvMB Com
include $(TOP)/configure/RULES
#----------------------------------------
# ADD RULES AFTER THIS LINE

View File

@@ -1,965 +0,0 @@
/* MockClientImpl.cpp */
/* Author: Matej Sekoranja Date: 2010.12.18 */
#include <epicsExit.h>
#include <pv/pvAccess.h>
#include <iostream>
#include <pv/lock.h>
#include <pv/standardPVField.h>
using namespace epics::pvData;
using namespace epics::pvAccess;
PVACCESS_REFCOUNT_MONITOR_DEFINE(mockChannelProcess);
class MockChannelProcess : public ChannelProcess
{
private:
ChannelProcessRequester* m_channelProcessRequester;
PVStructure* m_pvStructure;
PVScalar* m_valueField;
private:
~MockChannelProcess()
{
PVACCESS_REFCOUNT_MONITOR_DESTRUCT(mockChannelProcess);
}
public:
MockChannelProcess(ChannelProcessRequester* channelProcessRequester, PVStructure *pvStructure, PVStructure *pvRequest) :
m_channelProcessRequester(channelProcessRequester), m_pvStructure(pvStructure)
{
PVACCESS_REFCOUNT_MONITOR_CONSTRUCT(mockChannelProcess);
PVField* field = pvStructure->getSubField(std::string("value"));
if (field == 0)
{
Status noValueFieldStatus(Status::STATUSTYPE_ERROR, "no 'value' field");
m_channelProcessRequester->channelProcessConnect(noValueFieldStatus, this);
// NOTE client must destroy this instance...
// do not access any fields and return ASAP
return;
}
if (field->getField()->getType() != scalar)
{
Status notAScalarStatus(Status::STATUSTYPE_ERROR, "'value' field not scalar type");
m_channelProcessRequester->channelProcessConnect(notAScalarStatus, this);
// NOTE client must destroy this instance….
// do not access any fields and return ASAP
return;
}
m_valueField = static_cast<PVScalar*>(field);
// TODO pvRequest
m_channelProcessRequester->channelProcessConnect(Status::OK, this);
}
virtual void process(bool lastRequest)
{
switch (m_valueField->getScalar()->getScalarType())
{
case pvBoolean:
{
// negate
PVBoolean *pvBoolean = static_cast<PVBoolean*>(m_valueField);
pvBoolean->put(!pvBoolean->get());
break;
}
case pvByte:
{
// increment by one
PVByte *pvByte = static_cast<PVByte*>(m_valueField);
pvByte->put(pvByte->get() + 1);
break;
}
case pvShort:
{
// increment by one
PVShort *pvShort = static_cast<PVShort*>(m_valueField);
pvShort->put(pvShort->get() + 1);
break;
}
case pvInt:
{
// increment by one
PVInt *pvInt = static_cast<PVInt*>(m_valueField);
pvInt->put(pvInt->get() + 1);
break;
}
case pvLong:
{
// increment by one
PVLong *pvLong = static_cast<PVLong*>(m_valueField);
pvLong->put(pvLong->get() + 1);
break;
}
case pvFloat:
{
// increment by one
PVFloat *pvFloat = static_cast<PVFloat*>(m_valueField);
pvFloat->put(pvFloat->get() + 1.0f);
break;
}
case pvDouble:
{
// increment by one
PVDouble *pvDouble = static_cast<PVDouble*>(m_valueField);
pvDouble->put(pvDouble->get() + 1.0);
break;
}
case pvString:
{
// increment by one
PVString *pvString = static_cast<PVString*>(m_valueField);
string val = pvString->get();
if (val.empty())
pvString->put("gen0");
else
{
char c = val[0];
c++;
pvString->put("gen" + c);
}
break;
}
default:
// noop
break;
}
m_channelProcessRequester->processDone(Status::OK);
if (lastRequest)
destroy();
}
virtual void destroy()
{
delete this;
}
};
PVACCESS_REFCOUNT_MONITOR_DEFINE(mockChannelGet);
class MockChannelGet : public ChannelGet
{
private:
ChannelGetRequester* m_channelGetRequester;
PVStructure* m_pvStructure;
BitSet* m_bitSet;
bool m_first;
private:
~MockChannelGet()
{
PVACCESS_REFCOUNT_MONITOR_DESTRUCT(mockChannelGet);
}
public:
MockChannelGet(ChannelGetRequester* channelGetRequester, PVStructure *pvStructure, PVStructure *pvRequest) :
m_channelGetRequester(channelGetRequester), m_pvStructure(pvStructure),
m_bitSet(new BitSet(pvStructure->getNumberFields())), m_first(true)
{
PVACCESS_REFCOUNT_MONITOR_CONSTRUCT(mockChannelGet);
// TODO pvRequest
m_channelGetRequester->channelGetConnect(Status::OK, this, m_pvStructure, m_bitSet);
}
virtual void get(bool lastRequest)
{
m_channelGetRequester->getDone(Status::OK);
if (m_first)
{
m_first = false;
m_bitSet->set(0); // TODO
}
if (lastRequest)
destroy();
}
virtual void destroy()
{
delete m_bitSet;
delete this;
}
};
PVACCESS_REFCOUNT_MONITOR_DEFINE(mockChannelPut);
class MockChannelPut : public ChannelPut
{
private:
ChannelPutRequester* m_channelPutRequester;
PVStructure* m_pvStructure;
BitSet* m_bitSet;
bool m_first;
private:
~MockChannelPut()
{
PVACCESS_REFCOUNT_MONITOR_DESTRUCT(mockChannelPut);
}
public:
MockChannelPut(ChannelPutRequester* channelPutRequester, PVStructure *pvStructure, PVStructure *pvRequest) :
m_channelPutRequester(channelPutRequester), m_pvStructure(pvStructure),
m_bitSet(new BitSet(pvStructure->getNumberFields())), m_first(true)
{
PVACCESS_REFCOUNT_MONITOR_CONSTRUCT(mockChannelPut);
// TODO pvRequest
m_channelPutRequester->channelPutConnect(Status::OK, this, m_pvStructure, m_bitSet);
}
virtual void put(bool lastRequest)
{
m_channelPutRequester->putDone(Status::OK);
if (lastRequest)
destroy();
}
virtual void get()
{
m_channelPutRequester->getDone(Status::OK);
}
virtual void destroy()
{
delete m_bitSet;
delete this;
}
};
PVACCESS_REFCOUNT_MONITOR_DEFINE(mockMonitor);
class MockMonitor : public Monitor, public MonitorElement
{
private:
MonitorRequester* m_monitorRequester;
PVStructure* m_pvStructure;
BitSet* m_changedBitSet;
BitSet* m_overrunBitSet;
bool m_first;
Mutex m_lock;
int m_count;
private:
~MockMonitor()
{
PVACCESS_REFCOUNT_MONITOR_DESTRUCT(mockMonitor);
}
public:
MockMonitor(MonitorRequester* monitorRequester, PVStructure *pvStructure, PVStructure *pvRequest) :
m_monitorRequester(monitorRequester), m_pvStructure(pvStructure),
m_changedBitSet(new BitSet(pvStructure->getNumberFields())),
m_overrunBitSet(new BitSet(pvStructure->getNumberFields())),
m_first(true),
m_lock(),
m_count(0)
{
PVACCESS_REFCOUNT_MONITOR_CONSTRUCT(mockMonitor);
m_changedBitSet->set(0);
// TODO pvRequest
m_monitorRequester->monitorConnect(Status::OK, this, m_pvStructure->getStructure());
}
virtual Status start()
{
// fist monitor
m_monitorRequester->monitorEvent(this);
return Status::OK;
}
virtual Status stop()
{
return Status::OK;
}
virtual MonitorElement* poll()
{
Lock xx(m_lock);
if (m_count)
{
return 0;
}
else
{
m_count++;
return this;
}
}
virtual void release(MonitorElement* monitorElement)
{
Lock xx(m_lock);
if (m_count)
m_count--;
}
virtual void destroy()
{
stop();
delete m_overrunBitSet;
delete m_changedBitSet;
delete this;
}
// ============ MonitorElement ============
virtual PVStructure* getPVStructure()
{
return m_pvStructure;
}
virtual BitSet* getChangedBitSet()
{
return m_changedBitSet;
}
virtual BitSet* getOverrunBitSet()
{
return m_overrunBitSet;
}
};
PVACCESS_REFCOUNT_MONITOR_DEFINE(mockChannel);
class MockChannel : public Channel {
private:
ChannelProvider* m_provider;
ChannelRequester* m_requester;
string m_name;
string m_remoteAddress;
PVStructure* m_pvStructure;
private:
~MockChannel()
{
PVACCESS_REFCOUNT_MONITOR_DESTRUCT(mockChannel);
}
public:
MockChannel(
ChannelProvider* provider,
ChannelRequester* requester,
string name,
string remoteAddress) :
m_provider(provider),
m_requester(requester),
m_name(name),
m_remoteAddress(remoteAddress)
{
PVACCESS_REFCOUNT_MONITOR_CONSTRUCT(mockChannel);
ScalarType stype = pvDouble;
string allProperties("alarm,timeStamp,display,control,valueAlarm");
m_pvStructure = getStandardPVField()->scalar(
0,name,stype,allProperties);
PVDouble *pvField = m_pvStructure->getDoubleField(std::string("value"));
pvField->put(1.123);
// already connected, report state
m_requester->channelStateChange(this, CONNECTED);
}
virtual void destroy()
{
delete m_pvStructure;
delete this;
};
virtual string getRequesterName()
{
return getChannelName();
};
virtual void message(std::string const & message,MessageType messageType)
{
std::cout << "[" << getRequesterName() << "] message(" << message << ", " << messageTypeName[messageType] << ")" << std::endl;
}
virtual ChannelProvider* getProvider()
{
return m_provider;
}
virtual std::string getRemoteAddress()
{
return m_remoteAddress;
}
virtual std::string getChannelName()
{
return m_name;
}
virtual ChannelRequester* getChannelRequester()
{
return m_requester;
}
virtual ConnectionState getConnectionState()
{
return CONNECTED;
}
virtual bool isConnected()
{
return getConnectionState() == CONNECTED;
}
virtual AccessRights getAccessRights(epics::pvData::PVField *pvField)
{
return readWrite;
}
virtual void getField(GetFieldRequester *requester,std::string subField)
{
requester->getDone(Status::OK,m_pvStructure->getSubField(subField)->getField());
}
virtual ChannelProcess* createChannelProcess(
ChannelProcessRequester *channelProcessRequester,
epics::pvData::PVStructure *pvRequest)
{
return new MockChannelProcess(channelProcessRequester, m_pvStructure, pvRequest);
}
virtual ChannelGet* createChannelGet(
ChannelGetRequester *channelGetRequester,
epics::pvData::PVStructure *pvRequest)
{
return new MockChannelGet(channelGetRequester, m_pvStructure, pvRequest);
}
virtual ChannelPut* createChannelPut(
ChannelPutRequester *channelPutRequester,
epics::pvData::PVStructure *pvRequest)
{
return new MockChannelPut(channelPutRequester, m_pvStructure, pvRequest);
}
virtual ChannelPutGet* createChannelPutGet(
ChannelPutGetRequester *channelPutGetRequester,
epics::pvData::PVStructure *pvRequest)
{
// TODO
return 0;
}
virtual ChannelRPC* createChannelRPC(ChannelRPCRequester *channelRPCRequester,
epics::pvData::PVStructure *pvRequest)
{
// TODO
return 0;
}
virtual epics::pvData::Monitor* createMonitor(
epics::pvData::MonitorRequester *monitorRequester,
epics::pvData::PVStructure *pvRequest)
{
return new MockMonitor(monitorRequester, m_pvStructure, pvRequest);
}
virtual ChannelArray* createChannelArray(
ChannelArrayRequester *channelArrayRequester,
epics::pvData::PVStructure *pvRequest)
{
// TODO
return 0;
}
virtual void printInfo() {
string info;
printInfo(&info);
std::cout << info.c_str() << std::endl;
}
virtual void printInfo(epics::pvData::StringBuilder out) {
//std::ostringstream ostr;
//static string emptyString;
out->append( "CHANNEL : "); out->append(m_name);
out->append("\nSTATE : "); out->append(ConnectionStateNames[getConnectionState()]);
if (isConnected())
{
out->append("\nADDRESS : "); out->append(getRemoteAddress());
//out->append("\nRIGHTS : "); out->append(getAccessRights());
}
out->append("\n");
}
};
class MockChannelProvider;
class MockChannelFind : public ChannelFind
{
public:
MockChannelFind(ChannelProvider* provider) : m_provider(provider)
{
}
virtual void destroy()
{
// one instance for all, do not delete at all
}
virtual ChannelProvider* getChannelProvider()
{
return m_provider;
};
virtual void cancel()
{
throw std::runtime_error("not supported");
}
private:
// only to be destroyed by it
friend class MockChannelProvider;
virtual ~MockChannelFind() {}
ChannelProvider* m_provider;
};
class MockChannelProvider : public ChannelProvider {
public:
MockChannelProvider() : m_mockChannelFind(new MockChannelFind(this)) {
}
virtual std::string getProviderName()
{
return "MockChannelProvider";
}
virtual void destroy()
{
delete m_mockChannelFind;
delete this;
}
virtual ChannelFind* channelFind(
std::string channelName,
ChannelFindRequester *channelFindRequester)
{
channelFindRequester->channelFindResult(Status::OK, m_mockChannelFind, true);
return m_mockChannelFind;
}
virtual Channel* createChannel(
std::string channelName,
ChannelRequester *channelRequester,
short priority)
{
return createChannel(channelName, channelRequester, priority, "local");
}
virtual Channel* createChannel(
std::string channelName,
ChannelRequester *channelRequester,
short priority,
std::string address)
{
if (address == "local")
{
Channel* channel = new MockChannel(this, channelRequester, channelName, address);
channelRequester->channelCreated(Status::OK, channel);
return channel;
}
else
{
Status errorStatus(Status::STATUSTYPE_ERROR, "only local supported");
channelRequester->channelCreated(errorStatus, 0);
return 0;
}
}
private:
~MockChannelProvider() {};
MockChannelFind* m_mockChannelFind;
};
class MockClientContext : public ClientContext
{
public:
MockClientContext() : m_version(new Version("Mock PVA Client", "cpp", 1, 0, 0, 0))
{
initialize();
}
virtual Version* getVersion() {
return m_version;
}
virtual ChannelProvider* getProvider() {
return m_provider;
}
virtual void initialize() {
m_provider = new MockChannelProvider();
}
virtual void printInfo() {
string info;
printInfo(&info);
std::cout << info.c_str() << std::endl;
}
virtual void printInfo(epics::pvData::StringBuilder out) {
out->append(m_version->getVersionString());
}
virtual void destroy()
{
m_provider->destroy();
delete m_version;
delete this;
}
virtual void dispose()
{
destroy();
}
private:
~MockClientContext() {};
Version* m_version;
MockChannelProvider* m_provider;
};
class ChannelFindRequesterImpl : public ChannelFindRequester
{
virtual void channelFindResult(const epics::pvData::Status& status,ChannelFind *channelFind,bool wasFound)
{
std::cout << "[ChannelFindRequesterImpl] channelFindResult("
<< status.toString() << ", ..., " << wasFound << ")" << std::endl;
}
};
class ChannelRequesterImpl : public ChannelRequester
{
virtual string getRequesterName()
{
return "ChannelRequesterImpl";
};
virtual void message(std::string const & message,MessageType messageType)
{
std::cout << "[" << getRequesterName() << "] message(" << message << ", " << messageTypeName[messageType] << ")" << std::endl;
}
virtual void channelCreated(const epics::pvData::Status& status, Channel *channel)
{
std::cout << "channelCreated(" << status.toString() << ", "
<< (channel ? channel->getChannelName() : "(null)") << ")" << std::endl;
}
virtual void channelStateChange(Channel *c, Channel::ConnectionState connectionState)
{
std::cout << "channelStateChange(" << c->getChannelName() << ", " << Channel::ConnectionStateNames[connectionState] << ")" << std::endl;
}
};
class GetFieldRequesterImpl : public GetFieldRequester
{
virtual string getRequesterName()
{
return "GetFieldRequesterImpl";
};
virtual void message(std::string const & message,MessageType messageType)
{
std::cout << "[" << getRequesterName() << "] message(" << message << ", " << messageTypeName[messageType] << ")" << std::endl;
}
virtual void getDone(const epics::pvData::Status& status,epics::pvData::FieldConstPtr field)
{
std::cout << "getDone(" << status.toString() << ", ";
if (field)
{
string str;
field->toString(&str);
std::cout << str;
}
else
std::cout << "(null)";
std::cout << ")" << std::endl;
}
};
class ChannelGetRequesterImpl : public ChannelGetRequester
{
ChannelGet *m_channelGet;
epics::pvData::PVStructure *m_pvStructure;
epics::pvData::BitSet *m_bitSet;
virtual string getRequesterName()
{
return "ChannelGetRequesterImpl";
};
virtual void message(std::string const & message,MessageType messageType)
{
std::cout << "[" << getRequesterName() << "] message(" << message << ", " << messageTypeName[messageType] << ")" << std::endl;
}
virtual void channelGetConnect(const epics::pvData::Status& status,ChannelGet *channelGet,
epics::pvData::PVStructure *pvStructure,epics::pvData::BitSet *bitSet)
{
std::cout << "channelGetConnect(" << status.toString() << ")" << std::endl;
// TODO sync
m_channelGet = channelGet;
m_pvStructure = pvStructure;
m_bitSet = bitSet;
}
virtual void getDone(const epics::pvData::Status& status)
{
std::cout << "getDone(" << status.toString() << ")" << std::endl;
string str;
m_pvStructure->toString(&str);
std::cout << str;
std::cout << std::endl;
}
};
class ChannelPutRequesterImpl : public ChannelPutRequester
{
ChannelPut *m_channelPut;
epics::pvData::PVStructure *m_pvStructure;
epics::pvData::BitSet *m_bitSet;
virtual string getRequesterName()
{
return "ChannelPutRequesterImpl";
};
virtual void message(std::string const & message,MessageType messageType)
{
std::cout << "[" << getRequesterName() << "] message(" << message << ", " << messageTypeName[messageType] << ")" << std::endl;
}
virtual void channelPutConnect(const epics::pvData::Status& status,ChannelPut *channelPut,
epics::pvData::PVStructure *pvStructure,epics::pvData::BitSet *bitSet)
{
std::cout << "channelPutConnect(" << status.toString() << ")" << std::endl;
// TODO sync
m_channelPut = channelPut;
m_pvStructure = pvStructure;
m_bitSet = bitSet;
}
virtual void getDone(const epics::pvData::Status& status)
{
std::cout << "getDone(" << status.toString() << ")" << std::endl;
string str;
m_pvStructure->toString(&str);
std::cout << str;
std::cout << std::endl;
}
virtual void putDone(const epics::pvData::Status& status)
{
std::cout << "putDone(" << status.toString() << ")" << std::endl;
string str;
m_pvStructure->toString(&str);
std::cout << str;
std::cout << std::endl;
}
};
class MonitorRequesterImpl : public MonitorRequester
{
virtual string getRequesterName()
{
return "MonitorRequesterImpl";
};
virtual void message(std::string const & message,MessageType messageType)
{
std::cout << "[" << getRequesterName() << "] message(" << message << ", " << messageTypeName[messageType] << ")" << std::endl;
}
virtual void monitorConnect(const Status& status, Monitor* monitor, StructureConstPtr structure)
{
std::cout << "monitorConnect(" << status.toString() << ")" << std::endl;
if (structure)
{
string str;
structure->toString(&str);
std::cout << str << std::endl;
}
}
virtual void monitorEvent(Monitor* monitor)
{
std::cout << "monitorEvent" << std::endl;
MonitorElement* element = monitor->poll();
string str("changed/overrun ");
element->getChangedBitSet()->toString(&str);
str += '/';
element->getOverrunBitSet()->toString(&str);
str += '\n';
element->getPVStructure()->toString(&str);
std::cout << str << std::endl;
monitor->release(element);
}
virtual void unlisten(Monitor* monitor)
{
std::cout << "unlisten" << std::endl;
}
};
class ChannelProcessRequesterImpl : public ChannelProcessRequester
{
ChannelProcess *m_channelProcess;
virtual string getRequesterName()
{
return "ProcessRequesterImpl";
};
virtual void message(std::string const & message,MessageType messageType)
{
std::cout << "[" << getRequesterName() << "] message(" << message << ", " << messageTypeName[messageType] << ")" << std::endl;
}
virtual void channelProcessConnect(const epics::pvData::Status& status,ChannelProcess *channelProcess)
{
std::cout << "channelProcessConnect(" << status.toString() << ")" << std::endl;
// TODO sync
m_channelProcess = channelProcess;
}
virtual void processDone(const epics::pvData::Status& status)
{
std::cout << "processDone(" << status.toString() << ")" << std::endl;
}
};
int main(int argc,char *argv[])
{
MockClientContext* context = new MockClientContext();
context->printInfo();
ChannelFindRequesterImpl findRequester;
context->getProvider()->channelFind("something", &findRequester);
ChannelRequesterImpl channelRequester;
//Channel* noChannel
context->getProvider()->createChannel("test", &channelRequester, ChannelProvider::PRIORITY_DEFAULT, "over the rainbow");
Channel* channel = context->getProvider()->createChannel("test", &channelRequester);
channel->printInfo();
GetFieldRequesterImpl getFieldRequesterImpl;
channel->getField(&getFieldRequesterImpl, "timeStamp.secondsPastEpoch");
ChannelGetRequesterImpl channelGetRequesterImpl;
ChannelGet* channelGet = channel->createChannelGet(&channelGetRequesterImpl, 0);
channelGet->get(false);
channelGet->destroy();
ChannelPutRequesterImpl channelPutRequesterImpl;
ChannelPut* channelPut = channel->createChannelPut(&channelPutRequesterImpl, 0);
channelPut->get();
channelPut->put(false);
channelPut->destroy();
MonitorRequesterImpl monitorRequesterImpl;
Monitor* monitor = channel->createMonitor(&monitorRequesterImpl, 0);
Status status = monitor->start();
std::cout << "monitor->start() = " << status.toString() << std::endl;
ChannelProcessRequesterImpl channelProcessRequester;
ChannelProcess* channelProcess = channel->createChannelProcess(&channelProcessRequester, 0);
channelProcess->process(false);
channelProcess->destroy();
status = monitor->stop();
std::cout << "monitor->stop() = " << status.toString() << std::endl;
monitor->destroy();
channel->destroy();
context->destroy();
//std::cout << "-----------------------------------------------------------------------" << std::endl;
//epicsExitCallAtExits();
return(0);
}

View File

@@ -1,88 +0,0 @@
/* testChannelAccessFactory.cpp */
/* Author: Matej Sekoranja Date: 2010.11.03 */
#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <pv/pvAccess.h>
#include <epicsAssert.h>
using namespace epics::pvData;
using namespace epics::pvAccess;
class DummyChannelProvider : public ChannelProvider {
private:
string m_name;
public:
DummyChannelProvider(std::string name) : m_name(name) {};
void destroy() {};
string getProviderName() { return m_name; };
ChannelFind* channelFind(std::string channelName,ChannelFindRequester *channelFindRequester)
{ return 0; }
Channel* createChannel(std::string channelName,ChannelRequester *channelRequester,short priority)
{ return 0; }
Channel* createChannel(std::string channelName,ChannelRequester *channelRequester,short priority,String address)
{ return 0; }
};
void testChannelAccessFactory() {
printf("testChannelAccessFactory... ");
ChannelAccess* ca = getChannelProviderRegistry();
assert(ca);
// empty
std::vector<String>* providers = ca->getProviderNames();
assert(providers);
assert(providers->size() == 0);
delete providers;
// register 2
ChannelProvider* cp1 = new DummyChannelProvider("dummy1");
registerChannelProvider(cp1);
ChannelProvider* cp2 = new DummyChannelProvider("dummy2");
registerChannelProvider(cp2);
providers = ca->getProviderNames();
assert(providers);
assert(providers->size() == 2);
assert(providers->at(0) == "dummy1");
assert(providers->at(1) == "dummy2");
assert(ca->getProvider("dummy1") == cp1);
assert(ca->getProvider("dummy2") == cp2);
delete providers;
// unregister first
unregisterChannelProvider(cp1);
providers = ca->getProviderNames();
assert(providers);
assert(providers->size() == 1);
assert(providers->at(0) == "dummy2");
assert(ca->getProvider("dummy2") == cp2);
delete providers;
printf("PASSED\n");
}
int main(int argc,char *argv[])
{
testChannelAccessFactory();
return(0);
}

View File

@@ -1 +0,0 @@
/* testMockClient.cpp */

View File

@@ -1,14 +0,0 @@
#include <iostream>
#include <pv/clientFactory.h>
int main() {
std::cout << "to start pvAccess ClientFactory" << std::endl;
::epics::pvAccess::ClientFactory::start();
std::cout << "do nothing after starting pvAccess ClientFactory" << std::endl;
std::cout << "to stop pvAccess ClientFactory" << std::endl;
::epics::pvAccess::ClientFactory::stop();
std::cout << "finish test" << std::endl;
return 0;
}

View File

@@ -0,0 +1,35 @@
/*
* Run pvData tests as a batch.
*
* Do *not* include performance measurements here, they don't help to
* prove functionality (which is the point of this convenience routine).
*/
#include <stdio.h>
#include <epicsThread.h>
#include <epicsUnitTest.h>
/* utils */
int testAtomicBoolean(void);
int testHexDump(void);
int testInetAddressUtils(void);
/* remote */
int testCodec(void);
int testChannelAccess(void);
void pvAccessAllTests(void)
{
testHarness();
/* utils */
runTest(testAtomicBoolean);
runTest(testHexDump);
runTest(testInetAddressUtils);
/* remote */
runTest(testCodec);
runTest(testChannelAccess);
}

View File

@@ -1,84 +1,43 @@
TOP=../..
# This is a Makefile fragment, see ../Makefile
include $(TOP)/configure/CONFIG
#PROD_HOST += testBlockingUDPSrv
testBlockingUDPSrv_SRCS += testBlockingUDPSrv.cpp
testBlockingUDPSrv_LIBS += pvAccess pvData pvMB Com
#PROD_HOST += testBlockingUDPClnt
testBlockingUDPClnt_SRCS += testBlockingUDPClnt.cpp
testBlockingUDPClnt_LIBS += pvAccess pvData pvMB Com
PROD_HOST += testRemoteClientImpl
testRemoteClientImpl_SRCS += testRemoteClientImpl.cpp
testRemoteClientImpl_LIBS += pvAccess pvData pvMB Com
PROD_HOST += testChannelConnect
testChannelConnect_SRCS += testChannelConnect.cpp
testChannelConnect_LIBS += pvAccess pvData pvMB Com
#PROD_HOST += testBeaconEmitter
testBeaconEmitter_SRCS += testBeaconEmitter.cpp
testBeaconEmitter_LIBS += pvAccess pvData Com
#PROD_HOST += testBeaconHandler
testBeaconHandler_SRCS += testBeaconHandler.cpp
testBeaconHandler_LIBS += pvAccess pvData Com
#PROD_HOST += testChannelSearchManager
#testChannelSearchManager_SRCS += testChannelSearchManager.cpp
#testChannelSearchManager_LIBS += pvAccess pvData Com
#PROD_HOST += testBlockingTCPSrv
testBlockingTCPSrv_SRCS += testBlockingTCPSrv.cpp
testBlockingTCPSrv_LIBS += pvAccess pvData pvMB Com
#PROD_HOST += testBlockingTCPClnt
testBlockingTCPClnt_SRCS += testBlockingTCPClnt.cpp
testBlockingTCPClnt_LIBS += pvAccess pvData pvMB Com
PROD_HOST += testServerContext
testServerContext_SRCS += testServerContext.cpp
testServerContext_LIBS += pvAccess pvData pvMB Com
PROD_HOST += testServer
testServer_SRCS += testServer.cpp
testServer_LIBS += pvAccess pvData pvMB Com
SRC_DIRS += $(PVACCESS_TEST)/remote
TESTPROD_HOST += testChannelAccess
testChannelAccess_SRCS = testChannelAccess channelAccessIFTest
testChannelAccess_LIBS += pvAccess pvData pvMB Com
testHarness_SRCS += testChannelAccess.cpp
TESTS += testChannelAccess
TESTPROD_HOST += testCodec
testCodec_SRCS = testCodec
testCodec_LIBS += pvAccess pvData pvMB Com
testHarness_SRCS += testChannelAccess.cpp
TESTS += testCodec
TESTPROD_HOST += testRemoteClientImpl
testRemoteClientImpl_SRCS += testRemoteClientImpl.cpp
TESTPROD_HOST += testChannelConnect
testChannelConnect_SRCS += testChannelConnect.cpp
TESTPROD_HOST += testServerContext
testServerContext_SRCS += testServerContext.cpp
PROD_HOST += testServer
testServer_SRCS += testServer.cpp
PROD_HOST += testGetPerformance
testGetPerformance_SRCS += testGetPerformance.cpp
testGetPerformance_LIBS += pvAccess pvData pvMB Com
PROD_HOST += testMonitorPerformance
testMonitorPerformance_SRCS += testMonitorPerformance.cpp
testMonitorPerformance_LIBS += pvAccess pvData pvMB Com
PROD_HOST += rpcServiceExample
rpcServiceExample_SRCS += rpcServiceExample.cpp
rpcServiceExample_LIBS += pvAccess pvData pvMB Com
PROD_HOST += rpcWildServiceExample
rpcWildServiceExample_SRCS += rpcWildServiceExample.cpp
rpcWildServiceExample_LIBS += pvAccess pvData pvMB Com
PROD_HOST += rpcClientExample
rpcClientExample_SRCS += rpcClientExample.cpp
rpcClientExample_LIBS += pvAccess pvData pvMB Com
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
include $(TOP)/configure/RULES
#----------------------------------------
# ADD RULES AFTER THIS LINE

View File

@@ -1,88 +0,0 @@
/*
* testBeaconEmitter.cpp
*/
#include <pv/remote.h>
#include <pv/blockingUDP.h>
#include <pv/beaconEmitter.h>
#include <pv/inetAddressUtil.h>
#include <osiSock.h>
#include <iostream>
#include <cstdio>
using namespace epics::pvAccess;
using namespace epics::pvData;
class DummyResponseHandler : public ResponseHandler
{
public:
DummyResponseHandler(Context* ctx) : ResponseHandler() {}
virtual void handleResponse(osiSockAddr* responseFrom,
Transport* transport, int8 version, int8 command, int payloadSize,
ByteBuffer* payloadBuffer)
{
cout << "DummyResponseHandler::handleResponse" << endl;
}
};
class ContextImpl : public Context {
public:
ContextImpl() :
_tr(new TransportRegistry()), _timer(new Timer("server thread",
lowPriority)), _conf(new SystemConfigurationImpl()) {
}
virtual ~ContextImpl() {
delete _tr;
delete _timer;
}
virtual Timer* getTimer() { return _timer; }
virtual TransportRegistry* getTransportRegistry() { return _tr; }
virtual Channel* getChannel(epics::pvAccess::pvAccessID) { return 0; }
virtual Transport* getSearchTransport() { return 0; }
virtual Configuration* getConfiguration() { return _conf; }
virtual void acquire() {}
virtual void release() {}
private:
TransportRegistry* _tr;
Timer* _timer;
Configuration* _conf;
};
void testBeaconEmitter()
{
ContextImpl ctx;
DummyResponseHandler drh(&ctx);
SOCKET socket = epicsSocketCreate(AF_INET, SOCK_DGRAM, 0);
auto_ptr<InetAddrVector> broadcastAddresses(getBroadcastAddresses(socket, 5067));
epicsSocketDestroy (socket);
BlockingUDPConnector connector(true, true);
osiSockAddr bindAddr;
bindAddr.ia.sin_family = AF_INET;
bindAddr.ia.sin_port = htons(5066);
bindAddr.ia.sin_addr.s_addr = htonl(INADDR_ANY);
BlockingUDPTransport* transport = (BlockingUDPTransport*)connector.connect(NULL, &drh, bindAddr, 1, 50);
transport->setBroadcastAddresses(broadcastAddresses.get());
cout<<"Sending beacons"<<endl;
BeaconEmitter beaconEmitter(transport, transport->getRemoteAddress());
beaconEmitter.start();
epicsThreadSleep (60.0);
delete transport;
}
int main(int argc, char *argv[])
{
testBeaconEmitter();
return (0);
}

View File

@@ -1,136 +0,0 @@
/*
* testBeaconEmitter.cpp
*/
#include <pv/remote.h>
#include <pv/blockingUDP.h>
#include <pv/beaconHandler.h>
#include <pv/inetAddressUtil.h>
#include <pv/introspectionRegistry.h>
#include <osiSock.h>
#include <iostream>
#include <cstdio>
using namespace epics::pvAccess;
using namespace epics::pvData;
using namespace std;
class BeaconResponseHandler : public ResponseHandler
{
public:
BeaconResponseHandler(Context* ctx) : ResponseHandler()
{
_pvDataCreate = getPVDataCreate();
}
virtual void handleResponse(osiSockAddr* responseFrom,
Transport* transport, int8 version, int8 command, int payloadSize,
ByteBuffer* payloadBuffer)
{
cout << "BeaconResponseHandler::handleResponse" << endl;
// reception timestamp
TimeStamp timestamp;
timestamp.getCurrent();
//TODO
//super.handleResponse(responseFrom, transport, version, command, payloadSize, payloadBuffer);
transport->ensureData((2*sizeof(int16)+2*sizeof(int32)+128)/sizeof(int8));
/*const int32 sequentalID = */ payloadBuffer->getShort();
const TimeStamp startupTimestamp(payloadBuffer->getInt(),payloadBuffer->getInt());
// 128-bit IPv6 address
osiSockAddr address;
decodeFromIPv6Address(payloadBuffer, &address);
// get port
const int32 port = payloadBuffer->getShort();
address.ia.sin_port = ntohs(port);
// accept given address if explicitly specified by sender
if (!ipv4AddressToInt(address))
{
responseFrom->ia.sin_port = port;
}
else
{
responseFrom->ia.sin_port = port;
responseFrom->ia.sin_addr.s_addr = address.ia.sin_addr.s_addr;
}
//org.epics.ca.client.impl.remote.BeaconHandler beaconHandler = context.getBeaconHandler(responseFrom);
// currently we care only for servers used by this context
//if (beaconHandler == null)
// return;
// extra data
PVFieldPtr data = NULL;
const FieldConstPtr field = IntrospectionRegistry::deserializeFull(payloadBuffer, transport);
if (field != NULL)
{
data = _pvDataCreate->createPVField(NULL, field);
data->deserialize(payloadBuffer, transport);
}
// notify beacon handler
//beaconHandler.beaconNotify(responseFrom, version, timestamp, startupTimestamp, sequentalID, data);
}
private:
PVDataCreate* _pvDataCreate;
BeaconHandler* _beaconHandler;
};
class ContextImpl : public Context {
public:
ContextImpl() :
_tr(new TransportRegistry()), _timer(new Timer("server thread",
lowPriority)), _conf(new SystemConfigurationImpl()) {
}
virtual ~ContextImpl() {
delete _tr;
delete _timer;
}
virtual Timer* getTimer() { return _timer; }
virtual TransportRegistry* getTransportRegistry() { return _tr; }
virtual Channel* getChannel(epics::pvAccess::pvAccessID) { return 0; }
virtual Transport* getSearchTransport() { return 0; }
virtual Configuration* getConfiguration() { return _conf; }
virtual void acquire() {}
virtual void release() {}
private:
TransportRegistry* _tr;
Timer* _timer;
Configuration* _conf;
};
void testBeaconHandler()
{
ContextImpl ctx;
BeaconResponseHandler brh(&ctx);
BlockingUDPConnector connector(false, true);
osiSockAddr bindAddr;
bindAddr.ia.sin_family = AF_INET;
bindAddr.ia.sin_port = htons(5067);
bindAddr.ia.sin_addr.s_addr = htonl(INADDR_ANY);
Transport* transport = connector.connect(NULL, &brh, bindAddr, 1, 50);
(static_cast<BlockingUDPTransport*>(transport))->start();
epicsThreadSleep (60.0);
delete transport;
}
int main(int argc, char *argv[])
{
testBeaconHandler();
return (0);
}

View File

@@ -1,178 +0,0 @@
/*
* testBlockingTCPClnt.cpp
*
* Created on: Jan 6, 2011
* Author: Miha Vitorovic
*/
#include <pv/remote.h>
#include <pv/blockingTCP.h>
#include <pv/logger.h>
#include <pv/inetAddressUtil.h>
#include <pv/pvaConstants.h>
#include <pv/timer.h>
#include <pv/epicsException.h>
#include <pv/pvType.h>
#include <osiSock.h>
#include <epicsThread.h>
#include <pv/logger.h>
#include <iostream>
#include <cstdio>
using std::tr1::static_pointer_cast;
using namespace epics::pvAccess;
using namespace epics::pvData;
using std::cout;
using std::endl;
using std::sscanf;
class ContextImpl : public Context {
public:
ContextImpl() :
_tr(new TransportRegistry()), _timer(new Timer("server thread",
lowPriority)), _conf(new SystemConfigurationImpl())
{}
virtual ~ContextImpl() {
}
virtual Timer::shared_pointer getTimer() {
return _timer;
}
virtual std::tr1::shared_ptr<TransportRegistry> getTransportRegistry() {
return _tr;
}
virtual std::tr1::shared_ptr<Channel> getChannel(epics::pvAccess::pvAccessID) {
return std::tr1::shared_ptr<Channel>();
}
virtual Transport::shared_pointer getSearchTransport() {
return Transport::shared_pointer();
}
virtual Configuration::shared_pointer getConfiguration() {
return _conf;
}
virtual void acquire() {}
virtual void release() {}
virtual void newServerDetected() {}
private:
std::tr1::shared_ptr<TransportRegistry> _tr;
Timer::shared_pointer _timer;
Configuration::shared_pointer _conf;
};
class DummyResponseHandler : public ResponseHandler {
public:
DummyResponseHandler() :
ResponseHandler() {
}
virtual void handleResponse(osiSockAddr* /*responseFrom*/,
Transport::shared_pointer const & transport, int8 /*version*/, int8 command, std::size_t /*payloadSize*/,
ByteBuffer* /*payloadBuffer*/) {
if(command==CMD_CONNECTION_VALIDATION) transport->verified();
}
};
class DummyTransportClient : public TransportClient {
public:
DummyTransportClient() {
}
virtual ~DummyTransportClient() {
}
virtual void transportUnresponsive() {
LOG(logLevelInfo, "unresponsive");
}
virtual void transportResponsive(Transport::shared_pointer const & /*transport*/) {
LOG(logLevelInfo, "responsive");
}
virtual void transportChanged() {
LOG(logLevelInfo, "changed");
}
virtual void transportClosed() {
LOG(logLevelInfo, "closed");
}
virtual void acquire() {};
virtual void release() {};
virtual pvAccessID getID() {return 0;};
};
class DummyTransportSender : public TransportSender {
public:
DummyTransportSender() {
for(int i = 0; i<20; i++)
data[i] = (char)(i+1);
count = 0;
}
virtual void send(ByteBuffer* buffer, TransportSendControl* control) {
// send the packet
count++;
// using invalid command to force msg dump
control->startMessage(0xC0, count);
buffer->put(data, 0, count);
//control->endMessage();
}
virtual void lock() {
}
virtual void unlock() {
}
virtual void acquire() {
}
virtual void release() {
}
private:
char data[20];
int count;
};
void testBlockingTCPSender() {
Context::shared_pointer ctx(new ContextImpl());
BlockingTCPConnector connector(ctx, 1024, 1.0);
TransportClient::shared_pointer dtc(new DummyTransportClient());
TransportSender::shared_pointer dts(new DummyTransportSender());
std::auto_ptr<ResponseHandler> drh(new DummyResponseHandler());
osiSockAddr srvAddr;
//srvAddr.ia.sin_family = AF_INET;
if(aToIPAddr("localhost", PVA_SERVER_PORT, &srvAddr.ia)<0) {
cout<<"error in aToIPAddr(...)"<<endl;
return;
}
try {
Transport::shared_pointer transport(connector.connect(dtc, drh, srvAddr,
PVA_VERSION, PVA_DEFAULT_PRIORITY));
cout<<"Sending 10 messages..."<<endl;
for(int i = 0; i<10; i++) {
cout<<" Message: "<<i+1<<endl;
if(!transport->isClosed())
transport->enqueueSendRequest(dts);
else
break;
epicsThreadSleep(1.0);
}
} catch(std::exception& e) {
cout<<e.what()<<endl;
}
}
int main() {
createFileLogger("testBlockingTCPClnt.log");
testBlockingTCPSender();
return 0;
}

View File

@@ -1,73 +0,0 @@
/*
* testBlockingTCPSrv.cpp
*
* Created on: Jan 6, 2011
* Author: Miha Vitorovic
*/
#include <pv/blockingTCP.h>
#include <pv/remote.h>
#include <pv/logger.h>
#include <pv/configuration.h>
#include <pv/serverContext.h>
#include <iostream>
using namespace epics::pvData;
using namespace epics::pvAccess;
using namespace std;
class ContextImpl : public ServerContextImpl {
public:
ContextImpl() :
_tr(new TransportRegistry()),
_timer(new Timer("server thread", lowPriority)),
_conf(new SystemConfigurationImpl()) {}
Timer::shared_pointer getTimer() { return _timer; }
std::tr1::shared_ptr<TransportRegistry> getTransportRegistry() { return _tr; }
Channel::shared_pointer getChannel(epics::pvAccess::pvAccessID) { return Channel::shared_pointer(); }
Transport::shared_pointer getSearchTransport() { return Transport::shared_pointer(); }
Configuration::shared_pointer getConfiguration() { return _conf; }
virtual void acquire() {}
virtual void release() {}
private:
std::tr1::shared_ptr<TransportRegistry> _tr;
Timer::shared_pointer _timer;
Configuration::shared_pointer _conf;
};
class DummyResponseHandler : public ResponseHandler {
public:
virtual void handleResponse(osiSockAddr* /*responseFrom*/,
Transport::shared_pointer const & /*transport*/, int8 /*version*/, int8 /*command*/, std::size_t /*payloadSize*/,
ByteBuffer* /*payloadBuffer*/) {
cout << "DummyResponseHandler::handleResponse" << endl;
}
};
class DummyResponseHandlerFactory : public ResponseHandlerFactory
{
public:
std::auto_ptr<ResponseHandler> createResponseHandler() {return std::auto_ptr<ResponseHandler>(new DummyResponseHandler());};
};
void testServerConnections() {
Context::shared_pointer ctx(new ContextImpl());
ResponseHandlerFactory::shared_pointer rhf(new DummyResponseHandlerFactory());
BlockingTCPAcceptor* srv = new BlockingTCPAcceptor(ctx, rhf, PVA_SERVER_PORT, 1024);
cout<<"Press any key to stop the server...";
cin.peek();
delete srv;
}
int main() {
createFileLogger("testBlockingTCPSrv.log");
testServerConnections();
}

View File

@@ -1,144 +0,0 @@
/*
* testBlockingUDPClnt.cpp
*
* Created on: Dec 28, 2010
* Author: Miha Vitorovic
*/
#include <pv/remote.h>
#include <pv/blockingUDP.h>
#include <pv/logger.h>
#include <pv/inetAddressUtil.h>
//#include <pv/CDRMonitor.h>
#include <osiSock.h>
#include <epicsThread.h>
#include <iostream>
#include <cstdio>
#define SRV_IP "127.0.0.1"
using namespace epics::pvAccess;
using namespace epics::pvData;
using std::tr1::static_pointer_cast;
using namespace std;
static osiSockAddr sendTo;
class ContextImpl : public Context {
public:
ContextImpl() {}
virtual ~ContextImpl() {
}
virtual Timer::shared_pointer getTimer() {
return Timer::shared_pointer();
}
virtual std::tr1::shared_ptr<TransportRegistry> getTransportRegistry() {
return std::tr1::shared_ptr<TransportRegistry>();
}
virtual std::tr1::shared_ptr<Channel> getChannel(epics::pvAccess::pvAccessID) {
return std::tr1::shared_ptr<Channel>();
}
virtual Transport::shared_pointer getSearchTransport() {
return Transport::shared_pointer();
}
virtual Configuration::shared_pointer getConfiguration() {
return Configuration::shared_pointer();
}
virtual void acquire() {}
virtual void release() {}
virtual void newServerDetected() {}
};
class DummyResponseHandler : public ResponseHandler {
public:
DummyResponseHandler(Context* /*ctx*/)
{ }
virtual ~DummyResponseHandler() {}
virtual void handleResponse(osiSockAddr* /*responseFrom*/,
Transport::shared_pointer const & /*transport*/, int8 /*version*/, int8 /*command*/, std::size_t /*payloadSize*/,
ByteBuffer* /*payloadBuffer*/) {
}
};
class DummyTransportSender : public TransportSender {
public:
typedef std::tr1::shared_ptr<DummyTransportSender> shared_pointer;
typedef std::tr1::shared_ptr<const DummyTransportSender> const_pointer;
DummyTransportSender() {
for(int i = 0; i<20; i++)
data[i] = (char)(i+1);
count = 0;
}
virtual void send(ByteBuffer* buffer, TransportSendControl* control) {
control->setRecipient(sendTo);
// send the packet
count++;
control->startMessage((int8)(count+0x10), 0);
buffer->put(data, 0, count);
//control->endMessage();
}
virtual void lock() {
}
virtual void unlock() {
}
virtual void acquire() {
}
virtual void release() {
}
private:
char data[20];
int count;
};
void testBlockingUDPSender() {
BlockingUDPConnector connector(false, true);
ContextImpl ctx;
auto_ptr<ResponseHandler> drh(new DummyResponseHandler(&ctx));
TransportSender::shared_pointer dts(new DummyTransportSender());
osiSockAddr bindAddr;
bindAddr.ia.sin_family = AF_INET;
bindAddr.ia.sin_port = htons(65001);
bindAddr.ia.sin_addr.s_addr = htonl(INADDR_ANY);
TransportClient::shared_pointer nullPointer;
Transport::shared_pointer transport(connector.connect(nullPointer, drh, bindAddr, 1, 50));
// SRV_IP defined at the top of the this file
if(aToIPAddr(SRV_IP, 65000, &sendTo.ia)<0) {
cout<<"error in aToIPAddr(...)"<<endl;
return;
}
cout<<"Sending 10 packets..."<<endl;
for(int i = 0; i<10; i++) {
cout<<" Packet: "<<i+1<<endl;
transport->enqueueSendRequest(dts);
epicsThreadSleep(1.0);
}
}
int main() {
// createFileLogger("testBlockingUDPClnt.log");
testBlockingUDPSender();
// std::cout << "-----------------------------------------------------------------------" << std::endl;
// getShowConstructDestruct()->constuctDestructTotals(stdout);
return (0);
}

View File

@@ -1,131 +0,0 @@
/*
* blockingUDPTest.cpp
*
* Created on: Dec 28, 2010
* Author: Miha Vitorovic
*/
#include <pv/remote.h>
#include <pv/blockingUDP.h>
#include <pv/logger.h>
#include <pv/hexDump.h>
#include <osiSock.h>
#include <epicsThread.h>
#include <iostream>
#include <sstream>
using namespace epics::pvAccess;
using namespace epics::pvData;
using namespace std;
using std::tr1::static_pointer_cast;
class ContextImpl : public Context {
public:
ContextImpl() {}
virtual ~ContextImpl() {
}
virtual Timer::shared_pointer getTimer() {
return Timer::shared_pointer();
}
virtual std::tr1::shared_ptr<TransportRegistry> getTransportRegistry() {
return std::tr1::shared_ptr<TransportRegistry>();
}
virtual std::tr1::shared_ptr<Channel> getChannel(epics::pvAccess::pvAccessID) {
return std::tr1::shared_ptr<Channel>();
}
virtual Transport::shared_pointer getSearchTransport() {
return Transport::shared_pointer();
}
virtual Configuration::shared_pointer getConfiguration() {
return Configuration::shared_pointer();
}
virtual void acquire() {}
virtual void release() {}
virtual void newServerDetected() {}
};
class DummyResponseHandler : public ResponseHandler {
public:
DummyResponseHandler(Context* /*context*/)
: packets(0) {
}
virtual ~DummyResponseHandler() {}
int getPackets() {
return packets;
}
virtual void handleResponse(osiSockAddr* responseFrom,
Transport::shared_pointer const &, int8 version, int8 command, std::size_t payloadSize,
ByteBuffer* payloadBuffer);
private:
int packets;
};
void DummyResponseHandler::handleResponse(osiSockAddr* responseFrom,
Transport::shared_pointer const &, int8 version, int8 command, std::size_t payloadSize,
ByteBuffer* payloadBuffer) {
std::ostringstream os;
cout<<"Received new UDP datagram["<<packets+1<<"]..."<<endl;
char ipAddressStr[24];
ipAddrToDottedIP(&responseFrom->ia, ipAddressStr, sizeof(ipAddressStr));
cout<<"From: "<<ipAddressStr<<endl;
cout<<"Version: 0x"<<hex<<(int)version<<endl;
cout<<"Command: 0x"<<hex<<(int)command<<endl;
cout<<"Payload size: "<<dec<<payloadSize<<endl;
char payload[50];
for(std::size_t i = 0; i<payloadSize;) {
int dataCount = payloadSize-i<50 ? payloadSize-i : 50;
payloadBuffer->get(payload, 0, dataCount);
os<<"Payload ("<<i<<"-"<<(dataCount-1)<<")";
hexDump(os.str(), (int8*)payload, dataCount);
i += dataCount;
}
cout<<endl<<endl;
packets++;
}
void testBlockingUDPConnector() {
BlockingUDPConnector connector(false, true);
ContextImpl ctx;
DummyResponseHandler* drh = new DummyResponseHandler(&ctx);
auto_ptr<ResponseHandler> rh(static_cast<ResponseHandler*>(drh));
osiSockAddr bindAddr;
bindAddr.ia.sin_family = AF_INET;
bindAddr.ia.sin_port = htons(65000);
bindAddr.ia.sin_addr.s_addr = htonl(INADDR_ANY);
TransportClient::shared_pointer nullPointer;
Transport::shared_pointer transport(connector.connect(nullPointer,rh, bindAddr, 1, 50));
static_pointer_cast<BlockingUDPTransport>(transport)->start();
cout<<"Waiting for 10 packets..."<<endl;
//TODO drh can be deleted in connector!
while(drh->getPackets()<10) {
epicsThreadSleep(1.0);
}
}
int main() {
// createFileLogger("testBlockingUDPSrv.log");
testBlockingUDPConnector();
return (0);
}

View File

@@ -87,7 +87,7 @@ class ChannelAccessIFRemoteTest: public ChannelAccessIFTest {
};
MAIN(testChannelProvider)
MAIN(testChannelAccess)
{
SET_LOG_LEVEL(logLevelError);
ChannelAccessIFRemoteTest caRemoteTest;

View File

@@ -1,203 +0,0 @@
/* testChannelSearcManager.cpp */
#include <epicsExit.h>
#include <epicsThread.h>
#include <epicsMessageQueue.h>
#include <pv/channelSearchManager.h>
#include <sstream>
epicsMessageQueueId join1;
epicsMessageQueueId join2;
using std::string;
using namespace epics::pvData;
using namespace epics::pvAccess;
//TODO this will be deleted
class ChannelImpl;
class ContextImpl : public Context
{
public:
ContextImpl(): _timer(new Timer("krneki",lowPriority))
{
}
virtual Version* getVersion()
{
return NULL;
}
virtual ChannelProvider* getProvider()
{
return NULL;
}
Timer::shared_pointer getTimer()
{
return _timer;
}
virtual void initialize()
{
}
virtual void printInfo()
{
}
virtual void printInfo(epics::pvData::StringBuilder out)
{
}
virtual void destroy()
{
}
virtual void dispose()
{
}
Transport::shared_pointer getSearchTransport()
{
return Transport::shared_pointer();
}
std::tr1::shared_ptr<Channel> getChannel(pvAccessID channelID)
{
return std::tr1::shared_ptr<Channel>();
}
Configuration::shared_pointer getConfiguration()
{
return Configuration::shared_pointer();
}
std::tr1::shared_ptr<TransportRegistry> getTransportRegistry()
{
return std::tr1::shared_ptr<TransportRegistry>();
}
void beaconAnomalyNotify() {};
private:
Timer::shared_pointer _timer;
void loadConfiguration() { }
void internalInitialize() { }
void initializeUDPTransport() { }
void internalDestroy() { }
void destroyAllChannels() { }
void checkChannelName(std::string const & name) {}
void checkState() { }
pvAccessID generateCID()
{
return 0;
}
void freeCID(int cid)
{
}
Transport* getTransport(TransportClient* client, osiSockAddr* serverAddress, int minorRevision, int priority)
{
return NULL;
}
Channel* createChannelInternal(std::string name, ChannelRequester* requester, short priority,
InetAddrVector* addresses)
{
return NULL;
}
void destroyChannel(ChannelImpl* channel, bool force) {
}
ChannelSearchManager* getChannelSearchManager() {
return NULL;
}
virtual void acquire() {}
virtual void release() {}
};
class TestSearcInstance : public BaseSearchInstance
{
public:
TestSearcInstance(string channelName, pvAccessID channelID): _channelID(channelID), _channelName(channelName) {}
pvAccessID getSearchInstanceID() { return _channelID;};
string getSearchInstanceName() {return _channelName;};
void searchResponse(int8 minorRevision, osiSockAddr* serverAddress) {};
void acquire() {};
void release() {};
private:
pvAccessID _channelID;
string _channelName;
};
static const int max_channels = 100;
ContextImpl* context = new ContextImpl();
ChannelSearchManager* manager = new ChannelSearchManager(static_cast<Context*>(context));
TestSearcInstance** chanArray = new TestSearcInstance*[max_channels];
void testWorker1(void* p)
{
for(int i = 0; i < 1000; i++)
{
for(int j = 0; j < max_channels/2; j++)
{
manager->unregisterChannel(chanArray[j]);
epicsThreadSleep(100e-6);
manager->registerChannel(chanArray[j]);
}
}
int dummy = 1;
epicsMessageQueueSend(join1, &dummy, 1);
}
void testWorker2(void* p)
{
for(int i = 0; i < 1000; i++)
{
for(int j = max_channels/2; j < max_channels; j++)
{
manager->unregisterChannel(chanArray[j]);
epicsThreadSleep(100e-6);
manager->registerChannel(chanArray[j]);
manager->beaconAnomalyNotify();
}
}
int dummy = 2;
epicsMessageQueueSend(join1, &dummy, 1);
}
int main(int argc,char *argv[])
{
epicsThreadId _worker1Id;
epicsThreadId _worker2Id;
std::ostringstream obuffer;
for(int i = 0; i < max_channels; i++)
{
obuffer.clear();
obuffer.str("");
obuffer << i;
string name = "chan" + obuffer.str();
chanArray[i] = new TestSearcInstance(name.c_str(), i);
manager->registerChannel(chanArray[i]);
}
join1 = epicsMessageQueueCreate(1, 1);
join2 = epicsMessageQueueCreate(1, 1);
//create two threads
_worker1Id = epicsThreadCreate("worker1", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium),
testWorker1, NULL);
assert(_worker1Id != NULL);
_worker2Id = epicsThreadCreate("worker2", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium),
testWorker2, NULL);
assert(_worker1Id != NULL);
int dummy;
epicsMessageQueueReceive(join1, &dummy, 1);
epicsMessageQueueReceive(join2, &dummy, 1);
manager->cancel();
context->destroy();
//epicsExitCallAtExits();
for(int i = 0; i < max_channels; i++)
{
if(chanArray[i]) delete chanArray[i];
}
if(chanArray) delete [] chanArray;
if(manager) delete manager;
if(context) delete context;
return(0);
}

View File

@@ -1,15 +1,15 @@
TOP=../..
# This is a Makefile fragment, see ../Makefile
include $(TOP)/configure/CONFIG
PROD_LIBS += pvAccess pvData pvMB Com
SRC_DIRS += $(PVACCESS_TEST)/utils
TESTPROD_HOST += testAtomicBoolean
testAtomicBoolean_SRCS = testAtomicBoolean.cpp
testHarness_SRCS += testAtomicBoolean.cpp
TESTS += testAtomicBoolean
TESTPROD_HOST += testHexDump
testHexDump = testHexDump.cpp
testHarness_SRCS += testHexDump.cpp
TESTS += testHexDump
TESTPROD_HOST += testInetAddressUtils
@@ -19,30 +19,32 @@ testInetAddressUtils = testInetAddressUtils.cpp
testInetAddressUtils_CXXFLAGS = -O0
# needed for 64-bit Windows
testInetAddressUtils_SYS_LIBS_WIN32 += ws2_32
testHarness_SRCS += testInetAddressUtils.cpp
TESTS += testInetAddressUtils
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
#PROD_HOST += loggerTest
#TESTPROD_HOST += loggerTest
#loggerTest_SRCS += loggerTest.cpp
#loggerTest_LIBS += pvAccess pvData Com
#testHarness_SRCS += loggerTest.cpp
#TESTS += loggerTest
#PROD_HOST += introspectionRegisterTest
#TESTPROD_HOST += introspectionRegisterTest
#introspectionRegisterTest_SRCS += introspectionRegistryTest.cpp
#introspectionRegisterTest_LIBS += pvAccess Com pvData
#testHarness_SRCS += introspectionRegistryTest.cpp
#TESTS += introspectionRegistryTest
#PROD_HOST += transportRegisterTest
#TESTPROD_HOST += transportRegisterTest
#transportRegisterTest_SRCS += transportRegistryTest.cpp
#transportRegisterTest_LIBS += pvAccess Com pvData
#testHarness_SRCS += transportRegistryTest.cpp
#TESTS += transportRegistryTest
#PROD_HOST += namedLockPatternTest
#TESTPROD_HOST += namedLockPatternTest
#namedLockPatternTest_SRCS += namedLockPatternTest.cpp
#namedLockPatternTest_LIBS += pvAccess Com pvData
#testHarness_SRCS += namedLockPatternTest.cpp
#TESTS += namedLockPatternTest
#PROD_HOST += configurationTest
#TESTPROD_HOST += configurationTest
#configurationTest_SRCS += configurationTest.cpp
#configurationTest_LIBS += pvAccess Com pvData
include $(TOP)/configure/RULES
#----------------------------------------
# ADD RULES AFTER THIS LINE
#testHarness_SRCS += configurationTest.cpp
#TESTS += configurationTest