diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-11-09 12:11:11 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-11-12 13:26:22 +0100 |
commit | 6efc831f0ff3d975fa9086a46c3a67b6f2b95100 (patch) | |
tree | 0abb96a9bac37a9a07470d7645ef74139fd9738a /testsuites/libtests/malloctest | |
parent | score: Add and use malloc() family attributes (diff) | |
download | rtems-6efc831f0ff3d975fa9086a46c3a67b6f2b95100.tar.bz2 |
Add rtems_malloc() and rtems_calloc()
Close #3583.
Diffstat (limited to 'testsuites/libtests/malloctest')
-rw-r--r-- | testsuites/libtests/malloctest/init.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c index be6f2c4755..1d91385683 100644 --- a/testsuites/libtests/malloctest/init.c +++ b/testsuites/libtests/malloctest/init.c @@ -1148,6 +1148,55 @@ static void test_rtems_heap_allocate_aligned_with_boundary(void) rtems_test_assert( p == NULL ); } +static void test_rtems_malloc(void) +{ + void *p; + + p = rtems_malloc(0); + rtems_test_assert(p == NULL); + + errno = 0; + p = rtems_malloc(SIZE_MAX / 2); + rtems_test_assert(p == NULL); + rtems_test_assert(errno == 0); + + p = rtems_malloc(1); + rtems_test_assert(p != NULL); + + free(p); +} + +static void test_rtems_calloc(void) +{ + void *p; + int *i; + + p = rtems_calloc(0, 0); + rtems_test_assert(p == NULL); + + p = rtems_calloc(0, 1); + rtems_test_assert(p == NULL); + + p = rtems_calloc(1, 0); + rtems_test_assert(p == NULL); + + errno = 0; + p = rtems_calloc(1, SIZE_MAX / 2); + rtems_test_assert(p == NULL); + rtems_test_assert(errno == 0); + + errno = 0; + p = rtems_calloc(SIZE_MAX / 2, 1); + rtems_test_assert(p == NULL); + rtems_test_assert(errno == 0); + + i = rtems_calloc(1, sizeof(*i)); + rtems_test_assert(i != NULL); + rtems_test_assert(*i == 0); + + free(i); +} + static void test_heap_size_with_overhead(void) { uintptr_t s; @@ -1296,6 +1345,8 @@ rtems_task Init( test_heap_size_with_overhead(); test_protected_heap_info(); test_rtems_heap_allocate_aligned_with_boundary(); + test_rtems_malloc(); + test_rtems_calloc(); test_greedy_allocate(); test_posix_memalign(); |