Пример #1
0
int main( int argc, char *argv[] )
{
    char x[300];
    char *ret;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "memset() function");
    CYG_TEST_INFO("This testcase provides simple basic tests");

    // Check 1
    my_strcpy(x, "      ");
    ret = memset(x, 'X', 5);
    if ((my_strcmp(x, "XXXXX ") == 0) && (ret == x))
        CYG_TEST_PASS("Simple memset");
    else
        CYG_TEST_FAIL("Simple memset");

    // Check 2
    my_strcpy(x, "XXXXX ");
    ret = memset(x, 'Y', 0);
    if ((my_strcmp(x, "XXXXX ") == 0) && (ret == x))
        CYG_TEST_PASS("Boundary case of 0 bytes");
    else
        CYG_TEST_FAIL("Boundary case of 0 bytes");

//    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "memset() function");

} // main()
Пример #2
0
// Called when a new connection was accepted.
static err_t
http_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
    struct http_state *hs;

    CYG_TEST_INFO("Incoming connection");

    tcp_setprio(pcb, TCP_PRIO_MIN);

    // Allocate memory for the structure that holds the state of the connection
    hs = mem_malloc(sizeof(struct http_state));
    if (hs == NULL)
        return ERR_MEM;

    // Initialize the structure
    hs->file = NULL;
    hs->left = 0;
    hs->retries = 0;

    // Tell TCP that this is the structure we wish to be passed for our
    // callbacks
    tcp_arg(pcb, hs);

    // Register callbacks
    tcp_recv(pcb, http_recv);
    tcp_err(pcb, http_err);
    tcp_poll(pcb, http_poll, 4);

    CYG_TEST_INFO("Connection accepted");

    return ERR_OK;
}
Пример #3
0
int main( int argc, char *argv[] )
{
    char x[300];
    char y[300];
    char *ret;
    int ctr;
    int fail;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "strncpy() function");
    CYG_TEST_INFO("This testcase tests robustness, and may take some time");

    fail = 0;
    for (ctr = 0; ctr < NUM_ROBUSTNESS_RUNS; ctr++) {
        my_strcpy(x, "Green plastic watering can, ");
        my_strcpy(y, "for her fake Chineese rubber plant");
        ret = strncpy(x, y, my_strlen(y)+1);
        if ( (my_strcmp(x, "for her fake Chineese rubber plant") != 0) ||
             ( ret != x ) )
        {
            fail = 1;
            break;
        } // if
    } // for
    CYG_TEST_PASS_FAIL( (fail == 0), "Robustness test" );

