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()
void entry(void) { int res; res = function(0); res &= function(1, 11); res &= function(2, 22, 23); res &= function(3, 33, 34, 35); res &= function(4, 44, 45, 46, 47); res &= function(5, 55, 56, 57, 58, 59); res &= function(6, 66, 67, 68, 69, 70, 71); res &= function(7, 77, 78, 79, 80, 81, 82, 83); CYG_TEST_PASS_FAIL(res, "Direct vaargs calls"); res = proxy(0); res &= proxy(1, 11); res &= proxy(2, 22, 23); res &= proxy(3, 33, 34, 35); res &= proxy(4, 44, 45, 46, 47); res &= proxy(5, 55, 56, 57, 58, 59); res &= proxy(6, 66, 67, 68, 69, 70, 71); res &= proxy(7, 77, 78, 79, 80, 81, 82, 83); CYG_TEST_PASS_FAIL(res, "Proxy vaargs calls"); CYG_TEST_FINISH("HAL vaargs test"); }
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()
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()
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()
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()
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()
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()
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()
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()
static void myfun2( void ) { if (!failed) { CYG_TEST_PASS_FAIL( stage==1, "Second function called correctly" ); stage=2; } // if } // myfun2()
static void myfun1( void ) { if (!failed) { CYG_TEST_PASS_FAIL( stage==0, "first function called correctly" ); stage=1; } // if } // myfun1()
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()
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()
static void myfun3( void ) { if (!failed) { CYG_TEST_PASS_FAIL( stage==2, "Second function called correctly" ); stage=3; } // if CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C " "library atexit() function"); } // myfun3()
int main(int argc, char *argv[]) { time_t t1, t2; unsigned long ctr; CYG_TEST_INIT(); CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " "time() function"); t1 = time(&t2); CYG_TEST_PASS_FAIL(t1==t2, "time() return value == argument"); if (t1 == (time_t)-1) // unimplemented is just as valid { #ifndef CYGSEM_LIBC_TIME_TIME_WORKING CYG_TEST_PASS_FINISH( "time() returns -1, meaning unimplemented"); #else CYG_TEST_FAIL("time() returned -1 unnecessarily"); #endif } // if // First wait for a clock tick for (ctr = 0; ctr<MAX_TIMEOUT; ctr++) { if ((t2=time(NULL)) > t1) break; // Hit the next time pulse } CYG_TEST_PASS_FAIL( ctr< MAX_TIMEOUT, "time()'s state changes"); #ifdef CYGSEM_LIBC_TIME_SETTIME_WORKING CYG_TEST_PASS_FAIL(cyg_libc_time_settime(0)==0, "Set time to 0"); t1 = time(NULL); // give it a small amount of tolerance CYG_TEST_PASS_FAIL(t1 < 3, "t1 remembered setting"); CYG_TEST_PASS_FAIL(cyg_libc_time_settime(1000)==0, "Set time to 1000"); // give it a small amount of tolerance CYG_TEST_PASS_FAIL(t1 < 1003, "t1 remembered setting"); #else // ! CYGSEM_LIBC_TIME_SETTIME_WORKING CYG_TEST_PASS_FAIL(cyg_libc_time_settime(0)!=0, "Set time expected fail"); #endif // CYGSEM_LIBC_TIME_SETTIME_WORKING CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " "time() function"); } // main()
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()
static void myhandler(int sig) { __sighandler_t handler1; CYG_TEST_INFO("myhandler() called"); ++state; handler1 = signal(sig, &myhandler); CYG_TEST_PASS_FAIL(handler1 == SIG_DFL, "handler reset itself to default"); longjmp(jbuf, 1); } // myhandler()
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()
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()
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()
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()
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()
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()
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()
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()
static void sigusr1_handler( int signo, siginfo_t *info, void *context ) { ssize_t recvlen; char mybuf[20]; unsigned int myprio; mqd_t *q = (mqd_t *)info->si_value.sival_ptr; CYG_TEST_PASS_FAIL( SIGUSR1 == signo, "correct signal number #1" ); CYG_TEST_PASS_FAIL( SIGUSR1 == info->si_signo, "correct signal number #2" ); CYG_TEST_PASS_FAIL( SI_MESGQ == info->si_code, "correct signal code" ); signals++; // retrieve message and compare with buf recvlen = mq_receive( *q, mybuf, sizeof(mybuf), &myprio ); CYG_TEST_PASS_FAIL( recvlen == my_strlen(buf), "receive message length" ); CYG_TEST_PASS_FAIL( 0 == my_memcmp( buf, mybuf, my_strlen(buf)), "received message data intact" ); CYG_TEST_PASS_FAIL( prio == myprio, "received at correct priority" ); }
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()
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()
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()