thread8.c 1.87 KB
#include <os.h>
#include <rmon.h>
#include "corefunc.h"

/*
 * thread8
 *
 * Tests for:
 *	osDestroyThread (on stopped threads)
 *
 * Assumed working:
 *	osSetIntMask
 *	osGetIntMask
 *	osCreateThread
 *	osStartThread
 *	osYieldThread
 *	osStopThread
 *
 * Description:
 *	Check that osDestroyThread called on newly created thread has no
 *		unexpected results.
 *	Check that osDestroyThread called on thread that has stopped itself
 *		has no expected results.
 *	Check that osDestroyThread does not affect interrupt mask.
 */

static void		slave1(void *);

static OSThread		slaveThread;
static char		slaveStack[STACKSIZE];

int
thread8(void)
{
    OSIntMask savedMask, currentMask;
    OSMesg actualMesg, expectedMesg;
    int i, j;
    int numFailures = 0;

    savedMask = osSetIntMask(OS_IM_ALL);

    /*
     * Set thread priority to the same as slaves.
     */
    osSetThreadPri(NULL, 10);

    /*
     * Try and destroy a newly created one just for fun.
     */

    osCreateThread(&slaveThread, 101, slave1, (void *)0,
		   slaveStack+STACKSIZE, 10);

    osDestroyThread(&slaveThread);

    currentMask = osGetIntMask();
    if (currentMask != OS_IM_ALL) {
	osSyncPrintf("thread8: expected interrupt mask 0x%x, actual 0x%x\n",
		OS_IM_ALL, currentMask);
	numFailures++;
    }

    
    /*
     * This time, create it, let it stop itself, and then destroy it.
     */
    osCreateThread(&slaveThread, 101, slave1, (void *)0,
		   slaveStack+STACKSIZE, 10);

    osStartThread(&slaveThread);

    osYieldThread();

    osDestroyThread(&slaveThread);

    /*
     * Restore original interrupt mask and check it once more.
     */
    currentMask = osSetIntMask(savedMask);
    if (currentMask != OS_IM_ALL) {
	osSyncPrintf("thread8: expected interrupt mask 0x%x, actual 0x%x\n",
		OS_IM_ALL, currentMask);
	numFailures++;
    }
    return(numFailures);
}

static void
slave1(void *arg)
{
	osStopThread(NULL);
}