From 5dd24b7ad28fbaf5c3b2713df207e887da020ea1 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 26 Oct 2006 19:28:30 +0000 Subject: [PATCH] Permit multiple test programs to be run sequentially in the same process (for RTEMS and vxWorks). --- src/libCom/misc/epicsUnitTest.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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) {