Exemplo n.º 1
0
void except0_main( void )
{
    // Use CYG_TEST_GDBCMD _before_ CYG_TEST_INIT()
    CYG_TEST_GDBCMD("handle SIGBUS nostop");
    CYG_TEST_GDBCMD("handle SIGSEGV nostop");
    CYG_TEST_GDBCMD("handle SIGFPE nostop");

    CYG_TEST_INIT();

#ifdef HAL_VSR_SET_TO_ECOS_HANDLER
    // Reclaim the VSR off CygMon possibly
#ifdef CYGNUM_HAL_EXCEPTION_DATA_ACCESS
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_ACCESS, NULL );
#endif
#ifdef CYGNUM_HAL_EXCEPTION_DATA_TLBMISS_ACCESS
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_TLBMISS_ACCESS, NULL );
#endif
#ifdef CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DATA_UNALIGNED_ACCESS, NULL );
#endif
#ifdef CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_ILLEGAL_INSTRUCTION, NULL );
#endif
#ifdef CYGNUM_HAL_EXCEPTION_DIV_BY_ZERO
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_DIV_BY_ZERO, NULL );
#endif
#ifdef CYGNUM_HAL_EXCEPTION_FPU
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_FPU, NULL );
#endif
#ifdef CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO
    HAL_VSR_SET_TO_ECOS_HANDLER( CYGNUM_HAL_EXCEPTION_FPU_DIV_BY_ZERO, NULL );
#endif
#endif

    cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kexcept1",
        (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]);
    cyg_thread_resume(thread[0]);

    cyg_scheduler_start();

    CYG_TEST_FAIL_FINISH("Not reached");
}
Exemplo n.º 2
0
int
main( int argc, char *argv[] )
#endif
{
    __sighandler_t handler1;
    int rc;

    // special callout to request GDB to alter its handling of signals
    CYG_TEST_GDBCMD("handle SIGTERM nostop");
    CYG_TEST_GDBCMD("handle SIGABRT nostop");

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C "
                  "library signal functions");

    // Test 1

    CYG_TEST_INFO("Test 1");
    state = 1;
    handler1 = signal(SIGTERM, &myhandler1);

    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
                       "SIGTERM handler initialized to default");

    rc = raise(SIGTERM);

    CYG_TEST_PASS_FAIL(0==rc, "raise(SIGTERM) did not return error");

    CYG_TEST_PASS_FAIL(2==state, "SIGTERM handler returned correctly");

    // Test 2

    CYG_TEST_INFO("Test 2");

    state = 2;
    handler1 = signal(SIGTERM, &myhandler2);

    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
                       "SIGTERM handler reset to default after test 1");

    handler1 = signal(SIGTERM, &myhandler1);

    CYG_TEST_PASS_FAIL(handler1 == &myhandler2,
                       "SIGTERM handler was set correctly");

    rc = raise(SIGTERM);

    CYG_TEST_PASS_FAIL(0==rc, "raise(SIGTERM) did not return error");

    CYG_TEST_PASS_FAIL(3==state, "SIGTERM handler returned correctly");

    // Test 3

    CYG_TEST_INFO("Test 3");

    handler1 = signal(SIGTERM, &myhandler2);
    
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
                       "SIGTERM handler reset to default after test 2");

    handler1 = signal(SIGTERM, SIG_DFL);

    CYG_TEST_PASS_FAIL(handler1 == &myhandler2,
                       "SIGTERM handler was set correctly");

    // Test 4

    CYG_TEST_INFO("Test 4");

    state = 4;
    handler1 = signal(SIGTERM, SIG_IGN);

    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
                       "SIGTERM handler was set correctly after test 3");
    rc = raise(SIGTERM);

    CYG_TEST_PASS_FAIL(0==rc, "raise(SIGTERM) did not return error");

    CYG_TEST_PASS_FAIL(4==state, "SIGTERM ignored");
    
    // Test 5

    CYG_TEST_INFO("Test 5");

    state = 5;
    handler1 = signal(SIGTERM, &myhandler2);

    // SIG_IGN doesn't reset back to SIG_DFL after a raise()
    CYG_TEST_PASS_FAIL(handler1 == SIG_IGN,
                       "SIGTERM handler was set correctly after test 4");
    
    if (0==setjmp(jbuf)) {
        raise(SIGTERM);
        CYG_TEST_FAIL("raise returned");
    }
    
    CYG_TEST_PASS_FAIL(6==state, "SIGTERM handler returned correctly");

#if defined(CYGINT_ISO_ENVIRON) && (CYGINT_ISO_ENVIRON > 0)    
    // Test 6

    CYG_TEST_INFO("Test 6");

    state = 6;
    handler1 = signal(SIGABRT, &myhandler2);
    
    CYG_TEST_PASS_FAIL(handler1 == SIG_DFL,
                       "SIGABRT handler initialized to default");
    
    if (0==setjmp(jbuf)) {
        abort();
        CYG_TEST_FAIL("abort returned");
    }

    CYG_TEST_PASS_FAIL(7==state, "SIGABRT handler returned correctly");
#else
    CYG_TEST_INFO("skipping abort() test, function not implemented");
#endif    
    
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C "
                    "library signal functions");

} // main()