add tests; build new way

This commit is contained in:
Marty Kraimer
2000-01-27 17:07:22 +00:00
parent 0184d31020
commit 393671c0b2
8 changed files with 417 additions and 15 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#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; i<nthreads; i++) {
name[i] = calloc(10,sizeof(char));
sprintf(name[i],"task%d",i);
pinfo[i] = calloc(1,sizeof(info));
pinfo[i]->threadnum = 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; i<nthreads; i++) {
pinfo[i]->quit = 1;
}
semBinaryGive(binary);
threadSleep(2.0);
}

View File

@@ -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 <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#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);
}

View File

@@ -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 <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#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; i<nthreads; i++) {
name[i] = calloc(10,sizeof(char));
sprintf(name[i],"task%d",i);
pinfo[i] = calloc(1,sizeof(info));
pinfo[i]->threadnum = 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; i<nthreads; i++) {
pinfo[i]->quit = 1;
}
semMutexGive(mutex);
threadSleep(2.0);
}

View File

@@ -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 <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#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);
}

View File

@@ -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 <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <pthread.h>
#include <sched.h>
#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<ntasks; i++) {
int *argvalue;
name[i] = calloc(10,sizeof(char));
sprintf(name[i],"task%d",i);
arg[i] = calloc(1,sizeof(int));
argvalue = (int *)arg[i];
*argvalue = i;
id[i] = threadCreate(name[i],40+i,stackSize,threadFunc,arg[i]);
errlogPrintf("threadTest created %d id %p\n",i,id[i]);
}
threadSleep(5.0);
}

View File

@@ -0,0 +1,36 @@
/* threadTestMain.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 <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#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);
}