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

📄 test7.c

📁 eCos/RedBoot for勤研ARM AnywhereII(4510) 含全部源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
                // so to do is pointless; further, we would check for the
                // wrong error code.  So we do not test PLAIN tests with
                // TIMOUT kill operations.
                //
                // 3) SLEEP or DELAY tests with DELETE operations: there is
                // no synchronization to delete in those cases.
                // 3a) Individual object types are tested for delete support,
                // and if there is none, the test is skipped.

                if ( DELAY == wait && TIMED == type )
                    continue;

                if ( PLAIN == type &&
                     ( (        TIMEOUT        == kill) ||
                       (SUSPEND_TIMEOUT_RESUME == kill) ||
                       (SUSPEND_TIMEOUT_KILL   == kill) ) )
                    continue;

                if ( ( 
#ifndef CYGPKG_UITRON_SEMAS_CREATE_DELETE
                    (SEMGET      == wait) ||
#endif
#ifndef CYGPKG_UITRON_FLAGS_CREATE_DELETE
                    (FLAGWAIT    == wait) ||
#endif
#ifndef CYGPKG_UITRON_MBOXES_CREATE_DELETE
                    (MSGGET      == wait) ||
#endif
#ifndef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
                    (MEMFIXEDGET == wait) ||
#endif
#ifndef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
                    (MEMVARGET   == wait) ||
#endif
                    (SLEEP       == wait) ||
                    (DELAY       == wait)
                    ) &&
                     ((DELETE                == kill) ||
                      (SUSPEND_DELETE_RESUME == kill) ||
                      (SUSPEND_DELETE_KILL   == kill)) )
                    continue;


                CYG_TEST_INFO( makemsg( "T1: ", wait, type, kill ) );

                intercom = 0;

                // prepare the synchronization objects
                // (actually, just empty the mempools)
                do_prep( wait );

                // start task 2 at a higher priority than myself
                ercd = dis_dsp();
                CYG_TEST_CHECK( E_OK == ercd, "dis_dsp bad ercd" );
                ercd = sta_tsk( 2, task2arg( wait, type, kill ) );
                CYG_TEST_CHECK( E_OK == ercd, "sta_tsk bad ercd" );
                ercd = chg_pri( 2, 5 );
                CYG_TEST_CHECK( E_OK == ercd, "chg_pri bad ercd" );
                ercd = ena_dsp();
                CYG_TEST_CHECK( E_OK == ercd, "ena_dsp bad ercd" );
                // task 2 should run now, until it waits.

                ercd = ref_tsk( &rtsk, 2 );
                CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
                CYG_TEST_CHECK( TTS_WAI == rtsk.tskstat, "bad tskstat" );
                CYG_TEST_CHECK( 5 == rtsk.tskpri, "bad tskpri" );

                switch ( kill ) {
                case SIGNAL:
                    // signal the task appropriately
                    do_signal( wait );
                    // it should now have run to completion
                    break;
                case TIMEOUT:
                    // wait for the timeout to occur
                    ercd = dly_tsk( T1_WAIT );
                    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
                    // it should now have run to completion
                    break;
                case RELEASE:
                    // hit the task with a release-wait
                    ercd = rel_wai( 2 );
                    CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
                    // it should now have run to completion
                    break;
                case DELETE:
                    // delete the object appropriately
                    do_delete( wait );
                    // it should now have run to completion
                    break;
                case KILL:
                    // kill the task
                    ercd = ter_tsk( 2 );
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
                    // it should now have terminated without running
                    break;
                case SUSPEND_SIGNAL_RESUME:
                    // suspend the task
                    do_suspend();
                    // signal the task appropriately
                    do_signal( wait );
                    // resume the task
                    do_resume();
                    // it should now have run to completion
                    break;
                case SUSPEND_TIMEOUT_RESUME:
                    // suspend the task
                    do_suspend();
                    // wait for the timeout to occur
                    ercd = dly_tsk( T1_WAIT );
                    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
                    // resume the task
                    do_resume();
                    // it should now have run to completion
                    break;
                case SUSPEND_RELEASE_RESUME:
                    // suspend the task
                    do_suspend();
                    // hit the task with a release-wait
                    ercd = rel_wai( 2 );
                    CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
                    // resume the task
                    do_resume();
                    // it should now have run to completion
                    break;
                case SUSPEND_DELETE_RESUME:
                    // suspend the task
                    do_suspend();
                    // delete the object appropriately
                    do_delete( wait );
                    // resume the task
                    do_resume();
                    // it should now have run to completion
                    break;
                case SUSPEND_KILL:
                    // suspend the task
                    do_suspend();
                    // kill the task
                    ercd = ter_tsk( 2 );
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
                    // it should now have terminated without running
                    break;
                case SUSPEND_SIGNAL_KILL:
                    // suspend the task
                    do_suspend();
                    // signal the task appropriately
                    do_signal( wait );
                    // kill the task
                    ercd = ter_tsk( 2 );
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
                    // it should now have terminated without running
                    break;
                case SUSPEND_TIMEOUT_KILL:
                    // suspend the task
                    do_suspend();
                    // wait for the timeout to occur
                    ercd = dly_tsk( T1_WAIT );
                    CYG_TEST_CHECK( E_OK == ercd, "dly_tsk bad ercd" );
                    // kill the task
                    ercd = ter_tsk( 2 );
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
                    // it should now have terminated without running
                    break;
                case SUSPEND_RELEASE_KILL:
                    // suspend the task
                    do_suspend();
                    // hit the task with a release-wait
                    ercd = rel_wai( 2 );
                    CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
                     // kill the task
                    ercd = ter_tsk( 2 );
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
                    // it should now have terminated without running
                    break;
                case SUSPEND_DELETE_KILL:
                    // suspend the task
                    do_suspend();
                    // delete the object appropriately
                    do_delete( wait );
                    // kill the task
                    ercd = ter_tsk( 2 );
                    CYG_TEST_CHECK( E_OK == ercd, "ter_tsk bad ercd" );
                    // it should now have terminated without running
                    break;
                default:
                    CYG_TEST_FAIL( "bad switch" );
                    break;
                }
                
                // task 2 should be dormant now, however it got there
                ercd = ref_tsk( &rtsk, 2 );
                CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
                CYG_TEST_CHECK( TTS_DMT == rtsk.tskstat, "bad tskstat" );

                if ( (SUSPEND_SIGNAL_KILL == kill) &&
                     ((MEMFIXEDGET == wait) || (MEMVARGET == wait)) ) {
                    // it was a killed successful memory alloc, so we have
                    // lost the pointer to memory allocated; there is an
                    // implicit storeleak problem when the task trying
                    // to allocate is signalled then killed.
                    // Recreate the pointer from an old version:
                    CYG_TEST_CHECK( NULL == t2vp, "t2vp WAS allocated!" );
                    t2vp = t2vp_backup;
                }

                switch ( kill ) {
                case KILL:
                case SUSPEND_KILL:
                case SUSPEND_SIGNAL_KILL:
                case SUSPEND_TIMEOUT_KILL:
                case SUSPEND_RELEASE_KILL:
                case SUSPEND_DELETE_KILL:
                    // if task 2 was killed, expect only one increment
                    CYG_TEST_CHECK( 1 == intercom, "intercom bad value !1" );
                    break;
                default:
                    // otherwise expect two increments
                    CYG_TEST_CHECK( 2 == intercom, "intercom bad value !2" );
                    break;
                }
                
                // tidy up or recreate the synchronization objects
                if ( (DELETE                == kill) ||
                     (SUSPEND_DELETE_RESUME == kill) ||
                     (SUSPEND_DELETE_KILL   == kill) )
                    do_recreate( wait );
                else
                    do_tidyup( wait );
            }
        }
    }
    CYG_TEST_PASS("synchronization interaction tests");

    // all done
    CYG_TEST_EXIT( "All done" );
    ext_tsk();
}



void task2( unsigned int arg )
{
    ER ercd;
    WAITOP wait;
    WAITTYPE waittype;
    KILLOP kill;

    decodearg( arg, &wait, &waittype, &kill );

//    CYG_TEST_INFO( makemsg( " 2: ", wait, waittype, kill ) );

    intercom++;
    ercd = do_wait( wait, waittype );
    intercom++;

    switch ( kill ) {
    case SIGNAL:
    case SUSPEND_SIGNAL_RESUME:
        // we expect to have been signalled correctly
        CYG_TEST_CHECK( E_OK == ercd, "T2 wait bad ercd" );
        // here we know that the op completed OK
        if ( (MEMFIXEDGET == wait) || (MEMVARGET == wait) ) {
            // it was a successful memory alloc of whichever type,
            // so we can save away a copy of t2vp for working round an
            // implicit storeleak problem when the task trying to allocate
            // is signalled then killed:
            CYG_TEST_CHECK( NULL != t2vp, "No t2vp allocated!" );
            t2vp_backup = t2vp;
        }
        break;
    case TIMEOUT:
    case SUSPEND_TIMEOUT_RESUME:
        // we expect to have timed out - if it's a timeout op.
        CYG_TEST_CHECK( E_TMOUT == ercd, "T2 timeout bad ercd, !E_TMOUT" );
        break;
    case RELEASE:
    case SUSPEND_RELEASE_RESUME:
        // we expect to have suffered a release wait.
        CYG_TEST_CHECK( E_RLWAI == ercd, "T2 release bad ercd, !E_RLWAI" );
        break;
    case DELETE:
    case SUSPEND_DELETE_RESUME:
        // we expect to be told the object is gone
        CYG_TEST_CHECK( E_DLT == ercd, "T2 release bad ercd, !E_DLT" );
        break;
    case KILL:
    case SUSPEND_KILL:
    case SUSPEND_SIGNAL_KILL:
    case SUSPEND_TIMEOUT_KILL:
    case SUSPEND_RELEASE_KILL:
    case SUSPEND_DELETE_KILL:
        // we expect to have been killed here, ie. this won't execute!
        CYG_TEST_FAIL( "Task 2 ran to completion!" );
        break;
    default:
        CYG_TEST_FAIL( "bad switch" );
        break;
    }
}

