From 1d6de601e5370be1f7e2138a099c8a10d2c7d19e Mon Sep 17 00:00:00 2001 From: zimoch Date: Wed, 27 Nov 2013 13:59:50 +0000 Subject: [PATCH] merge with 3.14.12-pre1 --- src/libCom/osi/devLibVME.h | 5 - src/libCom/osi/devLibVMEImpl.h | 1 + src/libCom/osi/epicsSignal.h | 9 +- src/libCom/osi/os/RTEMS/osdThread.c | 20 +-- src/libCom/osi/os/RTEMS/osdVME.h | 4 +- src/libCom/osi/os/WIN32/osdMutex.c | 6 +- src/libCom/osi/os/WIN32/osdStdio.c | 19 +-- src/libCom/osi/os/WIN32/osdThread.c | 38 +++-- .../osi/os/cygwin32/systemCallIntMech.cpp | 6 +- src/libCom/osi/os/default/devLibVMEOSD.c | 5 +- src/libCom/osi/os/default/epicsReadline.c | 13 +- src/libCom/osi/os/posix/osdThread.c | 21 +-- src/libCom/osi/os/posix/osdTime.cpp | 2 +- src/libCom/osi/os/vxWorks/atReboot.cpp | 25 ++-- src/libCom/osi/os/vxWorks/osdPoolStatus.c | 4 +- src/libCom/osi/os/vxWorks/osdSock.c | 36 +++-- src/libCom/osi/os/vxWorks/osdThread.c | 20 +-- src/libCom/osi/os/vxWorks/osdTime.cpp | 12 +- src/libCom/osi/osiPoolStatus.h | 11 +- src/libCom/osi/osiProcess.h | 11 +- src/libCom/ring/epicsRingPointer.cpp | 7 +- src/libCom/ring/epicsRingPointer.h | 8 +- src/libCom/taskwd/taskwd.c | 4 +- src/libCom/test/Makefile | 6 + src/libCom/test/cvtFastPerform.cpp | 6 +- src/libCom/test/epicsCalcTest.cpp | 15 +- src/libCom/test/epicsRunLibComTests.c | 3 + src/libCom/test/epicsSockResolveTest.c | 92 +++++++++++++ src/libCom/test/epicsStdioTest.c | 9 +- src/libCom/test/epicsTimeTest.cpp | 130 ++++++++++-------- 30 files changed, 334 insertions(+), 214 deletions(-) create mode 100644 src/libCom/test/epicsSockResolveTest.c diff --git a/src/libCom/osi/devLibVME.h b/src/libCom/osi/devLibVME.h index 6d7476098..8e526a139 100644 --- a/src/libCom/osi/devLibVME.h +++ b/src/libCom/osi/devLibVME.h @@ -300,11 +300,6 @@ epicsShareFunc long locationProbe (epicsAddressType addrType, char *pLocation); #endif /* NO_DEVLIB_OLD_INTERFACE */ -/* - * Some vxWorks convenience routines - */ -void bcopyLongs(char *source, char *destination, int nlongs); - #ifdef __cplusplus } #endif diff --git a/src/libCom/osi/devLibVMEImpl.h b/src/libCom/osi/devLibVMEImpl.h index 63d794ca3..e695edeb9 100644 --- a/src/libCom/osi/devLibVMEImpl.h +++ b/src/libCom/osi/devLibVMEImpl.h @@ -94,6 +94,7 @@ epicsShareExtern devLibVME *pdevLibVME; #ifndef NO_DEVLIB_COMPAT # define pdevLibVirtualOS pdevLibVME +typedef devLibVME devLibVirtualOS; #endif diff --git a/src/libCom/osi/epicsSignal.h b/src/libCom/osi/epicsSignal.h index 2fd0e5839..79adf71d1 100644 --- a/src/libCom/osi/epicsSignal.h +++ b/src/libCom/osi/epicsSignal.h @@ -3,11 +3,13 @@ * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. - * EPICS BASE Versions 3.13.7 - * and higher are distributed subject to a Software License Agreement found - * in file LICENSE that is included with this distribution. + * EPICS BASE is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. \*************************************************************************/ +#ifndef INC_epicsSignal_H +#define INC_epicsSignal_H + #ifdef __cplusplus extern "C" { #endif @@ -44,3 +46,4 @@ epicsShareFunc void epicsShareAPI epicsSignalRaiseSigAlarm ( struct epicsThreadO } #endif +#endif /* INC_epicsSignal_H */ diff --git a/src/libCom/osi/os/RTEMS/osdThread.c b/src/libCom/osi/os/RTEMS/osdThread.c index 5cdb15441..85900e5bf 100644 --- a/src/libCom/osi/os/RTEMS/osdThread.c +++ b/src/libCom/osi/os/RTEMS/osdThread.c @@ -6,7 +6,7 @@ \*************************************************************************/ /* * RTEMS osdThread.c - * Revision-Id: anj@aps.anl.gov-20101005192737-disfz3vs0f3fiixd + * Revision-Id: anj@aps.anl.gov-20120618195203-fn89v5ir0faou35v * Author: W. Eric Norum * eric@cls.usask.ca * (306) 966-6055 @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -364,16 +365,15 @@ epicsThreadSleep (double seconds) { rtems_status_code sc; rtems_interval delay; - extern double rtemsTicksPerTwoSeconds_double; - - if (seconds <= 0.0) { - delay = 0; + extern double rtemsTicksPerSecond_double; + + if (seconds > 0.0) { + seconds *= rtemsTicksPerSecond_double; + seconds += 0.99999999; /* 8 9s here is optimal */ + delay = (seconds >= INT_MAX) ? INT_MAX : (int) seconds; } - else { - delay = seconds * rtemsTicksPerTwoSeconds_double; - delay = (delay + 1) / 2; - if (delay == 0) - delay++; + else { /* seconds <= 0 or NAN */ + delay = 0; } sc = rtems_task_wake_after (delay); if(sc != RTEMS_SUCCESSFUL) diff --git a/src/libCom/osi/os/RTEMS/osdVME.h b/src/libCom/osi/os/RTEMS/osdVME.h index 2de190683..959389d87 100644 --- a/src/libCom/osi/os/RTEMS/osdVME.h +++ b/src/libCom/osi/os/RTEMS/osdVME.h @@ -7,7 +7,7 @@ * and higher are distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ -/* Revision-Id: anj@aps.anl.gov-20101005192737-disfz3vs0f3fiixd */ +/* Revision-Id: anj@aps.anl.gov-20130328221741-gjmdorru0oolmpt3 */ /* * OS-dependent VME support @@ -19,3 +19,5 @@ #endif #endif #endif + +void bcopyLongs(char *source, char *destination, int nlongs); diff --git a/src/libCom/osi/os/WIN32/osdMutex.c b/src/libCom/osi/os/WIN32/osdMutex.c index 19314b556..172ba937e 100644 --- a/src/libCom/osi/os/WIN32/osdMutex.c +++ b/src/libCom/osi/os/WIN32/osdMutex.c @@ -9,7 +9,7 @@ \*************************************************************************/ /* osdMutex.c */ /* - * Revision-Id: anj@aps.anl.gov-20101005192737-disfz3vs0f3fiixd + * Revision-Id: anj@aps.anl.gov-20131120004245-drexj41vy3vynah9 * WIN32 version * * Author Jeffrey O. Hill @@ -38,7 +38,9 @@ * It appears that the only entry point used here that causes * portability problems with W95\W98\WME is TryEnterCriticalSection. */ -#define _WIN32_WINNT 0x0400 +#ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x0400 +#endif #include #define epicsExportSharedSymbols diff --git a/src/libCom/osi/os/WIN32/osdStdio.c b/src/libCom/osi/os/WIN32/osdStdio.c index 602651f8b..8a2d58ea9 100644 --- a/src/libCom/osi/os/WIN32/osdStdio.c +++ b/src/libCom/osi/os/WIN32/osdStdio.c @@ -11,6 +11,11 @@ #include #include +#ifndef _MSC_VER +/* Older versions of MinGW omitted this prototype from stdio.h */ +_CRTIMP int __cdecl __MINGW_NOTHROW _vscprintf (const char*, va_list); +#endif + #define epicsExportSharedSymbols #include "epicsStdio.h" @@ -18,26 +23,12 @@ int epicsShareAPI epicsVsnprintf(char *str, size_t len, const char *fmt, va_list ap) { int retval = _vsnprintf(str, len, fmt, ap); - -#ifdef _MSC_VER int needed = _vscprintf(fmt, ap); if ((int) len < needed + 1) { str[len - 1] = 0; return needed; } -#else - /* Unfortunately MINGW doesn't provide _vscprintf and their - * _vsnprintf follows MS' broken return value semantics. - */ - if (retval == -1) { - if (len) - str[len - 1] = 0; - return len; - } else if (retval == (int) len) { - str[--retval] = 0; - } -#endif return retval; } diff --git a/src/libCom/osi/os/WIN32/osdThread.c b/src/libCom/osi/os/WIN32/osdThread.c index aa360cfc0..6261869bf 100644 --- a/src/libCom/osi/os/WIN32/osdThread.c +++ b/src/libCom/osi/os/WIN32/osdThread.c @@ -3,13 +3,12 @@ * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ /* - * Revision-Id: anj@aps.anl.gov-20111108215715-d8j6l4lycpi3gvvb + * Revision-Id: anj@aps.anl.gov-20131120004245-drexj41vy3vynah9 * * Author: Jeff Hill * @@ -23,8 +22,8 @@ #define VC_EXTRALEAN #define STRICT -#if _WIN64 -# define _WIN32_WINNT 0x400 /* defining this drops support for W95 */ +#ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x400 /* No support for W95 */ #endif #include #include /* for _endthread() etc */ @@ -246,10 +245,7 @@ static void epicsParmCleanupWIN32 ( win32ThreadParam * pParm ) ellDelete ( & pGbl->threadList, & pParm->node ); LeaveCriticalSection ( & pGbl->mutex ); - /* close the handle if its an implicit thread id */ - if ( ! pParm->funptr ) { - CloseHandle ( pParm->handle ); - } + CloseHandle ( pParm->handle ); free ( pParm ); TlsSetValue ( pGbl->tlsIndexThreadLibraryEPICS, 0 ); } @@ -446,7 +442,10 @@ epicsShareFunc epicsThreadBooleanStatus epicsShareAPI epicsThreadHighestPriority epicsShareFunc unsigned int epicsShareAPI epicsThreadGetStackSize ( epicsThreadStackSizeClass stackSizeClass ) { - static const unsigned stackSizeTable[epicsThreadStackBig+1] = {4000, 6000, 11000}; + #define STACK_SIZE(f) (f * 0x10000 * sizeof(void *)) + static const unsigned stackSizeTable[epicsThreadStackBig+1] = { + STACK_SIZE(1), STACK_SIZE(2), STACK_SIZE(4) + }; if (stackSizeClass 0.0 ) { + seconds *= mSecPerSec; + seconds += 0.99999999; /* 8 9s here is optimal */ + milliSecDelay = ( seconds >= INFINITE ) ? + INFINITE - 1 : ( DWORD ) seconds; + } + else { /* seconds <= 0 or NAN */ milliSecDelay = 0u; } - else if ( seconds >= INFINITE / mSecPerSec ) { - milliSecDelay = INFINITE - 1; - } - else { - milliSecDelay = ( DWORD ) ( ( seconds * mSecPerSec ) + 0.5 ); - if ( milliSecDelay == 0 ) { - milliSecDelay = 1; - } - } Sleep ( milliSecDelay ); } diff --git a/src/libCom/osi/os/cygwin32/systemCallIntMech.cpp b/src/libCom/osi/os/cygwin32/systemCallIntMech.cpp index 1f5c3abed..4b1b40c06 100644 --- a/src/libCom/osi/os/cygwin32/systemCallIntMech.cpp +++ b/src/libCom/osi/os/cygwin32/systemCallIntMech.cpp @@ -8,7 +8,7 @@ * and higher are distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ -/* Revision-Id: anj@aps.anl.gov-20101104192413-fxlfgfq0kuhsi23a */ +/* Revision-Id: anj@aps.anl.gov-20131120004103-rrs4qf6hlp20naol */ /* * Author: Jeff Hill */ @@ -21,8 +21,8 @@ enum epicsSocketSystemCallInterruptMechanismQueryInfo epicsSocketSystemCallInterruptMechanismQuery () { -#if (CYGWIN_VERSION_DLL_MAJOR >= 1007) - // Behaviour changed in Cygwin 1.7 release. +#if 0 + // Some broken versions of cygwin needed this: return esscimqi_socketCloseRequired; #else return esscimqi_socketBothShutdownRequired; diff --git a/src/libCom/osi/os/default/devLibVMEOSD.c b/src/libCom/osi/os/default/devLibVMEOSD.c index a1c659f4e..773fffc33 100644 --- a/src/libCom/osi/os/default/devLibVMEOSD.c +++ b/src/libCom/osi/os/default/devLibVMEOSD.c @@ -6,12 +6,13 @@ * in file LICENSE that is included with this distribution. \*************************************************************************/ -/* Revision-Id: anj@aps.anl.gov-20101005192737-disfz3vs0f3fiixd */ +/* Revision-Id: anj@aps.anl.gov-20131120004245-drexj41vy3vynah9 */ #include +#define epicsExportSharedSymbols #include "devLibVME.h" /* This file must contain no definitions other than the following: */ -devLibVME *pdevLibVME; +epicsShareDef devLibVME *pdevLibVME; diff --git a/src/libCom/osi/os/default/epicsReadline.c b/src/libCom/osi/os/default/epicsReadline.c index 4df20ed2e..91f2c2283 100644 --- a/src/libCom/osi/os/default/epicsReadline.c +++ b/src/libCom/osi/os/default/epicsReadline.c @@ -5,7 +5,7 @@ * EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ -/* Revision-Id: anj@aps.anl.gov-20101005192737-disfz3vs0f3fiixd */ +/* Revision-Id: anj@aps.anl.gov-20120831210514-z6b2h7o317s14cqi */ /* Author: Eric Norum Date: 12DEC2001 */ #include @@ -190,8 +190,7 @@ epicsReadlineEnd (void *context) #define LEDLIB_LINESIZE 1000 #ifndef _WRS_VXWORKS_MAJOR -/* vxWorks 5 uses int but vxWorks 6 uses LED_ID */ -#define LED_ID int +typedef int LED_ID; #endif struct readlineContext { @@ -210,7 +209,7 @@ epicsReadlineBegin(FILE *in) readlineContext = malloc(sizeof *readlineContext); if (readlineContext != NULL) { - readlineContext->ledId = (LED_ID)ERROR; + readlineContext->ledId = (LED_ID) ERROR; readlineContext->in = in; if (in == NULL) { long i = 50; @@ -218,7 +217,7 @@ epicsReadlineBegin(FILE *in) envGetLongConfigParam(&IOCSH_HISTSIZE, &i); if (i < 1) i = 1; readlineContext->ledId = ledOpen(fileno(stdin), fileno(stdout), i); - if (readlineContext->ledId == (LED_ID)ERROR) { + if (readlineContext->ledId == (LED_ID) ERROR) { readlineContext->in = stdin; printf("Warning -- Unabled to allocate space for command-line history.\n"); printf("Warning -- Command-line editting disabled.\n"); @@ -241,7 +240,7 @@ epicsReadline (const char *prompt, void *context) fputs(prompt, stdout); fflush(stdout); } - if (readlineContext->ledId != (LED_ID)ERROR) { + if (readlineContext->ledId != (LED_ID) ERROR) { i = ledRead(readlineContext->ledId, readlineContext->line, LEDLIB_LINESIZE-1); if (i < 0) return NULL; @@ -267,7 +266,7 @@ epicsReadlineEnd (void *context) struct readlineContext *readlineContext = context; if (readlineContext) { - if (readlineContext->ledId != (LED_ID)ERROR) + if (readlineContext->ledId != (LED_ID) ERROR) ledClose(readlineContext->ledId); free(readlineContext); } diff --git a/src/libCom/osi/os/posix/osdThread.c b/src/libCom/osi/os/posix/osdThread.c index f7e47b100..30583e162 100644 --- a/src/libCom/osi/os/posix/osdThread.c +++ b/src/libCom/osi/os/posix/osdThread.c @@ -398,9 +398,6 @@ static void epicsThreadInit(void) } -#define ARCH_STACK_FACTOR 1024 - - epicsShareFunc unsigned int epicsShareAPI epicsThreadGetStackSize (epicsThreadStackSizeClass stackSizeClass) { #if ! defined (_POSIX_THREAD_ATTR_STACKSIZE) @@ -408,8 +405,10 @@ epicsShareFunc unsigned int epicsShareAPI epicsThreadGetStackSize (epicsThreadSt #elif defined (OSITHREAD_USE_DEFAULT_STACK) return 0; #else - static const unsigned stackSizeTable[epicsThreadStackBig+1] = - {128*ARCH_STACK_FACTOR, 256*ARCH_STACK_FACTOR, 512*ARCH_STACK_FACTOR}; + #define STACK_SIZE(f) (f * 0x10000 * sizeof(void *)) + static const unsigned stackSizeTable[epicsThreadStackBig+1] = { + STACK_SIZE(1), STACK_SIZE(2), STACK_SIZE(4) + }; if (stackSizeClass 0) { + delayTime.tv_sec = seconds; + nanoseconds = (seconds - delayTime.tv_sec) *1e9; + delayTime.tv_nsec = nanoseconds; + } + else { + delayTime.tv_sec = 0; + delayTime.tv_nsec = 0; + } while (nanosleep(&delayTime, &remainingTime) == -1 && errno == EINTR) delayTime = remainingTime; diff --git a/src/libCom/osi/os/posix/osdTime.cpp b/src/libCom/osi/os/posix/osdTime.cpp index 62939a427..987629f51 100644 --- a/src/libCom/osi/os/posix/osdTime.cpp +++ b/src/libCom/osi/os/posix/osdTime.cpp @@ -24,7 +24,7 @@ #define TIME_INIT ClockTime_Init(CLOCKTIME_NOSYNC) #else - /* Some posix systems like Darwin don't have CLOCK_REALTIME */ + /* Some posix systems may not have CLOCK_REALTIME */ #define TIME_INIT generalTimeCurrentTpRegister("GetTimeOfDay", \ LAST_RESORT_PRIORITY, osdTimeGetCurrent) diff --git a/src/libCom/osi/os/vxWorks/atReboot.cpp b/src/libCom/osi/os/vxWorks/atReboot.cpp index cb4bff5cc..9a35286ef 100644 --- a/src/libCom/osi/os/vxWorks/atReboot.cpp +++ b/src/libCom/osi/os/vxWorks/atReboot.cpp @@ -1,10 +1,9 @@ /*************************************************************************\ -* Copyright (c) 2002 The University of Chicago, as Operator of Argonne +* Copyright (c) 2013 UChicago Argonne LLC, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found +* EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ /* atReboot.cpp */ @@ -16,34 +15,28 @@ #include "epicsDynLink.h" #include "epicsExit.h" -/* osdThread references atRebootExtern just to make this module load*/ -int atRebootExtern; +extern "C" { typedef int (*sysAtReboot_t)(void(func)(void)); -class atRebootRegister { -public: - atRebootRegister(); -}; - -atRebootRegister::atRebootRegister() +void atRebootRegister(void) { STATUS status; sysAtReboot_t sysAtReboot; SYM_TYPE type; status = symFindByNameEPICS(sysSymTbl, "_sysAtReboot", - (char **)&sysAtReboot, &type); + (char **)&sysAtReboot, &type); if (status == OK) { status = sysAtReboot(epicsExitCallAtExits); if (status != OK) { printf("atReboot: sysAtReboot returned error %d\n", status); } } else { - printf("BSP routine sysAtReboot() not found, epicsExit() will not be\n" - "called by reboot. For reduced functionality, call\n" - " rebootHookAdd(epicsExitCallAtExits)\n"); + printf("BSP routine sysAtReboot() not found, epicsExit() will not be\n" + "called by reboot. For reduced functionality, call\n" + " rebootHookAdd(epicsExitCallAtExits)\n"); } } -static atRebootRegister atRebootRegisterObj; +} diff --git a/src/libCom/osi/os/vxWorks/osdPoolStatus.c b/src/libCom/osi/os/vxWorks/osdPoolStatus.c index c8418a236..06447c1f7 100644 --- a/src/libCom/osi/os/vxWorks/osdPoolStatus.c +++ b/src/libCom/osi/os/vxWorks/osdPoolStatus.c @@ -30,9 +30,7 @@ static size_t osdMaxBlockSize = 0; static void osdSufficentSpaceInPoolQuery () { - int temp = memFindMax (); - - osdMaxBlockSize = ( temp > 0 ) ? (size_t) temp : 0; + osdMaxBlockSize = (size_t) memFindMax (); } static void osdSufficentSpaceInPoolPoll ( void *pArgIn ) diff --git a/src/libCom/osi/os/vxWorks/osdSock.c b/src/libCom/osi/os/vxWorks/osdSock.c index dd6bab973..13798803b 100644 --- a/src/libCom/osi/os/vxWorks/osdSock.c +++ b/src/libCom/osi/os/vxWorks/osdSock.c @@ -27,7 +27,7 @@ int osiSockAttach() { - return 1; + return 1; } void osiSockRelease() @@ -112,27 +112,25 @@ epicsShareFunc unsigned epicsShareAPI ipAddrToHostName /* * hostToIPAddr () */ -epicsShareFunc int epicsShareAPI hostToIPAddr - (const char *pHostName, struct in_addr *pIPA) +epicsShareFunc int epicsShareAPI +hostToIPAddr(const char *pHostName, struct in_addr *pIPA) { - int addr; + int addr; - addr = hostGetByName ((char *)pHostName); - if (addr==ERROR) { - addr = inet_addr ((char *)pHostName); - if (addr==ERROR) { - /* - * return indicating an error - */ - return -1; - } + addr = hostGetByName((char *)pHostName); + if (addr != ERROR) { + pIPA->s_addr = (unsigned long) addr; + } + else if (inet_aton((char *)pHostName, pIPA) == ERROR) { + /* + * return indicating an error + */ + return -1; } - pIPA->s_addr = (unsigned long) addr; - - /* - * success - */ - return 0; + /* + * success + */ + return 0; } diff --git a/src/libCom/osi/os/vxWorks/osdThread.c b/src/libCom/osi/os/vxWorks/osdThread.c index 09d451fab..237347117 100644 --- a/src/libCom/osi/os/vxWorks/osdThread.c +++ b/src/libCom/osi/os/vxWorks/osdThread.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -42,12 +43,8 @@ static const unsigned stackSizeTable[epicsThreadStackBig+1] = {4000*ARCH_STACK_FACTOR, 6000*ARCH_STACK_FACTOR, 11000*ARCH_STACK_FACTOR}; -/*The following forces atReboot to be loaded*/ -extern int atRebootExtern; -static struct pext { - int *pExtern; - struct pext *pext; -} pext = {&atRebootExtern, &pext}; +/* This routine is found in atReboot.cpp */ +extern void atRebootRegister(void); /* definitions for implementation of epicsThreadPrivate */ static void **papTSD = 0; @@ -92,6 +89,7 @@ static void epicsThreadInit(void) epicsThreadOnceMutex = semMCreate( SEM_DELETE_SAFE|SEM_INVERSION_SAFE|SEM_Q_PRIORITY); assert(epicsThreadOnceMutex); + atRebootRegister(); } lock = 0; } @@ -279,11 +277,13 @@ void epicsThreadSleep(double seconds) STATUS status; int ticks; - if(seconds<=0.0) { + if (seconds > 0.0) { + seconds *= sysClkRateGet(); + seconds += 0.99999999; /* 8 9s here is optimal */ + ticks = (seconds >= INT_MAX) ? INT_MAX : (int) seconds; + } + else { /* seconds <= 0 or NAN */ ticks = 0; - } else { - ticks = seconds*sysClkRateGet() + 0.5; - if(ticks<=0) ticks = 1; } status = taskDelay(ticks); if(status) errlogPrintf("epicsThreadSleep\n"); diff --git a/src/libCom/osi/os/vxWorks/osdTime.cpp b/src/libCom/osi/os/vxWorks/osdTime.cpp index a0e2422e9..eed1ad078 100644 --- a/src/libCom/osi/os/vxWorks/osdTime.cpp +++ b/src/libCom/osi/os/vxWorks/osdTime.cpp @@ -67,14 +67,18 @@ void osdNTPReport(void) } -// vxWorks localtime_r interface does not match POSIX standards +// vxWorks localtime_r returns different things in different versions. +// It can't fail though, so we just ignore the return value. int epicsTime_localtime(const time_t *clock, struct tm *result) { - return localtime_r(clock, result) == OK ? epicsTimeOK : epicsTimeERROR; + localtime_r(clock, result); + return epicsTimeOK; } -// vxWorks gmtime_r interface does not match POSIX standards +// vxWorks gmtime_r returns different things in different versions. +// It can't fail though, so we just ignore the return value. int epicsTime_gmtime ( const time_t *pAnsiTime, struct tm *pTM ) { - return gmtime_r(pAnsiTime, pTM) == OK ? epicsTimeOK : epicsTimeERROR; + gmtime_r(pAnsiTime, pTM); + return epicsTimeOK; } diff --git a/src/libCom/osi/osiPoolStatus.h b/src/libCom/osi/osiPoolStatus.h index 24cd9c4a6..20c3d781e 100644 --- a/src/libCom/osi/osiPoolStatus.h +++ b/src/libCom/osi/osiPoolStatus.h @@ -3,13 +3,15 @@ * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ +#ifndef INC_osiPoolStatus_H +#define INC_osiPoolStatus_H + /* - * Revision-Id: anj@aps.anl.gov-20101005192737-disfz3vs0f3fiixd + * Revision-Id: anj@aps.anl.gov-20130411175656-dor1h3zt7zo46epw * * Author: Jeff Hill * @@ -39,3 +41,4 @@ epicsShareFunc int epicsShareAPI osiSufficentSpaceInPool ( size_t contiguousBloc #include "osdPoolStatus.h" +#endif /* INC_osiPoolStatus_H */ diff --git a/src/libCom/osi/osiProcess.h b/src/libCom/osi/osiProcess.h index ddf375a57..3eb7115a8 100644 --- a/src/libCom/osi/osiProcess.h +++ b/src/libCom/osi/osiProcess.h @@ -3,13 +3,15 @@ * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ +#ifndef INC_osiProcess_H +#define INC_osiProcess_H + /* - * Revision-Id: anj@aps.anl.gov-20101005192737-disfz3vs0f3fiixd + * Revision-Id: anj@aps.anl.gov-20130411175656-dor1h3zt7zo46epw * * Operating System Independent Interface to Process Environment * @@ -44,3 +46,4 @@ epicsShareFunc osiSpawnDetachedProcessReturn epicsShareAPI osiSpawnDetachedProce } #endif +#endif /* INC_osiProcess_H */ diff --git a/src/libCom/ring/epicsRingPointer.cpp b/src/libCom/ring/epicsRingPointer.cpp index 5118c9347..3a5cc8c72 100644 --- a/src/libCom/ring/epicsRingPointer.cpp +++ b/src/libCom/ring/epicsRingPointer.cpp @@ -3,9 +3,8 @@ * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ /*epicsRingPointer.cpp*/ /* Author: Marty Kraimer Date: 13OCT2000 */ @@ -63,7 +62,7 @@ epicsShareFunc int epicsShareAPI epicsRingPointerGetUsed(epicsRingPointerId id) return(pvoidPointer->getUsed()); } -epicsShareFunc int epicsShareAPI epicsRingPointerSize(epicsRingPointerId id) +epicsShareFunc int epicsShareAPI epicsRingPointerGetSize(epicsRingPointerId id) { voidPointer *pvoidPointer = reinterpret_cast(id); return(pvoidPointer->getSize()); diff --git a/src/libCom/ring/epicsRingPointer.h b/src/libCom/ring/epicsRingPointer.h index 57534586a..3332782a4 100644 --- a/src/libCom/ring/epicsRingPointer.h +++ b/src/libCom/ring/epicsRingPointer.h @@ -3,9 +3,8 @@ * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. -* EPICS BASE Versions 3.13.7 -* and higher are distributed subject to a Software License Agreement found -* in file LICENSE that is included with this distribution. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. \*************************************************************************/ /*epicsRingPointer.h */ @@ -67,6 +66,9 @@ epicsShareFunc int epicsShareAPI epicsRingPointerGetSize(epicsRingPointerId id) epicsShareFunc int epicsShareAPI epicsRingPointerIsEmpty(epicsRingPointerId id); epicsShareFunc int epicsShareAPI epicsRingPointerIsFull(epicsRingPointerId id); +/* This routine was incorrectly named in previous releases */ +#define epicsRingPointerSize epicsRingPointerGetSize + #ifdef __cplusplus } #endif diff --git a/src/libCom/taskwd/taskwd.c b/src/libCom/taskwd/taskwd.c index b77361236..c034e1828 100644 --- a/src/libCom/taskwd/taskwd.c +++ b/src/libCom/taskwd/taskwd.c @@ -69,8 +69,8 @@ static epicsMutexId fLock; static ELLLIST fList = ELLLIST_INIT; /* Watchdog task control */ -static enum { - twdctlRun, twdctlDisable, twdctlExit +static volatile enum { + twdctlInit, twdctlRun, twdctlDisable, twdctlExit } twdCtl; static epicsEventId loopEvent; static epicsEventId exitEvent; diff --git a/src/libCom/test/Makefile b/src/libCom/test/Makefile index 9bf92f528..0d6ab1487 100644 --- a/src/libCom/test/Makefile +++ b/src/libCom/test/Makefile @@ -47,6 +47,12 @@ epicsStdioTest_SRCS += epicsStdioTest.c testHarness_SRCS += epicsStdioTest.c TESTS += epicsStdioTest +TESTPROD_HOST += epicsSockResolveTest +epicsSockResolveTest_SRCS += epicsSockResolveTest.c +testHarness_SRCS += epicsSockResolveTest.c +epicsSockResolveTest_SYS_LIBS_WIN32 = ws2_32 +TESTS += epicsSockResolveTest + TESTPROD_HOST += epicsStringTest epicsStringTest_SRCS += epicsStringTest.c testHarness_SRCS += epicsStringTest.c diff --git a/src/libCom/test/cvtFastPerform.cpp b/src/libCom/test/cvtFastPerform.cpp index 5b1ab4c38..f8ae7c270 100644 --- a/src/libCom/test/cvtFastPerform.cpp +++ b/src/libCom/test/cvtFastPerform.cpp @@ -60,9 +60,9 @@ void Test :: execute () for ( unsigned i = 0; i < 3; i++ ) { double mVal = rand (); - mVal /= (RAND_MAX + 1); + mVal /= (RAND_MAX + 1.0); double fEVal = rand (); - fEVal /= (RAND_MAX + 1); + fEVal /= (RAND_MAX + 1.0); fEVal *= DBL_MAX_EXP - DBL_MIN_EXP; fEVal += DBL_MIN_EXP; int eVal = static_cast < int > ( fEVal + 0.5 ); @@ -72,7 +72,7 @@ void Test :: execute () _measure (); } _srcVal = rand (); - _srcVal /= (RAND_MAX + 1); + _srcVal /= (RAND_MAX + 1.0); _srcVal *= 10.0; _srcVal -= 5.0; for ( _prec = lowPrecision; diff --git a/src/libCom/test/epicsCalcTest.cpp b/src/libCom/test/epicsCalcTest.cpp index 4b82f8163..49faa42b4 100644 --- a/src/libCom/test/epicsCalcTest.cpp +++ b/src/libCom/test/epicsCalcTest.cpp @@ -4,7 +4,7 @@ * EPICS BASE is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. \*************************************************************************/ -// Revision-Id: anj@aps.anl.gov-20110407222502-um4y5q4rzq5vlk3e +// Revision-Id: anj@aps.anl.gov-20121203185826-cd68u8o9fu5vbr7u // Author: Andrew Johnson #include "epicsUnitTest.h" @@ -238,7 +238,7 @@ MAIN(epicsCalcTest) const double a=1.0, b=2.0, c=3.0, d=4.0, e=5.0, f=6.0, g=7.0, h=8.0, i=9.0, j=10.0, k=11.0, l=12.0; - testPlan(566); + testPlan(577); /* LITERAL_OPERAND elements */ testExpr(0); @@ -253,6 +253,11 @@ MAIN(epicsCalcTest) testExpr(9); testExpr(.1); testExpr(0.1); + testExpr(0X0); + testExpr(0x10); + testExpr(0x7fffffff); + testCalc("0x80000000", -2147483648.0); + testCalc("0xffffffff", -1); testExpr(Inf); testCalc("Infinity", Inf); testExpr(NaN); @@ -287,6 +292,7 @@ MAIN(epicsCalcTest) testExpr(-1); testExpr(-Inf); testExpr(- -1); + testCalc("-0x80000000", 2147483648.0); /* UNARY_OPERATOR elements */ testExpr((1)); @@ -325,11 +331,15 @@ MAIN(epicsCalcTest) testExpr(isinf(NaN)); testExpr(isnan(0)); testExpr(isnan(Inf)); + testExpr(isnan(-Inf)); testExpr(isnan(NaN)); testCalc("isnan(0,1,2)", 0); testCalc("isnan(0,1,NaN)", 1); testCalc("isnan(0,NaN,2)", 1); testCalc("isnan(NaN,1,2)", 1); + testCalc("isnan(0,1,Inf)", 0); + testCalc("isnan(0,Inf,2)", 0); + testCalc("isnan(Inf,1,2)", 0); testCalc("isnan(0,1,-Inf)", 0); testCalc("isnan(0,-Inf,2)", 0); testCalc("isnan(-Inf,1,2)", 0); @@ -851,6 +861,7 @@ MAIN(epicsCalcTest) testArgs("13.1;B:=A;A:=B;C:=D;D:=C", A_A|A_D, A_A|A_B|A_C|A_D); // Malformed expressions + testBadExpr("0x0.1", CALC_ERR_SYNTAX); testBadExpr("1*", CALC_ERR_INCOMPLETE); testBadExpr("*1", CALC_ERR_SYNTAX); testBadExpr("MIN", CALC_ERR_INCOMPLETE); diff --git a/src/libCom/test/epicsRunLibComTests.c b/src/libCom/test/epicsRunLibComTests.c index 80ddbf3b3..7a6da1e66 100644 --- a/src/libCom/test/epicsRunLibComTests.c +++ b/src/libCom/test/epicsRunLibComTests.c @@ -38,6 +38,7 @@ int macEnvExpandTest(void); int ringPointerTest(void); int ringBytesTest(void); int blockingSockTest(void); +int epicsSockResolveTest(void); int taskwdTest(void); int epicsExitTest(void); @@ -94,6 +95,8 @@ void epicsRunLibComTests(void) runTest(ringBytesTest); runTest(blockingSockTest); + + runTest(epicsSockResolveTest); runTest(taskwdTest); diff --git a/src/libCom/test/epicsSockResolveTest.c b/src/libCom/test/epicsSockResolveTest.c new file mode 100644 index 000000000..166a29b90 --- /dev/null +++ b/src/libCom/test/epicsSockResolveTest.c @@ -0,0 +1,92 @@ +/*************************************************************************\ +* Copyright (c) 2012 Brookhaven Science Associates as Operator of +* Brookhaven National Lab. +* Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +\*************************************************************************/ + +#include "dbDefs.h" +#include "osiSock.h" + +#include "epicsUnitTest.h" +#include "testMain.h" + +#define DEFAULT_PORT 4000 + +typedef struct { + const char *input; + unsigned long IP; + unsigned short port; +} testData; + +static testData okdata[] = { + {"127.0.0.1", 0x7f000001, DEFAULT_PORT}, + {"127.0.0.1:42", 0x7f000001, 42}, + {"localhost", 0x7f000001, DEFAULT_PORT}, + {"localhost:42", 0x7f000001, 42}, + {"2424", 2424, DEFAULT_PORT}, + {"2424:42", 2424, 42}, + {"255.255.255.255", 0xffffffff, DEFAULT_PORT}, + {"255.255.255.255:65535", 0xffffffff, 65535}, +}; + +static const char * baddata[] = { + "127.0.0.hi", + "127.0.0.hi:42", + "16invalidhostname", + "16invalidhostname:42", + "256.255.255.255", + "255.256.255.255", + "255.255.256.255", + "255.255.255.256", + "255.255.255.255:65536", +}; + +MAIN(epicsSockResolveTest) +{ + int i; + + testPlan(3*NELEMENTS(okdata) + NELEMENTS(baddata)); + + { + struct in_addr addr; + + if (hostToIPAddr("obviously.invalid.host", &addr) == 0) { + testAbort("hostToIPAddr() is broken, testing not possible"); + } + } + + testDiag("Tests of aToIPAddr"); + + for (i=0; i %d", + okdata[i].input, DEFAULT_PORT, ret); + if (ret) { + testSkip(2, " aToIPAddr() failed"); + } + else { + testOk(addr.sin_addr.s_addr == htonl(okdata[i].IP), " IP correct"); + testOk(addr.sin_port == htons(okdata[i].port), " Port correct"); + } + } + + for (i=0; i %d", + baddata[i], DEFAULT_PORT, ret); + if (ret==0) { + testDiag(" IP=0x%lx, port=%d", + (unsigned long) ntohl(addr.sin_addr.s_addr), + ntohs(addr.sin_port)); + } + } + + return testDone(); +} diff --git a/src/libCom/test/epicsStdioTest.c b/src/libCom/test/epicsStdioTest.c index da4256805..54fc3a48a 100644 --- a/src/libCom/test/epicsStdioTest.c +++ b/src/libCom/test/epicsStdioTest.c @@ -85,8 +85,13 @@ void testStdoutRedir (const char *report) testOk1(stdout == realStdout); errno = 0; - if (!testOk1(!fclose(stream))) - testDiag("fclose error: %s\n", strerror(errno)); + if (!testOk1(!fclose(stream))) { + testDiag("fclose error: %s", strerror(errno)); +#ifdef vxWorks + testDiag("The above test fails if you don't cd to a writable directory"); + testDiag("before running the test. The next test will also fail..."); +#endif + } if (!testOk1((stream = fopen(report, "r")) != NULL)) { testDiag("'%s' could not be opened for reading: %s", diff --git a/src/libCom/test/epicsTimeTest.cpp b/src/libCom/test/epicsTimeTest.cpp index 98cedd4bd..c108eca7f 100644 --- a/src/libCom/test/epicsTimeTest.cpp +++ b/src/libCom/test/epicsTimeTest.cpp @@ -38,42 +38,33 @@ struct l_fp { /* NTP time stamp */ epicsUInt32 l_uf; /* fractional seconds */ }; -epicsTime useSomeCPU; - static const unsigned mSecPerSec = 1000u; static const unsigned uSecPerSec = 1000u * mSecPerSec; static const unsigned nSecPerSec = 1000u * uSecPerSec; - +static const double precisionEPICS = 1.0 / nSecPerSec; MAIN(epicsTimeTest) { - const unsigned wasteTime = 100000u; + const int wasteTime = 100000; const int nTimes = 10; - const double precisionEPICS = 1.0 / nSecPerSec; - testPlan(15 + nTimes * 18); + testPlan(12 + nTimes * 18); - const epicsTime begin = epicsTime::getCurrent(); - - { + try { const epicsTimeStamp epochTS = {0, 0}; epicsTime epochET = epochTS; struct gm_tm_nano_sec epicsEpoch = epochET; - testOk1(epicsEpoch.ansi_tm.tm_sec == 0); - testOk1(epicsEpoch.ansi_tm.tm_min == 0); - testOk1(epicsEpoch.ansi_tm.tm_hour == 0); - testOk1(epicsEpoch.ansi_tm.tm_yday == 0); - testOk1(epicsEpoch.ansi_tm.tm_year == 90); - } - { - epicsTime tsi = epicsTime::getCurrent (); - l_fp ntp = tsi; - epicsTime tsf = ntp; - const double diff = fabs ( tsf - tsi ); - // the difference in the precision of the two time formats - static const double precisionNTP = 1.0 / ( 1.0 + 0xffffffff ); - testOk1(diff <= precisionEPICS + precisionNTP); + testOk(epicsEpoch.ansi_tm.tm_sec == 0 && + epicsEpoch.ansi_tm.tm_min == 0 && + epicsEpoch.ansi_tm.tm_hour == 0 && + epicsEpoch.ansi_tm.tm_yday == 0 && + epicsEpoch.ansi_tm.tm_year == 90, + "epicsTime_gmtime() for EPICS epoch"); + } + catch ( ... ) { + testFail("epicsTime_gmtime() failed"); + testAbort("Can't continue, check your OS!"); } { // badNanosecTest @@ -90,7 +81,7 @@ MAIN(epicsTimeTest) } } - { + { // strftime() output char buf[80]; epicsTime et; @@ -125,70 +116,87 @@ MAIN(epicsTimeTest) pFormat = "%%S.%%05f"; et.strftime(buf, sizeof(buf), pFormat); testOk(strcmp(buf, "%S.%05f") == 0, "'%s' => '%s'", pFormat, buf); + + char bigBuf [512]; + memset(bigBuf, '\a', sizeof(bigBuf)); + bigBuf[ sizeof(bigBuf) - 1] = '\0'; + et.strftime(buf, sizeof(buf), bigBuf); + testOk(strcmp(buf, "") == 0, "bad format => '%s'", buf); } - { // invalidFormatTest - char bigBuf [512]; - char buf [32]; - memset(bigBuf, '\a', sizeof(bigBuf )); - bigBuf[ sizeof(bigBuf) - 1] = '\0'; - begin.strftime(buf, sizeof(buf), bigBuf); - testOk(strcmp(buf, "") == 0, "bad format => '%s'", buf); + epicsTime now; + try { + now = epicsTime::getCurrent(); + testPass("default time provider"); + } + catch ( ... ) { + testFail("epicsTime::getCurrent() throws"); + testAbort("Can't continue, check your time provider"); + } + + { + l_fp ntp = now; + epicsTime tsf = ntp; + const double diff = fabs(tsf - now); + // the difference in the precision of the two time formats + static const double precisionNTP = 1.0 / (1.0 + 0xffffffff); + testOk1(diff <= precisionEPICS + precisionNTP); } testDiag("Running %d loops", nTimes); - for (int iTimes=0; iTimes < nTimes; ++iTimes) { - for (unsigned i=0; i= end); + epicsTime copy = now; + testOk1(copy == now); + testOk1(copy <= now); + testOk1(copy >= now); - testOk1(end > begin); - testOk1(end >= begin); - testOk1(begin != end); - testOk1(begin < end); - testOk1(begin <= end); + testOk1(now > begin); + testOk1(now >= begin); + testOk1(begin != now); + testOk1(begin < now); + testOk1(begin <= now); - testOk1(end - end == 0); - testOk(fabs((end - begin) - diff) < precisionEPICS * 0.01, - "end - begin ~= diff"); + testOk1(now - now == 0); + testOk(fabs((now - begin) - diff) < precisionEPICS * 0.01, + "now - begin ~= diff"); testOk1(begin + 0 == begin); - testOk1(begin + diff == end); - testOk1(end - 0 == end); - testOk1(end - diff == begin); + testOk1(begin + diff == now); + testOk1(now - 0 == now); + testOk1(now - diff == begin); - epicsTime end2 = begin; - end2 += diff; - testOk(end2 == end, "(begin += diff) == end"); + epicsTime end = begin; + end += diff; + testOk(end == now, "(begin += diff) == now"); - end2 = end; - end2 -= diff; - testOk(end2 == begin, "(end -= diff) == begin"); + end = now; + end -= diff; + testOk(end == begin, "(now -= diff) == begin"); // test struct tm round-trip conversion local_tm_nano_sec ansiDate = begin; epicsTime beginANSI = ansiDate; - testOk1(beginANSI + diff == end); + testOk1(beginANSI + diff == now); // test struct timespec round-trip conversion struct timespec ts = begin; epicsTime beginTS = ts; - testOk1(beginTS + diff == end); + testOk1(beginTS + diff == now); } return testDone();