⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validate.c

📁 linux环境支持psos的操作系统。非常适合进行移植的朋友。
💻 C
📖 第 1 页 / 共 5 页
字号:
    printf( "\n16-byte q_vreceive for 128-byte VLQ2 returned error %lx\r\n", err );
    /************************************************************************
    **  Waiting Task 'Queuing Order' (FIFO vs. PRIORITY) Test
    ************************************************************************/
    puts( "\n.......... During the EVENT tests above, tasks 3, 6, and 9" );
    puts( "           were forced by EVENTs to wait on VLQ1 in that order." );
    puts( "           The events were sent to lowest-priority tasks first." );
    puts( "           Since the queues awaken tasks in PRIORITY 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 9, 6, and 3 - in that order - should each" );
    puts( "           receive 3 messages from VLQ1" );

    puts( "\r\nTask 1 blocking while messages are consumed..." );
    puts( "Task 1 waiting to receive ALL of EVENT3 | EVENT6 | EVENT9." );
    puts( "\n.......... Task1 should re-awaken only after ALL events received." );
    err = ev_receive( EVENT3 | EVENT6 | EVENT9, 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 VLQ3 with" );
    puts( "           Task 9 waiting on VLQ3... This should succeed." );
    puts( "           This tests the zero-length queue send logic." );

    puts( "Task 1 enabling Task 9 (priority 20) to consume VLQ3 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 EVENT9." );
    err = ev_receive( 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 );
            
    printf( "Task 1 Sending msg %ld to %s", message_num, msg.qname.name );
    msg.msg_no = message_num;
    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( "\r\nTask 1 blocking while message is consumed..." );
    puts( "Task 1 waiting to receive ANY of EVENT9." );
    err = ev_receive( EVENT9, EV_ANY, 0, (ULONG *)NULL );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    else
        printf( "\r\n" );

    /************************************************************************
    **  Variable-Length Queue-Broadcast Test
    ************************************************************************/
    puts( "\n.......... Next we enable Tasks 3, 6, and 9 to wait for" );
    puts( "           a message on VLQ1.  Then we send a broadcast" );
    puts( "           message to VLQ1.  This should wake each of Tasks 3," );
    puts( "           6, and 9.   This tests the queue broadcast logic." );

    puts( "Task 1 enabling Tasks 3, 6, and 9 to consume VLQ1 messages.");
    err = ev_send( task3_id, EVENT3 );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    err = ev_send( task6_id, EVENT6 );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    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 Tasks 3, 6, and 9..." );
    puts( "Task 1 waiting to receive ALL of EVENT3 | EVENT6 | EVENT9." );
    err = ev_receive( EVENT3 | EVENT6 | EVENT9, 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_vbroadcast( vqueue1_id, (ULONG *)&msg, 16, &task_count );
    if ( err != ERR_NO_ERROR )
        printf( " returned error %lx\r\n", err );
    else
        printf( "Task 1 vqueue 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 EVENT3 | EVENT6 | EVENT9." );
    err = ev_receive( EVENT3 | EVENT6 | EVENT9, EV_ALL, 0, (ULONG *)NULL );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    else
        printf( "\r\n" );

    /************************************************************************
    **  Variable-Length Queue-Delete Test
    ************************************************************************/
    puts( "\n.......... Next we enable Tasks 3, 6, and 9 to wait for" );
    puts( "           a message on VLQ1.  Then we delete VLQ1." );
    puts( "           This should wake each of Tasks 3, 6, and 9," );
    puts( "           and they should each return an error 0x36." );
    puts( "           The q_vdelete should return an error 0x38." );
    puts( "           This tests the queue delete logic." );

    puts( "Task 1 enabling Tasks 3, 6, and 9 to consume VLQ1 messages.");
    err = ev_send( task3_id, EVENT3 );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    err = ev_send( task6_id, EVENT6 );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    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 Tasks 3, 6, and 9..." );
    puts( "Task 1 waiting to receive ALL of EVENT3 | EVENT6 | EVENT9." );
    err = ev_receive( EVENT3 | EVENT6 | EVENT9, 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_vdelete( vqueue1_id );
    if ( err != ERR_NO_ERROR )
        printf( "Task 1 q_vdelete on VLQ1 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 EVENT3 | EVENT6 | EVENT9." );
    err = ev_receive( EVENT3 | EVENT6 | EVENT9, 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 VLQ3 with no tasks waiting" );
    err = q_vdelete( vqueue3_id );
    if ( err != ERR_NO_ERROR )
        printf( "Task 1 q_vdelete on VLQ3 returned error %lx\r\n", err );
    else
        printf( "\r\n" );


    /************************************************************************
    **  Variable-Length Queue Urgent Message Test
    ************************************************************************/
    puts( "\n.......... During the queue-full tests above, four messages" );
    puts( "           were sent, filling variable-length queue VLQ2." );
    puts( "           Now we will send an urgent message and then enable" );
    puts( "           a consumer task to receive all the messages in VLQ2." );
    puts( "           The consumer task should receive five messages in all" );
    puts( "           from VLQ2, 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." );

    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_vurgent( vqueue2_id, (ULONG *)&msg, 16 );
    if ( err != ERR_NO_ERROR )
        printf( " returned error %lx\r\n", err );
    else
        printf( "\r\n" );

    puts( "Task 1 enabling Task 6 to consume VLQ2 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 EVENT6." );
    err = ev_receive( EVENT6, 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 EVENT6." );
    err = ev_receive( EVENT6, EV_ANY, 0, (ULONG *)NULL );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    else
        printf( "\r\n" );

    /************************************************************************
    **  Variable-Length Queue-Ident and Queue-Not_Found Test
    ************************************************************************/
    puts( "\n.......... Finally, we test the q_vident logic..." );
    puts( "           Then we verify the error codes returned when" );
    puts( "           a non-existent queue is specified." );

    err = q_vident( "VLQ2", 0, &my_vqueue_id );
    if ( err != ERR_NO_ERROR )
        printf( "\nq_vident for VLQ2 returned error %lx\r\n", err );
    else
        printf( "\nq_vident for VLQ2 returned ID %lx... vqueue2_id == %lx\r\n",
                 my_vqueue_id, vqueue2_id );

    err = q_vident( "VLQ1", 0, &my_vqueue_id );
    if ( err != ERR_NO_ERROR )
        printf( "\nq_vident for VLQ1 returned error %lx\r\n", err );
    else
        printf( "\nq_vident for VLQ1 returned ID %lx vqueue2_id %lx\r\n",
                  my_vqueue_id, vqueue1_id );

    err = q_vsend( vqueue1_id, (void *)&msg, 16 );
    printf( "\nq_vsend for VLQ1 returned error %lx\r\n", err );

    err = q_vreceive( vqueue1_id, Q_NOWAIT, 0L, rcvd_msg.blk, 16, &my_msglen );
    printf( "\nq_vreceive for VLQ1 (no waiting) returned error %lx\r\n", err );

    err = q_vreceive( vqueue1_id, Q_WAIT, 0L, rcvd_msg.blk, 16, &my_msglen );
    printf( "\nq_vreceive for VLQ1 (wait forever) returned error %lx\r\n", err );

    err = q_vdelete( vqueue1_id );
    printf( "\nq_vdelete for VLQ1 returned error %lx\r\n", err );
}

/*****************************************************************************
**  validate_semaphores
**         This function sequences through a series of actions to exercise
**         the various features and characteristics of p2pthread semaphores
**
*****************************************************************************/
void validate_semaphores( void )
{
    ULONG err;
    ULONG my_sema4_id;
    int i;

    puts( "\r\n********** Semaphore validation:" );

    /************************************************************************
    **  Semaphore Creation Test
    ************************************************************************/
    puts( "\n.......... First we create three semaphores:" );
 
    puts( "\nCreating Semaphore 1, FIFO queuing and initially 'locked'" );
    err = sm_create( "SEM1", 0, SM_FIFO, &sema41_id );
    if ( err != ERR_NO_ERROR )
        printf( "... returned error %lx\r\n", err );
 
    puts( "Creating Semaphore 2, FIFO queuing with 2 tokens initially" );
    err = sm_create( "SEM2", 2, SM_FIFO, &sema42_id );
    if ( err != ERR_NO_ERROR )
        printf( "... returned error %lx\r\n", err );
 
    puts( "Creating Semaphore 3, PRIORITY queuing and initially 'locked'" );
    err = sm_create( "SEM3", 0, SM_PRIOR, &sema43_id );
    if ( err != ERR_NO_ERROR )
        printf( "... returned error %lx\r\n", err );

    /************************************************************************
    **  Semaphore Waiting and Task Queueing Order Test
    ************************************************************************/
 
    puts( "\n.......... Next we enable Tasks 4, 7, and 10 to wait for" );
    puts( "           a token from SEM1 in reverse-priority order.  Then" );
    puts( "           Then we send three tokens to SEM1, waiting between" );
    puts( "           each token posting to see which task gets the token." );
    puts( "           This tests the semaphore post and queueing logic." );
    puts( "           The token should be acquired by Task 4, 7, and 10" );
    puts( "           in that order." );

    puts( "Task 1 enabling Tasks 4, 7, and 10 to consume SEM1 tokens.");
    err = ev_send( task4_id, EVENT4 );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    tm_wkafter( 2 );
    err = ev_send( task7_id, EVENT7 );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    tm_wkafter( 2 );
    err = ev_send( task10_id, EVENT10 );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    tm_wkafter( 2 );

    puts( "Task 1 blocking for handshake from Tasks 4, 7, and 10..." );
    puts( "Task 1 waiting to receive ALL of EVENT4 | EVENT7 | EVENT10." );
    err = ev_receive( EVENT4 | EVENT7 | EVENT10, EV_ALL, 0, (ULONG *)NULL );
    if ( err != ERR_NO_ERROR )
         printf( " returned error %lx\r\n", err );
    else
        printf( "\r\n" );
    tm_wkafter( 2 );

    for ( i = 0; i < 3; i++ )
    {
        puts( "Task 1 sending token to semaphore SEM1." );
        err = sm_v( sema41_id );
        if ( err != ERR_NO_ERROR )
            printf( "\nTask 1 send token to SEM1 returned error %lx\r\n", err );
    }

    puts( "Task 1 blocking for handshake from Tasks 4, 7, and 10..." );
    puts( "Task 1 waiting to receive ALL of EVENT4 | EVENT7 | EVENT10." );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -