Exemplo n.º 1
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");
}
Exemplo n.º 2
0
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");
}
Exemplo n.º 3
0
static void
test( CYG_ADDRWORD data )
{
    time_t t;
    char *ret;
    
    // make this predictable - independent of the user option
    cyg_libc_time_setzoneoffsets(0, 3600);
    cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF );

    t = (time_t)130710184;

    ret = ctime(&t);
    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Thu Feb 21 20:23:04 1974\n"),
                       "ctime test #1");

    t = (time_t)946689894;

    ret = ctime(&t);
    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Sat Jan 01 01:24:54 2000\n"),
                       "ctime Y2K test #2");

    cyg_libc_time_setdst( CYG_LIBC_TIME_DSTON );

    t = (time_t)-113186106;

    ret = ctime(&t);
    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Tue Jun 01 00:24:54 1966\n"),
                       "ctime test #3");

#ifdef CYGFUN_LIBC_TIME_POSIX
    cyg_libc_time_setdst( CYG_LIBC_TIME_DSTOFF );

    t = (time_t)915510061;
    
    {
        char ret2[26];

        ret = ctime_r(&t, ret2);
        CYG_TEST_PASS_FAIL(!my_strcmp(ret2, "Tue Jan 05 04:21:01 1999\n"),
                           "ctime_r test #1");
    }
#endif

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "ctime() function");
} // test()
Exemplo n.º 4
0
int
main(int argc, char *argv[])
{
#if TEST_VALID
    int i;
    int r, prev, prevprev;
    int how_many_periodics = 0;
#endif

    CYG_TEST_INIT();

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

    CYG_TEST_INFO("This test tests the distribution of random numbers and");
    CYG_TEST_INFO("may take some time");

#if TEST_VALID
    r = rand() % 2;
    prev = r;
    r = rand() % 2;
    for (i = 0; i < TEST_LENGTH; ++i) {
      prevprev = prev;
      prev = r;
      r = rand() % 2;
      if (r == prevprev) {
        ++how_many_periodics;
      }
      if (how_many_periodics > (2*TEST_LENGTH)/3) {
        break;
      }
    }

    CYG_TEST_PASS_FAIL( (how_many_periodics <= (2*TEST_LENGTH)/3),
                        "periodicity of rand() in lowest bit");

#else
    
    // TODO: should be an _expected_ fail i.e. XFAIL
    CYG_TEST_NA("Chosen rand algorithm is known to fail this test");
    
#endif

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for "
                    "C library rand() function");
} // main()
Exemplo n.º 5
0
static void
test( CYG_ADDRWORD data )
{
    int ctr;
    static int array_1[TEST_SIZE];
    static int array_2[TEST_SIZE];
    static int array_3[TEST_SIZE];
    int hits;
    int fail;


    srand(3);
    for (ctr=0; ctr<TEST_SIZE; ++ctr)
        array_1[ctr] = rand();

    srand(9);
    for (ctr=0; ctr<TEST_SIZE; ++ctr)
        array_2[ctr] = rand();

    srand(3);
    for (ctr=0; ctr<TEST_SIZE; ++ctr)
        array_3[ctr] = rand();

    // Make sure arrays 1 and 3 are the same
    fail = 0;
    for (ctr=0; ctr<TEST_SIZE; ++ctr) {
        if (array_1[ctr] != array_3[ctr])
            ++fail;
    } // for

    CYG_TEST_PASS_FAIL( fail == 0, "resetting the seed to the same value");

    // Check sequences of different seeds are different
    hits = 0;
    for (ctr=0; ctr<TEST_SIZE; ++ctr) {
        if (array_1[ctr] == array_2[ctr])
            ++hits;
    } // for

    CYG_TEST_PASS_FAIL(hits < X_CORREL,
                       "random sequence for different seeds is different");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for "
                    "C library srand() function");
} // test()
Exemplo n.º 6
0
int
main( int argc, char *argv[] )
#endif
{
    int x;

    CYG_TEST_INIT();

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

    // Check 1
    x = 5;
    CYG_TEST_PASS_FAIL( abs(x) == 5, "abs(5)");

    // Check 2
    x = -5;
    CYG_TEST_PASS_FAIL( abs(x) == 5, "abs(-5)");
    
    // Check 3
    x = 12345;
    CYG_TEST_PASS_FAIL( abs(x) == 12345, "abs(12345)");

    // Check 4
    x = -23456;
    CYG_TEST_PASS_FAIL( abs(x) == 23456, "abs(-23456");

    // Check 5
    x = 0;
    CYG_TEST_PASS_FAIL( abs(x) == 0, "abs(0)");

    // Check 6
    x = INT_MAX;
    CYG_TEST_PASS_FAIL( abs(x) == INT_MAX, "abs(INT_MAX)");

    // Check 7
    x = -INT_MAX;
    CYG_TEST_PASS_FAIL( abs(x) == INT_MAX, "abs(-INT_MAX)");

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

} // main()
Exemplo n.º 7
0
static void
test( CYG_ADDRWORD data )
{
    static char x[32];
    static char y[4];
    int xret;
    int yret;
    int xstrlen;
    int ystrlen;

    // fill buffer to ensure that there are no zeros in the buffers
    memset(x, 0xFF, sizeof(x));
    memset(y, 0xFF, sizeof(y));
    
    // print into a buffer with sufficient size 
    xret = snprintf(x, sizeof(x), "%d:%d:%d:%d", 1, 2, 3, 4);
    xstrlen = my_strnlen(x, sizeof(x));
    
    // print into a buffer that is too small
    yret = snprintf(y, sizeof(y), "%d:%d:%d:%d", 1, 2, 3, 4);
    ystrlen = my_strnlen(y, sizeof(y));
    
    CYG_TEST_PASS_FAIL(xret == xstrlen, "[buffer > strlen] return code");
    
#ifdef CYGIMP_LIBC_STDIO_C99_SNPRINTF
    // C99 compliant implementation returns the number of characters that 
    // would have been written had size been sufficiently large, 
    // not counting the terminating nul character
    CYG_TEST_PASS_FAIL(xret == yret, "[buffer < strlen] return code");
    CYG_TEST_INFO("C99 compliant implementation of snprintf()");
#else
    // default eCos implementation returns number of bytes written into
    // the buffer without terminating nul character
    CYG_TEST_PASS_FAIL(yret == ystrlen, "[buffer < strlen] return code");
    CYG_TEST_INFO("Default implementation of snprintf() (no C99 compliance)");
#endif


    CYG_TEST_FINISH("Finished tests from testcase " __FILE__
                    " for C library snprintf() function return values");

} // test()
Exemplo n.º 8
0
void cyg_user_start(void)
#endif
{
    char x[300];
    char y[300];
    char z[300];
    int ctr;
    int fail;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "strcmp() 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, "Spare a talent for an old ex-leper");
        my_strcpy(y, "Spare a talent for an old ex-leper");
        my_strcpy(z, "I was hopping along, when suddenly he");

        if (strcmp(x, y) != 0)
        {
            fail = 1;
            break;
        }
        if (strcmp(x, z) == 0)
        {
            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 "
                    "strcmp() function");
} // main()
Exemplo n.º 9
0
static void
test( CYG_ADDRWORD data )
{
    struct tm tm1;
    char s[1000], *sp, *dp, *fp;
    size_t size;
    
    dp = "Fri Jan 24 08:33:14 2003";
    fp = "%a %b %d %H:%M:%S %Y";
    sp = strptime(dp, fp, &tm1);
    
    // Set an invalid year day. The following converters don't use
    // this, so it should not cause a problem.
    tm1.tm_yday = 1000;

    CYG_TEST_PASS_FAIL(((sp!=NULL) && (*sp=='\0')), "strptime test #1");
    size = strftime(s, sizeof(s), fp, &tm1);
    CYG_TEST_PASS_FAIL(((size==strlen(dp)) && (my_strcmp(s, dp) == 0)), "strptime test #2");
    
    dp = "Friday January 24 08:33:14 2003";
    fp = "%A %B %d %H:%M:%S %Y";
    sp = strptime(dp, fp, &tm1);    
    CYG_TEST_PASS_FAIL(((sp!=NULL) && (*sp=='\0')), "strptime test #3");
    size = strftime(s, sizeof(s), fp, &tm1);
    CYG_TEST_PASS_FAIL(((size==strlen(dp)) && (my_strcmp(s, dp) == 0)), "strptime test #4");

    dp = "2006:06:13 12:22:01";
    fp = "%x %X";
    sp = strptime(dp, fp, &tm1);    
    CYG_TEST_PASS_FAIL(((sp!=NULL) && (*sp=='\0')), "strptime test #5");
    CYG_TEST_PASS_FAIL((tm1.tm_sec == 01) &&
                       (tm1.tm_min == 22) &&
                       (tm1.tm_hour == 12) &&
                       (tm1.tm_mday == 13) &&
                       (tm1.tm_mon ==  (06 - 1)) &&
                       (tm1.tm_year == (2006 - 1900)), "strptime test #6");
    size = strftime(s, sizeof(s), fp, &tm1);
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strptime() function");
} // test()
Exemplo n.º 10
0
static void
test( CYG_ADDRWORD data )
{
    cyg_ucount32 vec_size;
    cyg_bool ret;

    vec_size = sizeof(pow_vec) / sizeof(Cyg_libm_test_double_vec_t);
    ret = doTestVec( (CYG_ADDRWORD) &pow, CYG_LIBM_TEST_VEC_DOUBLE,
                     CYG_LIBM_TEST_VEC_DOUBLE,
                     CYG_LIBM_TEST_VEC_DOUBLE,
                     &pow_vec[0], vec_size );

    if (ret==true) {
        CYG_TEST_PASS("pow() is stable");
    } // if
    else {
        CYG_TEST_FAIL("pow() failed tests");
    } // else

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for Math "
                    "library pow() function");
} // test()
Exemplo n.º 11
0
static void
test( CYG_ADDRWORD data )
{
    int ctr;
    static int array[1024];
    int hits=0;

    for (ctr=0; ctr<1024; ctr++)
        array[ctr] = rand();

    for (ctr=0; ctr< 1021; ctr++)
        if ((array[ctr]==array[ctr+1]) ||
            (array[ctr]==array[ctr+2]) ||
            (array[ctr]==array[ctr+3]))
            hits++;
    
    CYG_TEST_PASS_FAIL(hits <= TOLERANCE,
                       "Simple test for rand() repetition");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for "
                    "C library rand() function");
} // test()
Exemplo n.º 12
0
static void alarm_fn(cyg_handle_t alarm, cyg_addrword_t data)
{
    alarm_ticks++;

    if( alarm_ticks >= run_ticks )
    {
        if( errors )
            CYG_TEST_FAIL("Errors detected");
        else
            CYG_TEST_PASS("OK");            
        
        CYG_TEST_FINISH("FP Test done");
    }
    else
    {
        cyg_thread_set_priority( thread[cur_thread], BASE_PRI );

        cur_thread = (cur_thread+1)%3;

        cyg_thread_set_priority( thread[cur_thread], BASE_PRI-1 );
    }
}
Exemplo n.º 13
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 "
                  "strcat() 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, "in the land of Mordor, ");
        my_strcpy(y, "where the shadows lie.");
        ret = strcat(x, y);
        if ((my_strcmp(x, "in the land of Mordor, where the shadows lie.")!=0))
        {
            fail = 1;
            break;
        } // if
        if (ret != x)
        {
            fail = 1;
            break;
        } // if
    }
    CYG_TEST_PASS_FAIL( (fail == 0), "Robustness test passed" );

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

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

} // main()
Exemplo n.º 14
0
int main( int argc, char *argv[] )
{
    char x[300];
    char y[300];
    char z[300];
    int ctr;
    int fail;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "strcoll() 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, "Spare a talent for an old ex-leper");
        my_strcpy(y, "Spare a talent for an old ex-leper");
        my_strcpy(z, "I was hopping along, when suddenly he");

        if (strcoll(x, y) != 0)
        {
            fail = 1;
            break;
        }
        if (strcoll(x, z) == 0)
        {
            fail = 1;
            break;
        } // if
    } // for

    CYG_TEST_PASS_FAIL( (fail==0), "Robustness test");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strcoll() function");
} // main()
Exemplo n.º 15
0
static void
test( CYG_ADDRWORD data )
{
    cyg_ucount32 vec_size;
    cyg_bool ret;

    vec_size = sizeof(expm1f_vec) / sizeof(Cyg_libm_test_float_vec_t);
    ret = doTestVecFloat( (CYG_ADDRWORD) &expm1f, CYG_LIBM_TEST_VEC_FLOAT,
                     CYG_LIBM_TEST_VEC_NONE, CYG_LIBM_TEST_VEC_FLOAT,
                     &expm1f_vec[0], vec_size );

    if (ret==true)
    {
        CYG_TEST_PASS("expm1f() is stable");
    } // if
    else
    {
        CYG_TEST_FAIL("expm1f() failed tests");
    } // else

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for Math "
                    "library expm1f() function");
} // test()
Exemplo n.º 16
0
int main( int argc, char *argv[] )
{
    char x[300];
    char y[300];
    void *ret, *ptr1, *ptr2;
    char *c_ret;
    int ctr;
    int fail;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "memcpy() 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, "in the land of Mordor");
        my_strcpy(y, "                     ");
        ptr1 = x; 
        ptr2 = y;
        ret = memcpy(ptr2, ptr1, my_strlen(x) + 1);
        c_ret = ret;
        if ((my_strcmp(y, x) != 0) || (my_strcmp(c_ret, x)!=0)) {
            fail = 1;
            break;
        }
    }

    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 "
                    "memcpy() function");
} // main()
Exemplo n.º 17
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()
Exemplo n.º 18
0
static void
test( CYG_ADDRWORD data )
{
    struct tm tm1, tm2;
    time_t t;
    
    // make this predictable - independent of the user option
    cyg_libc_time_setzoneoffsets(0, 3600);

    tm1.tm_sec = 4;
    tm1.tm_min = 23;
    tm1.tm_hour = 20;
    tm1.tm_mday = 21;
    tm1.tm_mon = 1;
    tm1.tm_year = 74;
    tm1.tm_isdst = 0;

    tm2 = tm1;
    tm2.tm_wday = 4;
    tm2.tm_yday = 51;

    t = mktime(&tm1);
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime test #1");
    CYG_TEST_PASS_FAIL(t == 130710184, "mktime return test #1");

    tm1.tm_sec = 61;
    tm1.tm_min = 20;
    tm1.tm_hour = 4;
    tm1.tm_mday = 5;
    tm1.tm_mon = 0;
    tm1.tm_year = 99;
    tm1.tm_isdst = 0;

    tm2 = tm1;
    tm2.tm_sec=1;
    tm2.tm_min = 21;
    tm2.tm_wday = 2;
    tm2.tm_yday = 4;

    t = mktime(&tm1);
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime test #2");
    CYG_TEST_PASS_FAIL(t == 915510061, "mktime return test #2");

    tm1.tm_sec = 54;
    tm1.tm_min = 24;
    tm1.tm_hour = 1;
    tm1.tm_mday = 1;
    tm1.tm_mon = 0;
    tm1.tm_year = 100;
    tm1.tm_isdst = 0;

    tm2 = tm1;
    tm2.tm_wday = 6;
    tm2.tm_yday = 0;

    t = mktime(&tm1);
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime Y2K test #3");
    CYG_TEST_PASS_FAIL(t == 946689894, "mktime Y2K return test #3");

    tm1.tm_sec = 54;
    tm1.tm_min = 24;
    tm1.tm_hour = 23;
    tm1.tm_mday = 31;
    tm1.tm_mon = 4;
    tm1.tm_year = 66;
    tm1.tm_isdst = 1;

    tm2 = tm1;
    tm2.tm_wday = 2;
    tm2.tm_yday = 150;

    t = mktime(&tm1);
    CYG_TEST_PASS_FAIL(!cmp_structtm(&tm1, &tm2), "mktime test #4");
    CYG_TEST_PASS_FAIL(t == -113186106, "mktime return test #4");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "mktime() function");
} // test()
Exemplo n.º 19
0
static void
test( CYG_ADDRWORD data )
{
    struct tm tm1;
    char *ret;
    
    tm1.tm_sec = 4;
    tm1.tm_min = 23;
    tm1.tm_hour = 20;
    tm1.tm_mday = 21;
    tm1.tm_mon = 1;
    tm1.tm_year = 74;
    tm1.tm_wday = 4;
    tm1.tm_yday = 51;
    tm1.tm_isdst = 0;

    ret = asctime(&tm1);

    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Thu Feb 21 20:23:04 1974\n"),
                       "asctime test #1");
    tm1.tm_sec = 3;
    tm1.tm_min = 51;
    tm1.tm_hour = 5;
    tm1.tm_mday = 2;
    tm1.tm_mon = 11;
    tm1.tm_year = 68;
    tm1.tm_wday = 1;
    tm1.tm_yday = 336;
    tm1.tm_isdst = 0;

    ret = asctime(&tm1);

    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Mon Dec 02 05:51:03 1968\n"),
                       "asctime test #2");

    // make this predictable - independent of the user option
    cyg_libc_time_setzoneoffsets(0, 3600);

    tm1.tm_sec = 3;
    tm1.tm_min = 51;
    tm1.tm_hour = 5;
    tm1.tm_mday = 2;
    tm1.tm_mon = 6;
    tm1.tm_year = 68;
    tm1.tm_wday = 2;
    tm1.tm_yday = 183;
    tm1.tm_isdst = 1;

    ret = asctime(&tm1);

    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Tue Jul 02 05:51:03 1968\n"),
                       "asctime test #3");

    tm1.tm_sec = 0;
    tm1.tm_min = 0;
    tm1.tm_hour = 0;
    tm1.tm_mday = 1;
    tm1.tm_mon = 0;
    tm1.tm_year = 0;
    tm1.tm_wday = 1;
    tm1.tm_yday = 0;
    tm1.tm_isdst = 0;

    ret = asctime(&tm1);

    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Mon Jan 01 00:00:00 1900\n"),
                       "asctime test #4");

    tm1.tm_sec = 0;
    tm1.tm_min = 0;
    tm1.tm_hour = 0;
    tm1.tm_mday = 1;
    tm1.tm_mon = 0;
    tm1.tm_year = 100;
    tm1.tm_wday = 6;
    tm1.tm_yday = 0;
    tm1.tm_isdst = 0;

    ret = asctime(&tm1);

    CYG_TEST_PASS_FAIL(!my_strcmp(ret, "Sat Jan 01 00:00:00 2000\n"),
                       "asctime Y2K test #5");