//    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strncpy() function");
} // main()
Пример #4
0
int main( int argc, char **argv )
{
    void *retval;
    pthread_attr_t attr;
    struct sched_param schedparam;

    CYG_TEST_INIT();

#ifdef TEST_NET
    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();
#endif
    
    // Create test threads

    {
        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 *)&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 = 5;
        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 );

    CYG_TEST_PASS_FINISH("select");
}
Пример #5
0
void *pthread_entry2( void *arg)
{
    sigset_t mask;
    
    CYG_TEST_INFO( "Thread 2 running" );

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

    // remove USR2 signal
    sigdelset( &mask, SIGUSR2 );

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

    while( sigusr2_called < 6 )
    {
        CYG_TEST_INFO( "Thread2: calling pause()");        
        pause();
    }

    CYG_TEST_INFO( "Thread2: calling pthread_exit()");    
    pthread_exit( arg );
}
Пример #6
0
void *pthread_entry2( void *arg)
{
    struct timespec zzz;
    int err;
    
    zzz.tv_sec = 0;
    zzz.tv_nsec = 10*1000000;
    
    CYG_TEST_INFO( "Thread 2: running" );

    CYG_TEST_INFO( "Thread 2: sleeping" );
    nanosleep( &zzz, NULL );
    nanosleep( &zzz, NULL );
    nanosleep( &zzz, NULL );
    
    while( sigusr1_sent < NUM_TEST_SIGNALS )
    {
        nanosleep( &zzz, NULL );

        err = pthread_kill( thread1, SIGUSR1 );
        if( err < 0 ) SHOW_RESULT( pthread_kill, err );

        sigusr1_sent++;

        if( (sigusr1_sent % 500) == 0 )
            diag_printf("INFO: <Thread 2: %d signals sent>\n",sigusr1_sent);
    }

    running = false;
        
    CYG_TEST_INFO( "Thread 2: exit" );
    pthread_exit( arg );
}
Пример #7
0
static void
handle_req_state(void)
{
    switch (req_state) {
    case REQ_DNS_INIT:
        CYG_TEST_INFO("Trying to resolve host name");
        if (dns_gethostbyname(CYGDAT_NET_LWIP_PPP_TEST_HOST, &host_addr,
                              dns_found_cb, NULL) == ERR_OK) {
            // Cached
            req_state = REQ_DNS_SUCCESS;
            break;
        }
        req_state = REQ_DNS_WAIT;
        break;
    case REQ_DNS_WAIT:
        break;
    case REQ_DNS_FAILED:
        CYG_TEST_INFO("Failed to resolve host name");
        test_state = TEST_PPP_CLOSE;
        break;
    case REQ_DNS_SUCCESS:
        CYG_TEST_INFO("Successfully resolved host name");
        success++;
        test_state = TEST_PPP_CLOSE;
        break;
    }
}
Пример #8
0
void fptest_main( void )
{
    
    CYG_TEST_INIT();

    if( cyg_test_is_simulator )
    {
        run_ticks = RUN_TICKS_SIM;
    }

    CYG_TEST_INFO("Run fptest in cyg_start");
    do_test( fpt3_values, FP3_COUNT, 1000, 0, "start" );
    CYG_TEST_INFO( "cyg_start run done");
    
    cyg_thread_create( BASE_PRI-1,
                       fptest1,
                       0,
                       "fptest1",
                       &stacks[0][0],
                       STACK_SIZE,
                       &thread[0],
                       &thread_struct[0]);

    cyg_thread_resume( thread[0] );

    cyg_thread_create( BASE_PRI,
                       fptest2,
                       1,
                       "fptest2",
                       &stacks[1][0],
                       STACK_SIZE,
                       &thread[1],
                       &thread_struct[1]);

    cyg_thread_resume( thread[1] );

    cyg_thread_create( BASE_PRI,
                       fptest3,
                       2,
                       "fptest3",
                       &stacks[2][0],
                       STACK_SIZE,
                       &thread[2],
                       &thread_struct[2]);

    cyg_thread_resume( thread[2] );

    cyg_alarm_create( cyg_real_time_clock(),
                      alarm_fn,
                      0,
                      &alarm,
                      &alarm_struct );

    cyg_alarm_initialize( alarm, cyg_current_time()+1, 1 );
    
    cyg_scheduler_start();

}
Пример #9
0
void cyg_user_start(void)
#endif
{
    char x[300];
    char y[300];

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "strcmp() function");
    CYG_TEST_INFO("This testcase provides simple basic tests");

    // Check 1
    my_strcpy(x, "I have become, comfortably numb");
    my_strcpy(y, "I have become, comfortably numb");
    CYG_TEST_PASS_FAIL( (strcmp(x, y) == 0), "Simple compare");


    // Check 2
    my_strcpy(x, "");
    my_strcpy(y, "");
    CYG_TEST_PASS_FAIL( (strcmp(x, y) == 0), "Simple empty string compare");


    // Check 3
    my_strcpy(x, "..shall snuff it. And the Lord did grin");
    my_strcpy(y, "..shall snuff it. And the Lord did grio");
    CYG_TEST_PASS_FAIL( (strcmp(x, y) < 0),
                        "Memory less than #1" );


    // Check 4
    my_strcpy(x, "A reading from the Book of Armaments, Chapter 4, "
              "Verses 16 to 20:");
    my_strcpy(y, "Bless this, O Lord, that with it thou mayst blow thine "
              "enemies to tiny bits, in thy mercy.");
    CYG_TEST_PASS_FAIL( (strcmp(x, y) < 0),
                        "Memory less than #2");

    // Check 5
    my_strcpy(x, "Lobeth this thy holy hand grenade at thy foe");
    my_strcpy(y, "Lobeth this thy holy hand grenade at thy fod");
    CYG_TEST_PASS_FAIL( (strcmp(x, y) > 0),
                        "Memory greater than #1" );


    // Check 6
    my_strcpy(y, "Three shall be the number of the counting and the");
    my_strcpy(x, "number of the counting shall be three");
    CYG_TEST_PASS_FAIL( (strcmp(x, y) > 0),
                        "Memory greater than #2" );

