thread5.c 2.24 KB
#include <os.h>
#include <rmon.h>
#include "corefunc.h"

/*
 * thread5
 *
 * Tests for:
 *	osStartThread
 *	osStopThread
 *
 * Assumed working:
 *
 * Description:
 */

static void	t1(void *);
static void	t2(void *);

static OSThread	t1Thread;
static char	t1ThreadStack[STACKSIZE];

static OSThread	t2Thread;
static char	t2ThreadStack[STACKSIZE];

static OSMesgQueue	mesgQueue;
static OSMesg		mesgBuf[100];
static OSMesg		mesgSend, mesgRecv;

static int checkpoint;
static int numFailures;

int
thread5(void)
{
	osSetThreadPri(NULL, 10);
	osCreateMesgQueue(&mesgQueue, mesgBuf, 100);
	checkpoint = 0;
	numFailures = 0;
	osCreateThread(&t1Thread, 101, t1, (void *)0, t1ThreadStack+STACKSIZE,
		(OSPri)10);
	osStartThread(&t1Thread);
	osCreateThread(&t2Thread, 102, t2, (void *)0, t2ThreadStack+STACKSIZE,
		(OSPri)10);
	osStartThread(&t2Thread);
	while (checkpoint != 18)
		osYieldThread();
	return(numFailures);
}

static void
t1(void *arg)
{
	checkpoint = 1;
	osYieldThread();
	if (++checkpoint != 3)
		numFailures++;
	mesgSend = (OSMesg) 200;
	osSendMesg(&mesgQueue, mesgSend, OS_MESG_BLOCK);
	if (++checkpoint != 4)
		numFailures++;
	osYieldThread();
	if (++checkpoint != 10)
		numFailures++;
	osRecvMesg(&mesgQueue, &mesgRecv, OS_MESG_BLOCK);
	if (++checkpoint != 17)
		numFailures++;
	if (mesgSend != mesgRecv)
		numFailures++;;
}

static void
t2(void *arg)
{
	if (++checkpoint != 2)
		numFailures++;
	osYieldThread();
	if (++checkpoint != 5)
		numFailures++;
	osRecvMesg(&mesgQueue, &mesgRecv, OS_MESG_BLOCK);
	if (++checkpoint != 6)
		numFailures++;
	if (mesgSend != mesgRecv)
		numFailures++;
	osStopThread(&t1Thread);
	if (++checkpoint != 7)
		numFailures++;
	osYieldThread();
	if (++checkpoint != 8)
		numFailures++;
	osStartThread(&t1Thread);
	if (++checkpoint != 9)
		numFailures++;
	osYieldThread();
	if (++checkpoint != 11)
		numFailures++;
	osStopThread(&t1Thread);
	if (++checkpoint != 12)
		numFailures++;
	osYieldThread();
	if (++checkpoint != 13)
		numFailures++;
	osStartThread(&t1Thread);
	if (++checkpoint != 14)
		numFailures++;
	osYieldThread();
	if (++checkpoint != 15)
		numFailures++;
	mesgSend = (OSMesg) 300;
	osSendMesg(&mesgQueue, mesgSend, OS_MESG_BLOCK);
	if (++checkpoint != 16)
		numFailures++;
	osYieldThread();
	if (++checkpoint != 18)
		numFailures++;
}