summaryrefslogtreecommitdiffstats
path: root/testsuites
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-02-25 09:02:43 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-02-25 11:35:54 +0100
commit9d1f39434585e8d3f8897d95a2bfe1ddccb79aec (patch)
tree2d3a0868f410cff137871f5ce493df4f27a22b1a /testsuites
parentmalloc: Use dedicated lock for deferred frees (diff)
downloadrtems-9d1f39434585e8d3f8897d95a2bfe1ddccb79aec.tar.bz2
malloc: Add _Malloc_System_state()
Replace malloc_is_system_state_OK() with _Malloc_System_state() to allow early allocations, e.g. in bsp_start(). Here the _Thread_Executing is NULL, thus an _API_Mutex_Lock() would lead to a NULL pointer access. Move malloc() support code to general case rtems_heap_allocate_aligned_with_boundary(). Use rtems_heap_allocate_aligned_with_boundary() to avoid duplicated code.
Diffstat (limited to 'testsuites')
-rw-r--r--testsuites/libtests/malloctest/init.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c
index 7e1728dbde..acf25d7cc5 100644
--- a/testsuites/libtests/malloctest/init.c
+++ b/testsuites/libtests/malloctest/init.c
@@ -2,7 +2,7 @@
* COPYRIGHT (c) 1989-2011, 2014.
* On-Line Applications Research Corporation (OAR).
*
- * Copyright (c) 2009, 2010 embedded brains GmbH.
+ * Copyright (c) 2009, 2016 embedded brains GmbH.
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -22,6 +22,7 @@
#include <errno.h>
#include <rtems/score/protectedheap.h>
#include <rtems/malloc.h>
+#include <rtems/sysinit.h>
const char rtems_test_name[] = "MALLOCTEST";
@@ -1369,3 +1370,27 @@ rtems_task Init(
status = rtems_task_delete( RTEMS_SELF );
directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
}
+
+static void test_early_malloc( void )
+{
+ void *p;
+ char *q;
+
+ p = malloc( 1 );
+ rtems_test_assert( p != NULL );
+
+ free( p );
+
+ q = calloc( 1, 1 );
+ rtems_test_assert( q != NULL );
+ rtems_test_assert( p != q );
+ rtems_test_assert( q[0] == 0 );
+
+ free( q );
+}
+
+RTEMS_SYSINIT_ITEM(
+ test_early_malloc,
+ RTEMS_SYSINIT_INITIAL_EXTENSIONS,
+ RTEMS_SYSINIT_ORDER_FIRST
+);