From 393671c0b29bf0879adf2aefadd9c7afe3710ff0 Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Thu, 27 Jan 2000 17:07:22 +0000 Subject: [PATCH] add tests; build new way --- src/libCom/test/Makefile | 23 +++++- src/libCom/test/Makefile.Host | 13 ---- src/libCom/test/semBinaryTest.c | 113 +++++++++++++++++++++++++++ src/libCom/test/semBinaryTestMain.c | 37 +++++++++ src/libCom/test/semMutexTest.c | 114 ++++++++++++++++++++++++++++ src/libCom/test/semMutexTestMain.c | 37 +++++++++ src/libCom/test/threadTest.c | 59 ++++++++++++++ src/libCom/test/threadTestMain.c | 36 +++++++++ 8 files changed, 417 insertions(+), 15 deletions(-) delete mode 100644 src/libCom/test/Makefile.Host create mode 100644 src/libCom/test/semBinaryTest.c create mode 100644 src/libCom/test/semBinaryTestMain.c create mode 100644 src/libCom/test/semMutexTest.c create mode 100644 src/libCom/test/semMutexTestMain.c create mode 100644 src/libCom/test/threadTest.c create mode 100644 src/libCom/test/threadTestMain.c diff --git a/src/libCom/test/Makefile b/src/libCom/test/Makefile index cb0865897..5d9adaed2 100644 --- a/src/libCom/test/Makefile +++ b/src/libCom/test/Makefile @@ -1,7 +1,26 @@ - TOP=../../.. include $(TOP)/configure/CONFIG -include $(TOP)/configure/RULES_ARCHS +PROD_LIBS += Com + +semBinaryTestHost_SRCS += semBinaryTestMain.c semBinaryTest.c +PROD += semBinaryTestHost +OBJS_IOC += semBinaryTest.o + +semMutexTestHost_SRCS += semMutexTestMain.c semMutexTest.c +PROD += semMutexTestHost +OBJS_IOC += semMutexTest.o + +threadTestHost_SRCS += threadTestMain.c threadTest.c +PROD += threadTestHost +OBJS_IOC += threadTest.o + +#fdmgrTest_SRCS += fdmgrTest.c +#PROD += fdmgrTest + +#osiTimeTest_SRCS += osiTimeTest.cc +#PROD += osiTimeTest + +include $(TOP)/configure/RULES diff --git a/src/libCom/test/Makefile.Host b/src/libCom/test/Makefile.Host deleted file mode 100644 index 4b74afa69..000000000 --- a/src/libCom/test/Makefile.Host +++ /dev/null @@ -1,13 +0,0 @@ - -TOP=../../.. - -include $(TOP)/configure/CONFIG - -fdmgrTest_LIBS += Com -fdmgrTest_SRCS += fdmgrTest.c -fdmgrTest_LIBS += Com -fdmgrTest_SRCS += osiTimeTest.cc -PROD= osiTimeTest fdmgrTest - -include $(TOP)/configure/RULES_BUILD - diff --git a/src/libCom/test/semBinaryTest.c b/src/libCom/test/semBinaryTest.c new file mode 100644 index 000000000..025f63616 --- /dev/null +++ b/src/libCom/test/semBinaryTest.c @@ -0,0 +1,113 @@ +/* semBinaryTest.c */ + +/* Author: Marty Kraimer Date: 26JAN2000 */ + +/********************COPYRIGHT NOTIFICATION********************************** +This software was developed under a United States Government license +described on the COPYRIGHT_UniversityOfChicago file included as part +of this distribution. +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include "osiThread.h" +#include "osiSem.h" +#include "errlog.h" + + +typedef struct info { + int threadnum; + semId binary; + int quit; +}info; + +static void binaryThread(void *arg) +{ + info *pinfo = (info *)arg; + time_t tp; + printf("binaryThread %d starting time %d\n",pinfo->threadnum,time(&tp)); + threadSleep(1.0); + while(1) { + semTakeStatus status; + if(pinfo->quit) { + printf("binaryThread %d returning time %d\n", + pinfo->threadnum,time(&tp)); + semBinaryGive(pinfo->binary); + return; + } + status = semBinaryTake(pinfo->binary); + if(status!=semTakeOK) { + printf("task %d semBinaryTake returned %d time %d\n", + pinfo->threadnum,(int)status,time(&tp)); + } + printf("binaryThread %d semBinaryTake time %d\n", + pinfo->threadnum,time(&tp)); + semBinaryGive(pinfo->binary); + threadSleep(1.0); + } +} + +void semBinaryTest(int nthreads) +{ + unsigned int stackSize; + threadId *id; + int i; + char **name; + void **arg; + info **pinfo; + semId binary; + int status; + time_t tp; + + binary = semBinaryMustCreate(semEmpty); + printf("calling semBinaryTakeTimeout(binary,2.0) time %d\n",time(&tp)); + status = semBinaryTakeTimeout(binary,2.0); + if(status!=semTakeTimeout) printf("status %d\n",status); + printf("calling semBinaryTakeNoWait(binary) time %d\n",time(&tp)); + status = semBinaryTakeNoWait(binary); + if(status!=semTakeTimeout) printf("status %d\n",status); + printf("calling semBinaryGive() time %d\n",time(&tp)); + semBinaryGive(binary); + printf("calling semBinaryTakeTimeout(binary,2.0) time %d\n",time(&tp)); + status = semBinaryTakeTimeout(binary,2.0); + if(status) printf("status %d\n",status); + printf("calling semBinaryGive() time %d\n",time(&tp)); + semBinaryGive(binary); + printf("calling semBinaryTakeNoWait(binary) time %d\n",time(&tp)); + status = semBinaryTakeNoWait(binary); + if(status) printf("status %d\n",status); + + if(nthreads<=0) return; + id = calloc(nthreads,sizeof(threadId)); + name = calloc(nthreads,sizeof(char *)); + arg = calloc(nthreads,sizeof(void *)); + pinfo = calloc(nthreads,sizeof(info *)); + stackSize = threadGetStackSize(threadStackSmall); + for(i=0; ithreadnum = i; + pinfo[i]->binary = binary; + arg[i] = pinfo[i]; + id[i] = threadCreate(name[i],40,stackSize,binaryThread,arg[i]); + printf("semTest created binaryThread %d id %p time %d\n", + i, id[i],time(&tp)); + } + threadSleep(2.0); + printf("semTest calling semBinaryGive(binary) time %d\n",time(&tp)); + semBinaryGive(binary); + threadSleep(5.0); + printf("semTest setting quit time %d\n",time(&tp)); + for(i=0; iquit = 1; + } + semBinaryGive(binary); + threadSleep(2.0); +} diff --git a/src/libCom/test/semBinaryTestMain.c b/src/libCom/test/semBinaryTestMain.c new file mode 100644 index 000000000..72191b0dd --- /dev/null +++ b/src/libCom/test/semBinaryTestMain.c @@ -0,0 +1,37 @@ +/* semBinaryTestMain.c */ + +/* Author: Marty Kraimer Date: 26JAN2000 */ + +/********************COPYRIGHT NOTIFICATION********************************** +This software was developed under a United States Government license +described on the COPYRIGHT_UniversityOfChicago file included as part +of this distribution. +****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "osiThread.h" +void semBinaryTest(int nthreads); + + +int main(int argc,char *argv[]) +{ + int nthreads = 2; + + if(argc>1) { + if(isdigit(*argv[1])) { + sscanf(argv[1],"%d",&nthreads); + printf("nthreads %d\n",nthreads); + } else { + printf("Illegal argument %s\n",argv[0]); + } + } + semBinaryTest(nthreads); + printf("main terminating\n"); + return(0); +} diff --git a/src/libCom/test/semMutexTest.c b/src/libCom/test/semMutexTest.c new file mode 100644 index 000000000..13c2274b6 --- /dev/null +++ b/src/libCom/test/semMutexTest.c @@ -0,0 +1,114 @@ +/* semMutexTest.c */ + +/* Author: Marty Kraimer Date: 26JAN2000 */ + +/********************COPYRIGHT NOTIFICATION********************************** +This software was developed under a United States Government license +described on the COPYRIGHT_UniversityOfChicago file included as part +of this distribution. +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include "osiThread.h" +#include "osiSem.h" +#include "errlog.h" + + +typedef struct info { + int threadnum; + semId mutex; + int quit; +}info; + +static void mutexThread(void *arg) +{ + info *pinfo = (info *)arg; + time_t tp; + printf("mutexThread %d starting time %d\n",pinfo->threadnum,time(&tp)); + threadSleep(1.0); + while(1) { + semTakeStatus status; + if(pinfo->quit) { + printf("mutexThread %d returning time %d\n", + pinfo->threadnum,time(&tp)); + semMutexGive(pinfo->mutex); + return; + } + status = semMutexTake(pinfo->mutex); + if(status!=semTakeOK) { + printf("task %d semMutexTake returned %d time %d\n", + pinfo->threadnum,(int)status,time(&tp)); + } + printf("mutexThread %d semMutexTake time %d\n", + pinfo->threadnum,time(&tp)); + semMutexGive(pinfo->mutex); + threadSleep(1.0); + } +} + +void semMutexTest(int nthreads) +{ + unsigned int stackSize; + threadId *id; + int i; + char **name; + void **arg; + info **pinfo; + semId mutex; + int status; + time_t tp; + + mutex = semMutexMustCreate(); + printf("calling semMutexTake(mutex) time %d\n",time(&tp)); + status = semMutexTake(mutex); + if(status) printf("status %d\n",status); + printf("calling semMutexTakeTimeout(mutex,2.0) time %d\n",time(&tp)); + status = semMutexTakeTimeout(mutex,2.0); + if(status) printf("status %d\n",status); + printf("calling semMutexTakeNoWait(mutex) time %d\n",time(&tp)); + status = semMutexTakeNoWait(mutex); + if(status) printf("status %d\n",status); + semMutexShow(mutex); + printf("calling semMutexGive() time %d\n",time(&tp)); + semMutexGive(mutex); + printf("calling semMutexGive() time %d\n",time(&tp)); + semMutexGive(mutex); + printf("calling semMutexGive() time %d\n",time(&tp)); + semMutexGive(mutex); + semMutexShow(mutex); + + if(nthreads<=0) return; + id = calloc(nthreads,sizeof(threadId)); + name = calloc(nthreads,sizeof(char *)); + arg = calloc(nthreads,sizeof(void *)); + pinfo = calloc(nthreads,sizeof(info *)); + stackSize = threadGetStackSize(threadStackSmall); + for(i=0; ithreadnum = i; + pinfo[i]->mutex = mutex; + arg[i] = pinfo[i]; + id[i] = threadCreate(name[i],40,stackSize,mutexThread,arg[i]); + printf("semTest created mutexThread %d id %p time %d\n", + i, id[i],time(&tp)); + } + threadSleep(2.0); + printf("semTest calling semMutexGive(mutex) time %d\n",time(&tp)); + semMutexGive(mutex); + threadSleep(5.0); + printf("semTest setting quit time %d\n",time(&tp)); + for(i=0; iquit = 1; + } + semMutexGive(mutex); + threadSleep(2.0); +} diff --git a/src/libCom/test/semMutexTestMain.c b/src/libCom/test/semMutexTestMain.c new file mode 100644 index 000000000..fcc9ffa36 --- /dev/null +++ b/src/libCom/test/semMutexTestMain.c @@ -0,0 +1,37 @@ +/* semMutexTestMain.c */ + +/* Author: Marty Kraimer Date: 26JAN2000 */ + +/********************COPYRIGHT NOTIFICATION********************************** +This software was developed under a United States Government license +described on the COPYRIGHT_UniversityOfChicago file included as part +of this distribution. +****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "osiThread.h" +void semMutexTest(int nthreads); + + +int main(int argc,char *argv[]) +{ + int nthreads = 2; + + if(argc>1) { + if(isdigit(*argv[1])) { + sscanf(argv[1],"%d",&nthreads); + printf("nthreads %d\n",nthreads); + } else { + printf("Illegal argument %s\n",argv[0]); + } + } + semMutexTest(nthreads); + printf("main terminating\n"); + return(0); +} diff --git a/src/libCom/test/threadTest.c b/src/libCom/test/threadTest.c new file mode 100644 index 000000000..a2911a0dd --- /dev/null +++ b/src/libCom/test/threadTest.c @@ -0,0 +1,59 @@ +/* threadTest.c */ + +/* Author: Marty Kraimer Date: 26JAN2000 */ + +/********************COPYRIGHT NOTIFICATION********************************** +This software was developed under a United States Government license +described on the COPYRIGHT_UniversityOfChicago file included as part +of this distribution. +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "osiThread.h" +#include "osiSem.h" +#include "errlog.h" + + +static void threadFunc(void *arg) +{ + int argvalue = *(int *)arg; + errlogPrintf("threadFunc %d starting\n",argvalue); + threadSleep(2.0); + errlogPrintf("threadFunc %d stopping\n",argvalue); +} + +void threadTest(int ntasks) +{ + unsigned int stackSize; + threadId *id; + int i; + char **name; + void **arg; + + id = calloc(ntasks,sizeof(threadId *)); + name = calloc(ntasks,sizeof(char **)); + arg = calloc(ntasks,sizeof(void *)); + errlogPrintf("threadTest starting\n"); + stackSize = threadGetStackSize(threadStackSmall); + errlogPrintf("stackSize %u\n",stackSize); + for(i=0; i +#include +#include +#include +#include +#include + +#include "osiThread.h" +void threadTest(int nthreads); + +int main(int argc,char *argv[]) +{ + int nthreads = 2; + + if(argc>1) { + if(isdigit(*argv[1])) { + sscanf(argv[1],"%d",&nthreads); + printf("nthreads %d\n",nthreads); + } else { + printf("Illegal argument %s\n",argv[0]); + } + } + if(nthreads>0) threadTest(nthreads); + printf("main terminating\n"); + return(0); +}