static BaseType_t prvTaskQueryFunctions()

in Debug_extra/FreeRTOS_demo/code_coverage_additions.c [362:472]


static BaseType_t prvTaskQueryFunctions( void )
{
static TaskStatus_t xStatus, *pxStatusArray;
TaskHandle_t xTimerTask, xIdleTask;
BaseType_t xReturn = pdPASS;
UBaseType_t uxNumberOfTasks, uxReturned, ux;
uint32_t ulTotalRunTime1, ulTotalRunTime2;
const uint32_t ulRunTimeTollerance = ( uint32_t ) 0xfff;

	/* Obtain task status with the stack high water mark and without the
	state. */
	vTaskGetInfo( NULL, &xStatus, pdTRUE, eRunning );

	if( uxTaskGetStackHighWaterMark( NULL ) != xStatus.usStackHighWaterMark )
	{
		xReturn = pdFAIL;
	}

	if( uxTaskGetStackHighWaterMark2( NULL ) != ( configSTACK_DEPTH_TYPE ) xStatus.usStackHighWaterMark )
	{
		xReturn = pdFAIL;
	}

	/* Now obtain a task status without the high water mark but with the state,
	which in the case of the idle task should be Read. */
	xTimerTask = xTimerGetTimerDaemonTaskHandle();
	vTaskSuspend( xTimerTask ); /* Should never suspend Timer task normally!. */
	vTaskGetInfo( xTimerTask, &xStatus, pdFALSE, eInvalid );
	if( xStatus.eCurrentState != eSuspended )
	{
		xReturn = pdFAIL;
	}
	if( xStatus.uxBasePriority != uxTaskPriorityGetFromISR( xTimerTask ) )
	{
		xReturn = pdFAIL;
	}
	if( xStatus.uxBasePriority != ( configMAX_PRIORITIES - 1 ) )
	{
		xReturn = pdFAIL;
	}
	xTaskResumeFromISR( xTimerTask );
	vTaskGetInfo( xTimerTask, &xStatus, pdTRUE, eInvalid );
	if( ( xStatus.eCurrentState != eReady ) && ( xStatus.eCurrentState != eBlocked ) )
	{
		xReturn = pdFAIL;
	}
	if( uxTaskGetStackHighWaterMark( xTimerTask ) != xStatus.usStackHighWaterMark )
	{
		xReturn = pdFAIL;
	}
	if( uxTaskGetStackHighWaterMark2( xTimerTask ) != ( configSTACK_DEPTH_TYPE ) xStatus.usStackHighWaterMark )
	{
		xReturn = pdFAIL;
	}

	/* Attempting to abort a delay in the idle task should be guaranteed to
	fail as the idle task should never block. */
	xIdleTask = xTaskGetIdleTaskHandle();
	if( xTaskAbortDelay( xIdleTask ) != pdFAIL )
	{
		xReturn = pdFAIL;
	}

	/* Create an array of task status objects large enough to hold information
	on the number of tasks at this time - note this may change at any time if
	higher priority tasks are executing and creating tasks. */
	uxNumberOfTasks = uxTaskGetNumberOfTasks();
	pxStatusArray = ( TaskStatus_t * ) pvPortMalloc( uxNumberOfTasks * sizeof( TaskStatus_t ) );

	if( pxStatusArray != NULL )
	{
		/* Pass part of the array into uxTaskGetSystemState() to ensure it doesn't
		try using more space than there is available. */
		uxReturned = uxTaskGetSystemState( pxStatusArray, uxNumberOfTasks / ( UBaseType_t ) 2, NULL );
		if( uxReturned != ( UBaseType_t ) 0 )
		{
			xReturn = pdFAIL;
		}

		/* Now do the same but passing in the complete array size, this is done
		twice to check for a difference in the total run time. */
		uxTaskGetSystemState( pxStatusArray, uxNumberOfTasks, &ulTotalRunTime1 );
		memset( ( void * ) pxStatusArray, 0xaa, uxNumberOfTasks * sizeof( TaskStatus_t ) );
		uxReturned = uxTaskGetSystemState( pxStatusArray, uxNumberOfTasks, &ulTotalRunTime2 );
		if( ( ulTotalRunTime2 - ulTotalRunTime1 ) > ulRunTimeTollerance )
		{
			xReturn = pdFAIL;
		}

		/* Basic santity check of array contents. */
		for( ux = 0; ux < uxReturned; ux++ )
		{
			if( pxStatusArray[ ux ].eCurrentState >= ( UBaseType_t ) eInvalid )
			{
				xReturn = pdFAIL;
			}
			if( pxStatusArray[ ux ].uxCurrentPriority >= ( UBaseType_t ) configMAX_PRIORITIES )
			{
				xReturn = pdFAIL;
			}
		}

		vPortFree( pxStatusArray );
	}
	else
	{
		xReturn = pdFAIL;
	}

	return xReturn;
}