示例#1
0
// This is the main starting point for our example application.
void cyg_user_start(void)
{
    int err;
    void* lib_handle;
    void (*fn)(void);
    
    CYG_TEST_INIT();

    CYG_TEST_INFO("Object loader module test started");

    err = chdir("/");

    if(err < 0) 
        SHOW_RESULT(chdir, err);

    lib_handle = cyg_ldr_open_library((CYG_ADDRWORD)"/hello.o", 0);
    CYG_TEST_CHECK(lib_handle , "Unable to load object file to load");

    fn = cyg_ldr_find_symbol(lib_handle, "print_message");
    CYG_TEST_CHECK(fn , "Unable to find print_message function");

    fn();

    fn = cyg_ldr_find_symbol(lib_handle, "weak_function");
    CYG_TEST_CHECK(fn , "Unable to find weak_function");
    
    fn();

    fn = cyg_ldr_find_symbol (lib_handle, "unresolvable_symbol");
    CYG_TEST_CHECK(!fn , "Found none existing symbol!");
    
    thread_a = cyg_ldr_find_symbol(lib_handle, "thread_a");
    thread_b = cyg_ldr_find_symbol(lib_handle, "thread_b");
    CYG_TEST_CHECK(thread_a && thread_b , "Unable to find thread functions");
    
    // Create our two threads.
    cyg_thread_create(THREAD_PRIORITY,
                       thread_a,
                       (cyg_addrword_t) 75,
                       "Thread A",
                       (void *)thread_a_stack,
                       THREAD_STACK_SIZE,
                       &thread_a_hdl,
                       &thread_a_obj);

    cyg_thread_create(THREAD_PRIORITY + 1,
                       thread_b,
                       (cyg_addrword_t) 68,
                       "Thread B",
                       (void *)thread_b_stack,
                       THREAD_STACK_SIZE,
                       &thread_b_hdl,
                       &thread_b_obj);

    // Resume the threads so they start when the scheduler begins.
    cyg_thread_resume(thread_a_hdl);
    cyg_thread_resume(thread_b_hdl);

    cyg_scheduler_start();
}
示例#2
0
static void check_in_mp0(cyg_uint8 *p, cyg_int32 size)
{
    CYG_TEST_CHECK(NULL != p,
                   "Allocation failed");
    CYG_TEST_CHECK(mem[0] <= p && p+size < mem[1],
                   "Block outside memory pool");
}
示例#3
0
文件: intr.c 项目: KarenHung/ecosgit
void dsr( cyg_uint32 vector, cyg_ucount32 count, CYG_ADDRWORD data )
{
    CYG_TEST_CHECK( ISR_DATA == data , "Bad data passed to DSR");
    CYG_TEST_CHECK( CYGNUM_HAL_INTERRUPT_RTC == vector ,
                    "Bad vector passed to DSR");

    dsr_ticks += count;
}
示例#4
0
static void sigalrm( int signo )
{
    CYG_TEST_INFO( "sigalrm() handler called" );
    CYG_TEST_CHECK( signo == SIGALRM, "Signal not SIGALRM");
    CYG_TEST_CHECK( pthread_equal(pthread_self(), thread1), "Not called in thread1");

    sigalrm_called++;
}
示例#5
0
static void sigusr2( int signo )
{
    CYG_TEST_INFO( "sigusr2() handler called" );
    CYG_TEST_CHECK( signo == SIGUSR2, "Signal not SIGUSR2");
    CYG_TEST_CHECK( pthread_equal(pthread_self(), thread1), "Not called in thread1");

    sigusr2_called++;
}
示例#6
0
int main(int argc, char **argv)
{
    int i, j;
    int ret;
    void *retval[NTHREADS];

    CYG_TEST_INIT();

    // Create test threads
    for( i = 0; i < NTHREADS; i++ )
    {
        pthread_attr_t attr;
        pthread_attr_init( &attr );

        pthread_attr_setstackaddr( &attr, (void *)&thread_stack[i][sizeof(thread_stack[i])] );
        pthread_attr_setstacksize( &attr, sizeof(thread_stack[i]) );

        ret = pthread_create( &thread[i],
                              &attr,
                              pthread_entry[i],
                              (void *)(0x12340000+i));
        CYG_TEST_CHECK( ret == 0, "pthread_create() returned error");
    }

    // Let the threads get going    
    for ( i = 0; i < NTHREADS ; i++ ) {
        while ( thread_ready[i] == false )
            sched_yield();
    }

    // Now wait a bit to be sure that the other threads have reached
    // their cancellation points.
    for ( j = 0; j < 20 ; j++ )
        sched_yield();
    
    // Now cancel them
    for( i = 0; i < NTHREADS; i++ )    
        pthread_cancel( thread[i] );
        
    // Now join with threads
    for( i = 0; i < NTHREADS; i++ )
        pthread_join( thread[i], &retval[i] );


    // check retvals
    for( i = 0; i < NTHREADS; i++ )
        CYG_TEST_CHECK( retval[i] == PTHREAD_CANCELED,
                        "thread didn't exit with PTHREAD_CANCELED" );

    CYG_TEST_CHECK( cancel_handler1_called, "cancel_handler1 not called" );
    CYG_TEST_CHECK( cancel_handler2_called, "cancel_handler2 not called" );
    CYG_TEST_CHECK( cancel_handler3_called, "cancel_handler3 not called" );

    CYG_TEST_PASS_FINISH( "pthread3" );
        
}
示例#7
0
static void sigusr2( int signo, siginfo_t *info, void *context )
{
    CYG_TEST_INFO( "sigusr2() handler called" );
    CYG_TEST_CHECK( signo == SIGUSR2, "Signal not SIGUSR2");
    CYG_TEST_CHECK( signo == info->si_signo, "Bad signal number in siginfo" );
    CYG_TEST_CHECK( info->si_code == SI_TIMER, "Siginfo code not SI_TIMER" );
    CYG_TEST_CHECK( info->si_value.sival_int == 0xABCDEF02, "Siginfo value wrong");
    CYG_TEST_CHECK( pthread_equal(pthread_self(), thread2), "Not called in thread2");

    sigusr2_called++;
}
示例#8
0
static void handler1(cyg_addrword_t data, cyg_code_t number, cyg_addrword_t info)
{
    CYG_TEST_INFO("handler 1 called");

    CYG_TEST_CHECK((cyg_addrword_t)&d0 == data, "handler given wrong data");

#ifdef CYGSEM_KERNEL_EXCEPTIONS_DECODE
    CYG_TEST_CHECK(number == CYGNUM_HAL_EXCEPTION_MAX, "handler given wrong number");
#else
    CYG_UNUSED_PARAM(cyg_code_t, number);
#endif

    CYG_TEST_CHECK((cyg_addrword_t)99 == info, "handler given wrong info");
}
示例#9
0
文件: intr.c 项目: 0xCA5A/dd-wrt
cyg_uint32 isr( cyg_uint32 vector, CYG_ADDRWORD data )
{
    CYG_TEST_CHECK( ISR_DATA == data , "Bad data passed to ISR");
    CYG_TEST_CHECK( CYGNUM_HAL_INTERRUPT_RTC == vector ,
                    "Bad vector passed to ISR");

    HAL_CLOCK_RESET( vector, CYGNUM_HAL_RTC_PERIOD );

    HAL_INTERRUPT_ACKNOWLEDGE( vector );
    
    ticks++;

    return CYG_ISR_HANDLED;
}
示例#10
0
文件: iram1.c 项目: KarenHung/ecosgit
externC void
cyg_start( void)
{
    int i;
    int data1_sum;
    
    CYG_TEST_INIT();
    // For human inspection
    diag_printf("INFO:<IRAM usage : %p -> %p\n", _hal_iram_section_start_vma, _hal_iram_section_end_vma);
    diag_printf("INFO:<IRAM bss   @ %p\n", _hal_iram_bss_section_start);
    diag_printf("INFO:<RAM        : %p -> %p\n", (void*)CYGMEM_REGION_ram, (void*)(CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE));
    diag_printf("INFO:<onchip_fn1   @ %p>\n", &onchip_fn1);
    diag_printf("INFO:<onchip_fn2   @ %p>\n", &onchip_fn2);
    diag_printf("INFO:<onchip_data1 @ %p>\n", &onchip_data1[0]);

    // Make sure that IRAM is really separate from main memory.
    if ((_hal_iram_section_start_vma >= (cyg_uint8*)CYGMEM_REGION_ram) &&
        (_hal_iram_section_start_vma <  (cyg_uint8*)(CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE))) {
        CYG_TEST_FAIL("IRAM start overlaps SDRAM");
    }
    if ((_hal_iram_section_end_vma >= (cyg_uint8*)CYGMEM_REGION_ram) &&
        (_hal_iram_section_end_vma <  (cyg_uint8*)(CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE))) {
        CYG_TEST_FAIL("IRAM end overlaps SDRAM");
    }

    // Make sure that various objects are correctly placed.
    check_addr(&onchip_fn1);
    check_addr(&onchip_fn2);
    check_addr(&onchip_data1[0]);
    check_addr(&onchip_data2);
    // Not data3, we want that one to be garbage collected.
    check_addr(&onchip_bss1);
    check_addr(&onchip_bss2[0]);

    // Check that on-chip data is correctly initialized.
    CYG_TEST_CHECK( 42 == onchip_data2, "onchip_data2 should be the answer");
    for (i = 0, data1_sum = 0; i < 8; i++) {
        data1_sum   += onchip_data1[i];
    }
    CYG_TEST_CHECK( 36 == data1_sum, "onchip data1 array should add up to 36");

    // Make sure we can call code located in iram.
    {
        void (*onchip_fn1_ptr)(void) = &onchip_fn1;
        (*onchip_fn1_ptr)();
    }

    CYG_TEST_PASS_FINISH("IRAM test");
}
示例#11
0
文件: sigsetjmp.c 项目: 0xCA5A/dd-wrt
static void sigusr1( int signo, siginfo_t *info, void *context )
{
    CYG_TEST_INFO( "sigusr1() handler called" );
    CYG_TEST_CHECK( signo == SIGUSR1, "Signal not SIGUSR1");
    CYG_TEST_CHECK( signo == info->si_signo, "Bad signal number in siginfo" );
    CYG_TEST_CHECK( info->si_code == SI_TIMER, "Siginfo code not SI_TIMER" );
    CYG_TEST_CHECK( info->si_value.sival_int == 0xABCDEF01, "Siginfo value wrong");
    CYG_TEST_CHECK( pthread_equal(pthread_self(), thread1), "Not called in thread1");

    sigusr1_called++;

    CYG_TEST_INFO( "sigusr1() handler calling siglongjmp()" );
    
    siglongjmp( jmpbuf1, sigusr1_called );
}
示例#12
0
// Thread A - signals thread B via semaphore.
void thread_a(cyg_addrword_t data)
{
    // Store the data value passed in for this thread.
    int msg = (int)data;

    weak_function ();
    
    while(thread_a_count < 5)
    {
        // Increment the thread a count.
        thread_a_count++;


        // Send out a message to the diagnostic port.
        diag_printf("INFO:<Thread A, count: %d  message: %d>\n", thread_a_count, msg);

        // Delay for 1 second.
        cyg_thread_delay(100);

        // Signal thread B using the semaphore.
        cyg_semaphore_post(&sem_signal_thread);
    }
    
    CYG_TEST_CHECK(weak_fn_called == 2 , "Application week function not called");
    CYG_TEST_FINISH("Object loader test finished");
}
示例#13
0
static void sigusr1( int signo )
{
    CYG_TEST_INFO( "sigusr1() handler called" );
    CYG_TEST_CHECK( signo == SIGUSR1, "Signal not SIGUSR1");

    sigusr1_called++;
}
示例#14
0
void cancel_handler1( void * arg )
{
    CYG_TEST_INFO( "cancel_handler1 called" );

    CYG_TEST_CHECK( (long)arg == 0x12340000, "cancel_handler1: bad arg value");
    
    cancel_handler1_called = true;
}
示例#15
0
void alarm0_main(void)
{
    int i;
    
    CYG_TEST_INIT();

    // Create the counter
    cyg_counter_create( &counter, &counter_obj );

    // Create the alarms
    cyg_alarm_create( counter,
                      alarmfn0,
                      0,
                      &alarm[0],
                      &alarm_obj[0]);


    cyg_alarm_create( counter,
                      alarmfn1,
                      1,
                      &alarm[1],
                      &alarm_obj[1]);

    cyg_alarm_create( counter,
                      alarmfn2,
                      2,
                      &alarm[2],
                      &alarm_obj[2]);


    // Kick it all off by starting alarm[2]
    cyg_alarm_initialize( alarm[2], 0, 10 );

    // Run the whole thing for 10000 ticks
    for( i = 0; i < 10000; i++ )
        cyg_counter_tick( counter );

    db_printf("alarmfn_called: %d %d %d\n",
                alarmfn_called[0],alarmfn_called[1],alarmfn_called[2]);

    CYG_TEST_CHECK( alarmfn_called[0]==5000, "alarmfn0 not called 5000 times\n");
    CYG_TEST_CHECK( alarmfn_called[1]==2000, "alarmfn1 not called 2000 times\n");
    CYG_TEST_CHECK( alarmfn_called[2]==1001, "alarmfn2 not called 1001 times\n");
    
    CYG_TEST_PASS_FINISH("KAlarm0");
}
示例#16
0
void cancel_handler2( void * arg )
{
    CYG_TEST_INFO( "cancel_handler2 called" );

    CYG_TEST_CHECK( (long)arg == 0xFFFF1111, "cancel_handler2: bad arg value");
    
    cancel_handler2_called = true;    
}
示例#17
0
void task2( unsigned int arg )
{
    ER ercd;
    int i;
    CYG_TEST_INFO( "Task 2 running" );
    ercd = get_tid( &i );
    CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
    CYG_TEST_CHECK( 2 == i, "tid not 2" );
    if ( 22222 != arg )
        CYG_TEST_FAIL( "Task 2 arg not 22222" );

    for ( i = 0 ; i < 100; i++ ) {
        ercd = rel_wai( 1 );
        CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
    }        
    // we expect task2 to be killed here
    CYG_TEST_FAIL( "Task 2 ran to completion!" );
}
示例#18
0
void dummy( cyg_addrword_t which )
{
    // Share the same socket... we appear to run out otherwise.
    static int s_s1 = -1;
    static struct sockaddr_in local;

    // locals...
    fd_set in_fds;
    int num;

    CYG_TEST_CHECK( 0 <= which, "which under" );
    CYG_TEST_CHECK( NDUMMIES > which, "which over" );

    diag_printf( "Dummy %d alive\n", which );

    if ( s_s1 < 0 ) {
        s_s1 = socket(AF_INET, SOCK_STREAM, 0);
        if (s_s1 < 0) {
            pexit("stream socket 1");
        }
        memset(&local, 0, sizeof(local));
        local.sin_family = AF_INET;
        local.sin_len = sizeof(local);
        local.sin_port = ntohs(SOURCE_PORT3 + which);
        local.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
        if(bind(s_s1, (struct sockaddr *) &local, sizeof(local)) < 0) {
            pexit("dummy bind /source_1/ error");
        }
        listen(s_s1, SOMAXCONN);
    }

    while (true) {
        FD_ZERO(&in_fds);
        FD_SET(s_s1, &in_fds);
        num = select( s_s1+1, &in_fds,0,0,0);
        
        if (FD_ISSET(s_s1,&in_fds)) {
            CYG_TEST_FAIL( "Activity on dummy port!" );
        }
    }   /* while (true) */ 
}
示例#19
0
static void handler0(cyg_addrword_t data, cyg_code_t number, cyg_addrword_t info)
{
    CYG_TEST_INFO("handler 0 called");
    
    CYG_TEST_CHECK((cyg_addrword_t)123 == data, "handler given wrong data");
    
    // ignore machine specific stuff
    CYG_UNUSED_PARAM(cyg_code_t, number);
    CYG_UNUSED_PARAM(cyg_addrword_t, info);

    CYG_TEST_PASS_FINISH("Except 1 OK");
}
示例#20
0
static void *test_thread( void *arg )
{
	sem_t *sem1, *sem2;
	int ret;

	sem2 = sem_open(name2, O_CREAT, 0, 1);

    CYG_TEST_CHECK(sem2 !=  SEM_FAILED, "sem_open failed in test thread");

    ret = sem_wait(sem2);

    CYG_TEST_CHECK(ret ==  0, "sem_wait failed in test thread");

    sem1 = sem_open(name1, 0);

    CYG_TEST_CHECK(sem1 !=  SEM_FAILED, "sem_open failed in test thread");

    ret = sem_post(sem1);

    CYG_TEST_CHECK(ret ==  0, "sem_post failed in test thread");

    ret = sem_wait(sem2);

    CYG_TEST_CHECK(ret == 0, "sem_wait failed in test thread");

    ret= sem_unlink(name2);

    CYG_TEST_CHECK(ret == 0, "sem_unlink failed in test thread");

    ret = sem_close(sem2);

    CYG_TEST_CHECK(ret == 0, "sem_close failed in test thread");

    ret = sem_post(sem1);

    CYG_TEST_CHECK(ret == 0, "sem_post failed in test thread");

    ret =sem_close(sem1);

    CYG_TEST_CHECK(ret ==  0, "sem_close failed in test thread");

    sem_post(&main_sem);

    return NULL;
}
示例#21
0
static void checkallbut( int z )
{
    int i;
    for ( i = 1; i < 16; i++ ) {
        int level, up, hipri, mask, req;
        if ( z == i )
            continue;

        SETSTR( i, z, lstr );
        SETSTR( i, z, mstr );
        SETSTR( i, z, ustr );

        HAL_INTERRUPT_QUERY_INFO( i, level, up, hipri, mask, req);
        l = level;
        u = up;
        m = mask;
        j = i;

#if 0 // for manual testing really...
        if ( level != levels[i] )
            CYG_TEST_INFO( lstr );
        if (    up !=    ups[i] )
            CYG_TEST_INFO( ustr );
        if (  mask !=  masks[i] )
            CYG_TEST_INFO( mstr );
        if ( (level != levels[i] ) 
        |    (   up !=    ups[i] ) 
        |    ( mask !=  masks[i] ) ) {
            CYG_TEST_INFO( "Re-reading" );
            HAL_INTERRUPT_QUERY_INFO( i, level, up, hipri, mask, req);
        }
#endif
        CYG_TEST_CHECK( level == levels[i], lstr );
        CYG_TEST_CHECK(    up ==    ups[i], ustr );
        CYG_TEST_CHECK(  mask ==  masks[i], mstr );
    }
}
示例#22
0
static void
entry0( cyg_addrword_t data )
{
    int tick;

    // Scheduler and thus timer interrupts are running by the
    // time we get here.

    // Wait for next tick
    tick = cyg_current_time();
    do {} while (cyg_current_time() == tick);
    tick = cyg_current_time();

    // Then mask timer interrupts
    HAL_INTERRUPT_MASK(CYGNUM_HAL_INTERRUPT_RTC);

    // and wait for the time when the next tick should have come
    // and check it didn't trigger an interrupt
    hal_delay_us(TICK_DELAY);
    CYG_TEST_CHECK(cyg_current_time() == tick, "Timer interrupt while masked");

    // Now change interrupt level, and make the check again. Changing
    // level should not affect interrupt mask state.
    HAL_INTERRUPT_SET_LEVEL(CYGNUM_HAL_INTERRUPT_RTC, 8);
    hal_delay_us(TICK_DELAY);
    CYG_TEST_CHECK(cyg_current_time() == tick, 
                   "Timer interrupt after changing level");

    // Finally unmask the interrupt and make sure it results in ticks.
    HAL_INTERRUPT_UNMASK(CYGNUM_HAL_INTERRUPT_RTC);
    hal_delay_us(TICK_DELAY);
    CYG_TEST_CHECK(cyg_current_time() != tick, 
                   "No timer interrupt after unmask");

    CYG_TEST_PASS_FINISH("SH intr0 test end");
}
示例#23
0
cyg_start( void )
#endif
{
    int loops;
    CYG_TEST_INIT();
    CYG_TEST_INFO( "cyg_user_start()" );
    HAL_ENABLE_INTERRUPTS();
    loops = start();
    // Typically about 1200 loops execute on the 33MHz 86832;
    // I hoped to put in a check that we hadn't wasted time in
    // spurious interrupts, but kernel instrumentation, for example,
    // is more than enough to slow the world down... so keep this
    // very weak test in, as a placeholder.
    CYG_TEST_CHECK( 100 <= loops, "Not enough tests executed" );
    CYG_TEST_EXIT( "All done" );
}
示例#24
0
文件: dns2.c 项目: LucidOne/Rovio
void
dns_test(cyg_addrword_t p)
{
    struct in_addr addr;
    struct hostent *hent;
    char dn[256];

    CYG_TEST_INIT();

    init_all_network_interfaces();

    CYG_TEST_INFO("Starting dns2 test");

    getdomainname(dn,sizeof(dn));
    diag_printf("INFO:<DHCP said domain name is %s>\n",dn);
#ifndef USE_HARDCODED_DOMAIN
    // If not hard-coded we can't tell what it's _meant_ to be
    CYG_TEST_CHECK(!strncmp(dn,_LOOKUP_DOMAINNAME,sizeof(_LOOKUP_DOMAINNAME)),
                   "DHCP got the wrong domainname");
#endif //ifdef _LOOKUP_DOMAINNAME
    
    /* Expect _LOOKUP_IP as the answer. This is a CNAME lookup */
    inet_aton(_LOOKUP_IP, &addr);
    hent = gethostbyname(_LOOKUP_FQDN);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
        if (0 != memcmp((void*)&addr, (void*)(hent->h_addr), sizeof(struct in_addr))) {
          diag_printf("FAIL:<expected " _LOOKUP_FQDN " to be " _LOOKUP_IP ">\n");
        }
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno));
    }

    /* Now just the hostname */
#ifdef USE_HARDCODED_DOMAIN
    // set the domain by hand if required.
    setdomainname(_LOOKUP_DOMAINNAME, sizeof(_LOOKUP_DOMAINNAME));
#endif //ifdef _LOOKUP_DOMAINNAME
    hent = gethostbyname(_LOOKUP_HOSTNAME);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", _LOOKUP_HOSTNAME, inet_ntoa(*(struct in_addr *)hent->h_addr));
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_HOSTNAME ". No answer: %s>\n", hstrerror(h_errno));
    }

    CYG_TEST_FINISH("dns2 test completed");
}
示例#25
0
文件: sigsetjmp.c 项目: 0xCA5A/dd-wrt
void *pthread_entry1( void *arg)
{
    sigset_t mask;

    
    CYG_TEST_INFO( "Thread 1 running" );

    // Make a full set
    sigfillset( &mask );

    // remove USR1 signal
    sigdelset( &mask, SIGUSR1 );

    // Set signal mask
    pthread_sigmask( SIG_SETMASK, &mask, NULL );
    
    // Get main thread going again
    sem_post( &sem );

    do
    {
        sigset_t curmask;

        CYG_TEST_INFO( "Thread1: calling sigsetjmp()");                
        if( sigsetjmp( jmpbuf1, 1 ) != 0 )
            CYG_TEST_INFO( "Thread1: sigsetjmp() returned non-zero");
        
        pthread_sigmask( SIG_SETMASK, NULL, &curmask );
        CYG_TEST_CHECK( curmask == mask, "Thread1: Signal masks not equal" );

        if ( sigusr1_called >= 1 )
            break;
        
        CYG_TEST_INFO( "Thread1: calling pause()");        
        pause();

        CYG_TEST_INFO( "Thread1: pause() returned");        
    } while(1);

    CYG_TEST_INFO( "Thread1: calling pthread_exit()");    
    pthread_exit( arg );
}
示例#26
0
文件: intr.c 项目: KarenHung/ecosgit
void intr_main( void )
{
    CYG_INTERRUPT_STATE oldints;

    cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_RTC, 1,
                             ISR_DATA, isr, dsr, &intr_handle, &intr);
    cyg_drv_interrupt_attach(intr_handle);
    HAL_CLOCK_INITIALIZE( CYGNUM_HAL_RTC_PERIOD );
    cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_RTC);

    HAL_ENABLE_INTERRUPTS();

    while( ticks < 10 )
    {
        
    }


    CYG_TEST_CHECK( dsr_ticks == 10, "DSR not called sufficient times");
    
    HAL_DISABLE_INTERRUPTS(oldints);

    CYG_TEST_PASS_FINISH("HAL interrupt test");
}
示例#27
0
int main( int argc, char **argv )
{
    int err;
    FILE *f;
    fpos_t fpos;
    
    int flibble = 4567;
    char *wibble = "abcdefghijk";

    int flibble1;
    char wibble1[20];
    
    CYG_TEST_INIT();

    
    f = fopen("/foo", "w" );
    if( f == NULL ) SHOW_RESULT( fopen, -1 );

    err = fprintf(f, "flibble %d wibble %s\n", flibble, wibble );
    if( err < 0 ) SHOW_RESULT( fprintf, err );
    
    err = fprintf(f, "another flibble %d another wibble %s\n", flibble, wibble );
    if( err < 0 ) SHOW_RESULT( fprintf, err );
    
    err = fclose( f );
    if( err == EOF ) SHOW_RESULT( fclose, -1 );


    
    f = fopen("/foo", "r" );
    if( f == NULL ) SHOW_RESULT( fopen, -1 );

    err = fscanf(f, "flibble %d wibble %s\n", &flibble1, wibble1 );
    if( err < 0 ) SHOW_RESULT( fscanf, err );

    diag_printf("<INFO>: flibble1 %d wibble1 %s\n",flibble1,wibble1);
    
    CYG_TEST_CHECK( flibble1 == flibble , "Bad flibble result from fscanf");
    CYG_TEST_CHECK( strcmp(wibble,wibble1) == 0, "Bad wibble result from fscanf");


    err = fgetpos( f, &fpos );
    if( err < 0 ) SHOW_RESULT( fgetpos, err );    
    
    err = fseek( f, 0, SEEK_SET );
    if( err < 0 ) SHOW_RESULT( fseek, err );

    err = fscanf(f, "flibble %d wibble %s\n", &flibble1, wibble1 );
    if( err < 0 ) SHOW_RESULT( fscanf, err );

    diag_printf("<INFO>: flibble1 %d wibble1 %s\n",flibble1,wibble1);
    
    CYG_TEST_CHECK( flibble1 == flibble , "Bad flibble result from fscanf");
    CYG_TEST_CHECK( strcmp(wibble,wibble1) == 0, "Bad wibble result from fscanf");


    err = fseek( f, 0, SEEK_END );
    if( err < 0 ) SHOW_RESULT( fseek, err );

    err = fsetpos( f, &fpos );
    if( err < 0 ) SHOW_RESULT( fsetpos, err );    
    
    err = fscanf(f, "another flibble %d another wibble %s\n", &flibble1, wibble1 );
    if( err < 0 ) SHOW_RESULT( fscanf, err );

    diag_printf("<INFO>: flibble1 %d wibble1 %s\n",flibble1,wibble1);
    
    CYG_TEST_CHECK( flibble1 == flibble , "Bad flibble result from fscanf");
    CYG_TEST_CHECK( strcmp(wibble,wibble1) == 0, "Bad wibble result from fscanf");


    
    err = fclose( f );


    
    CYG_TEST_PASS_FINISH("stdio");
    
    return 0;
}
示例#28
0
int main( int argc, char **argv )
{
    void *retval;
    pthread_attr_t attr;
    struct sched_param schedparam;

    CYG_TEST_INIT();

    sa.sin_family = AF_INET;
    sa.sin_len = sizeof(sa);
    inet_aton("127.0.0.1", &sa.sin_addr);
    sa.sin_port = htons(1234);
    init_all_network_interfaces();
    
    // Create test threads

    {
        pthread_attr_init( &attr );

        schedparam.sched_priority = 5;
        pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
        pthread_attr_setschedpolicy( &attr, SCHED_RR );
        pthread_attr_setschedparam( &attr, &schedparam );
        pthread_attr_setstackaddr( &attr, (void *)&thread1_stack[sizeof(thread1_stack)] );
        pthread_attr_setstacksize( &attr, sizeof(thread1_stack) );

        pthread_create( &thread1,
                        &attr,
                        pthread_entry1,
                        (void *)0x12345671);
    }

    {
        pthread_attr_init( &attr );

        schedparam.sched_priority = 10;
        pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
        pthread_attr_setschedpolicy( &attr, SCHED_RR );
        pthread_attr_setschedparam( &attr, &schedparam );
        pthread_attr_setstackaddr( &attr, (void *)&thread2_stack[sizeof(thread2_stack)] );
        pthread_attr_setstacksize( &attr, sizeof(thread2_stack) );

        pthread_create( &thread2,
                        &attr,
                        pthread_entry2,
                        (void *)0x12345672);
    }
    
    // Now join with thread1
    CYG_TEST_INFO( "Main: calling pthread_join(thread1)");
    pthread_join( thread1, &retval );

    // And thread 2
    CYG_TEST_INFO( "Main: calling pthread_join(thread2)");
    pthread_join( thread2, &retval );

    diag_printf("INFO: pselect returns: %d\n", pselect_wakeups );
    diag_printf("INFO: pselect EINTR returns: %d\n", pselect_eintr );
    diag_printf("INFO: SIGUSR1 sent: %d\n", sigusr1_sent );
    diag_printf("INFO: SIGUSR1 delivered: %d\n", sigusr1_calls );
    
    CYG_TEST_CHECK( sigusr1_sent == sigusr1_calls, "SIGUSR1 calls != delivered");
    CYG_TEST_CHECK( sigusr1_sent == pselect_eintr, "SIGUSR1 calls != pselect EINTR wakeups");
    
    CYG_TEST_PASS_FINISH("pselect");
}
示例#29
0
void *pthread_entry1( void *arg)
{
    int fd = 0;
    int err;
    fd_set rd, wr;
    sigset_t mask, oldmask;
    struct sigaction sigact;
    struct timespec ts;
    
    CYG_TEST_INFO( "Thread 1 running" );

    FD_ZERO( &rd );
    FD_ZERO( &wr );

    sigfillset( &mask );
    pthread_sigmask( SIG_SETMASK, &mask, &oldmask );
    
    sigdelset( &mask, SIGUSR1 );

    sigact.sa_mask = mask;
    sigact.sa_flags = SA_SIGINFO;
    sigact.sa_sigaction = sigusr1;

    err = sigaction( SIGUSR1, &sigact, NULL );
    if( err < 0 ) SHOW_RESULT( sigact, err );

    CYG_TEST_INFO( "Thread1: calling socket()");        
    fd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
    if( fd < 0 ) SHOW_RESULT( socket, fd );
    CYG_TEST_CHECK( fd >= 0, "socket() returned error");

    CYG_TEST_INFO( "Thread1: calling bind()");
    err = bind( fd, (struct sockaddr *)&sa, sizeof(sa));
    if( err < 0 ) SHOW_RESULT( bind, err );    
    CYG_TEST_CHECK( err == 0, "bind() returned error");

    CYG_TEST_INFO( "Thread1: calling listen()");
    err = listen( fd, 3);
    if( err < 0 ) SHOW_RESULT( listen, err );    
    CYG_TEST_CHECK( err == 0, "listen() returned error");

    FD_SET( fd, &rd );

    ts.tv_sec = 0;
    ts.tv_nsec = 0;
        
    
    while( running )
    {
        fd_set rd_res = rd;
        fd_set wr_res = wr;

//        ts.tv_nsec = 1000000 * (pselect_wakeups % 10);
        
        err = pselect( 8, &rd_res, &wr_res, NULL, &ts, &mask );
        if( err < 0 )
        {
            if( errno == EINTR ) pselect_eintr++;
            else SHOW_RESULT( pselect, err );
        }
        if( err > 0 ) show_fdsets( "Thread1 result: ", 8, &rd_res, &wr_res, NULL );
        pselect_wakeups++;
        
    }

    // If we were interrupted at just the wrong point above we may still
    // have a SIGUSR1 signal pending that we didn't handle, and so won't
    // have accounted for. So let's look...
    CYG_TEST_CHECK( 0 == sigpending( &mask ), "sigpending() returned error");
    if (1 == sigismember(&mask, SIGUSR1) )
        pselect_eintr++;

    pthread_sigmask( SIG_SETMASK, &oldmask, NULL );

    pthread_exit(arg);
}
示例#30
0
void sigusr1( int sig, siginfo_t *info, void *context )
{
    CYG_TEST_CHECK( pthread_self() == thread1, "Sigusr1: not called by thread 1\n");
    
    sigusr1_calls++;
}