📄 validate.c
字号:
/*****************************************************************************
* validate.c - validation suite for testing the implementation of a Wind
* River pSOS+ (R) kernel API in a POSIX Threads environment.
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "not_quite_p_os.h"
#include "p2pthread.h"
typedef union
{
ULONG blk;
char name[4];
} objname_t;
typedef struct qmessage
{
objname_t qname;
ULONG nullterm;
ULONG t_cycle;
ULONG msg_no;
} my_qmsg_t;
typedef union
{
ULONG blk[4];
my_qmsg_t msg;
} msgblk_t;
/*
** One event bit per consumer task
*/
#define EVENT2 0x001
#define EVENT3 0x002
#define EVENT4 0x004
#define EVENT5 0x008
#define EVENT6 0x010
#define EVENT7 0x020
#define EVENT8 0x040
#define EVENT9 0x080
#define EVENT10 0x100
extern p2pthread_cb_t *
my_tcb( void );
extern p2pthread_cb_t *
tcb_for( ULONG taskid );
#undef errno
extern int errno;
/*****************************************************************************
** demo program global data structures
*****************************************************************************/
static char partition_1[512];
static ULONG part1_numblks;
static char partition_2[1024];
static ULONG part2_numblks;
static char partition_3[2048];
static ULONG part3_numblks;
static ULONG task1_id;
static ULONG task2_id;
static ULONG task3_id;
static ULONG task4_id;
static ULONG task5_id;
static ULONG task6_id;
static ULONG task7_id;
static ULONG task8_id;
static ULONG task9_id;
static ULONG task10_id;
static ULONG queue1_id;
static ULONG queue2_id;
static ULONG queue3_id;
static ULONG vqueue1_id;
static ULONG vqueue2_id;
static ULONG vqueue3_id;
static ULONG partn1_id;
static ULONG partn2_id;
static ULONG partn3_id;
static ULONG sema41_id;
static ULONG sema42_id;
static ULONG sema43_id;
static ULONG test_cycle;
/*****************************************************************************
** display_tcb
*****************************************************************************/
void display_tcb( ULONG tid )
{
int policy;
p2pthread_cb_t *cur_tcb;
cur_tcb = tcb_for( tid );
if ( cur_tcb == (p2pthread_cb_t *)NULL )
return;
printf( "\r\nTask ID: %ld Thread ID: %ld", cur_tcb->taskid,
cur_tcb->pthrid );
policy = (cur_tcb->attr).__schedpolicy;
switch (policy )
{
case SCHED_FIFO:
printf( "\r\n schedpolicy: SCHED_FIFO " );
break;
case SCHED_RR:
printf( "\r\n schedpolicy: SCHED_RR " );
break;
case SCHED_OTHER:
printf( "\r\n schedpolicy: SCHED_OTHER " );
break;
default :
printf( "\r\n schedpolicy: %d ", policy );
}
printf( " priority %d ", ((cur_tcb->attr).__schedparam).sched_priority );
printf( " prv_priority %d ", (cur_tcb->prv_priority).sched_priority );
printf( " detachstate %d ", (cur_tcb->attr).__detachstate );
}
/*****************************************************************************
** validate_events
** This function sequences through a series of actions to exercise
** the various features and characteristics of p2pthread events
**
*****************************************************************************/
void validate_events( void )
{
ULONG err;
puts( "\r\n********** Event validation:" );
puts( "\r\n.......... Now we send a sequence of EVENTS to consumer tasks" );
puts( " which will begin consuming queue messages." );
puts( " The consumer tasks are each waiting on a single EVENT," );
puts( " while Task 1 waits on any EVENT from a consumer task." );
puts( " This tests most of the event flag logic." );
puts( " Since Task 1 is at the highest priority level, the" );
puts( " other tasks will not execute until Task 1 blocks.\r\n" );
puts( "Task 1 enabling Task 2 (priority 10) to consume QUE1 messages.");
err = ev_send( task2_id, EVENT2 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
puts( "Task 1 blocking for handshake from Task 2..." );
puts( "Task 1 waiting to receive ANY of EVENT2 | EVENT5 | EVENT8." );
err = ev_receive( EVENT2 | EVENT5 | EVENT8, EV_ANY, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
tm_wkafter( 2 );
puts( "Task 1 enabling Task 5 (priority 15) to consume QUE1 messages.");
err = ev_send( task5_id, EVENT5 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
puts( "Task 1 blocking for handshake from Task 5..." );
puts( "Task 1 waiting to receive ANY of EVENT2 | EVENT5 | EVENT8." );
err = ev_receive( EVENT2 | EVENT5 | EVENT8, EV_ANY, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
tm_wkafter( 2 );
puts( "Task 1 enabling Task 8 (priority 20) to consume QUE1 messages.");
err = ev_send( task8_id, EVENT8 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
puts( "Task 1 blocking for handshake from Task 8..." );
puts( "Task 1 waiting to receive ANY of EVENT2 | EVENT5 | EVENT8." );
err = ev_receive( EVENT2 | EVENT5 | EVENT8, EV_ANY, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
tm_wkafter( 2 );
puts( "Task 1 enabling Task 3 (priority 10) to consume VLQ1 messages.");
err = ev_send( task3_id, EVENT3 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
puts( "Task 1 blocking for handshake from Task 3..." );
puts( "Task 1 waiting to receive ANY of EVENT3 | EVENT6 | EVENT9." );
err = ev_receive( EVENT3 | EVENT6 | EVENT9, EV_ANY, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
tm_wkafter( 2 );
puts( "Task 1 enabling Task 6 (priority 15) to consume VLQ1 messages.");
err = ev_send( task6_id, EVENT6 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
puts( "Task 1 blocking for handshake from Task 6..." );
puts( "Task 1 waiting to receive ANY of EVENT3 | EVENT6 | EVENT9." );
err = ev_receive( EVENT3 | EVENT6 | EVENT9, EV_ANY, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
tm_wkafter( 2 );
puts( "Task 1 enabling Task 9 (priority 20) to consume VLQ1 messages.");
err = ev_send( task9_id, EVENT9 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
puts( "Task 1 blocking for handshake from Task 9..." );
puts( "Task 1 waiting to receive ANY of EVENT3 | EVENT6 | EVENT9." );
err = ev_receive( EVENT3 | EVENT6 | EVENT9, EV_ANY, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
tm_wkafter( 2 );
}
/*****************************************************************************
** validate_queues
** This function sequences through a series of actions to exercise
** the various features of p2pthread standard queues.
**
*****************************************************************************/
void validate_queues( void )
{
ULONG err;
ULONG message_num;
ULONG task_count;
ULONG my_queue_id;
my_qmsg_t msg;
msgblk_t rcvd_msg;
puts( "\r\n********** Queue validation:" );
/************************************************************************
** Queue-full / Queue Extensibility Test
************************************************************************/
puts( "\n.......... First we created three standard queues" );
puts( "\n.......... Next we attempt to send nine messages to each queue" );
puts( " This tests queue full / queue extensibility logic." );
puts( " The extensible standard QUE1 should return no errors" );
puts( " but QUE2 should return five 0x35 errs" );
puts( " and QUE3 should return nine 0x35 errs" );
/*
** This is a 'sneaky trick' to null-terminate the object name string.
*/
msg.nullterm = (ULONG)NULL;
/*
**
*/
msg.qname.name[0] = 'Q';
msg.qname.name[1] = 'U';
msg.qname.name[2] = 'E';
for ( message_num = 1; message_num < 10; message_num++ )
{
/*
*/
msg.t_cycle = test_cycle;
msg.msg_no = message_num;
msg.qname.name[3] = '1';
printf( "Task 1 sending msg %ld to %s", message_num, msg.qname.name );
err = q_send( queue1_id, (ULONG *)&msg );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
msg.qname.name[3] = '2';
printf( "Task 1 sending msg %ld to %s", message_num, msg.qname.name );
err = q_send( queue2_id, (ULONG *)&msg );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
msg.qname.name[3] = '3';
printf( "Task 1 sending msg %ld to %s", message_num, msg.qname.name );
err = q_send( queue3_id, (ULONG *)&msg );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
}
/************************************************************************
** Waiting Task 'Queuing Order' (FIFO vs. PRIORITY) Test
************************************************************************/
puts( "\n.......... During the EVENT tests above, tasks 2, 5, and 8" );
puts( " were forced by EVENTs to wait on QUE1 in that order." );
puts( " The events were sent to lowest-priority tasks first." );
puts( " Since the queues awaken tasks in FIFO order, this" );
puts( " tests the task queueing order logic." );
puts( " Since Task 1 is at the highest priority level, the" );
puts( " other tasks will not execute until Task 1 blocks.\r\n" );
puts( " Tasks 2, 5, and 8 - in that order - should each" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -