drop long defunct test code

This commit is contained in:
Michael Davidsaver
2017-11-06 12:52:26 -06:00
parent dcb74b781d
commit 02a11fc539
5 changed files with 0 additions and 979 deletions

View File

@@ -22,26 +22,6 @@ testInetAddressUtils_SYS_LIBS_WIN32 += ws2_32
testHarness_SRCS += testInetAddressUtils.cpp
TESTS += testInetAddressUtils
#TESTPROD_HOST += loggerTest
#loggerTest_SRCS += loggerTest.cpp
#testHarness_SRCS += loggerTest.cpp
#TESTS += loggerTest
#TESTPROD_HOST += introspectionRegisterTest
#introspectionRegisterTest_SRCS += introspectionRegistryTest.cpp
#testHarness_SRCS += introspectionRegistryTest.cpp
#TESTS += introspectionRegistryTest
#TESTPROD_HOST += transportRegisterTest
#transportRegisterTest_SRCS += transportRegistryTest.cpp
#testHarness_SRCS += transportRegistryTest.cpp
#TESTS += transportRegistryTest
#TESTPROD_HOST += namedLockPatternTest
#namedLockPatternTest_SRCS += namedLockPatternTest.cpp
#testHarness_SRCS += namedLockPatternTest.cpp
#TESTS += namedLockPatternTest
TESTPROD_HOST += configurationTest
configurationTest_SRCS += configurationTest.cpp
configurationTest_SYS_LIBS_WIN32 += ws2_32

View File

