mesg0.c 6.74 KB
#include <os.h>
#include <rmon.h>
#include "corefunc.h"

/*
 * mesg0
 *
 * Tests for:
 *	osCreateMesgQueue
 *	osSendMesg
 *	osRecvMesg
 *
 * Assumed working:
 *	osGetIntMask
 *	osSetIntMask
 *
 * Description:
 *	Check that osCreateMesgQueue does not affect interrupt mask
 *	Check that osSendMesg does not affect interrupt mask
 *	Check that osRecvMesg does not affect interrupt mask
 *	Create a number of message queues of length 1-255.  For each:
 *	   Send 1 through <message queue length> messages.
 *	   Attempt to send one more and check for overflow.
 *	   Receive 1 through <message queue length> messages and check.
 *	   Attempt to receive 1 more and check for error return.
 *	   Try all combinations of blocking/nonblocking flags and verify
 *		that they have no effect when blocking would not occur.
 */

#define	MAX_MESSAGE	256

static int		mesgLoopUp(int, int);
static int		mesgLoopDown(int, int);

static OSMesgQueue	mesgQueue;
static OSMesg		mesgBuf[MAX_MESSAGE];

int
mesg0(void)
{
    OSIntMask savedMask, currentMask;
    int numFailures = 0;
    
    savedMask = osSetIntMask(OS_IM_ALL);

    /*
     * Try each combination of blocking/nonblock sends and receives
     * in turn.  Loop and and loop down the message values to deliberately
     * cause stale data in message buffer to change.
     */
    numFailures += mesgLoopUp(OS_MESG_NOBLOCK, OS_MESG_NOBLOCK);
    numFailures += mesgLoopDown(OS_MESG_NOBLOCK, OS_MESG_BLOCK);
    numFailures += mesgLoopUp(OS_MESG_BLOCK, OS_MESG_NOBLOCK);
    numFailures += mesgLoopDown(OS_MESG_BLOCK, OS_MESG_BLOCK);

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

    return(numFailures);
}

static int
mesgLoopUp(int sendFlag, int recvFlag)
{
    int retValue;
    int i, j;
    OSMesg expectedMesg, actualMesg;
    OSIntMask currentMask;
    int numFailures = 0;

    for (i = 1; i < MAX_MESSAGE; i++) {

	/*
	 * Create message queue of length i.
	 */

	osCreateMesgQueue(&mesgQueue, mesgBuf, i);
    	currentMask = osGetIntMask();
    	if (currentMask != OS_IM_ALL) {
    	    osSyncPrintf("mesg0: expected interrupt mask 0x%x, actual 0x%x\n",
   			OS_IM_ALL, currentMask);
    	    numFailures++;
    	}

	/* 
	 * Fill up the message queue with distinct messages.
	 */

	for (j = 0; j < i; j++) {
	    expectedMesg = (OSMesg)((j<<24)|(j<<16)|(j<<8)|j);
	    retValue = osSendMesg(&mesgQueue, expectedMesg, sendFlag);
	    if (retValue != 0) {
		osSyncPrintf(
			"mesg0: expected osSendMesg ret value %d, actual %d\n",
			0, retValue);
		numFailures++;
	    }
	    currentMask = osGetIntMask();
	    if (currentMask != OS_IM_ALL) {
		osSyncPrintf("mesg0: expected interrupt mask 0x%x, actual 0x%x\n",
			OS_IM_ALL, currentMask);
		numFailures++;
	    }
	}

	/*
	 * Attempt to send one more.
	 */

	retValue = osSendMesg(&mesgQueue, expectedMesg, OS_MESG_NOBLOCK);
	if (retValue != -1) {
	    osSyncPrintf(
		"mesg0: expected osSendMesg return value %d, actual %d\n",
		-1, retValue);
	    numFailures++;
	}
    	if (currentMask != OS_IM_ALL) {
    	    osSyncPrintf("mesg0: expected interrupt mask 0x%x, actual 0x%x\n",
    			OS_IM_ALL, currentMask);
    	    numFailures++;
    	}

	/*
	 * Read and check all messages.
	 */

	for (j = 0; j < i; j++) {
	    expectedMesg = (OSMesg)((j<<24)|(j<<16)|(j<<8)|j);
	    (void)osRecvMesg(&mesgQueue, &actualMesg, recvFlag);
	    if (expectedMesg != actualMesg) {
		osSyncPrintf("mesg0: expected message 0x%x, actual 0x%x\n",
    			expectedMesg, actualMesg);
		numFailures++;
	    }
	    currentMask = osGetIntMask();
	    if (currentMask != OS_IM_ALL) {
		osSyncPrintf("mesg0: expected interrupt mask 0x%x, actual 0x%x\n",
			OS_IM_ALL, currentMask);
		numFailures++;
	    }
	}

	/*
	 * Attempt to read one more.
	 */

	retValue = osRecvMesg(&mesgQueue, &actualMesg, OS_MESG_NOBLOCK);
	if (retValue != -1) {
	    osSyncPrintf("mesg0: return value %d, actual %d\n",
			-1, retValue);
	    numFailures++;
	}
    	if (currentMask != OS_IM_ALL) {
    	    osSyncPrintf("mesg0: expected interrupt mask 0x%x, actual 0x%x\n",
    			OS_IM_ALL, currentMask);
    	    numFailures++;
    	}
    }

    return(numFailures);
}

