diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-12-20 20:58:11 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-12-20 20:58:11 +0000 |
commit | 6bd316209be2720ae754983cbb778eac657908ad (patch) | |
tree | 287bb9e9ca10014efacf9eddce00eb03b12ed42f /testsuites/libtests | |
parent | 2007-12-20 Jennifer Averett <jennifer.averett@OARcorp.com> (diff) | |
download | rtems-6bd316209be2720ae754983cbb778eac657908ad.tar.bz2 |
2007-12-20 Joel Sherrill <joel.sherrill@OARcorp.com>
* malloctest/init.c: Add test cases suggested by Sergei Organov
<s.organov@javad.com>.
Diffstat (limited to 'testsuites/libtests')
-rw-r--r-- | testsuites/libtests/ChangeLog | 5 | ||||
-rw-r--r-- | testsuites/libtests/malloctest/init.c | 62 |
2 files changed, 62 insertions, 5 deletions
diff --git a/testsuites/libtests/ChangeLog b/testsuites/libtests/ChangeLog index c0db39ecfb..26a8259820 100644 --- a/testsuites/libtests/ChangeLog +++ b/testsuites/libtests/ChangeLog @@ -1,3 +1,8 @@ +2007-12-20 Joel Sherrill <joel.sherrill@OARcorp.com> + + * malloctest/init.c: Add test cases suggested by Sergei Organov + <s.organov@javad.com>. + 2007-12-19 Joel Sherrill <joel.sherrill@OARcorp.com> * malloctest/init.c, malloctest/task1.c: Add test for posix_memalign. diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c index 95019074ee..3115ed275e 100644 --- a/testsuites/libtests/malloctest/init.c +++ b/testsuites/libtests/malloctest/init.c @@ -32,14 +32,66 @@ */ void test_realloc(void) { - void *p1, *p2; + void *p1, *p2, *p3; int i; + int sc; - p2 = p1 = malloc(1); - for (i=2 ; i<2048 ; i++) - p2 = realloc(p2, i); - + /* Test growing reallocation "in place" */ + p1 = malloc(1); + for (i=2 ; i<2048 ; i++) { + p2 = realloc(p1, i); + if (p2 != p1) + printf( "realloc - failed grow in place: " + "%p != realloc(%p,%d)\n", p1, p2, i ); + p1 = p2; + } + free(p1); + + /* Test shrinking reallocation "in place" */ + p1 = malloc(2048); + for (i=2047 ; i>=1; i--) { + p2 = realloc(p1, i); + if (p2 != p1) + printf( "realloc - failed shrink in place: " + "%p != realloc(%p,%d)\n", p1, p2, i ); + p1 = p2; + } + free(p1); + + /* Test realloc that should fail "in place", i.e., + * fallback to free()--malloc() + */ + p1 = malloc(32); + p2 = malloc(32); + p3 = realloc(p1, 64); + if (p3 == p1 || p3 == NULL) + printf( + "realloc - failed non-in place: realloc(%p,%d) = %p\n", p1, 64, p3 ); + free(p3); free(p2); + + /* + * Yet another case + */ + p1 = malloc(8); + p2 = malloc(8); + free(p1); + sc = posix_memalign(&p1, 16, 32); + printf( "sc = %d\n", sc ); + if (!sc) + free(p1); + + /* + * Bad hack to get coverage + */ + + { + void *p5; + extern Heap_Control RTEMS_Malloc_Heap; + p5 = _Protected_heap_Allocate_aligned( &RTEMS_Malloc_Heap, 8, 0 ); + if ( p5 ) + free( p5 ); + } } /* |