//    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strcmp() function");
} // main()
Пример #10
0
void cyg_user_start(void)
#endif
{
    char x[300];
    char y[300];
    char *ret;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "strcat() function");
    CYG_TEST_INFO("This testcase provides simple basic tests");

    // Check 1
    my_strcpy(x, "One ring to rule them all.");
    my_strcpy(y, "One ring to find them.");
    ret = strcat(x, y);
    if ( my_strcmp(x, "One ring to rule them all.One ring to find them.")==0 ) 
        CYG_TEST_PASS("Simple concatenation");
    else 
        CYG_TEST_FAIL("Simple concatenation");
    // Check return val
    CYG_TEST_PASS_FAIL( ( ret == x ), "Simple concatenation return value" );


    // Check 2
    my_strcpy(x, "One ring to bring them all,");
    my_strcpy(y, "");
    ret = strcat(x, y);
    if ( my_strcmp(x, "One ring to bring them all,")==0 ) 
        CYG_TEST_PASS("Concatenation of empty string");
    else 
        CYG_TEST_FAIL("Concatenation of empty string");
    // Check return val
    CYG_TEST_PASS_FAIL( ( ret == x ),
                        "Concatenation of empty string return value" );


    // Check 3
    my_strcpy(x, "and in the darkness bind them");
    my_strcpy(y, "");
    ret = strcat(y, x);
    if ( my_strcmp(x, "and in the darkness bind them")==0 ) 
        CYG_TEST_PASS("Concatenation to empty string");
    else 
        CYG_TEST_FAIL("Concatenation to empty string");
    // Check return val
    CYG_TEST_PASS_FAIL( ( ret == y ),
                        "Concatenation to empty string return value" );

//    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strcat() function");
} // main()
Пример #11
0
void cyg_user_start(void)
#endif
{
    char x[300];
    char y[300];
    void *ret, *ptr1, *ptr2;
    char *c_ret;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "memcpy() function");
    CYG_TEST_INFO("This testcase provides simple basic tests");

    // Check 1
    ptr1 = x; 
    ptr2 = y;
    my_strcpy(x, "Great shot kid! That was one in a million!");
    ret = memcpy(ptr2, ptr1, my_strlen(x) + 1);
    CYG_TEST_PASS_FAIL( (my_strcmp(x, ptr2)==0), "Simple copy" );

    // Check return value
    CYG_TEST_PASS_FAIL( (my_strcmp(ret, ptr2)==0), "Simple copy return value");


    // Check 2
    ptr1 = x; 
    ptr2 = y;
    my_strcpy(x, "");
    my_strcpy(y, "xxxx"); // Bogus val to get overwritten
    ret = memcpy(ptr2, ptr1, 1);
    c_ret = ret;
    if ((*c_ret == '\0') && (y[0] == '\0') && (y[1] == 'x'))
        CYG_TEST_PASS("Simple copy with boundary check worked");
    else
        CYG_TEST_FAIL("Simple copy with boundary check failed");

    // Check 3
    ptr1 = x; 
    ptr2 = y;
    my_strcpy(x, "xxxx");
    my_strcpy(y, "yyyy");
    ret = memcpy(ptr1, ptr2, 0);
    c_ret = ret;
    if ((*c_ret =='x') && (x[0] == 'x'))
        CYG_TEST_PASS("Simple copy with size=0 worked");
    else
        CYG_TEST_FAIL("Simple copy with size=0 failed");