static int
mesgLoopDown(int sendFlag, int recvFlag)
{
    int retValue;
    int i, j;
    OSMesg expectedMesg, actualMesg;
    OSIntMask currentMask;
    int numFailures = 0;

    for (i = 1; i < MAX_MESSAGE; i++) {

	/*
	 * Create message queue of length i.
	 */

	osCreateMesgQueue(&mesgQueue, mesgBuf, i);
	currentMask = osGetIntMask();
    	if (currentMask != OS_IM_ALL) {
    	    osSyncPrintf("mesg0: expected interrupt mask 0x%x, actual 0x%x\n",
    			OS_IM_ALL, currentMask);
    	    numFailures++;
    	}

	/* 
	 * Fill up the message queue with distinct messages.
	 */

	for (j = i; j > 0; j--) {
	    expectedMesg = (OSMesg)((j<<24)|(j<<16)|(j<<8)|j);
	    retValue = osSendMesg(&mesgQueue, expectedMesg, sendFlag);
	    if (retValue != 0) {
		osSyncPrintf(
			"mesg0: expected osSendMesg ret value %d, actual %d\n",
			0, retValue);
		numFailures++;
	    }
	    currentMask = osGetIntMask();
	    if (currentMask != OS_IM_ALL) {
		osSyncPrintf("mesg0: expected interrupt mask 0x%x, actual 0x%x\n",
			OS_IM_ALL, currentMask);
		numFailures++;
	    }
	}

	/*
	 * Attempt to send one more.
	 */

	retValue = osSendMesg(&mesgQueue, expectedMesg, OS_MESG_NOBLOCK);
	if (retValue != -1) {
	    osSyncPrintf(
		"mesg0: expected osSendMesg return value %d, actual %d\n",
    		-1, retValue);
	   numFailures++;
	}
	currentMask = osGetIntMask();
    	if (currentMask != OS_IM_ALL) {
    	    osSyncPrintf("mesg0: expected interrupt mask 0x%x, actual 0x%x\n",
    			OS_IM_ALL, currentMask);
    	    numFailures++;
    	}

	/*
	 * Read and check all messages.
	 */

	for (j = i; j > 0; j--) {
	    expectedMesg = (OSMesg)((j<<24)|(j<<16)|(j<<8)|j);
	    (void)osRecvMesg(&mesgQueue, &actualMesg, recvFlag);
	    if (expectedMesg != actualMesg) {
		osSyncPrintf("mesg0: expected message 0x%x, actual 0x%x\n",
    			expectedMesg, actualMesg);
		numFailures++;
	    }
	    currentMask = osGetIntMask();
	    if (currentMask != OS_IM_ALL) {
		osSyncPrintf("mesg0: expected interrupt mask 0x%x, actual 0x%x\n",
			OS_IM_ALL, currentMask);
		numFailures++;
	    }
	}

	/*
	 * Attempt to read one more.
	 */

	retValue = osRecvMesg(&mesgQueue, &actualMesg, OS_MESG_NOBLOCK);
	if (retValue != -1) {
	    osSyncPrintf("mesg0: expected return value %d, actual %d\n",
			-1, retValue);
	    numFailures++;
	}
	currentMask = osGetIntMask();
    	if (currentMask != OS_IM_ALL) {
    	    osSyncPrintf("mesg0: expected interrupt mask 0x%x, actual 0x%x\n",
    			OS_IM_ALL, currentMask);
    	    numFailures++;
    	}
    }
    return(numFailures);
}