mesg4.c 6.72 KB
#include <os.h>
#include <rmon.h>
#include "corefunc.h"

/*
 * mesg4
 *
 * Tests for:
 *	osCreateMesgQueue
 *	osJamMesg
 *	osRecvMesg
 *
 * Assumed working:
 *	osGetIntMask
 *	osSetIntMask
 *
 * Description:
 *	Check that osCreateMesgQueue does not affect interrupt mask
 *	Check that osJamMesg 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:
 *	   Jam 1 through <message queue length> messages.
 *	   Attempt to jam 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
mesg4(void)
{
    OSIntMask savedMask, currentMask;
    int numFailures = 0;
    
    savedMask = osSetIntMask(OS_IM_ALL);

    /*
     * Try each combination of blocking/nonblock sends and receives
     * in turn.  Loop up 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("mesg4: 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("mesg4: 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 = osJamMesg(&mesgQueue, expectedMesg, sendFlag);
	    if (retValue != 0) {
		osSyncPrintf(
			"mesg4: expected osJamMesg return value %d,actual %d\n",
			0, retValue);
		numFailures++;
	    }
	    currentMask = osGetIntMask();
	    if (currentMask != OS_IM_ALL) {
		osSyncPrintf("mesg4: expected interrupt mask 0x%x, actual 0x%x\n",
			OS_IM_ALL, currentMask);
		numFailures++;
	    }
	}

	/*
	 * Attempt to send one more.
	 */

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

	/*
	 * Read and check all messages.
	 */
	for (j = i-1; j >= 0; j--) {
	    expectedMesg = (OSMesg)((j<<24)|(j<<16)|(j<<8)|j);
	    (void)osRecvMesg(&mesgQueue, &actualMesg, recvFlag);
	    if (expectedMesg != actualMesg) {
		osSyncPrintf("mesg4: expected message 0x%x, actual 0x%x\n",
    			expectedMesg, actualMesg);
		numFailures++;
	    }
	    currentMask = osGetIntMask();
	    if (currentMask != OS_IM_ALL) {
		osSyncPrintf("mesg4: 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("mesg4: expected return value %d, actual %d\n",
		   -1, retValue);
	    numFailures++;
	}
    	if (currentMask != OS_IM_ALL) {
    	    osSyncPrintf("mesg4: 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("mesg4: 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 = osJamMesg(&mesgQueue, expectedMesg, sendFlag);
	    if (retValue != 0) {
		osSyncPrintf("mesg4: expected osJamMesg return value %d,actual %d\n",
			0, retValue);
		numFailures++;
	    }
	    currentMask = osGetIntMask();
	    if (currentMask != OS_IM_ALL) {
		osSyncPrintf("mesg4: expected interrupt mask 0x%x, actual 0x%x\n",
			OS_IM_ALL, currentMask);
		numFailures++;
	    }
	}

	/*
	 * Attempt to jam (push) one more.
	 */

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

	/*
	 * Read (pop) and check all messages.
	 */
	for (j = i-1; j >= 0; j--) {
	    expectedMesg = (OSMesg)((j<<24)|(j<<16)|(j<<8)|j);
	    (void)osRecvMesg(&mesgQueue, &actualMesg, recvFlag);
	    if (expectedMesg != actualMesg) {
		osSyncPrintf("mesg4: expected message 0x%x, actual 0x%x\n",
    			expectedMesg, actualMesg);
		numFailures++;
	    }
	    currentMask = osGetIntMask();
	    if (currentMask != OS_IM_ALL) {
		osSyncPrintf("mesg4: 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("mesg4: return value %d, actual %d\n",
			-1, retValue);
	    numFailures++;
	}
	currentMask = osGetIntMask();
    	if (currentMask != OS_IM_ALL) {
    	    osSyncPrintf("mesg4: expected interrupt mask 0x%x, actual 0x%x\n",
 			OS_IM_ALL, currentMask);
    	    numFailures++;
    	}
    }
    return(numFailures);
}