@@ -1,520 +0,0 @@
/*
* introspectionRegistryTest.cpp
*
* Created on: Dec 23, 2010
* Author: Gasper Jansa
*/
#include <pv/introspectionRegistry.h>
#include <epicsAssert.h>
#include <epicsExit.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <pv/CDRMonitor.h>
using std::tr1::static_pointer_cast;
using namespace epics::pvData;
namespace epics {
namespace pvAccess {
class SerializableControlImpl : public SerializableControl,
public NoDefaultMethods {
public:
virtual void flushSerializeBuffer() {
}
virtual void ensureBuffer(int size) {
}
virtual void alignBuffer(int alignment) {
}
SerializableControlImpl() {
}
virtual ~SerializableControlImpl() {
}
};
class DeserializableControlImpl : public DeserializableControl,
public NoDefaultMethods {
public:
virtual void ensureData(int size) {
}
virtual void alignData(int alignment) {
}
DeserializableControlImpl() {
}
virtual ~DeserializableControlImpl() {
}
};
}
}
using namespace epics::pvAccess;
using namespace std;
static SerializableControl* flusher;
static DeserializableControl* control;
static ByteBuffer* buffer;
static PVDataCreate* pvDataCreate;
static FieldCreate* fieldCreate;
static StandardField *standardField;
static IntrospectionRegistry* registry;
static IntrospectionRegistry* clientRegistry;
static IntrospectionRegistry* serverRegistry;
vector<PVField*> pvFieldArray;
static string builder;
//helper methods
ScalarConstPtr getScalar(string name)
{
ScalarConstPtr scalar = standardField->scalar(name,pvFloat);
PVField *pvField = pvDataCreate->createPVField(0,scalar);
pvFieldArray.push_back(pvField);
return scalar;
}
ScalarArrayConstPtr getScalarArray(string name)
{
ScalarArrayConstPtr scalarArray = standardField->scalarArray(name,pvFloat);
PVField *pvField = pvDataCreate->createPVField(0,scalarArray);
pvFieldArray.push_back(pvField);
return scalarArray;
}
StructureConstPtr getStructure(string name)
{
String properties("alarm");
FieldConstPtrArray powerSupply = new FieldConstPtr[3];
powerSupply[0] = standardField->scalar(
String("voltage"),pvDouble,properties);
powerSupply[1] = standardField->scalar(
String("power"),pvDouble,properties);
powerSupply[2] = standardField->scalar(
String("current"),pvDouble,properties);
StructureConstPtr structure = standardField->structure(name,3,powerSupply);
PVField *pvField = pvDataCreate->createPVField(0,structure);
pvFieldArray.push_back(pvField);
return structure;
}
StructureArrayConstPtr getStructureArray(string name1, string name2)
{
String properties("alarm");
FieldConstPtrArray powerSupply = new FieldConstPtr[3];
powerSupply[0] = standardField->scalar(
String("voltage"),pvDouble,properties);
powerSupply[1] = standardField->scalar(
String("power"),pvDouble,properties);
powerSupply[2] = standardField->scalar(
String("current"),pvDouble,properties);
StructureConstPtr structure = standardField->structure(name1,3,powerSupply);
StructureArrayConstPtr structureArray = standardField->structureArray(name2,structure);
PVField *pvField = pvDataCreate->createPVField(0,structureArray);
pvFieldArray.push_back(pvField);
return structureArray;
}
UnionConstPtr getUnion(string name)
{
String properties("alarm");
FieldConstPtrArray powerSupply = new FieldConstPtr[3];
powerSupply[0] = standardField->scalar(
String("voltage"),pvDouble,properties);
powerSupply[1] = standardField->scalar(
String("power"),pvDouble,properties);
powerSupply[2] = standardField->scalar(
String("current"),pvDouble,properties);
UnionConstPtr punion = getFieldCreate()->createUnion(name,3,powerSupply);
PVField *pvField = pvDataCreate->createPVField(0,punion);
pvFieldArray.push_back(pvField);
return punion;
}
UnionArrayConstPtr getUnionArray(string name1, string name2)
{
String properties("alarm");
FieldConstPtrArray powerSupply = new FieldConstPtr[3];
powerSupply[0] = standardField->scalar(
String("voltage"),pvDouble,properties);
powerSupply[1] = standardField->scalar(
String("power"),pvDouble,properties);
powerSupply[2] = standardField->scalar(
String("current"),pvDouble,properties);
UnionConstPtr punion = getFieldCreate()->createUnion(name1,3,powerSupply);
UnionArrayConstPtr unionArray = standardField->unionArray(name2,punion);
PVField *pvField = pvDataCreate->createPVField(0,unionArray);
pvFieldArray.push_back(pvField);
return unionArray;
}
//test methods
void testRegistryPutGet()
{
short id = 0;
ScalarConstPtr scalarIn = getScalar("field1");
registry->registerIntrospectionInterface(id,scalarIn);
id++;
ScalarArrayConstPtr scalarArrayIn = getScalarArray("fieldArray1");
registry->registerIntrospectionInterface(id,scalarArrayIn);
id++;
StructureConstPtr structureIn = getStructure("struct1");
registry->registerIntrospectionInterface(id,structureIn);
id++;
StructureArrayConstPtr structureArrayIn = getStructureArray("struct1","structArray1");
registry->registerIntrospectionInterface(id,structureArrayIn);
id = 0;
ScalarConstPtr scalarOut = static_pointer_cast<const Scalar>(registry->getIntrospectionInterface(id));
assert(scalarIn == scalarOut);
id++;
ScalarArrayConstPtr scalarArrayOut = static_pointer_cast<const ScalarArray>(registry->getIntrospectionInterface(id));
assert(scalarArrayIn == scalarArrayOut);
id++;
StructureConstPtr structureOut = static_pointer_cast<const Structure>(registry->getIntrospectionInterface(id));
assert(structureIn == structureOut);
id++;
StructureArrayConstPtr structureArrayOut = static_pointer_cast<const StructureArray>(registry->getIntrospectionInterface(id));
assert(structureArrayIn == structureArrayOut);
bool existing;
id = registry->registerIntrospectionInterface(static_pointer_cast<const Field>(scalarIn),existing);
assert(existing == true);
assert(id == 0);
id = registry->registerIntrospectionInterface(static_pointer_cast<const Field>(scalarArrayIn),existing);
assert(existing == true);
assert(id == 1);
id = registry->registerIntrospectionInterface(static_pointer_cast<const Field>(structureIn),existing);
assert(existing == true);
assert(id == 2);
id = registry->registerIntrospectionInterface(static_pointer_cast<const Field>(structureArrayIn),existing);
assert(existing == true);
assert(id == 3);
//should exist
ScalarConstPtr scalarInNew = getScalar("field1");
id = registry->registerIntrospectionInterface(static_pointer_cast<const Field>(scalarInNew),existing);
assert(existing == true);
assert(id == 0);
scalarOut = static_pointer_cast<const Scalar>(registry->getIntrospectionInterface(id));
assert(scalarIn == scalarOut);
}
void testRegistryReset()
{
registry->reset();
short id = 0;
assert(static_pointer_cast<const Scalar>(registry->getIntrospectionInterface(id)) == 0);
}
void serialize(FieldConstPtr field, IntrospectionRegistry* registry)
{
buffer->clear();
registry->serialize(field,buffer,flusher);
//should be in registry
bool existing;
registry->registerIntrospectionInterface(field,existing);
assert(existing == true);
}
FieldConstPtr deserialize(IntrospectionRegistry* registry)
{
FieldConstPtr field = registry->deserialize(buffer,control);
PVField *pvField = pvDataCreate->createPVField(0,field);
pvFieldArray.push_back(pvField);
//should be in registry
bool existing;
registry->registerIntrospectionInterface(field,existing);
assert(existing == true);
return field;
}
void checkTypeCode(int8 typeCodeIn)
{
int8 typeCode = buffer->getByte();
//printf("%d == %d\n", typeCode, typeCodeIn);
assert(typeCode == typeCodeIn);
buffer->rewind();
}
void testSerializeCommon(FieldConstPtr serverField1, FieldConstPtr clientField2)
{
//server serializes field 1
serialize(serverField1,serverRegistry);
//full should be serialized
buffer->flip();
checkTypeCode(IntrospectionRegistry::FULL_WITH_ID_TYPE_CODE);
//client deserializes 1
FieldConstPtr clientField1 = deserialize(clientRegistry);
assert(serverField1->getFieldName() == clientField1->getFieldName());
assert(serverField1->getType() == clientField1->getType());
//client serializes the same field
serialize(serverField1,clientRegistry);
//only id should be serialized
buffer->flip();
checkTypeCode(IntrospectionRegistry::ONLY_ID_TYPE_CODE);
//server deserializes the same field
serverField1 = deserialize(serverRegistry);
assert(serverField1->getFieldName() == clientField1->getFieldName());
assert(serverField1->getType() == clientField1->getType());
//client requests new field
serialize(clientField2,clientRegistry);
//full should be serialized
buffer->flip();
checkTypeCode(IntrospectionRegistry::FULL_WITH_ID_TYPE_CODE);
//server deserializes new field
FieldConstPtr serverField2 = deserialize(serverRegistry);
assert(serverField2->getFieldName() == clientField2->getFieldName());
assert(serverField2->getType() == clientField2->getType());
}
void testSerialize()
{
clientRegistry->reset();
serverRegistry->reset();
stringstream ss;
string name1,name2,name3,name4;
for(int i = 0, j = 0; i < 10 ; i++, j++)
{
name1.clear();
name2.clear();
ss.str("");
ss << j;
name1 = "field" + ss.str();
ss.str("");
j++;
ss << j;
name2 = "field" + ss.str();
testSerializeCommon(static_pointer_cast<const Field>(getScalar(name1)),static_pointer_cast<const Field>(getScalar(name2)));
name1.clear();
name2.clear();
ss.str("");
ss << j;
name1 = "fieldArray" + ss.str();
ss.str("");
j++;
ss << j;
name2 = "fieldArray" + ss.str();
testSerializeCommon(static_pointer_cast<const Field>(getScalarArray(name1)),static_pointer_cast<const Field>(getScalarArray(name2)));
name1.clear();
name2.clear();
ss.str("");
ss << j;
name1 = "structure" + ss.str();
ss.str("");
j++;
ss << j;
name2 = "structure" + ss.str();
testSerializeCommon(static_pointer_cast<const Field>(getStructure(name1)),static_pointer_cast<const Field>(getStructure(name2)));
name1.clear();
name2.clear();
name3.clear();
name4.clear();
ss.str("");
ss << j;
name1 = "structure" + ss.str();
name2 = "structureArray" + ss.str();
ss.str("");
j++;
ss << j;
name3 = "structure" + ss.str();
name4 = "structureArray" + ss.str();
testSerializeCommon(static_pointer_cast<const Field>(getStructureArray(name1,name2)),static_pointer_cast<const Field>(getStructureArray(name3,name4)));
name1.clear();
name2.clear();
ss.str("");
ss << j;
name1 = "union" + ss.str();
ss.str("");
j++;
ss << j;
name2 = "union" + ss.str();
testSerializeCommon(static_pointer_cast<const Field>(getUnion(name1)),static_pointer_cast<const Field>(getUnion(name2)));
name1.clear();
name2.clear();
name3.clear();
name4.clear();
ss.str("");
ss << j;
name1 = "union" + ss.str();
name2 = "unionArray" + ss.str();
ss.str("");
j++;
ss << j;
name3 = "union" + ss.str();
name4 = "unionArray" + ss.str();
testSerializeCommon(static_pointer_cast<const Field>(getUnionArray(name1,name2)),static_pointer_cast<const Field>(getUnionArray(name3,name4)));
}
//serverRegistry->printKeysAndValues("server");
//clientRegistry->printKeysAndValues("client");
}
void testSerializeFull()
{
buffer->clear();
ScalarConstPtr scalarIn = getScalar("field1");
IntrospectionRegistry::serializeFull(static_pointer_cast<const Field>(scalarIn),buffer,flusher);
buffer->flip();
ScalarConstPtr scalarOut = static_pointer_cast<const Scalar>(IntrospectionRegistry::deserializeFull(buffer,control));
PVField *pvField = pvDataCreate->createPVField(0,scalarOut);
pvFieldArray.push_back(pvField);
assert(scalarIn->getFieldName() == scalarOut->getFieldName());
assert(scalarIn->getType() == scalarOut->getType());
buffer->clear();
ScalarArrayConstPtr scalarArrayIn = getScalarArray("fieldArray1");
IntrospectionRegistry::serializeFull(static_pointer_cast<const Field>(scalarArrayIn),buffer,flusher);
buffer->flip();
ScalarArrayConstPtr scalarArrayOut = static_pointer_cast<const ScalarArray>(IntrospectionRegistry::deserializeFull(buffer,control));
pvField = pvDataCreate->createPVField(0,scalarArrayOut);
pvFieldArray.push_back(pvField);
assert(scalarArrayIn->getFieldName() == scalarArrayOut->getFieldName());
assert(scalarArrayIn->getType() == scalarArrayOut->getType());
buffer->clear();
StructureConstPtr structureIn = getStructure("struct1");
IntrospectionRegistry::serializeFull(static_pointer_cast<const Field>(structureIn),buffer,flusher);
buffer->flip();
StructureConstPtr structureOut = static_pointer_cast<const Structure>(IntrospectionRegistry::deserializeFull(buffer,control));
pvField = pvDataCreate->createPVField(0,structureOut);
pvFieldArray.push_back(pvField);
assert(structureIn->getFieldName() == structureOut->getFieldName());
assert(structureIn->getType() == structureOut->getType());
buffer->clear();
StructureArrayConstPtr structureArrayIn = getStructureArray("struct1","structArray1");
IntrospectionRegistry::serializeFull(static_pointer_cast<const Field>(structureArrayIn),buffer,flusher);
buffer->flip();
StructureArrayConstPtr structureArrayOut = static_pointer_cast<const StructureArray>(IntrospectionRegistry::deserializeFull(buffer,control));
pvField = pvDataCreate->createPVField(0,structureArrayOut);
pvFieldArray.push_back(pvField);
assert(structureArrayIn->getFieldName() == structureArrayOut->getFieldName());
assert(structureArrayIn->getType() == structureArrayOut->getType());
}
void testSerializePVRequest()
{
buffer->clear();
registry->reset();
PVStructurePtr pvStructureIn = pvDataCreate->createPVStructure(NULL,getStructure("structure1"));
registry->serializePVRequest(buffer,flusher,pvStructureIn);
buffer->flip();
PVStructurePtr pvStructureOut = registry->deserializePVRequest(buffer,control);
assert(*pvStructureIn == *pvStructureOut);
delete pvStructureIn;
delete pvStructureOut;
}
void testDeserializeStructureAndCreatePVStructure()
{
buffer->clear();
registry->reset();
StructureConstPtr structureIn = getStructure("structure1");
serialize(structureIn,registry);
buffer->flip();
PVStructurePtr pvStructureOut = registry->deserializeStructureAndCreatePVStructure(buffer,control);
StructureConstPtr structureOut = pvStructureOut->getStructure();
assert(structureIn->getFieldName() == structureOut->getFieldName());
assert(structureIn->getType() == structureOut->getType());
delete pvStructureOut;
}
void testSerializeStatus()
{
buffer->clear();
registry->reset();
Status statusIn(Status::STATUSTYPE_WARNING, "msg", "dumpy");
registry->serializeStatus(buffer,flusher,statusIn);
buffer->flip();
Status statusOut;
registry->deserializeStatus(statusOut, buffer,control);
assert(statusIn.getType() == statusOut.getType());
assert(statusIn.getMessage() == statusOut.getMessage());
assert(statusIn.getStackDump() == statusOut.getStackDump());
}
int main(int argc, char *argv[])
{
pvDataCreate = getPVDataCreate();
fieldCreate = getFieldCreate();
standardField = getStandardField();
flusher = new SerializableControlImpl();
control = new DeserializableControlImpl();
buffer = new ByteBuffer(1<<16);
registry = new IntrospectionRegistry(true);
clientRegistry = new IntrospectionRegistry(false);
serverRegistry = new IntrospectionRegistry(true);
testRegistryPutGet();
testRegistryReset();
testSerialize();
testSerializeFull();
testDeserializeStructureAndCreatePVStructure();
testSerializeStatus();
registry->reset();
clientRegistry->reset();
serverRegistry->reset();
for (unsigned int i=0; i < pvFieldArray.size(); i++)
{
delete pvFieldArray[i];
}
pvFieldArray.clear();
if(flusher) delete flusher;
if(control) delete control;
if(buffer) delete buffer;
if(registry) delete registry;
if(clientRegistry) delete clientRegistry;
if(serverRegistry) delete serverRegistry;
epicsExitCallAtExits();
CDRMonitor::get().show(stdout, true);
cout << "DONE" << endl;
return 0;
}