//    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "memcpy() function");
} // main()
Пример #12
0
void
serial_test( void )
{
    cyg_io_handle_t ser_handle;
    cyg_ser_cfg_t *cfg=&test_configs[0];
    cyg_ser_cfg_t new_cfg;
    int count = sizeof(test_configs) / sizeof(cyg_ser_cfg_t);
    int i;

    test_open_ser(&ser_handle);

    // We need the filter for this test.
    test_ping(ser_handle);

    // Choose the configuration with the fastest baud rate, to be most
    // provocative. Start at 1 coz cfg already points at 0
    for (i=1; i<count; i++) {
        if (cfg->baud_rate < test_configs[i].baud_rate)
            cfg=&test_configs[i];
    }

    // Set flow control from configuration
    // Choose software first

#ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_SOFTWARE
    CYG_TEST_INFO("Setting software flow control");

    new_cfg = *cfg;
    new_cfg.flags |= CYGNUM_SERIAL_FLOW_XONXOFF_RX |
                     CYGNUM_SERIAL_FLOW_XONXOFF_TX;
    if (ENOERR == change_config(ser_handle, &new_cfg))
        run_tests( ser_handle );
#endif

    // hardware flow control
#ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_HW
    CYG_TEST_INFO("Setting RTS/CTS hardware flow control");

    new_cfg = *cfg;
    new_cfg.flags |= CYGNUM_SERIAL_FLOW_RTSCTS_RX|CYGNUM_SERIAL_FLOW_RTSCTS_TX;
    if (ENOERR == change_config(ser_handle, &new_cfg))
        run_tests( ser_handle );

    CYG_TEST_INFO("Setting DSR/DTR hardware flow control");

    new_cfg = *cfg;
    new_cfg.flags |= CYGNUM_SERIAL_FLOW_DSRDTR_RX|CYGNUM_SERIAL_FLOW_DSRDTR_TX;
    if (ENOERR == change_config(ser_handle, &new_cfg))
        run_tests( ser_handle );
#endif
 
    CYG_TEST_PASS_FINISH("flow2 test OK");
}
Пример #13
0
void
net_test(cyg_addrword_t param)
{
    cyg_serial_baud_rate_t old;    
    cyg_ppp_options_t options;
    cyg_ppp_handle_t ppp_handle;

    CYG_TEST_INIT();
    
    diag_printf("Start TCP test - ECHO mode\n");
    init_all_network_interfaces();
    calibrate_load(DESIRED_BACKGROUND_LOAD);
#ifdef CYGPKG_SNMPAGENT
    {
        extern void cyg_net_snmp_init(void);
        cyg_net_snmp_init();
    }
#endif

    old = ppp_test_set_baud( CYGNUM_SERIAL_BAUD_115200 );

    ppp_test_announce( "TCP_ECHO" );
    
    cyg_ppp_options_init( &options );

//    options.debug = 1;
//    options.kdebugflag = 1;
//    options.flowctl = CYG_PPP_FLOWCTL_SOFTWARE;

    ppp_handle = cyg_ppp_up( CYGPKG_PPP_TEST_DEVICE, &options );

    CYG_TEST_INFO( "Waiting for PPP to come up");
    
    cyg_ppp_wait_up( ppp_handle );

    echo_test(param);

    CYG_TEST_INFO( "Bringing PPP down");

    cyg_ppp_down( ppp_handle );
    
    CYG_TEST_INFO( "Waiting for PPP to go down");

    cyg_ppp_wait_down( ppp_handle );

    cyg_thread_delay( 200 );
    
    ppp_test_set_baud( old );

    ppp_test_finish();
    
    CYG_TEST_PASS_FINISH("TCP ECHO test OK");
}
Пример #14
0
void cyg_user_start(void)
#endif
{
    char x[300];
    char y[300];
    char *ret;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "strstr() function");
    CYG_TEST_INFO("This testcase provides simple basic tests");

    // Check 1
    my_strcpy(x, "I will not have my fwends widiculed by the common soldiewy");
    my_strcpy(y, "fwends");
    ret = strstr(x, y);
    CYG_TEST_PASS_FAIL( (ret == &x[19]), "Simple strstr()" );


    // Check 2 (boundary condition)
    my_strcpy(x, "Not bad for a little fur ball. You! Stay here.");
    my_strcpy(y, "ball ");
    ret = strstr(x, y);
    CYG_TEST_PASS_FAIL( (ret == NULL), "String to search for not present" );


    // Check 3 (boundary condition)
    my_strcpy(x, "");
    my_strcpy(y, "zx");
    ret = strstr(x, y);
    CYG_TEST_PASS_FAIL( (ret == NULL), "Empty string to search" );


    // Check 4 (boundary condition)
    my_strcpy(x, "fdafdafdfahjgf");
    my_strcpy(y, "");
    ret = strstr(x, y);
    CYG_TEST_PASS_FAIL( (ret == x), "Empty search string" );

    // Check 5 (boundary condition)
    my_strcpy(x, "");
    my_strcpy(y, "");
    ret = strstr(x, y);
    CYG_TEST_PASS_FAIL( (ret == x), "Both strings empty" );

//    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strstr() function");

} // main()
Пример #15
0
int
main(int argc, char *argv[])
{
    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C "
                  "library snprintf() function return values");
    CYG_TEST_INFO("These test return values of snprinf() family of functions");

    test(0);

    return 0;
} // main()
Пример #16
0
int
main(int argc, char *argv[])
{
    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "sprintf() function");
    CYG_TEST_INFO("These test individual features separately");

    test(0);

    return 0;
} // main()
Пример #17
0
int
main(int argc, char *argv[])
{
    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C "
                  "library sprintf() function");
    CYG_TEST_INFO("These test combinations of sprintf() features");

    test(0);

    return 0;
} // main()
Пример #18
0
int
main(int argc, char *argv[])
{
    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "strtok() function");
    CYG_TEST_INFO("This testcase provides simple basic tests");

    test(0);

    CYG_TEST_NA("Testing is not applicable to this configuration");
} // main()
Пример #19
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++;

    CYG_TEST_INFO( "sigusr2() handler calling siglongjmp()" );
    siglongjmp( jmpbuf2, sigusr2_called );    
}
Пример #20
0
int main( int argc, char *argv[] )
{
    char x[300];
    char y[300];
    int  ret;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "strxfrm() function");
    CYG_TEST_INFO("This testcase provides simple basic tests");

    // Check 1
    my_strcpy(x, "Nine rings for men doomed to die");
    ret = strxfrm(y, x, my_strlen(x)+1);
    if (my_strcmp(x, y) == 0)
        CYG_TEST_PASS("Simple strxfrm()");
    else
        CYG_TEST_FAIL("Simple strxfrm()");
    // Check return value
    CYG_TEST_PASS_FAIL( (my_strlen(x) == ret),
                        "Simple strxfrm() return value");

    // Check 2
    x[0] = '\0';
    my_strcpy(y, "Seven rings for the dwarves in their halls of stone");
    ret = strxfrm(y, x, my_strlen(x)+1);
    if (my_strcmp(y, "") == 0)
        CYG_TEST_PASS("strxfrm() of empty string");
    else
        CYG_TEST_FAIL("strxfrm() of empty string");
    // Check return value
    CYG_TEST_PASS_FAIL( (my_strlen(x) == ret),
                        "strxfrm() of empty string return value");

    // Check 3
    my_strcpy(y, "Seven rings for the dwarves in their halls of stone");
    ret = strxfrm(NULL, y, 0);

    // Check return value
    CYG_TEST_PASS_FAIL( (my_strlen(y) == ret),
                        "strxfrm() of NULL string for 0 bytes return value");

