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

@@ -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);
}