void task3( unsigned int arg )
{
}

void task4( unsigned int arg )
{
}

#else // not enough (or too many) uITRON objects configured in
#define N_A_MSG "not enough uITRON objects to run test"
#endif // not enough (or too many) uITRON objects configured in
#else  // not C++ and some C++ specific options enabled
#define N_A_MSG "C++ specific options selected but this is C"
#endif  // not C++ and some C++ specific options enabled
#else // ! CYGVAR_KERNEL_COUNTERS_CLOCK   - can't test without it
#define N_A_MSG "no CYGVAR_KERNEL_COUNTERS_CLOCK"
#endif // ! CYGVAR_KERNEL_COUNTERS_CLOCK  - can't test without it
#else  // ! CYGFUN_KERNEL_THREADS_TIMER   - can't test without it
#define N_A_MSG "no CYGFUN_KERNEL_THREADS_TIMER"
#endif // ! CYGFUN_KERNEL_THREADS_TIMER   - can't test without it
#else  // ! CYGIMP_THREAD_PRIORITY        - can't test without it
#define N_A_MSG "no CYGSEM_KERNEL_SCHED_MLQUEUE"
#endif // ! CYGSEM_KERNEL_SCHED_MLQUEUE   - can't test without it
#else  // ! CYGPKG_UITRON
#define N_A_MSG "uITRON Compatibility layer disabled"
#endif // CYGPKG_UITRON

#ifdef N_A_MSG
void
cyg_start( void )
{
    CYG_TEST_INIT();
    CYG_TEST_NA( N_A_MSG );
}
#endif // N_A_MSG defined ie. we are N/A.

// EOF test7.c

⌨️ 快捷键说明

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