View File

@@ -1,27 +0,0 @@
/*
* loggerTest.cpp
*
* Created on: Dec 10, 2010
* Author: Miha Vitorovic
*/
#include <pv/logger.h>
#include <epicsExit.h>
#include <iostream>
using namespace epics::pvAccess;
using std::cout;
int main(int argc, char *argv[]) {
createFileLogger("loggerTest.log");
SET_LOG_LEVEL(logLevelDebug);
LOG( logLevelInfo, "This will not appear");
LOG( logLevelError, "This is a test %d", 42);
LOG( logLevelFatal, "This is another test %f", 3.14);
epicsExit(0);
}

View File

@@ -1,227 +0,0 @@
/*
* namedLockPatternTest.cpp
*
*/
#include <pv/namedLockPattern.h>
#include <pv/inetAddressUtil.h>
#include <pv/status.h>
#include <pv/CDRMonitor.h>
#include <epicsAssert.h>
#include <epicsExit.h>
#include <epicsThread.h>
#include <epicsMessageQueue.h>
#include <osiSock.h>
#include <iostream>
#include <string.h>
using namespace epics::pvData;
using namespace epics::pvAccess;
using namespace std;
epicsMessageQueueId join1;
epicsMessageQueueId join2;
void testIntLockPattern()
{
int64 timeout = 100;
NamedLockPattern<int> namedLockPattern;
int name1 = 1;
assert(namedLockPattern.acquireSynchronizationObject(name1,timeout));
assert(namedLockPattern.acquireSynchronizationObject(name1,timeout));
namedLockPattern.releaseSynchronizationObject(name1);
namedLockPattern.releaseSynchronizationObject(name1);
int name2 = 2;
assert(namedLockPattern.acquireSynchronizationObject(name2,timeout));
namedLockPattern.releaseSynchronizationObject(name2);
}
void testIntPtrLockPattern()
{
int64 timeout = 100;
NamedLockPattern<int*> namedLockPattern;
int name1 = 1;
assert(namedLockPattern.acquireSynchronizationObject(&name1,timeout));
assert(namedLockPattern.acquireSynchronizationObject(&name1,timeout));
namedLockPattern.releaseSynchronizationObject(&name1);
namedLockPattern.releaseSynchronizationObject(&name1);
int name2 = 2;
assert(namedLockPattern.acquireSynchronizationObject(&name2,timeout));
namedLockPattern.releaseSynchronizationObject(&name2);
}
struct cmp_str
{
bool operator()(char const *a, char const *b)
{
return strcmp(a, b) < 0;
}
};
void testCharPtrLockPattern()
{
int64 timeout = 100;
NamedLockPattern<const char*,cmp_str> namedLockPattern;
string name1 = "lojze";
assert(namedLockPattern.acquireSynchronizationObject(name1.c_str(),timeout));
assert(namedLockPattern.acquireSynchronizationObject(name1.c_str(),timeout));
namedLockPattern.releaseSynchronizationObject(name1.c_str());
namedLockPattern.releaseSynchronizationObject(name1.c_str());
string name2 = "francka";
assert(namedLockPattern.acquireSynchronizationObject(name2.c_str(),timeout));
namedLockPattern.releaseSynchronizationObject(name2.c_str());
}
void testOsiSockAddrLockPattern()
{
int64 timeout = 10000;
NamedLockPattern<const osiSockAddr*,comp_osiSockAddrPtr> namedLockPattern;
osiSockAddr name1;
name1.ia.sin_addr.s_addr = 1;
name1.ia.sin_port = 1;
name1.ia.sin_family = AF_INET;
assert(namedLockPattern.acquireSynchronizationObject(&name1,timeout));
assert(namedLockPattern.acquireSynchronizationObject(&name1,timeout));
osiSockAddr name2;
name2.ia.sin_addr.s_addr = 1;
name2.ia.sin_port = 1;
name2.ia.sin_family = AF_INET;
assert(namedLockPattern.acquireSynchronizationObject(&name2,timeout));
assert(namedLockPattern.acquireSynchronizationObject(&name2,timeout));
namedLockPattern.releaseSynchronizationObject(&name1);
namedLockPattern.releaseSynchronizationObject(&name1);
namedLockPattern.releaseSynchronizationObject(&name2);
namedLockPattern.releaseSynchronizationObject(&name2);
osiSockAddr name3;
name3.ia.sin_addr.s_addr = 1;
name3.ia.sin_port = 1;
name3.ia.sin_family = AF_INET;
NamedLock<const osiSockAddr*,comp_osiSockAddrPtr> namedGuard(&namedLockPattern);
assert(namedGuard.acquireSynchronizationObject(&name3,timeout));
}
void testOsiSockAddrWithPtrKeyLockPattern()
{
int64 timeout = 10000;
NamedLockPattern<const osiSockAddr*,comp_osiSockAddrPtr> namedLockPattern;
osiSockAddr* name1 = new osiSockAddr;
name1->ia.sin_addr.s_addr = 1;
name1->ia.sin_port = 1;
name1->ia.sin_family = AF_INET;
assert(namedLockPattern.acquireSynchronizationObject(name1,timeout));
assert(namedLockPattern.acquireSynchronizationObject(name1,timeout));
namedLockPattern.releaseSynchronizationObject(name1);
namedLockPattern.releaseSynchronizationObject(name1);
delete name1;
}
void testWorker1(void* p)
{
int32 timeout = 1000;
const int32 max = 1000;
NamedLockPattern<osiSockAddr,comp_osiSockAddr>* namedLockPattern = (NamedLockPattern<osiSockAddr,comp_osiSockAddr>*)p;
for(int32 i = 0 ; i < max; i = i +2)
{
osiSockAddr addr;
addr.ia.sin_addr.s_addr = i;
addr.ia.sin_port = i;
addr.ia.sin_family = AF_INET;
NamedLock<osiSockAddr,comp_osiSockAddr> namedGuard(namedLockPattern);
assert(namedGuard.acquireSynchronizationObject(addr,timeout));
epicsThreadSleep(1e-6);
}
//this one takes a lock, thread 2 will be slower and will get timeout
{ //due to namedGuard
osiSockAddr addr;
addr.ia.sin_addr.s_addr = 1;
addr.ia.sin_port = 1;
addr.ia.sin_family = AF_INET;
NamedLock<osiSockAddr,comp_osiSockAddr> namedGuard(namedLockPattern);
assert(namedGuard.acquireSynchronizationObject(addr,timeout));
epicsThreadSleep(5.0);
}
int dummy = 1;
epicsMessageQueueSend(join1, &dummy, 1);
}
void testWorker2(void* p)
{
int32 timeout = 1000;
const int32 max = 1000;
NamedLockPattern<osiSockAddr,comp_osiSockAddr>* namedLockPattern = (NamedLockPattern<osiSockAddr,comp_osiSockAddr>*)p;
for(int32 i = 1 ; i < max; i = i + 2)
{
osiSockAddr addr;
addr.ia.sin_addr.s_addr = i;
addr.ia.sin_port = i;
addr.ia.sin_family = AF_INET;
NamedLock<osiSockAddr,comp_osiSockAddr> namedGuard(namedLockPattern);
assert(namedGuard.acquireSynchronizationObject(addr,timeout));
epicsThreadSleep(1e-6);
}
//this thread sleeps a while and gets timeout on lock
{
epicsThreadSleep(1.0);
osiSockAddr addr;
addr.ia.sin_addr.s_addr = 1;
addr.ia.sin_port = 1;
addr.ia.sin_family = AF_INET;
NamedLock<osiSockAddr,comp_osiSockAddr> namedGuard(namedLockPattern);
//TODO swap next two lines if timed lock used
//assert(!namedGuard.acquireSynchronizationObject(addr,timeout));
assert(namedGuard.acquireSynchronizationObject(addr,timeout));
}
int dummy = 2;
epicsMessageQueueSend(join2, &dummy, 1);
}
int main(int argc, char *argv[])
{
testIntLockPattern();
testIntPtrLockPattern();
testCharPtrLockPattern();
testOsiSockAddrLockPattern();
testOsiSockAddrWithPtrKeyLockPattern();
NamedLockPattern<osiSockAddr,comp_osiSockAddr> namedLockPattern;
join1 = epicsMessageQueueCreate(1, 1);
join2 = epicsMessageQueueCreate(1, 1);
//create two threads
epicsThreadId t1 = epicsThreadCreate("worker1", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium),
testWorker1, &namedLockPattern);
assert(t1);
epicsThreadId t2 = epicsThreadCreate("worker2", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium),
testWorker2, &namedLockPattern);
assert(t2);
int dummy;
epicsMessageQueueReceive(join1, &dummy, 1);
epicsMessageQueueReceive(join2, &dummy, 1);
epicsExitCallAtExits();
CDRMonitor::get().show(stdout, true);
return 0;
}

