diff --git a/src/libCom/misc/epicsUnitTest.c b/src/libCom/misc/epicsUnitTest.c index 4354f17f6..0479d8203 100644 --- a/src/libCom/misc/epicsUnitTest.c +++ b/src/libCom/misc/epicsUnitTest.c @@ -17,6 +17,7 @@ #include #include +#include "epicsThread.h" #include "epicsMutex.h" #define epicsExportSharedSymbols @@ -31,13 +32,20 @@ static int skipped; static int bonus; static const char *todo; -void testPlan(int tests) { - if (testLock) abort(); +static epicsThreadOnceId onceFlag = EPICS_THREAD_ONCE_INIT; + +static void testInit(void *dummy) { testLock = epicsMutexMustCreate(); +} + +void testPlan(int tests) { + epicsThreadOnce(&onceFlag, testInit, NULL); + epicsMutexMustLock(testLock); plan = tests; tests = passed = failed = skipped = bonus = 0; todo = NULL; if (plan) printf("1..%d\n", plan); + epicsMutexUnlock(testLock); } int testOk(int pass, const char *desc) {