#ifdef CYGFUN_LIBC_TIME_POSIX
    {
        char ret2[100];
        
        tm1.tm_sec = 3;
        tm1.tm_min = 51;
        tm1.tm_hour = 5;
        tm1.tm_mday = 2;
        tm1.tm_mon = 11;
        tm1.tm_year = 68;
        tm1.tm_wday = 1;
        tm1.tm_yday = 336;
        tm1.tm_isdst = 0;
        
        ret = asctime_r(&tm1, ret2);
        
        CYG_TEST_PASS_FAIL((ret==ret2) &&
                           !my_strcmp(ret, "Mon Dec 02 05:51:03 1968\n"),
                           "asctime_r test #1");

    }
#endif


    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "asctime() function");
} // test()
Exemplo n.º 20
0
static void
test( CYG_ADDRWORD data )
{
    char x[30];
    long z;
    char *endptr;

    my_strcpy(x, "20");
    CYG_TEST_PASS_FAIL( strtol(x, (char**)NULL, 10) == 20,
                        "Simple strtol(20 ,...)" );

    my_strcpy(x, "1972100");
    CYG_TEST_PASS_FAIL( strtol(x, (char**)NULL, 10) == 1972100,
                        "Simple strtol(1972100, ..." );

    my_strcpy(x, "0xFFEE");
    z = strtol(x, (char**)NULL, 16);
    CYG_TEST_PASS_FAIL(z == 65518, "Hex base strtol()");

    my_strcpy(x, "100111011");
    z = strtol(x, (char**)NULL, 2);
    CYG_TEST_PASS_FAIL(z == 315, "Binary base strtol()");

    my_strcpy(x, "10372");
    z = strtol(x, (char**)NULL, 8);
    CYG_TEST_PASS_FAIL(z == 4346, "Octal base strtol()" );

    my_strcpy(x, "317823");
    z = strtol(x, (char**)NULL, 8);
    CYG_TEST_PASS_FAIL(z == 207, "Partial string" );

    my_strcpy(x, " 53ab823");
    z = strtol(x, &endptr, 10);
    CYG_TEST_PASS_FAIL((z == 53) && (endptr==&x[3]), "Correct end pointer" );

    my_strcpy(x, "-479");
    z = strtol(x, (char**)NULL, 10);
    CYG_TEST_PASS_FAIL(z == -479, "Negative string");

    my_strcpy(x, "+4796");
    z = strtol(x, (char**)NULL, 10);
    CYG_TEST_PASS_FAIL(z == 4796, "Positive string");

    my_strcpy(x, "");
    z = strtol(x, (char**)NULL, 10);
    CYG_TEST_PASS_FAIL(z == 0, "Empty string");

    my_strcpy(x, "");
    z = strtol(x, &endptr, 10);
    CYG_TEST_PASS_FAIL((z == 0) && (endptr==x),
                       "Empty string sets endptr correctly");

    my_strcpy(x, "    ");
    z = strtol(x, &endptr, 10);
    CYG_TEST_PASS_FAIL((z == 0) && (endptr==x),
                       "White space only string sets endptr correctly");

    my_strcpy(x, "0XFFEE");
    z = strtol(x, (char**)NULL, 0);
    CYG_TEST_PASS_FAIL(z == 65518, "Base 0 but hex");

    my_strcpy(x, "\t    0629");
    z = strtol(x, (char**)NULL, 0);
    CYG_TEST_PASS_FAIL(z == 50, "Base 0 but octal");

    my_strcpy(x, "42");
    z = strtol(x, (char**)NULL, 0);
    CYG_TEST_PASS_FAIL(z == 42, "Base 0 but decimal");

    my_strcpy(x, "hello");
    z = strtol(x, &endptr, 0);
    CYG_TEST_PASS_FAIL((z == 0) && (endptr==x),
                       "endptr set correctly on conversion failure");

    my_strcpy(x, "z2f");
    z = strtol(x, (char**)NULL, 36);
    CYG_TEST_PASS_FAIL(z == 45447, "Base==36");

    my_strcpy(x, "h547324");
    z = strtol(x, (char**)NULL, 10);
    CYG_TEST_PASS_FAIL(z == 0, "No valid number string");

    my_strcpy(x, "545425876654547324");
    z = strtol(x, (char**)NULL, 10);
    CYG_TEST_PASS_FAIL( (z == LONG_MAX) && (errno == ERANGE),
                        "Number out of range");

    my_strcpy(x, "-545425876654547324");
    z = strtol(x, (char**)NULL, 10);
    CYG_TEST_PASS_FAIL( (z == LONG_MIN) && (errno == ERANGE),
                        "Number out of range");

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strtol() function");
} // test()
Exemplo n.º 21
0
static void
test( CYG_ADDRWORD data )
{
    static char x[200];
    static char y[200];
    static char z[200];
    int ret;
    int tmp;
    int *ptr;

    // Check 1
    my_strcpy(x, "I'm afraid the shield generator");
    ptr = &tmp;
    ret = sprintf(y, "%s%n will be quite operational - %5d%%%c%05X", x,
                  ptr, 13, '5', 0x89ab);
    my_strcpy( z, "I'm afraid the shield generator will be "
               "quite operational -    13%5089AB" );
    CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "%s%n%d%%%c%0X test");

    CYG_TEST_PASS_FAIL(ret == my_strlen(z),
                       "%s%n%d%%%c%0X test return code" );

    CYG_TEST_PASS_FAIL(tmp==31, "%n test");

    // Check 2
    ret = sprintf(y, "|%5d|%10s|%03d|%c|%o|", 2, "times", 6, '=', 10 );
    my_strcpy(z, "|    2|     times|006|=|12|");

    CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "|%5d|%10s|%03d|%c|%o| test");

    CYG_TEST_PASS_FAIL(ret == my_strlen(z),
                       "|%5d|%10s|%03d|%c|%o| test return code" );

    // Check 3
    ret = snprintf(y, 19, "print up to here >< and not this bit" );
    my_strcpy(z, "print up to here >");
    CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "simple snprintf test #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(z),
                       "simple snprintf test #1 return code" );

    // Check 4
    ret = snprintf(y, 31, "print a bit of this number: %05d nyer", 1234);
    my_strcpy(z, "print a bit of this number: 01");
    CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0, "simple snprintf test #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(z),
                       "simple snprintf test #2 return code" );

#ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT

    CYG_TEST_INFO("Starting floating point specific tests");

    // Check 5
    ret = sprintf(y, "|%5f|%10s|%03d|%c|%+-5.2G|%010.3G|",
                  2.0, "times", 6, '=', 12.0, -2.3451e-6 );
    my_strcpy(z, "|2.000000|     times|006|=|+12  |-02.35E-06|");

    CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0,
                       "|%5f|%10s|%03d|%c|%+-5.2G|%010.3G| test");

    CYG_TEST_PASS_FAIL(ret == my_strlen(z),
                       "|%5f|%10s|%03d|%c|%+-5.2G|%010.3G| test "
                       "return code" );

    // Check 6
    ret = snprintf(y, 20, "bit of this: %g double", 6.431e8);
    my_strcpy(z, "bit of this: 6.431e");
    CYG_TEST_PASS_FAIL(my_strcmp(y,z) == 0,
                       "snprintf double test #1");

    CYG_TEST_PASS_FAIL(ret == my_strlen(z),
                       "snprintf double test #1 return code");

#endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT

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

} // test()
Exemplo n.º 22
0
static void test(CYG_ADDRWORD data)
{
    static char x[500];
    static char y[500];
    int ret;
    int tmp;
    int *ptr;


    // Check 1
    ret = sprintf(x, "%d", 20);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "20")==0, "%d test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%d test return code");

    // Check 2
    my_strcpy(y, "Pigs noses. Get 'em while there 'ot");
    ret = sprintf(x, "%s", y);
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%s test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%s test return code");

    // Check 3
    ret = sprintf(x, "||%7d||", 2378);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "||   2378||")==0, "padding test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "padding test return code");

    // Check 4
    ret = sprintf(x, "%x", 3573);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "df5")==0, "hex conversion (lowercase)");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "hex conv (lowercase) return code");

    // Check 5
    ret = sprintf(x, "%X", 3573);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "DF5")==0, "hex conversion (uppercase)");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "hex conv (upperbase ) return code");

    // Check 6
    ret = sprintf(x, "%c", 65);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "A")==0, "%c test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%c test return code");

    // Check 7
    ret = sprintf(x, "%o",4628);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "11024")==0, "octal conversion");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "octal conversion return code");

    // Check 8
    ret = sprintf(x, "%u", (unsigned int) 4738);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "4738")==0, "%u test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%u test return code");

    // Check 9
    ptr = &tmp;
    ret = sprintf(x, "1234567x%n||", ptr);
    CYG_TEST_PASS_FAIL(tmp==8, "%n test");
    CYG_TEST_PASS_FAIL(ret==10, "%n test return code");

    // Check 10
    ret = sprintf(x, "%%");
    CYG_TEST_PASS_FAIL(my_strcmp(x, "%")==0, "%% test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%% test return code");

    // Check 11
    ret = sprintf(x, "%ld", (long)1<<30);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "1073741824")==0, "%ld test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%ld test return code");

    // Check 12
    ret = sprintf(x, "%lu", (unsigned long)(1<<31) + 100);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "2147483748")==0, "%lu test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%lu test return code");

    // Check 13
    ret = sprintf(x, "%x", 0x789a);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "789a")==0, "%x test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%x test return code");

    // Check 14
    ret = sprintf(x, "%X", 0x789ab2);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "789AB2")==0, "%X test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%x test return code");

    // Check 15
    ret = sprintf(x, "%08x", 0xdea2f2);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "00dea2f2")==0, "%0x test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%0x test return code");

    // Check 16
    ret = sprintf(x, "%09X", 0x12fa1c);
    CYG_TEST_PASS_FAIL(my_strcmp(x, "00012FA1C")==0, "%0X test");
    CYG_TEST_PASS_FAIL(ret==my_strlen(x), "%0X test return code");

    // Check 17
    ptr=&tmp;
    ret = sprintf(x, "%p", (void *)ptr);
    // just check _something_ was returned
    CYG_TEST_PASS_FAIL((ret==my_strlen(x)) && (ret > 0),
                       "%p test return code");

#ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT

    CYG_TEST_INFO("Starting floating point specific tests");

    // Check 18
    ret = sprintf(x, "%f", 2.5);
    my_strcpy( y, "2.500000" );
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "simple %f test #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "simple %f test #1 return code");

    // Check 19
    ret = sprintf(x, "hello %f world", 1.234);
    my_strcpy( y, "hello 1.234000 world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "simple %f test #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "simple %f test #2 return code");

    // Check 20
    ret = sprintf(x, "hello%fworld", 2.3456781);
    my_strcpy( y, "hello2.345678world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "simple %f test #3");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "simple %f test #3 return code");

    // Check 21
    ret = sprintf(x, "%s%f%d%s", "testing", -0.591, 3, "123");
    my_strcpy( y, "testing-0.5910003123");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%f mixed with others");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),"%f mixed with others return code");

    // Check 22
    ret = sprintf(x, "%s%f%d%s", "testing", -0.591, 3, "123");
    my_strcpy( y, "testing-0.5910003123");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%f mixed with others");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),"%f mixed with others return code");

    // Check 23
    ret = sprintf(x, "hello%fworld", 2.3456786);
    my_strcpy( y, "hello2.345679world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "rounding test #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "rounding test #1 return code");

    // Check 24
    ret = sprintf(x, "hello%fworld", -2.3456786);
    my_strcpy( y, "hello-2.345679world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "rounding test #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "rounding test #2 return code");

    // Check 25
    ret = sprintf(x, "hello%+fworld", -6.54321);
    my_strcpy( y, "hello-6.543210world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "+ modifier #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "+ modifier #1 return code");

    // Check 26
    ret = sprintf(x, "hello%+fworld", 6.54321);
    my_strcpy( y, "hello+6.543210world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "+ modifier #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "+ modifier #2 return code");

    // Check 27
    ret = sprintf(x, "hello%5fworld", 6.5);
    my_strcpy( y, "hello6.500000world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width modifier #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "width modifier #1 return code");

    // Check 28
    ret = sprintf(x, "hello%2fworld", 4.3);
    my_strcpy( y, "hello4.300000world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width modifier #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "width modifier #2 return code");

    // Check 29
    ret = sprintf(x, "hello%2.1fworld", 5.6);
    my_strcpy( y, "hello5.6world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width and precision modifier #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "width and precision modifier #1 return code");

    // Check 30
    ret = sprintf(x, "hello%5.1fworld", 6.7);
    my_strcpy( y, "hello  6.7world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width and precision modifier #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "width and precision modifier #2 return code");

    // Check 31
    ret = sprintf(x, "hello%3.1fworld", 7.8);
    my_strcpy( y, "hello7.8world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width and precision modifier #3");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "width and precision modifier #3 return code");

    // Check 32
    ret = sprintf(x, "hello%3.2fworld", 7.8);
    my_strcpy( y, "hello7.80world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "width and precision modifier #4");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "width and precision modifier #4 return code");

    // Check 33
    ret = sprintf(x, "hello%05.1fworld", 6.5);
    my_strcpy( y, "hello006.5world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0 modifier #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0 modifier #1 return code");

    // Check 34
    ret = sprintf(x, "hello%03.0fworld", 6.2);
    my_strcpy( y, "hello006world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0 modifier #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0 modifier #2 return code");

    // Check 35
    ret = sprintf(x, "hello%05.*fworld",2, 7.5);
    my_strcpy( y, "hello07.50world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0 modifier plus *");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "0 modifier plus * return code");

    // Check 36
    ret = sprintf(x, "hello%03.1fworld",-1.232);
    my_strcpy( y, "hello-1.2world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-ve number with 0 modifier #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "-ve number with 0 modifier #1 return code");

    // Check 37
    ret = sprintf(x, "hello%04.1fworld",-1.232);
    my_strcpy( y, "hello-1.2world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-ve number with 0 modifier #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "-ve number with 0 modifier #2 return code");

    // Check 38
    ret = sprintf(x, "hello%05.1fworld",-1.232);
    my_strcpy( y, "hello-01.2world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-ve number with 0 modifier #3");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "-ve number with 0 modifier #3 return code");

    // Check 39
    ret = sprintf(x, "hello%fworld",0.0);
    my_strcpy( y, "hello0.000000world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #1 return code");

    // Check 40
    ret = sprintf(x, "hello%1.0fworld",0.0);
    my_strcpy( y, "hello0world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #2 return code");

    // Check 41
    ret = sprintf(x, "hello%1.1fworld",0.0);
    my_strcpy( y, "hello0.0world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #3");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #3 return code");

    // Check 42
    ret = sprintf(x, "hello%5.1fworld",0.0);
    my_strcpy( y, "hello  0.0world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "0.0 test #4");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "0.0 test #4 return code");

    // Check 43
    ret = sprintf(x, "hello%fworld",-0.0);
    my_strcpy( y, "hello-0.000000world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "-0.0 test #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "-0.0 test #1 return code");

    // Check 44
    ret = sprintf(x, "hello%fworld",0.234);
    my_strcpy( y, "hello0.234000world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "number less than 1 #1 return code");

    // Check 45
    ret = sprintf(x, "hello%02fworld",-0.234);
    my_strcpy( y, "hello-0.234000world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "number less than 1 #2 return code");

    // Check 46
    ret = sprintf(x, "hello%02.2fworld",-0.234);
    my_strcpy( y, "hello-0.23world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #3");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "number less than 1 #3 return code");

    // Check 47
    ret = sprintf(x, "hello%06.2fworld",-0.234);
    my_strcpy( y, "hello-00.23world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "number less than 1 #4");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "number less than 1 #4 return code");

    // Check 48
    ret = sprintf(x, "hello%-6.2fworld",2.345);
    my_strcpy( y, "hello2.35  world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "left justification #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "left justification #1 return code");

    // Check 49
    ret = sprintf(x, "hello%-6.2fworld",2.345);
    my_strcpy( y, "hello2.35  world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "left justification #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "left justification #2 return code");

    // Check 50
    ret = sprintf(x, "hello%-3.2fworld",2.345);
    my_strcpy( y, "hello2.35world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "left justification #3");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "left justification #3 return code");

    // Check 51
    ret = sprintf(x, "hello%#1.0fworld",2.12);
    my_strcpy( y, "hello2.world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "# modifier #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "# modifier #1 return code");

    // Check 52
    ret = sprintf(x, "hello%#1.2fworld",2.0);
    my_strcpy( y, "hello2.00world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "# modifier #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "# modifier #2 return code");

    // Check 53
    ret = sprintf(x, "hello%eworld",2.3456);
    my_strcpy( y, "hello2.345600e+00world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #1 return code");

    // Check 54
    ret = sprintf(x, "hello%4.3eworld",-2.3456e-1);
    my_strcpy( y, "hello-2.346e-01world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #2 return code");

    // Check 55
    ret = sprintf(x, "hello%4.2eworld",2.56e2);
    my_strcpy( y, "hello2.56e+02world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #3");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #3 return code");

    // Check 56
    ret = sprintf(x, "hello%09.2eworld",2.56e2);
    my_strcpy( y, "hello02.56e+02world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #4");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #4 return code");

    // Check 57
    ret = sprintf(x, "hello%09.2Eworld",4.23e19);
    my_strcpy( y, "hello04.23E+19world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%e #5");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%e #5 return code");

    // Check 58
    ret = sprintf(x, "hello%gworld",4.0);
    my_strcpy( y, "hello4world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #1 return code");

    // Check 59
    ret = sprintf(x, "hello%gworld",4.56);
    my_strcpy( y, "hello4.56world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #2 return code");

    // Check 60
    ret = sprintf(x, "hello%5.2gworld",4.56);
    my_strcpy( y, "hello  4.6world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #3");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #3 return code");

    // Check 61
    ret = sprintf(x, "hello%gworld",0.002);
    my_strcpy( y, "hello0.002world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #4");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #4 return code");

    // Check 62
    ret = sprintf(x, "hello%06.1gworld",0.0026);
    my_strcpy( y, "hello00.003world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #5");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #5 return code");

    // Check 63
    ret = sprintf(x, "hello%06gworld",0.000026);
    my_strcpy( y, "hello2.6e-05world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #5");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #5 return code");

    // Check 64
    ret = sprintf(x, "hello%06Gworld",0.000037);
    my_strcpy( y, "hello3.7E-05world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #6");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #6 return code");

    // Check 65
    ret = sprintf(x, "hello%08Gworld",-123456.0);
    my_strcpy( y, "hello-0123456world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #7");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #7 return code");

    // Check 66
    ret = sprintf(x, "hello%07gworld",-1234567.0);
    my_strcpy( y, "hello-1.23457e+06world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #8");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #8 return code");

    // Check 67
    ret = sprintf(x, "hello%013Gworld",-1234567.0);
    my_strcpy( y, "hello-01.23457E+06world");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "%g #9");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y), "%g #9 return code");


#else
    CYG_TEST_PASS("Floating point tests skipped - not configured");
#endif // ifdef CYGSEM_LIBC_STDIO_PRINTF_FLOATING_POINT

    // Long string tests
    ret = sprintf(x, "This is a very long string so I hope this works as "
                  "otherwise I would be very, very, sad. The cat sat on the "
                  "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "
                  "blah, blah and all that jazz. Isn't he finished yet? My "
                  "old man's a dustman, why do I have to think up this "
                  "drivel, isn't that what summer students are for, if "
                  "anything that seems thinking up mindless drivel seems to "
                  "be their occupation in life. Yoof of today, eh? What, "
                  "what? %s So there.",
                  "And this is a middly bit.");
    my_strcpy(y, "This is a very long string so I hope this works as "
                  "otherwise I would be very, very, sad. The cat sat on the "
                  "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "
                  "blah, blah and all that jazz. Isn't he finished yet? My "
                  "old man's a dustman, why do I have to think up this "
                  "drivel, isn't that what summer students are for, if "
                  "anything that seems thinking up mindless drivel seems to "
                  "be their occupation in life. Yoof of today, eh? What, "
                  "what? And this is a middly bit. So there.");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "long (480 char) string output #1");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "long (480 char) string output #1 return code");

    ret = sprintf(x, "Boo! This %s So there.",
                  "is a very long string so I hope this works as "
                  "otherwise I would be very, very, sad. The cat sat on the "
                  "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "
                  "blah, blah and all that jazz. Isn't he finished yet? My "
                  "old man's a dustman, why do I have to think up this "
                  "drivel, isn't that what summer students are for, if "
                  "anything that seems thinking up mindless drivel seems to "
                  "be their occupation in life. Yoof of today, eh? What, "
                  "what? And this is a middly bit.");
    my_strcpy(y, "Boo! This is a very long string so I hope this works as "
                  "otherwise I would be very, very, sad. The cat sat on the "
                  "hat, and the mat sat on the rat. Quick brown fax, etc.etc. "
                  "blah, blah and all that jazz. Isn't he finished yet? My "
                  "old man's a dustman, why do I have to think up this "
                  "drivel, isn't that what summer students are for, if "
                  "anything that seems thinking up mindless drivel seems to "
                  "be their occupation in life. Yoof of today, eh? What, "
                  "what? And this is a middly bit. So there.");
    CYG_TEST_PASS_FAIL(my_strcmp(x, y)==0, "long (485 char) string output #2");
    CYG_TEST_PASS_FAIL(ret == my_strlen(y),
                       "long (485 char) string output #2 return code");




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

} // test()
Exemplo n.º 23
0
static void
test( CYG_ADDRWORD data )
{
    struct tm tm1;
    char s[1000];
    size_t size;
    
    tm1.tm_sec = 4;
    tm1.tm_min = 23;
    tm1.tm_hour = 20;
    tm1.tm_mday = 21;
    tm1.tm_mon = 1;
    tm1.tm_year = 74;
    tm1.tm_wday = 4;
    tm1.tm_yday = 51;
    tm1.tm_isdst = 0;
    
    size = strftime(s, 1000, "", &tm1);
    CYG_TEST_PASS_FAIL((size==0) && (*s=='\0'), "strftime test #1");

    size = strftime(s, 1000, "%a", &tm1);
    CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "Thu"), "strftime test #2");

    size = strftime(s, 1000, "%A", &tm1);
    CYG_TEST_PASS_FAIL((size==8) && !my_strcmp(s, "Thursday"),
                       "strftime test #3");

    size = strftime(s, 1000, "%b", &tm1);
    CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "Feb"),
                       "strftime test #4");

    size = strftime(s, 1000, "%B", &tm1);
    CYG_TEST_PASS_FAIL((size==8) && !my_strcmp(s, "February"),
                       "strftime test #5");

    size = strftime(s, 1000, "%d", &tm1);
    CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "21"),
                       "strftime test #6");

    size = strftime(s, 1000, "%H", &tm1);
    CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "20"),
                       "strftime test #7");

    size = strftime(s, 1000, "%I", &tm1);
    CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "09"),
                       "strftime test #8");

    size = strftime(s, 1000, "%j", &tm1);
    CYG_TEST_PASS_FAIL((size==3) && !my_strcmp(s, "051"),
                       "strftime test #9");

    size = strftime(s, 1000, "%m", &tm1);
    CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "02"),
                       "strftime test #10");

    size = strftime(s, 1000, "%M", &tm1);
    CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "23"),
                       "strftime test #11");

    size = strftime(s, 1000, "%p", &tm1);
    CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "pm"),
                       "strftime test #12");

    size = strftime(s, 1000, "%S", &tm1);
    CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "04"),
                       "strftime test #13");

    size = strftime(s, 1000, "%U", &tm1);
    CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "07"),
                       "strftime test #14");

    size = strftime(s, 1000, "%w", &tm1);
    CYG_TEST_PASS_FAIL((size==1) && !my_strcmp(s, "4"),
                       "strftime test #15");

    size = strftime(s, 1000, "%W", &tm1);
    CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "07"),
                       "strftime test #16");

    size = strftime(s, 1000, "%y", &tm1);
    CYG_TEST_PASS_FAIL((size==2) && !my_strcmp(s, "74"),
                       "strftime test #17");

    size = strftime(s, 1000, "%Y", &tm1);
    CYG_TEST_PASS_FAIL((size==4) && !my_strcmp(s, "1974"),
                       "strftime test #18");

    size = strftime(s, 1000, "%%", &tm1);
    CYG_TEST_PASS_FAIL((size==1) && !my_strcmp(s, "%"),
                       "strftime test #19");

    size = strftime(s, 5, "%Y", &tm1);
    CYG_TEST_PASS_FAIL((size==4) && !my_strcmp(s, "1974"),
                       "strftime test #20");

    size = strftime(s, 4, "%Y", &tm1);
    CYG_TEST_PASS_FAIL((size==0), "strftime test #21");


    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "strftime() function");
} // test()
Exemplo n.º 24
0
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("Connecting to DNS at " _DNS_IP);
    inet_aton(_DNS_IP, &addr);
    CYG_TEST_CHECK(cyg_dns_res_init(&addr) == 0, "Failed to initialize resolver");
    setdomainname(NULL,0);
    
    /* 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));
    }

    /* Reverse lookup the _LOOKUP_IP addres, expect _LOOKUP_FQDN
       as the answer. */
    hent = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
        if (0 != strcmp(_LOOKUP_FQDN, hent->h_name)) {
          diag_printf("FAIL:<expected " _LOOKUP_IP " to be " _LOOKUP_FQDN ">\n");
        }
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_IP ". No answer: %s>\n", hstrerror(h_errno));
    }
 
    /* This does not require a DNS lookup. Just turn the value into
       binary */
    hent = gethostbyname(_LOOKUP_IP);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_IP ". No answer: %s>\n", hstrerror(h_errno));
    }
 
    /* Reverse lookup an address this is not in the server. Expect a
       NULL back */
    inet_aton(_LOOKUP_IP_BAD, &addr);
    hent = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
    if (hent != NULL) {
        diag_printf("FAIL:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
    } else {
        diag_printf("PASS:<Asked for bad IP " _LOOKUP_IP_BAD ". No answer: %s>\n", hstrerror(h_errno));
    }

    /* Setup a domainname. We not don't have to use fully qualified
       domain names */
    setdomainname(_LOOKUP_DOMAINNAME, sizeof(_LOOKUP_DOMAINNAME));
    getdomainname(dn, sizeof(dn));
    diag_printf("INFO:<Domainname is now %s>\n", dn);

    /* Make sure FQDN still work */
    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));
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno));
    }

    /* Now just the hostname */
    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("dns1 test completed");
}
Exemplo n.º 25
0
int
main( int argc, char *argv[] )
#endif
{
    long num, denom;
    ldiv_t result;

    CYG_TEST_INIT();

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

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

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

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

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

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

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

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

    num = 90123456;
    denom = 12345678;
    result = ldiv(num, denom);
    CYG_TEST_PASS_FAIL( (result.quot==7) && (result.rem==3703710),
                   "ldiv( 90123456, 12345678 )");

    num = 90123456;
    denom = 123;
    result = ldiv(num, denom);
    CYG_TEST_PASS_FAIL( (result.quot==732711) && (result.rem==3),
                        "ldiv( 90123456, 123 )");

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

} // main()
Exemplo n.º 26
0
int
main( int argc, char *argv[] )
{
    char *str;
    int size;
    int poolmax;

    CYG_TEST_INIT();

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

    poolmax = mallinfo().maxfree;
    
    if ( poolmax <= 0 ) {
        CYG_TEST_FAIL_FINISH( "Can't determine allocation size to use" );
    }

    size = poolmax/2;

    str = (char *)realloc( NULL, size );
    CYG_TEST_PASS_FAIL( str != NULL, "realloc doing only allocation");
    CYG_TEST_PASS_FAIL( fill_with_alphabet( str, size, 0 ),
                        "allocation usability");

    str = (char *)realloc( str, 0 );
    CYG_TEST_PASS_FAIL( str == NULL, "realloc doing implicit free" );

    str = (char *)realloc( NULL, size/2 );
    CYG_TEST_PASS_FAIL( str != NULL, "realloc doing allocation to half size");
    CYG_TEST_PASS_FAIL( fill_with_alphabet( str, size/2, 5 ),
                        "half allocation usability");

    str = (char *)realloc( str, size );
    CYG_TEST_PASS_FAIL( str != NULL,
                        "reallocing allocation back to normal size");
    CYG_TEST_PASS_FAIL( compare_with_alphabet(str, size/2, 5),
                        "after realloc to normal size, old contents kept" );
    CYG_TEST_PASS_FAIL( fill_with_alphabet( str, size, 3 ),
                        "reallocation normal size usability");

    str = (char *)realloc( str, size/4 );
    CYG_TEST_PASS_FAIL( str != NULL, "reallocing allocation to quarter size");
    CYG_TEST_PASS_FAIL( compare_with_alphabet(str, size/4, 3),
                        "after realloc to quarter size, old contents kept" );
    CYG_TEST_PASS_FAIL( fill_with_alphabet( str, size/4, 1 ),
                        "reallocation quarter size usability");

    CYG_TEST_PASS_FAIL( realloc( str, size*4 ) == NULL,
                        "reallocing allocation that is too large" );
    CYG_TEST_PASS_FAIL( compare_with_alphabet( str, size/4, 1 ),
                        "Checking old contents maintained despite failure" );

    str = (char *)realloc( str, 0 );
    CYG_TEST_PASS_FAIL( str == NULL, "realloc doing implicit free again" );

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

    return 0;
} // main()
Exemplo n.º 27
0
int
main( int argc, char *argv[] )
{
    int *i;
    char *str, *str2, *str3;
    int j;
    int poolmax;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
                  "malloc(), calloc() and free() functions");

    poolmax = mallinfo().maxfree;
    
    if ( poolmax <= 0 ) {
        CYG_TEST_FAIL_FINISH( "Can't determine allocation size to use" );
    }

    // Test 1
    i = (int *) malloc( sizeof(int) );

    // check if it should fit into pool
    if (sizeof(int) > poolmax)
    {
        // didn't fit into pool, so should be NULL
        CYG_TEST_PASS_FAIL( i == NULL,
                            "1 int malloc with no space left works" );
    }
    else
    {
        // since it should fit into pool, we can fiddle with i
        *i=-12345;
        CYG_TEST_PASS_FAIL( i && (*i==-12345),
                            "1 int malloc with space left works" );
        free(i);
    } // else

    // Test 2
    str=(char *) malloc( 4096 );

    if ( 4096 > poolmax)
    {
        // didn't fit into pool, so should be NULL
        CYG_TEST_PASS_FAIL( str == NULL,"4K string with no space left works" );
    }
    else
    {
        // since it should fit into pool, we can fiddle with it.
        for (j=0; j<1024; j++)
        {
            str[j*4] = 'f';
            str[(j*4)+1] = 'r';
            str[(j*4)+2] = 'e';
            str[(j*4)+3] = 'd';
        } // for

        for (j=0; j<1024; j++)
        {
            if ( ((str[j*4] != 'f') ||
                  (str[(j*4)+1] != 'r') ||
                  (str[(j*4)+2] != 'e') ||
                  (str[(j*4)+3] != 'd')) )
                break;
        } // for

        // did j reach the top?
        CYG_TEST_PASS_FAIL( j==1024, "4K string with space left works" );

        free(str);
    } // else       
        

    // Test 3
    str=(char *) calloc( 2, 1024 );

    if ( 2048 > poolmax)
    {
        // didn't fit into pool, so should be NULL
        CYG_TEST_PASS_FAIL( str == NULL,
                            "calloc 2K string with no space left works" );
    }
    else
    {
        // check its zeroed
        for ( j=0; j<2048; j++ )
        {
            if (str[j] != 0)
                break;
        } // for

        CYG_TEST_PASS_FAIL( j==2048, "calloc 2K string is cleared" );

        // since it should fit into pool, we can fiddle with it.
        for (j=0; j<512; j++)
        {
            str[j*4] = 'j';
            str[(j*4)+1] = 'i';
            str[(j*4)+2] = 'f';
            str[(j*4)+3] = 'l';
        } // for

        for (j=0; j<512; j++)
        {
            if ( ((str[j*4] != 'j') ||
                  (str[(j*4)+1] != 'i') ||
                  (str[(j*4)+2] != 'f') ||
                  (str[(j*4)+3] != 'l')) )
                break;
        } // for

        // did j reach the top?
        CYG_TEST_PASS_FAIL( j==512, 
                            "calloc 2K string - with space left works" );

        free(str);
    } // else       

    // Test 4
#if defined(CYGIMP_MEMALLOC_MALLOC_VARIABLE_SIMPLE) && \
      defined(CYGSEM_MEMALLOC_ALLOCATOR_VARIABLE_COALESCE)
    poolmax = mallinfo().maxfree; // recalculate for non-coalescing allocator
#endif
    str=(char *)malloc( poolmax+1 );
    CYG_TEST_PASS_FAIL( str==NULL, "malloc too much data returns NULL" );

    // Test 5
    str=(char *)calloc( 1, poolmax+1 );
    CYG_TEST_PASS_FAIL( str==NULL, "calloc too much data returns NULL" );

    // Test 6
    str=(char *)malloc(0); if (str != NULL) free(str);
    str=(char *)calloc(0, 1); if (str != NULL) free(str);
    str=(char *)calloc(1, 0); if (str != NULL) free(str);
    str=(char *)calloc(0, 0); if (str != NULL) free(str);
    // simply shouldn't barf by this point

    CYG_TEST_PASS_FAIL( 1, "malloc and calloc of 0 bytes doesn't crash" );

    // Test 7
    str = (char *)malloc(10);
    i = (int *)malloc(sizeof(int));
    str2 = (char *)malloc(10);

    str3=(char *)i;

    CYG_TEST_PASS_FAIL( ((str3 <= str-sizeof(int))  || (str3 >= &str[10])) &&
                        ((str3 <= str2-sizeof(int)) || (str3 >= &str2[10])) &&
                        ((str+10 <= str2) || (str2+10 <= str)),
                        "Objects don't overlap" );

    // Test 8

    free(i);
    i=(int *)malloc(sizeof(int)*2);
    str3=(char *)i;

    CYG_TEST_PASS_FAIL( ((str3 <= str-sizeof(int))  || (str3 >= &str[10])) &&
                        ((str3 <= str2-sizeof(int)) || (str3 >= &str2[10])) &&
                        ((&str[10] <= str2) || (&str2[10] <= str)),
                        "Objects don't overlap when middle is freed" );
    
    free(i);
    free(str);
    free(str2);

    // Test 9

#if defined(CYGIMP_MEMALLOC_MALLOC_VARIABLE_SIMPLE) && \
      defined(CYGSEM_MEMALLOC_ALLOCATOR_VARIABLE_COALESCE)
    poolmax = mallinfo().maxfree; // recalculate for non-coalescing allocator
#endif
    str = (char *)malloc( poolmax );
    CYG_TEST_PASS_FAIL( str != NULL, "malloc of maximum free block size works");
    free(str);

    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
                    "malloc(), calloc() and free() functions");

    return 0;
} // main()
Exemplo n.º 28
0
int
main( int argc, char *argv[] )
{
    char *str1, *str2, *str3;
    int j;
    int poolmax;

    CYG_TEST_INIT();

    CYG_TEST_INFO("Starting stress tests from testcase " __FILE__ " for C "
                  "library malloc(), calloc() and free() functions");

    poolmax = mallinfo().maxfree;
    
    if ( poolmax <= 0 ) {
        CYG_TEST_FAIL_FINISH( "Can't determine allocation size to use" );
    }

    if ( poolmax < 300 )
    {
        CYG_TEST_FAIL_FINISH("This testcase cannot safely be used with a "
                             "memory pool for malloc less than 300 bytes");
    } // if


    for ( j=1; j < NUM_ITERATIONS; j++)
    {
//        if ((j % 100) == 0)
//            CYG_TEST_STILL_ALIVE( j, "Multiple mallocs and frees continuing" );

        
        str1 = (char *)safe_malloc(50);
        fill_with_data( str1, 50 );
        str2 = (char *)safe_calloc(11);
        fill_with_data( str2, 11 );
        str3 = (char *)safe_malloc(32);
        fill_with_data( str3, 32 );

        free(str2);
        free(str1);

        str2 = (char *)safe_calloc(11);
        fill_with_data( str2, 11 );
        free(str2);

        str1 = (char *)safe_calloc(50);
        fill_with_data( str1, 50 );
        free(str3);

        str3 = (char *)safe_malloc(32);
        fill_with_data( str3, 32 );
        free(str1);

        str2 = (char *)safe_calloc(11);
        fill_with_data( str2, 11 );
        str1 = (char *)safe_malloc(50);
        fill_with_data( str1, 50 );

        free(str3);
        free(str1);
        free(str2);

        if (problem != 0)
            break;
    } // for

    // Did it completely successfully?
    if (j==NUM_ITERATIONS)
        CYG_TEST_PASS("Stress test completed successfully");

    CYG_TEST_FINISH("Finished stress tests from testcase " __FILE__ " for C "
                    "library malloc(), calloc() and free() functions");

    return 0;
} // main()
Exemplo n.º 29
0
int
main( int argc, char *argv[] )
#endif
{
    int c; // character we use as a parameter

    CYG_TEST_INIT();

    CYG_TEST_INFO( "Starting tests from testcase " __FILE__ " for C library "
                   "<ctype.h> functions" );

    // Check isalnum
    c = 't';
    CYG_TEST_PASS_FAIL( isalnum(c), "isalnum('t')");
    c = '2';
    CYG_TEST_PASS_FAIL( isalnum(c), "isalnum('2')");
    c = 2;
    CYG_TEST_PASS_FAIL( !isalnum(c), "!isalnum(2)");
    c = 127;
    CYG_TEST_PASS_FAIL( !isalnum(c), "!isalnum(127)");

    // Check isalpha
    c = 'A';
    CYG_TEST_PASS_FAIL( isalpha(c), "isalpha('A')");
    c = 'a';
    CYG_TEST_PASS_FAIL( isalpha(c), "isalpha('a')");
    c = '2';
    CYG_TEST_PASS_FAIL( !isalpha(c), "!isalpha('2')");
    c = '\n';
    CYG_TEST_PASS_FAIL( !isalpha(c), "!isalpha('newline')");

    // Check iscntrl
    c = 'a';
    CYG_TEST_PASS_FAIL( !iscntrl(c), "!iscntrl('a')");
    c = 7;
    CYG_TEST_PASS_FAIL( iscntrl(c), "iscntrl('7')");
    c = '\n';
    CYG_TEST_PASS_FAIL( iscntrl(c), "iscntrl(newline)");
    c = 0x7F;
    CYG_TEST_PASS_FAIL( iscntrl(c), "iscntrl(0x7F)");

    // Check isdigit
    c = '2';
    CYG_TEST_PASS_FAIL( isdigit(c), "isdigit('2')");
    c = '0';
    CYG_TEST_PASS_FAIL( isdigit(c), "isdigit('0')");
    c = 't';
    CYG_TEST_PASS_FAIL( !isdigit(c), "!isdigit('t')");

    // Check isgraph
    c = ')';
    CYG_TEST_PASS_FAIL( isgraph(c), "isgraph(')')");
    c = '~';
    CYG_TEST_PASS_FAIL( isgraph(c), "isgraph('~')");
    c = '9';
    CYG_TEST_PASS_FAIL( isgraph(c), "isgraph('9')");
    c = 9;
    CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(9)");
    c = ' ';
    CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(' ')");
    c = '\t';
    CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(tab)");
    c = '\n';
    CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(newline)");
    c = 0x7F;
    CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(DEL)");
    c = 200;
    CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(200)");
    c = '\0';
    CYG_TEST_PASS_FAIL( !isgraph(c), "!isgraph(NUL)");

    // Check islower
    c = 'J';
    CYG_TEST_PASS_FAIL( !islower(c), "islower('J')");
    c = 'j';
    CYG_TEST_PASS_FAIL( islower(c), "islower('j')");
    c = '5';
    CYG_TEST_PASS_FAIL( !islower(c), "!islower(5)");

    // Check isprint
    c = ' ';
    CYG_TEST_PASS_FAIL( isprint(c), "isprint(' ')");
    c = 'x';
    CYG_TEST_PASS_FAIL( isprint(c), "isprint('x')");
    c = '\b';
    CYG_TEST_PASS_FAIL( !isprint(c), "!isprint(backspace)");

    // Check ispunct
    c = '.';
    CYG_TEST_PASS_FAIL( ispunct(c), "ispunct('.')");
    c = '#';
    CYG_TEST_PASS_FAIL( ispunct(c), "ispunct('#')");
    c = '@';
    CYG_TEST_PASS_FAIL( ispunct(c), "ispunct('@')");
    c = 'f';
    CYG_TEST_PASS_FAIL( !ispunct(c), "!ispunct('f')");
    c = '7';
    CYG_TEST_PASS_FAIL( !ispunct(c), "!ispunct('7')");
    c = '\n';
    CYG_TEST_PASS_FAIL( !ispunct(c), "!ispunct('newline')");

    // Check isspace
    c = ' ';
    CYG_TEST_PASS_FAIL( isspace(c), "isspace(' ')");
    c = '\t';
    CYG_TEST_PASS_FAIL( isspace(c), "isspace(tab)");
    c = '\r';
    CYG_TEST_PASS_FAIL( isspace(c), "isspace(return)");
    c = '\v';
    CYG_TEST_PASS_FAIL( isspace(c), "isspace(vertical tab)");
    c = '\n';
    CYG_TEST_PASS_FAIL( isspace(c), "isspace(newline)");
    c = 'd';
    CYG_TEST_PASS_FAIL( !isspace(c), "!isspace('d')");
    c = ',';
    CYG_TEST_PASS_FAIL( !isspace(c), "!isspace(',')");

    // Check isupper
    c = 'A';
    CYG_TEST_PASS_FAIL( isupper(c), "isupper('A')");
    c = 'a';
    CYG_TEST_PASS_FAIL( !isupper(c), "!isupper('a')");
    c = '2';
    CYG_TEST_PASS_FAIL( !isupper(c), "!isupper('2')");
    c = '\b';
    CYG_TEST_PASS_FAIL( !isupper(c), "!isupper(backspace)");

    // Check isxdigit
    c = 'f';
    CYG_TEST_PASS_FAIL( isxdigit(c), "isxdigit('f')");
    c = 'D';
    CYG_TEST_PASS_FAIL( isxdigit(c), "isxdigit('D')");
    c = '1';
    CYG_TEST_PASS_FAIL( isxdigit(c), "isxdigit('1')");
    c = '0';
    CYG_TEST_PASS_FAIL( isxdigit(c), "isxdigit('0')");
    c = 'g';
    CYG_TEST_PASS_FAIL( !isxdigit(c), "!isxdigit('g')");
    c = 'x';
    CYG_TEST_PASS_FAIL( !isxdigit(c), "!isxdigit('x')");

    // Check tolower
    c = 'F';
    CYG_TEST_PASS_FAIL( tolower(c) == 'f', "tolower('F')");
    c = 'g';
    CYG_TEST_PASS_FAIL( tolower(c) == 'g', "tolower('g')");
    c = '3';
    CYG_TEST_PASS_FAIL( tolower(c) == '3', "tolower('3')");

    // Check toupper
    c = 'f';
    CYG_TEST_PASS_FAIL( toupper(c) == 'F', "toupper('f')");
    c = 'G';
    CYG_TEST_PASS_FAIL( toupper(c) == 'G', "toupper('G')");
    c = ',';
    CYG_TEST_PASS_FAIL( toupper(c) == ',', "toupper(',')");

    CYG_TEST_FINISH( "Finished tests from testcase " __FILE__ " for C library "
                     "<ctype.h> functions" );
} // main()