summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests/malloc04/init.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2010-07-08 20:11:48 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2010-07-08 20:11:48 +0000
commit843ad7b5ffae3626d7097ba121c7af915556e7a4 (patch)
treead34a68750b4e795ab3a56d472722f50826e6a57 /testsuites/libtests/malloc04/init.c
parent2010-07-08 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-843ad7b5ffae3626d7097ba121c7af915556e7a4.tar.bz2
2010-07-08 Joel Sherrill <joel.sherrill@oarcorp.com>
* Makefile.am, configure.ac: Add test for exercising sbrk() extension to Malloc Family. * malloc04/.cvsignore, malloc04/Makefile.am, malloc04/init.c, malloc04/malloc04.doc, malloc04/malloc04.scn: New files.
Diffstat (limited to 'testsuites/libtests/malloc04/init.c')
-rw-r--r--testsuites/libtests/malloc04/init.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/testsuites/libtests/malloc04/init.c b/testsuites/libtests/malloc04/init.c
new file mode 100644
index 0000000000..17ece56980
--- /dev/null
+++ b/testsuites/libtests/malloc04/init.c
@@ -0,0 +1,121 @@
+/*
+ * COPYRIGHT (c) 1989-2010.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <tmacros.h>
+#include "test_support.h"
+#include <rtems/libcsupport.h>
+#include <rtems/malloc.h>
+
+char Malloc_Heap[ 128 ] CPU_STRUCTURE_ALIGNMENT;
+int sbrk_count;
+Heap_Control Heap_Holder;
+
+/* Heap variables we need to peek and poke at */
+extern Heap_Control *RTEMS_Malloc_Heap;
+extern size_t RTEMS_Malloc_Sbrk_amount;
+extern rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers;
+extern rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table;
+
+size_t offset;
+void * sbrk(ptrdiff_t incr)
+{
+ void *p = (void *) -1;
+
+ printf( "sbrk(%td)\n", incr );
+ if ( offset + incr < sizeof(Malloc_Heap) ) {
+ p = &Malloc_Heap[ offset ];
+ offset += incr;
+ } else {
+ if ( sbrk_count == 0 )
+ p = (void *) rtems_task_create;
+ sbrk_count++;
+ }
+
+ sbrk_count++;
+ return p;
+}
+
+rtems_task Init(
+ rtems_task_argument argument
+)
+{
+ void *p1, *p2, *p3, *p4;
+
+ sbrk_count = 0;
+ offset = 0;
+
+ puts( "\n\n*** TEST MALLOC 04 ***" );
+
+ /* Safe information on real heap */
+ Heap_Holder = *RTEMS_Malloc_Heap;
+ rtems_malloc_sbrk_helpers = &rtems_malloc_sbrk_helpers_table;
+
+ puts( "Initialize heap with some memory" );
+ offset = 64;
+ sbrk_count = 0;
+ RTEMS_Malloc_Initialize( Malloc_Heap, 64, 64 );
+ p1 = malloc(64);
+ p2 = malloc(64);
+ p3 = malloc(48);
+ p4 = malloc(48);
+
+ puts( "Initialize heap with some unaligned memory" );
+ offset = 65;
+ sbrk_count = 0;
+ RTEMS_Malloc_Initialize( &Malloc_Heap[1], 64, 64 );
+ p1 = malloc(64);
+ p2 = malloc(64);
+ p3 = malloc(48);
+
+ puts( "Initialize heap with no memory (sbrk aligned)" );
+ offset = 7;
+ sbrk_count = 0;
+ RTEMS_Malloc_Initialize( NULL, 0, 64 );
+ p1 = malloc(64);
+ p2 = malloc(64);
+ p3 = malloc(48);
+ p4 = malloc(48);
+
+ puts( "Initialize heap with no memory (sbrk aligned)" );
+ offset = 0;
+ sbrk_count = 0;
+ RTEMS_Malloc_Initialize( NULL, 0, 64 );
+ p1 = malloc(64);
+
+ puts( "Set sbrk amount in heap to 0" );
+ offset = 0;
+ sbrk_count = 0;
+ RTEMS_Malloc_Initialize( NULL, 0, 64 );
+ RTEMS_Malloc_Sbrk_amount = 0;
+ p4 = malloc(48);
+
+ /* Restore information on real heap */
+ *RTEMS_Malloc_Heap = Heap_Holder;
+ rtems_malloc_sbrk_helpers = NULL;
+
+
+ puts( "*** END OF TEST MALLOC 04 ***" );
+
+ rtems_test_exit(0);
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+/* end of file */