merge
This commit is contained in:
@@ -32,7 +32,7 @@ namespace epics {
|
||||
const int8 CA_UNKNOWN_MINOR_PROTOCOL_REVISION = 0;
|
||||
|
||||
/** CA version signature (e.g. 0x50). */
|
||||
const int8 CA_VERSION = ((unsigned int8)CA_MAJOR_PROTOCOL_REVISION<<4)|CA_MINOR_PROTOCOL_REVISION;
|
||||
const int8 CA_VERSION = ((uint8_t)CA_MAJOR_PROTOCOL_REVISION<<4)|CA_MINOR_PROTOCOL_REVISION;
|
||||
|
||||
/** CA protocol port base. */
|
||||
const int32 CA_PORT_BASE = 5056;
|
||||
|
||||
@@ -591,7 +591,7 @@ namespace epics {
|
||||
// second byte version - major/minor nibble
|
||||
int8 magic = _socketBuffer->getByte();
|
||||
_version = _socketBuffer->getByte();
|
||||
if(unlikely((magic != CA_MAGIC) || (((unsigned int8)_version) >> 4)!=CA_MAJOR_PROTOCOL_REVISION))
|
||||
if(unlikely((magic != CA_MAGIC) || (((uint8_t)_version) >> 4)!=CA_MAJOR_PROTOCOL_REVISION))
|
||||
{
|
||||
// error... disconnect
|
||||
LOG(
|
||||
|
||||
@@ -274,7 +274,7 @@ namespace epics {
|
||||
// second byte version - major/minor nibble
|
||||
int8 magic = receiveBuffer->getByte();
|
||||
int8 version = receiveBuffer->getByte();
|
||||
if(unlikely((magic != CA_MAGIC) || (((unsigned int8)version) >> 4)!=CA_MAJOR_PROTOCOL_REVISION))
|
||||
if(unlikely((magic != CA_MAGIC) || (((uint8_t)version) >> 4)!=CA_MAJOR_PROTOCOL_REVISION))
|
||||
return false;
|
||||
|
||||
// only data for UDP
|
||||
|
||||
@@ -26,7 +26,7 @@ testBeaconEmitter_LIBS += pvData pvAccess Com
|
||||
testBeaconHandler_SRCS += testBeaconHandler.cpp
|
||||
testBeaconHandler_LIBS += pvData pvAccess Com
|
||||
|
||||
PROD_HOST_Linux += testChannelSearchManager
|
||||
PROD_HOST += testChannelSearchManager
|
||||
testChannelSearchManager_SRCS += testChannelSearchManager.cpp
|
||||
testChannelSearchManager_LIBS += pvData pvAccess Com
|
||||
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
/* testChannelSearcManager.cpp */
|
||||
|
||||
#include <epicsExit.h>
|
||||
#include <epicsThread.h>
|
||||
#include <epicsMessageQueue.h>
|
||||
#include <pv/channelSearchManager.h>
|
||||
#include <sstream>
|
||||
#include <pv/CDRMonitor.h>
|
||||
|
||||
epicsMessageQueueId join1;
|
||||
epicsMessageQueueId join2;
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
|
||||
@@ -116,42 +121,43 @@ ContextImpl* context = new ContextImpl();
|
||||
ChannelSearchManager* manager = new ChannelSearchManager(static_cast<Context*>(context));
|
||||
TestSearcInstance** chanArray = new TestSearcInstance*[max_channels];
|
||||
|
||||
void* testWorker1(void* p)
|
||||
void testWorker1(void* p)
|
||||
{
|
||||
for(int i = 0; i < 1000; i++)
|
||||
{
|
||||
for(int j = 0; j < max_channels/2; j++)
|
||||
{
|
||||
manager->unregisterChannel(chanArray[j]);
|
||||
usleep(100);
|
||||
epicsThreadSleep(100e-6);
|
||||
manager->registerChannel(chanArray[j]);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
int dummy = 1;
|
||||
epicsMessageQueueSend(join1, &dummy, 1);
|
||||
}
|
||||
|
||||
|
||||
void* testWorker2(void* p)
|
||||
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]);
|
||||
usleep(100);
|
||||
epicsThreadSleep(100e-6);
|
||||
manager->registerChannel(chanArray[j]);
|
||||
manager->beaconAnomalyNotify();
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
int dummy = 2;
|
||||
epicsMessageQueueSend(join1, &dummy, 1);
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
pthread_t _worker1Id;
|
||||
pthread_t _worker2Id;
|
||||
epicsThreadId _worker1Id;
|
||||
epicsThreadId _worker2Id;
|
||||
|
||||
std::ostringstream obuffer;
|
||||
for(int i = 0; i < max_channels; i++)
|
||||
@@ -164,30 +170,21 @@ int main(int argc,char *argv[])
|
||||
manager->registerChannel(chanArray[i]);
|
||||
}
|
||||
|
||||
join1 = epicsMessageQueueCreate(1, 1);
|
||||
join2 = epicsMessageQueueCreate(1, 1);
|
||||
|
||||
//create two threads
|
||||
int32 retval = pthread_create(&_worker1Id, NULL, testWorker1, NULL);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
_worker1Id = epicsThreadCreate("worker1", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium),
|
||||
testWorker1, NULL);
|
||||
assert(_worker1Id != NULL);
|
||||
|
||||
retval = pthread_create(&_worker2Id, NULL, testWorker2, NULL);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
_worker2Id = epicsThreadCreate("worker2", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium),
|
||||
testWorker2, NULL);
|
||||
assert(_worker1Id != NULL);
|
||||
|
||||
retval = pthread_join(_worker1Id, NULL);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
|
||||
retval = pthread_join(_worker2Id, NULL);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
int dummy;
|
||||
epicsMessageQueueReceive(join1, &dummy, 1);
|
||||
epicsMessageQueueReceive(join2, &dummy, 1);
|
||||
|
||||
manager->cancel();
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ PROD_HOST += transportRegisterTest
|
||||
transportRegisterTest_SRCS += transportRegistryTest.cpp
|
||||
transportRegisterTest_LIBS += pvAccess Com pvData
|
||||
|
||||
PROD_HOST_Linux += namedLockPatternTest
|
||||
PROD_HOST += namedLockPatternTest
|
||||
namedLockPatternTest_SRCS += namedLockPatternTest.cpp
|
||||
namedLockPatternTest_LIBS += pvAccess Com pvData
|
||||
|
||||
PROD_HOST_Linux += configurationTest
|
||||
PROD_HOST += configurationTest
|
||||
configurationTest_SRCS += configurationTest.cpp
|
||||
configurationTest_LIBS += pvAccess Com pvData
|
||||
|
||||
|
||||
@@ -12,6 +12,15 @@
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
void setenv(char * a, char * b, int c)
|
||||
{
|
||||
char buf[1024];
|
||||
sprintf(buf, "%s=%s", a, b);
|
||||
_putenv(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace epics::pvAccess;
|
||||
using namespace epics::pvData;
|
||||
using namespace std;
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <epicsExit.h>
|
||||
#include <epicsThread.h>
|
||||
#include <epicsMessageQueue.h>
|
||||
#include <osiSock.h>
|
||||
|
||||
#include <iostream>
|
||||
@@ -20,6 +22,9 @@ using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
epicsMessageQueueId join1;
|
||||
epicsMessageQueueId join2;
|
||||
|
||||
void testIntLockPattern()
|
||||
{
|
||||
int64 timeout = 100;
|
||||
@@ -119,7 +124,7 @@ void testOsiSockAddrWithPtrKeyLockPattern()
|
||||
delete name1;
|
||||
}
|
||||
|
||||
void* testWorker1(void* p)
|
||||
void testWorker1(void* p)
|
||||
{
|
||||
int32 timeout = 1000;
|
||||
const int32 max = 1000;
|
||||
@@ -133,7 +138,7 @@ void* testWorker1(void* p)
|
||||
addr.ia.sin_family = AF_INET;
|
||||
NamedLock<osiSockAddr,comp_osiSockAddr> namedGuard(namedLockPattern);
|
||||
assert(namedGuard.acquireSynchronizationObject(addr,timeout));
|
||||
usleep(1);
|
||||
epicsThreadSleep(1e-6);
|
||||
}
|
||||
|
||||
//this one takes a lock, thread 2 will be slower and will get timeout
|
||||
@@ -144,14 +149,16 @@ void* testWorker1(void* p)
|
||||
addr.ia.sin_family = AF_INET;
|
||||
NamedLock<osiSockAddr,comp_osiSockAddr> namedGuard(namedLockPattern);
|
||||
assert(namedGuard.acquireSynchronizationObject(addr,timeout));
|
||||
sleep(5);
|
||||
epicsThreadSleep(5.0);
|
||||
}
|
||||
|
||||
int dummy = 1;
|
||||
epicsMessageQueueSend(join1, &dummy, 1);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void* testWorker2(void* p)
|
||||
void testWorker2(void* p)
|
||||
{
|
||||
int32 timeout = 1000;
|
||||
const int32 max = 1000;
|
||||
@@ -165,12 +172,12 @@ void* testWorker2(void* p)
|
||||
addr.ia.sin_family = AF_INET;
|
||||
NamedLock<osiSockAddr,comp_osiSockAddr> namedGuard(namedLockPattern);
|
||||
assert(namedGuard.acquireSynchronizationObject(addr,timeout));
|
||||
usleep(1);
|
||||
epicsThreadSleep(1e-6);
|
||||
}
|
||||
|
||||
//this thread sleeps a while and gets timeout on lock
|
||||
{
|
||||
sleep(1);
|
||||
epicsThreadSleep(1.0);
|
||||
osiSockAddr addr;
|
||||
addr.ia.sin_addr.s_addr = 1;
|
||||
addr.ia.sin_port = 1;
|
||||
@@ -181,7 +188,8 @@ void* testWorker2(void* p)
|
||||
assert(namedGuard.acquireSynchronizationObject(addr,timeout));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
int dummy = 2;
|
||||
epicsMessageQueueSend(join2, &dummy, 1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -191,36 +199,24 @@ int main(int argc, char *argv[])
|
||||
testCharPtrLockPattern();
|
||||
testOsiSockAddrLockPattern();
|
||||
testOsiSockAddrWithPtrKeyLockPattern();
|
||||
pthread_t _worker1Id;
|
||||
pthread_t _worker2Id;
|
||||
|
||||
NamedLockPattern<osiSockAddr,comp_osiSockAddr> namedLockPattern;
|
||||
|
||||
join1 = epicsMessageQueueCreate(1, 1);
|
||||
join2 = epicsMessageQueueCreate(1, 1);
|
||||
|
||||
//create two threads
|
||||
int32 retval = pthread_create(&_worker1Id, NULL, testWorker1, &namedLockPattern);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
epicsThreadId t1 = epicsThreadCreate("worker1", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium),
|
||||
testWorker1, &namedLockPattern);
|
||||
assert(t1);
|
||||
|
||||
epicsThreadId t2 = epicsThreadCreate("worker2", epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium),
|
||||
testWorker2, &namedLockPattern);
|
||||
assert(t2);
|
||||
|
||||
retval = pthread_create(&_worker2Id, NULL, testWorker2, &namedLockPattern);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
|
||||
//wait for threads
|
||||
retval = pthread_join(_worker1Id, NULL);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
|
||||
retval = pthread_join(_worker2Id, NULL);
|
||||
if(retval != 0)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
int dummy;
|
||||
epicsMessageQueueReceive(join1, &dummy, 1);
|
||||
epicsMessageQueueReceive(join2, &dummy, 1);
|
||||
|
||||
epicsExitCallAtExits();
|
||||
CDRMonitor::get().show(stdout, true);
|
||||
|
||||
Reference in New Issue
Block a user