//    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strxfrm() function");
} // main()
Пример #21
0
int
main( int argc, char *argv[] )
{
    char x[300];
    char y[300];
    char *ret;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "strncpy() function");
    CYG_TEST_INFO("This testcase provides simple basic tests");

    // Check 1
    my_strcpy(x, "Nine rings for men doomed to die");
    ret = strncpy(y, "Nine rings for men doomed to die", my_strlen(x));
    CYG_TEST_PASS_FAIL( (my_strncmp(x, y, my_strlen(x)) == 0),
                        "Simple copy" );
    // Check return value
    CYG_TEST_PASS_FAIL( (y == ret), "Simple copy return value" );


    // Check 2
    my_strcpy(x, "");
    my_strcpy(y, "Seven rings for the dwarves in their halls of stone");
    ret = strncpy(y, x, 1);
    CYG_TEST_PASS_FAIL( (my_strcmp(y, "") == 0), "Copy empty string" );
    // Check return value
    CYG_TEST_PASS_FAIL( (y == ret), "Copy empty string return value" );

    // Check 3
    my_strcpy(x, "");
    my_strcpy(y, "Seven rings for the dwarves in their halls of stone");
    ret = strncpy(y, x, 0);
    if (my_strcmp(y, "Seven rings for the dwarves "
                     "in their halls of stone") == 0)
        CYG_TEST_PASS("Copy 0 characters");
    else
        CYG_TEST_FAIL("Copy 0 characters");
    // Check return value
    CYG_TEST_PASS_FAIL( (y == ret), "Copy empty string return value" );

//    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strncpy() function");

} // main()
Пример #22
0
static void
myhandler2(int signal)
{
    CYG_TEST_INFO("myhandler2 called");
    ++state;
    longjmp(jbuf, 1);
} // myhandler2()
Пример #23
0
int
main( int argc, char *argv[] )
{
    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C "
                  "library atexit() function");

#if defined(CYGFUN_LIBC_ATEXIT)

    // we only have one test in us! We can only exit once :-)

    CYG_TEST_PASS_FAIL( atexit(&myfun3)==0, 
                        "Simple registration of first atexit() function" );

    CYG_TEST_PASS_FAIL( atexit(&myfun2)==0, 
                       "Simple registration of second atexit() function" );

    CYG_TEST_PASS_FAIL( atexit(&myfun1)==0, 
                        "Simple registration of third atexit() function" );

    return 0;
#else
    CYG_TEST_NA("Testing is not applicable to this configuration");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C "
                    "library atexit() function");

