📄 validate.c
字号:
puts( " receive 3 messages from QUE1" );
puts( "\r\nTask 1 blocking while messages are consumed..." );
puts( "Task 1 waiting to receive ALL of EVENT2 | EVENT5 | EVENT8." );
puts( "\n.......... Task1 should re-awaken only after ALL events received." );
err = ev_receive( EVENT2 | EVENT5 | EVENT8, EV_ALL, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
puts( "\n.......... Next we send a message to zero-length QUE3 with" );
puts( " Task 8 waiting on QUE3... This should succeed." );
puts( " This tests the zero-length queue send logic." );
puts( "Task 1 enabling Task 8 (priority 20) to consume QUE3 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 EVENT8." );
err = ev_receive( 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 );
printf( "Task 1 Sending msg %ld to %s", message_num, msg.qname.name );
msg.msg_no = message_num;
err = q_send( queue3_id, (ULONG *)&msg );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
puts( "\r\nTask 1 blocking while message is consumed..." );
puts( "Task 1 waiting to receive ANY of EVENT8." );
err = ev_receive( EVENT8, EV_ANY, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
/************************************************************************
** Queue-Broadcast Test
************************************************************************/
puts( "\n.......... Next we enable Tasks 2, 5, and 8 to wait for" );
puts( " a message on QUE1. Then we send a broadcast" );
puts( " message to QUE1. This should wake each of Tasks 2," );
puts( " 5, and 8. This tests the queue broadcast logic." );
puts( "Task 1 enabling Tasks 2, 5, and 8 to consume QUE1 messages.");
err = ev_send( task2_id, EVENT2 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
err = ev_send( task5_id, EVENT5 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
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 Tasks 2, 5, and 8..." );
puts( "Task 1 waiting to receive ALL of EVENT2, EVENT5 and EVENT8." );
err = ev_receive( EVENT2 | EVENT5 | EVENT8, EV_ALL, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
tm_wkafter( 2 );
msg.msg_no = ++message_num;
msg.qname.name[3] = '1';
printf( "Task 1 broadcasting msg %ld to %s", message_num, msg.qname.name );
err = q_broadcast( queue1_id, (ULONG *)&msg, &task_count );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "Task 1 queue broadcast awakened %ld tasks\r\n", task_count );
puts( "\r\nTask 1 blocking while message is consumed..." );
puts( "Task 1 waiting to receive ALL of EVENT2, EVENT5, and EVENT8." );
err = ev_receive( EVENT2 | EVENT5 | EVENT8, EV_ALL, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
/************************************************************************
** Queue-Delete Test
************************************************************************/
puts( "\n.......... Next we enable Tasks 2, 5, and 8 to wait for" );
puts( " a message on QUE1. Then we delete QUE1." );
puts( " This should wake each of Tasks 2, 5, and 8," );
puts( " and they should each return an error 0x36." );
puts( " The q_delete should return an error 0x38." );
puts( " This tests the queue delete logic." );
puts( "Task 1 enabling Tasks 2, 5, and 8 to consume QUE1 messages.");
err = ev_send( task2_id, EVENT2 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
err = ev_send( task5_id, EVENT5 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
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 Tasks 2, 5, and 8..." );
puts( "Task 1 waiting to receive ALL of EVENT2, EVENT5 and EVENT8." );
err = ev_receive( EVENT2 | EVENT5 | EVENT8, EV_ALL, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
tm_wkafter( 2 );
printf( "Task 1 deleting %s", msg.qname.name );
err = q_delete( queue1_id );
if ( err != ERR_NO_ERROR )
printf( "Task 1 q_delete on QUE1 returned error %lx\r\n", err );
else
printf( "\r\n" );
puts( "\r\nTask 1 blocking until consumer tasks acknowledge deletion..." );
puts( "Task 1 waiting to receive ALL of EVENT2, EVENT5, and EVENT8." );
err = ev_receive( EVENT2 | EVENT5 | EVENT8, EV_ALL, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
printf( "Task 1 deleting QUE3 with no tasks waiting" );
err = q_delete( queue3_id );
if ( err != ERR_NO_ERROR )
printf( "Task 1 q_delete on QUE3 returned error %lx\r\n", err );
else
printf( "\r\n" );
/************************************************************************
** Queue Urgent Message Test
************************************************************************/
puts( "\n.......... During the queue-full tests above, four messages" );
puts( " were sent, filling non-extensible queue QUE2." );
puts( " Now we will send an urgent message and then enable" );
puts( " a consumer task to receive all the messages in QUE2." );
puts( " The consumer task should receive five messages in all" );
puts( " from QUE2, starting with the urgent message." );
puts( " NOTE: This behavior is slightly more generous than" );
puts( " real pSOS+ (R) would be - it would return a QFULL error." );
puts( " However, this is a side effect of the 'extra' message" );
puts( " buffer added to support 'zero-length' behavior." );
puts( " (It also happens to model VRTXxx queue behavior.)" );
puts( " With the default (Q_NOLIMIT) queues it's a moot point." );
msg.msg_no = ++message_num;
msg.qname.name[3] = '2';
printf( "Task 1 Sending urgent msg %ld to %s", message_num, msg.qname.name );
err = q_urgent( queue2_id, (ULONG *)&msg );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
puts( "Task 1 enabling Task 5 to consume QUE2 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 EVENT5." );
err = ev_receive( EVENT5, 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( "\r\nTask 1 blocking while messages are consumed..." );
puts( "Task 1 waiting to receive ANY of EVENT5." );
err = ev_receive( EVENT5, EV_ANY, 0, (ULONG *)NULL );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
/************************************************************************
** Queue-Ident and Queue-Not_Found Test
************************************************************************/
puts( "\n.......... Finally, we test the q_ident logic..." );
puts( " Then we verify the error codes returned when" );
puts( " a non-existent queue is specified." );
err = q_ident( "QUE2", 0, &my_queue_id );
if ( err != ERR_NO_ERROR )
printf( "\nq_ident for QUE2 returned error %lx\r\n", err );
else
printf( "\nq_ident for QUE2 returned ID %lx... queue2_id == %lx\r\n",
my_queue_id, queue2_id );
err = q_ident( "QUE1", 0, &my_queue_id );
if ( err != ERR_NO_ERROR )
printf( "\nq_ident for QUE1 returned error %lx\r\n", err );
else
printf( "\nq_ident for QUE1 returned ID %lx queue2_id %lx\r\n",
my_queue_id, queue1_id );
err = q_send( queue1_id, (ULONG *)&msg );
printf( "\nq_send for QUE1 returned error %lx\r\n", err );
err = q_receive( queue1_id, Q_NOWAIT, 0L, rcvd_msg.blk );
printf( "\nq_receive for QUE1 (no waiting) returned error %lx\r\n", err );
err = q_receive( queue1_id, Q_WAIT, 0L, rcvd_msg.blk );
printf( "\nq_receive for QUE1 (wait forever) returned error %lx\r\n", err );
err = q_delete( queue1_id );
printf( "\nq_delete for QUE1 returned error %lx\r\n", err );
}
/*****************************************************************************
** validate_vqueues
** This function sequences through a series of actions to exercise
** the various features of p2pthread variable-length queues.
**
*****************************************************************************/
void validate_vqueues( void )
{
ULONG err;
ULONG message_num;
ULONG task_count;
ULONG my_vqueue_id;
ULONG my_msglen;
my_qmsg_t msg;
msgblk_t rcvd_msg;
char msg_string[80];
puts( "\r\n********** Variable-Length Queue validation:" );
/************************************************************************
** Variable-Length Queue-full / Queue Extensibility Test
************************************************************************/
puts( "\n.......... First we created three variable-length queues" );
puts( "\n.......... Next we attempt to send nine messages to each queue" );
puts( " This tests variable-length queue full logic." );
puts( " The variable length VLQ1 should return no errors" );
puts( " but VLQ2 should return five 0x35 errs" );
puts( " and VLQ3 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] = 'V';
msg.qname.name[1] = 'L';
msg.qname.name[2] = 'Q';
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_vsend( vqueue1_id, (ULONG *)&msg, 16 );
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_vsend( vqueue2_id, (ULONG *)&msg, 16 );
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_vsend( vqueue3_id, (ULONG *)&msg, 16 );
if ( err != ERR_NO_ERROR )
printf( " returned error %lx\r\n", err );
else
printf( "\r\n" );
}
puts( "\n.......... Sending a message to a variable-length queue which" );
puts( " is larger than the queue's maximum message size would" );
puts( " either have to truncate the message or cause buffer" );
puts( " overflow - neither of which is desirable. For this" );
puts( " reason, an attempt to do this generates an error 0x31." );
puts( " This tests the overlength message detection logic." );
err = q_vsend( vqueue1_id, (void *)msg_string, 80 );
printf( "\nq_vsend 80-byte msg for 16-byte VLQ1 returned error %lx\r\n", err );
puts( "\n.......... Receiving a message from a variable-length queue which" );
puts( " is larger than the caller's message buffer size would" );
puts( " either have to truncate the message or cause buffer" );
puts( " overflow - neither of which is desirable. For this" );
puts( " reason, an attempt to do this generates an error 0x32." );
puts( " This tests the underlength buffer detection logic." );
err = q_vreceive( vqueue2_id, Q_NOWAIT, 0L, rcvd_msg.blk, 16, &my_msglen );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -