From e1dc920661d87fb1e35d83ccefe2b1af5180cb92 Mon Sep 17 00:00:00 2001 From: jr76 Date: Mon, 19 Sep 2011 11:33:23 +0100 Subject: [PATCH 1/2] unsigned int8 replaced with uint8_t for windows build --- pvAccessApp/ca/caConstants.h | 2 +- pvAccessApp/remote/blockingTCPTransport.cpp | 2 +- pvAccessApp/remote/blockingUDPTransport.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pvAccessApp/ca/caConstants.h b/pvAccessApp/ca/caConstants.h index 5ab07ef..906c9b4 100644 --- a/pvAccessApp/ca/caConstants.h +++ b/pvAccessApp/ca/caConstants.h @@ -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; diff --git a/pvAccessApp/remote/blockingTCPTransport.cpp b/pvAccessApp/remote/blockingTCPTransport.cpp index 8e2d736..124530d 100644 --- a/pvAccessApp/remote/blockingTCPTransport.cpp +++ b/pvAccessApp/remote/blockingTCPTransport.cpp @@ -554,7 +554,7 @@ namespace epics { // second byte version - major/minor nibble int8 magic = _socketBuffer->getByte(); _version = _socketBuffer->getByte(); - if((magic != CA_MAGIC) || (((unsigned int8)_version) >> 4)!=CA_MAJOR_PROTOCOL_REVISION) + if((magic != CA_MAGIC) || (((uint8_t)_version) >> 4)!=CA_MAJOR_PROTOCOL_REVISION) { // error... disconnect LOG( diff --git a/pvAccessApp/remote/blockingUDPTransport.cpp b/pvAccessApp/remote/blockingUDPTransport.cpp index 75955cc..342572a 100644 --- a/pvAccessApp/remote/blockingUDPTransport.cpp +++ b/pvAccessApp/remote/blockingUDPTransport.cpp @@ -263,7 +263,7 @@ namespace epics { // second byte version - major/minor nibble int8 magic = receiveBuffer->getByte(); int8 version = receiveBuffer->getByte(); - if((magic != CA_MAGIC) || (((unsigned int8)version) >> 4)!=CA_MAJOR_PROTOCOL_REVISION) + if((magic != CA_MAGIC) || (((uint8_t)version) >> 4)!=CA_MAJOR_PROTOCOL_REVISION) return false; // only data for UDP From 6383b8933f7973514ed127cbaab283949f7b0106 Mon Sep 17 00:00:00 2001 From: jrowlandls Date: Mon, 19 Sep 2011 14:51:35 +0100 Subject: [PATCH 2/2] tests now using libCom osi --- testApp/remote/Makefile | 2 +- testApp/remote/testChannelSearchManager.cpp | 57 +++++++++---------- testApp/utils/Makefile | 4 +- testApp/utils/configurationTest.cpp | 9 +++ testApp/utils/namedLockPatternTest.cpp | 62 ++++++++++----------- 5 files changed, 68 insertions(+), 66 deletions(-) diff --git a/testApp/remote/Makefile b/testApp/remote/Makefile index 42fa3b5..4d39022 100644 --- a/testApp/remote/Makefile +++ b/testApp/remote/Makefile @@ -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 diff --git a/testApp/remote/testChannelSearchManager.cpp b/testApp/remote/testChannelSearchManager.cpp index 692d255..5b27d4a 100644 --- a/testApp/remote/testChannelSearchManager.cpp +++ b/testApp/remote/testChannelSearchManager.cpp @@ -1,10 +1,15 @@ /* testChannelSearcManager.cpp */ #include +#include +#include #include #include #include +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)); 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(); diff --git a/testApp/utils/Makefile b/testApp/utils/Makefile index a5192ce..28fe01b 100644 --- a/testApp/utils/Makefile +++ b/testApp/utils/Makefile @@ -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 diff --git a/testApp/utils/configurationTest.cpp b/testApp/utils/configurationTest.cpp index 9be50f6..5f9b9b8 100644 --- a/testApp/utils/configurationTest.cpp +++ b/testApp/utils/configurationTest.cpp @@ -12,6 +12,15 @@ #include #include +#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; diff --git a/testApp/utils/namedLockPatternTest.cpp b/testApp/utils/namedLockPatternTest.cpp index 2a944e6..eb5bc13 100644 --- a/testApp/utils/namedLockPatternTest.cpp +++ b/testApp/utils/namedLockPatternTest.cpp @@ -11,6 +11,8 @@ #include #include +#include +#include #include #include @@ -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 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 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 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 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);