#endif // if defined(CYGFUN_LIBC_ATEXIT)

} // main()
Пример #24
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();
}
Пример #25
0
static void sigusr1( int signo )
{
    CYG_TEST_INFO( "sigusr1() handler called" );
    CYG_TEST_CHECK( signo == SIGUSR1, "Signal not SIGUSR1");

    sigusr1_called++;
}
Пример #26
0
void sparc_ex_main( void )
{
    int i;

    CYG_TEST_INIT();

    for ( i = CYGNUM_HAL_EXCEPTION_MIN; i <= CYGNUM_HAL_EXCEPTION_MAX; i++ ){
        int j;
        HAL_TRANSLATE_VECTOR( i, j );
        HAL_INTERRUPT_ATTACH( j, &fail_exception_handler, j, 0 );
        // we must also ensure that eCos handles the exception;
        // do not drop into CygMon or equivalent.
        // Leave USER_TRAP undisturbed so that breakpoints work.
        if ( CYGNUM_HAL_VECTOR_USER_TRAP != i ) {
            extern void hal_default_exception_vsr( void );
            HAL_VSR_SET( i, (CYG_ADDRESS)hal_default_exception_vsr, NULL );
        }
    }

    HAL_TRANSLATE_VECTOR( CYGNUM_HAL_VECTOR_UNALIGNED, i );
    HAL_INTERRUPT_DETACH( i, &fail_exception_handler );
    HAL_INTERRUPT_ATTACH( i, &skip_exception_handler, i, 0 );

    CYG_TEST_INFO( "Vectors attached OK; calling do_test" );

    do_test();

    CYG_TEST_EXIT( "Done" );
}
Пример #27
0
externC void
cyg_package_start( void )
{
    CYG_TEST_INIT();
    CYG_TEST_INFO( "Calling cyg_uitron_start()" );
    cyg_uitron_start();
}
Пример #28
0
externC void
cyg_start( void )
{
    CYG_TEST_INIT();

    CYG_TEST_INFO("Calculating CRCs");

    if (1500790746l != cyg_posix_crc32(license_txt,sizeof(license_txt)-1)) {
        CYG_TEST_FAIL("Wrong POSIX CRC32 calculation");
    } else {
        CYG_TEST_PASS("POSIX CRC32 calculation");
    }

    if (1247800780 != cyg_crc32(license_txt,sizeof(license_txt)-1)) {
        CYG_TEST_FAIL("Wrong Gary S. Browns' crc32 calculation");
    } else {
        CYG_TEST_PASS("Gary S. Browns' crc32 calculation");
    }

    if (32256 != cyg_crc16(license_txt,sizeof(license_txt)-1)) {
        CYG_TEST_FAIL_FINISH("Wrong 16bit CRC calculation");
    } else {
        CYG_TEST_PASS_FINISH("16bit CRC calculation");
    }
}
Пример #29
0
void
chat_test(cyg_addrword_t p)
{
    cyg_serial_baud_rate_t old;
    cyg_int32 failures = 0;
    cyg_int32 result;
    struct test_info *test;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Start CHAT test");

    old = ppp_test_set_baud( CYGNUM_SERIAL_BAUD_115200 );

    for( test = &tests[0]; test->name != NULL; test++ )
    {
        CYG_TEST_INFO( test->name );
        ppp_test_announce( test->name );

        result = cyg_ppp_chat( CYGPKG_PPP_TEST_DEVICE, test->script );

        diag_printf("chat result %d expected %d\n",result,test->result );

        if( result != test->result )
        {
            CYG_TEST_FAIL( test->name );
            failures++;
        }
        else
            CYG_TEST_PASS( test->name );

        cyg_thread_delay( 300 );
    }

    ppp_test_set_baud( old );

    ppp_test_finish();

//    ppp_test_announce( "CHAT_TEST_1" );

//    success = cyg_ppp_chat( CYGPKG_PPP_TEST_DEVICE, script );

//    if( !success )
//        CYG_TEST_INFO("Chat script failed");

    CYG_TEST_FINISH("CHAT test done");
}
Пример #30
0
int
main( int argc, char *argv[] )
{
    int num, denom;
    div_t result;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "div() function");

    num = 10232;
    denom = 43;
    result = div(num, denom);
    CYG_TEST_PASS_FAIL( (result.quot==237) && (result.rem==41),
                        "div( 10232, 43 )");

    num = 4232;
    denom = 2000;
    result = div(num, denom);
    CYG_TEST_PASS_FAIL( (result.quot==2) && (result.rem==232),
                        "div( 4232, 2000 )");


    num = 20;
    denom = 20;
    result = div(num, denom);
    CYG_TEST_PASS_FAIL( (result.quot==1) && (result.rem==0),
                        "div( 20, 20 )");

    num = -5;
    denom = 4;
    result = div(num, denom);
    CYG_TEST_PASS_FAIL( (result.quot==-1) && (result.rem==-1),
                        "div( -5, 4 )");

    num = 5;
    denom = -4;
    result = div(num, denom);
    CYG_TEST_PASS_FAIL( (result.quot==-1) && (result.rem==1),
                        "div( 5, -4 )");

    num = -5;
    denom = -3;
    result = div(num, denom);
    CYG_TEST_PASS_FAIL( (result.quot==1) && (result.rem==-2),
                        "div( -5, -3 )");

    num = -7;
    denom = -7;
    result = div(num, denom);
    CYG_TEST_PASS_FAIL( (result.quot==1) && (result.rem==0),
                        "div( -7, -7 )");


    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "div() function");

} // main()