diff --git a/src/libCom/test/ringPointerTest.c b/src/libCom/test/ringPointerTest.c index cffb94bf0..2a5518e9d 100644 --- a/src/libCom/test/ringPointerTest.c +++ b/src/libCom/test/ringPointerTest.c @@ -26,14 +26,37 @@ #include "epicsUnitTest.h" #include "testMain.h" +static +void *int2ptr(size_t i) +{ + char *zero = 0; + i = i|(i<<16); + return zero+i; +} + +static int foundCorruption; + +static +size_t ptr2int(void *p) +{ + char *zero = 0, *p2 = p; + size_t i = p2-zero; + if((i&0xffff)!=((i>>16)&0xffff)) { + testDiag("Pointer value corruption %p", p); + foundCorruption = 1; + } + return i&0xffff; +} + static void testSingle(void) { - void *i; + int i; const int rsize = 100; - void * const zero = 0; /* avoid warnings about int<->pointer casting */ void *addr = 0; epicsRingPointerId ring = epicsRingPointerCreate(rsize); + foundCorruption = 0; + testDiag("Testing operations w/o threading"); testOk1(epicsRingPointerIsEmpty(ring)); @@ -44,7 +67,7 @@ static void testSingle(void) testOk1(epicsRingPointerPop(ring)==NULL); - addr = zero+1; + addr = int2ptr(1); testOk1(epicsRingPointerPush(ring, addr)==1); testOk1(!epicsRingPointerIsEmpty(ring)); @@ -54,15 +77,16 @@ static void testSingle(void) testOk1(epicsRingPointerGetUsed(ring)==1); testDiag("Fill it up"); - for(i=zero+2; i>16)&0xffff)) { - testDiag("Pointer value corruption %p", p); - foundCorruption = 1; - } - return i&0xffff; -} - typedef struct { epicsRingPointerId ring; epicsEventId sync, wait; @@ -229,7 +234,7 @@ static void testPair(int locked) MAIN(ringPointerTest) { - testPlan(36); + testPlan(37); testSingle(); testPair(0); testPair(1);