View File

@@ -1,185 +0,0 @@
/*
* transportRegistryTest.cpp
*
*/
#include <pv/transportRegistry.h>
#include <pv/introspectionRegistry.h>
#include <pv/CDRMonitor.h>
#include <epicsAssert.h>
#include <epicsExit.h>
#include <iostream>
#include <string>
namespace epics {
namespace pvAccess {
class TestTransport : public Transport {
public:
typedef std::tr1::shared_ptr<TestTransport> shared_pointer;
typedef std::tr1::shared_ptr<const TestTransport> const_shared_pointer;
TestTransport(string type, int16 priority, osiSockAddr* address): _type(type), _priority(priority), _address(address) {
/*cout << "Transport::Transport" << endl;*/
};
~TestTransport() {
/*cout << "Transport::~Transport" << endl;*/
};
virtual const string getType() const {
return _type;
};
virtual int16 getPriority() const {
return _priority;
};
virtual const osiSockAddr* getRemoteAddress() const {
return _address;
};
virtual int8 getMajorRevision() const {
return 0;
};
virtual int8 getMinorRevision() const {
return 0;
};
virtual int getReceiveBufferSize() const {
return 0;
};
virtual int getSocketReceiveBufferSize() const {
return 0;
};
virtual void setRemoteMinorRevision(int8 minor) {};
virtual void setRemoteTransportReceiveBufferSize(
int receiveBufferSize) {};
virtual void setRemoteTransportSocketReceiveBufferSize(
int socketReceiveBufferSize) {};
virtual void aliveNotification() {};
virtual void changedTransport() {};
virtual void close(bool force) {};
virtual bool isClosed() {
return false;
};
virtual bool isVerified() {
return false;
};
virtual void verified() {};
virtual void enqueueSendRequest(TransportSender::shared_pointer const & sender) {};
virtual void ensureData(int) {};
virtual void alignData(int) {};
virtual IntrospectionRegistry* getIntrospectionRegistry() {
return NULL;
};
private:
string _type;
int16 _priority;
osiSockAddr* _address;
};
}
}
using namespace epics::pvAccess;
using namespace std;
static TransportRegistry* registry;
static const int16 address_max = 10;
static const int16 priority_max = 100;
typedef std::vector<osiSockAddr*> osiSockAddrVector_t;
int main(int argc, char *argv[])
{
registry = new TransportRegistry();
epics::auto_ptr<TransportRegistry::transportVector_t> transportArrayOut;
std::vector<Transport::shared_pointer> transportArrayIn (address_max * priority_max);
osiSockAddrVector_t addrArray (address_max);
//address
for(int32 i = 0; i < address_max; i++)
{
osiSockAddr* addr = new osiSockAddr;
addr->ia.sin_addr.s_addr = i;
addr->ia.sin_port = i;
addr->ia.sin_family = AF_INET;
addrArray.at(i) = addr;
//priority
for(int16 j = 0; j < priority_max; j++)
{
Transport::shared_pointer testTransportIn(new TestTransport("tcp", j, addr));
transportArrayIn.at(i * priority_max + j) = testTransportIn;
registry->put(testTransportIn);
Transport::shared_pointer testTransportOut(registry->get("tcp",addr,(const int16)j));
assert(testTransportIn.get() == testTransportOut.get());
}
transportArrayOut = registry->get("tcp",addr);
assert((int16)transportArrayOut->size() == priority_max);
for(int32 k = 0; k < priority_max; k++)
{
assert(transportArrayIn.at(i * priority_max + k).get() == transportArrayOut->at(k).get());
}
}
//add one transport which has same addr and priority as last one and check that the size does not increase
osiSockAddr* addr = new osiSockAddr;
addr->ia.sin_addr.s_addr = address_max - 1;
addr->ia.sin_port = address_max - 1;
addr->ia.sin_family = AF_INET;
Transport::shared_pointer testTransportIn(new TestTransport("tcp", priority_max - 1, addr));
registry->put(testTransportIn);
Transport::shared_pointer testTransportOut(registry->get("tcp",addr,(const int16)priority_max - 1));
assert(testTransportIn.get() == testTransportOut.get());
delete addr;
//put back the old one
registry->put(transportArrayIn.at((address_max - 1) * priority_max + priority_max - 1));
assert(registry->numberOfActiveTransports() == (address_max * priority_max));
transportArrayOut = registry->toArray("tcp");
assert((int16)transportArrayOut->size() == (address_max * priority_max));
for(int32 i = 0; i < address_max * priority_max; i++)
{
assert(transportArrayIn.at(i).get() == transportArrayOut->at(i).get());
}
transportArrayOut = registry->toArray();
assert((int16)transportArrayOut->size() == (address_max * priority_max));
for(int32 i = 0; i < address_max * priority_max; i++)
{
assert(transportArrayIn.at(i).get() == transportArrayOut->at(i).get());
}
for(int32 i = 0; i < address_max; i++)
{
for(int16 j = 0; j < priority_max; j++)
{
assert(transportArrayIn.at(i * priority_max + j) == registry->remove(transportArrayIn.at(i * priority_max + j)));
}
}
assert(registry->numberOfActiveTransports() == 0);
for(int32 i = 0; i < address_max; i++)
{
for(int16 j = 0; j < priority_max; j++)
{
registry->put(transportArrayIn.at(i * priority_max + j));
}
}
assert(registry->numberOfActiveTransports() == (priority_max * address_max));
registry->clear();
assert(registry->numberOfActiveTransports() == 0);
for(osiSockAddrVector_t::iterator iter = addrArray.begin(); iter != addrArray.end(); iter++)
{
delete *iter;
}
addrArray.clear();
if(registry) delete registry;
epicsExitCallAtExits();
epics::pvData::CDRMonitor::get().show(stdout, true);
return 0;
}