summaryrefslogtreecommitdiffstats
path: root/testsuites
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2010-08-25 13:05:47 +0000
committerSebastian Huber <sebastian.huber@embedded-brains.de>2010-08-25 13:05:47 +0000
commit5bb3197dfe47aed5a41fe5fb655f9601924bc44e (patch)
tree336186a8d781b14cbbfcfb42c8e42e5b5ecb0408 /testsuites
parentRegenerate. (diff)
downloadrtems-5bb3197dfe47aed5a41fe5fb655f9601924bc44e.tar.bz2
2010-08-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
* spheapprot/.cvsignore, spheapprot/Makefile.am, spheapprot/spheapprot.doc, spheapprot/spheapprot.scn: New files. * Makefile.am, configure.ac: Reflect changes above.
Diffstat (limited to 'testsuites')
-rw-r--r--testsuites/sptests/ChangeLog6
-rw-r--r--testsuites/sptests/Makefile.am2
-rw-r--r--testsuites/sptests/configure.ac1
-rw-r--r--testsuites/sptests/spheapprot/.cvsignore2
-rw-r--r--testsuites/sptests/spheapprot/Makefile.am27
-rw-r--r--testsuites/sptests/spheapprot/init.c143
-rw-r--r--testsuites/sptests/spheapprot/spheapprot.doc29
-rw-r--r--testsuites/sptests/spheapprot/spheapprot.scn2
8 files changed, 211 insertions, 1 deletions
diff --git a/testsuites/sptests/ChangeLog b/testsuites/sptests/ChangeLog
index 598d447169..dcb037e445 100644
--- a/testsuites/sptests/ChangeLog
+++ b/testsuites/sptests/ChangeLog
@@ -1,3 +1,9 @@
+2010-08-25 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * spheapprot/.cvsignore, spheapprot/Makefile.am,
+ spheapprot/spheapprot.doc, spheapprot/spheapprot.scn: New files.
+ * Makefile.am, configure.ac: Reflect changes above.
+
2010-08-24 Sebastian Huber <sebastian.huber@embedded-brains.de>
* spchain/init.c, spchain/spchain.doc, spchain/spchain.scn: New test
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index bfb5b0c527..90a6fd886d 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -28,7 +28,7 @@ SUBDIRS = \
spintrcritical05 spintrcritical06 spintrcritical07 spintrcritical08 \
spintrcritical09 spintrcritical10 spintrcritical11 spintrcritical12 \
spintrcritical13 spintrcritical14 spintrcritical15 spintrcritical16 \
- spintrcritical17 spmkdir spmountmgr01
+ spintrcritical17 spmkdir spmountmgr01 spheapprot
DIST_SUBDIRS = $(SUBDIRS) spfatal_support spintrcritical_support
EXTRA_DIST = spfatal_support/init.c spfatal_support/system.h
diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac
index c6cf40702b..1f7b10cfb4 100644
--- a/testsuites/sptests/configure.ac
+++ b/testsuites/sptests/configure.ac
@@ -151,6 +151,7 @@ spintrcritical14/Makefile
spintrcritical15/Makefile
spintrcritical16/Makefile
spintrcritical17/Makefile
+spheapprot/Makefile
spmkdir/Makefile
spmountmgr01/Makefile
spnotepad01/Makefile
diff --git a/testsuites/sptests/spheapprot/.cvsignore b/testsuites/sptests/spheapprot/.cvsignore
new file mode 100644
index 0000000000..282522db03
--- /dev/null
+++ b/testsuites/sptests/spheapprot/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/testsuites/sptests/spheapprot/Makefile.am b/testsuites/sptests/spheapprot/Makefile.am
new file mode 100644
index 0000000000..6cfe9c45c3
--- /dev/null
+++ b/testsuites/sptests/spheapprot/Makefile.am
@@ -0,0 +1,27 @@
+##
+## $Id$
+##
+
+MANAGERS = io semaphore event
+
+rtems_tests_PROGRAMS = spheapprot
+spheapprot_SOURCES = init.c
+
+dist_rtems_tests_DATA = spheapprot.scn spheapprot.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+spheapprot_LDADD = $(MANAGERS_NOT_WANTED:%=$(PROJECT_LIB)/no-%.rel)
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(spheapprot_OBJECTS) $(spheapprot_LDADD)
+LINK_LIBS = $(spheapprot_LDLIBS)
+
+spheapprot$(EXEEXT): $(spheapprot_OBJECTS) $(spheapprot_DEPENDENCIES)
+ @rm -f spheapprot$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/sptests/spheapprot/init.c b/testsuites/sptests/spheapprot/init.c
new file mode 100644
index 0000000000..c0f6cdda30
--- /dev/null
+++ b/testsuites/sptests/spheapprot/init.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2010 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+
+#include <rtems.h>
+
+#ifdef HEAP_PROTECTION
+ static void test_heap_block_error(Heap_Control *heap, Heap_Block *block)
+ {
+ bool *error = heap->Protection.handler_data;
+
+ *error = true;
+ }
+
+ static void test_heap_initialize(
+ Heap_Control *heap,
+ void *begin,
+ uintptr_t size,
+ bool *error
+ )
+ {
+ size = _Heap_Initialize(heap, begin, size, 0);
+ assert(size > 0);
+
+ heap->Protection.handler_data = error;
+ heap->Protection.block_error = test_heap_block_error;
+
+ *error = false;
+ }
+
+ static void test_heap_protection(void)
+ {
+ Heap_Control heap;
+ Heap_Block *block = NULL;
+ char area [512];
+ uintptr_t *p = NULL;
+ uintptr_t max_size = 0;
+ bool ok = false;
+ bool error = false;
+
+ /* Test double free */
+
+ test_heap_initialize(&heap, area, sizeof(area), &error);
+
+ max_size = heap.stats.free_size
+ - HEAP_BLOCK_HEADER_SIZE + HEAP_ALLOC_BONUS;
+
+ p = _Heap_Allocate(&heap, max_size);
+ assert(p != NULL);
+
+ ok = _Heap_Free(&heap, p);
+ assert(ok && !error);
+
+ ok = _Heap_Free(&heap, p);
+ assert(ok && error);
+
+ /* Test begin overwrite */
+
+ test_heap_initialize(&heap, area, sizeof(area), &error);
+
+ p = _Heap_Allocate(&heap, max_size);
+ assert(p != NULL);
+
+ *(p - 1) = 0;
+
+ ok = _Heap_Free(&heap, p);
+ assert(ok && error);
+
+ /* Test end overwrite */
+
+ test_heap_initialize(&heap, area, sizeof(area), &error);
+
+ p = _Heap_Allocate(&heap, max_size);
+ assert(p != NULL);
+
+ *(uintptr_t *)((char *) p + max_size) = 0;
+
+ ok = _Heap_Free(&heap, p);
+ assert(ok && error);
+
+ /* Test use after free */
+
+ test_heap_initialize(&heap, area, sizeof(area), &error);
+
+ p = _Heap_Allocate(&heap, max_size);
+ assert(p != NULL);
+
+ ok = _Heap_Free(&heap, p);
+ assert(ok && !error);
+
+ *p = 0;
+
+ block = _Heap_Block_of_alloc_area((uintptr_t) p, heap.page_size);
+ block->Protection_begin.next_delayed_free_block = HEAP_PROTECTION_OBOLUS;
+ ok = _Heap_Free(&heap, p);
+ assert(ok && error);
+ }
+#else
+ #define test_heap_protection() ((void) 0)
+#endif
+
+static rtems_task Init(rtems_task_argument argument)
+{
+ puts( "\n\n*** TEST HEAP PROTECTION ***" );
+
+ test_heap_protection();
+
+ puts( "*** END OF TEST HEAP PROTECTION ***" );
+
+ exit(0);
+}
+
+#define CONFIGURE_INIT
+
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
+#define CONFIGURE_MAXIMUM_TASKS 2
+#define CONFIGURE_MAXIMUM_DRIVERS 1
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/sptests/spheapprot/spheapprot.doc b/testsuites/sptests/spheapprot/spheapprot.doc
new file mode 100644
index 0000000000..366abc6137
--- /dev/null
+++ b/testsuites/sptests/spheapprot/spheapprot.doc
@@ -0,0 +1,29 @@
+#
+# Copyright (c) 2010 embedded brains GmbH. All rights reserved.
+#
+# embedded brains GmbH
+# Obere Lagerstr. 30
+# 82178 Puchheim
+# Germany
+# <rtems@embedded-brains.de>
+#
+# 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$
+#
+
+This file describes the directives and concepts tested by this test set.
+
+test set name: spheapprot
+
+directives:
+
+ _Heap_Initialize
+ _Heap_Allocate_aligned_with_boundary
+ _Heap_Free
+
+concepts:
+
++ Check if heap protection works.
diff --git a/testsuites/sptests/spheapprot/spheapprot.scn b/testsuites/sptests/spheapprot/spheapprot.scn
new file mode 100644
index 0000000000..824164dd4f
--- /dev/null
+++ b/testsuites/sptests/spheapprot/spheapprot.scn
@@ -0,0 +1,2 @@
+*** TEST HEAP PROTECTION ***
+*** END OF TEST HEAP PROTECTION ***