[PATCH 6/6] libmm-test-cases. mmtest1 defines some memory regions and call libmm API to apply attributes for these regions. mmtest2 defines memory regions with attributes, set it up, and trigger some exceptions that should result in a fatal error.

Hesham AL-Matary heshamelmatary at gmail.com
Thu Sep 12 06:59:33 UTC 2013


---
 testsuites/libtests/Makefile.am         |  3 +-
 testsuites/libtests/configure.ac        |  2 +
 testsuites/libtests/mmtest1/Makefile.am | 18 +++++++
 testsuites/libtests/mmtest1/init.c      | 45 ++++++++++++++++++
 testsuites/libtests/mmtest1/mmtest1.doc |  1 +
 testsuites/libtests/mmtest1/mmtests.scn |  7 +++
 testsuites/libtests/mmtest1/system.h    | 33 +++++++++++++
 testsuites/libtests/mmtest2/Makefile.am | 17 +++++++
 testsuites/libtests/mmtest2/init.c      | 83 +++++++++++++++++++++++++++++++++
 testsuites/libtests/mmtest2/mmtest2.doc |  7 +++
 testsuites/libtests/mmtest2/mmtests.scn | 12 +++++
 testsuites/libtests/mmtest2/system.h    | 39 ++++++++++++++++
 12 files changed, 266 insertions(+), 1 deletion(-)
 create mode 100644 testsuites/libtests/mmtest1/Makefile.am
 create mode 100644 testsuites/libtests/mmtest1/init.c
 create mode 100644 testsuites/libtests/mmtest1/mmtest1.doc
 create mode 100644 testsuites/libtests/mmtest1/mmtests.scn
 create mode 100644 testsuites/libtests/mmtest1/system.h
 create mode 100644 testsuites/libtests/mmtest2/Makefile.am
 create mode 100644 testsuites/libtests/mmtest2/init.c
 create mode 100644 testsuites/libtests/mmtest2/mmtest2.doc
 create mode 100644 testsuites/libtests/mmtest2/mmtests.scn
 create mode 100644 testsuites/libtests/mmtest2/system.h

diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am
index d1ffabc..00325ed 100644
--- a/testsuites/libtests/Makefile.am
+++ b/testsuites/libtests/Makefile.am
@@ -19,7 +19,8 @@ SUBDIRS += bspcmdline01 cpuuse devfs01 devfs02 devfs03 devfs04 \
     putenvtest monitor monitor02 rtmonuse stackchk stackchk01 \
     termios termios01 termios02 termios03 termios04 termios05 \
     termios06 termios07 termios08 \
-    rtems++ tztest block01 block02 block03 block04 block05 block06 block07 \
+    rtems++ tztest mmtest1 mmtest2 block01 block02 block03 \
+    block04 block05 block06 block07 \
     block08 block09 block10 block11 block12 stringto01 \
     tar01 tar02 tar03 \
     math mathf mathl complex \
diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac
index 741c603..6533071 100644
--- a/testsuites/libtests/configure.ac
+++ b/testsuites/libtests/configure.ac
@@ -85,6 +85,8 @@ malloc02/Makefile
 malloc03/Makefile
 malloc04/Makefile
 malloc05/Makefile
+mmtest1/Makefile
+mmtest2/Makefile
 monitor/Makefile
 monitor02/Makefile
 mouse01/Makefile
diff --git a/testsuites/libtests/mmtest1/Makefile.am b/testsuites/libtests/mmtest1/Makefile.am
new file mode 100644
index 0000000..a08e557
--- /dev/null
+++ b/testsuites/libtests/mmtest1/Makefile.am
@@ -0,0 +1,18 @@
+
+rtems_tests_PROGRAMS = mmtest1
+mmtest1_SOURCES = init.c system.h
+
+dist_rtems_tests_DATA = mmtests.scn
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+LINK_OBJS = $(mmtest1_OBJECTS) $(mmtest1_LDADD)
+LINK_LIBS = $(mmtest1_LDLIBS)
+
+mmtest1$(EXEEXT): $(mmtest1_OBJECTS) $(mmtest1_DEPENDENCIES)
+	  @rm -f mmtest1$(EXEEXT)
+	  $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/libtests/mmtest1/init.c b/testsuites/libtests/mmtest1/init.c
new file mode 100644
index 0000000..0f32a36
--- /dev/null
+++ b/testsuites/libtests/mmtest1/init.c
@@ -0,0 +1,45 @@
+/* Init
+ *
+ * This routine is the initialization task for this test program.
+ *
+ */
+
+/*
+ * Copyright (c) 2012-2013 Hesham Al-Matary.
+ * Copyright (c) 2013 Gedare Bloom.
+ *
+ * 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.
+ */
+
+#define CONFIGURE_INIT
+#include "system.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <rtems/score/mmimpl.h>
+
+#define BLOCK_SIZE  1024 * 1024 /* 1MB */
+#define BLOCK_COUNT 3
+
+char memory_pool [BLOCK_SIZE * BLOCK_COUNT];
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  size_t size = BLOCK_SIZE;
+  char *region1 = &memory_pool;
+  char *region2 = (((char *) &memory_pool) + (BLOCK_SIZE));
+
+  puts( "\n\n*** Start of mmtest1 ***\n" );
+
+  printf("Test 1 : Set Region1 as write enabled\n");
+  _Memory_management_Set_attributes( region1, size, RTEMS_MM_REGION_WRITE);
+
+  printf("Test 2: Set Region2 as read only\n");
+  _Memory_management_Set_attributes( region2, size, RTEMS_MM_REGION_READ);
+
+  printf( "\n\n*** End of mmtest1 ***\n" );
+
+  exit( 0 );
+}
diff --git a/testsuites/libtests/mmtest1/mmtest1.doc b/testsuites/libtests/mmtest1/mmtest1.doc
new file mode 100644
index 0000000..210a761
--- /dev/null
+++ b/testsuites/libtests/mmtest1/mmtest1.doc
@@ -0,0 +1 @@
+Simple tests that tries to install memory management entries.
diff --git a/testsuites/libtests/mmtest1/mmtests.scn b/testsuites/libtests/mmtest1/mmtests.scn
new file mode 100644
index 0000000..7c30720
--- /dev/null
+++ b/testsuites/libtests/mmtest1/mmtests.scn
@@ -0,0 +1,7 @@
+*** Start of mmtest1 ***
+
+Test 1 : Set Region1 as write enabled
+Test 2: Set Region2 as read only
+
+
+*** End of mmtest1 ***
diff --git a/testsuites/libtests/mmtest1/system.h b/testsuites/libtests/mmtest1/system.h
new file mode 100644
index 0000000..c71df69
--- /dev/null
+++ b/testsuites/libtests/mmtest1/system.h
@@ -0,0 +1,33 @@
+/* system.h
+ *
+ * Copyright (c) 2013 Gedare Bloom.
+ *
+ * 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.
+ */
+
+#include <rtems.h>
+
+/* functions */
+
+rtems_task Init(
+  rtems_task_argument argument
+);
+
+/* configuration information */
+
+#include <bsp.h> /* for device driver prototypes */
+
+/* NOTICE: the clock driver is explicitly disabled */
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1 
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
+
+#include <rtems/confdefs.h>
+/* end of include file */
diff --git a/testsuites/libtests/mmtest2/Makefile.am b/testsuites/libtests/mmtest2/Makefile.am
new file mode 100644
index 0000000..fc25fd9
--- /dev/null
+++ b/testsuites/libtests/mmtest2/Makefile.am
@@ -0,0 +1,17 @@
+rtems_tests_PROGRAMS = mmtest2
+mmtest2_SOURCES = init.c system.h
+
+dist_rtems_tests_DATA = mmtests.scn
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+LINK_OBJS = $(mmtest2_OBJECTS) $(mmtest2_LDADD)
+LINK_LIBS = $(mmtest2_LDLIBS)
+
+mmtest2$(EXEEXT): $(mmtest2_OBJECTS) $(mmtest2_DEPENDENCIES)
+	  @rm -f mmtest2$(EXEEXT)
+	  $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/libtests/mmtest2/init.c b/testsuites/libtests/mmtest2/init.c
new file mode 100644
index 0000000..4c834c3
--- /dev/null
+++ b/testsuites/libtests/mmtest2/init.c
@@ -0,0 +1,83 @@
+/* Init
+ *
+ * This routine is the initialization task for this test program.
+ */
+
+/*
+ * Copyright (c) 2012-2013 Hesham Al-Matary.
+ * Copyright (c) 2013 Gedare Bloom.
+ *
+ * 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.
+ */
+#define CONFIGURE_INIT
+
+#include "system.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <rtems/score/mmimpl.h>
+#include <assert.h>
+
+#define BLOCK_SIZE  1024 * 1024 /* 1MB */
+#define BLOCK_COUNT 3
+
+char memory_pool [BLOCK_SIZE * BLOCK_COUNT];
+
+void fatal_extension(
+  rtems_fatal_source source,
+  bool is_internal,
+  rtems_fatal_code error
+)
+{
+  if (source == RTEMS_FATAL_SOURCE_EXCEPTION)
+     {
+	printk("Internal Exception Occured \n");
+     }
+
+  exit(0);
+}
+
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  char *a1;
+  char *a2;
+  char a;
+  size_t size = BLOCK_SIZE;
+
+  char *region1 = &memory_pool;
+  char *region2 = (((char *) &memory_pool) + (BLOCK_SIZE));
+
+  puts( "\n\n*** Start of mmtest2 ***\n" );
+
+  printf("Region1 starts at 0x%x \nRegion 2 starts at 0x%x\n",region1, region2);
+  printf("Test 1: set Region1  as write enabled\n");
+  _Memory_management_Set_attributes(region1, size, RTEMS_MM_REGION_WRITE);
+
+  printf("Test 2: set Region2  as read only\n");
+  _Memory_management_Set_attributes(region2, size, RTEMS_MM_REGION_READ);
+
+  a1 = region1;
+  printf("Test 3: Write to write enabled block\n");
+  *a1 = 0xCC;
+
+  a1 = (char *)0xffffffffU;
+  printf("Checking MMU exception 1: Read from Unmapped block\n");
+  a = *a1++;
+
+  printf("Checking MMU exception 2: Write to Unmapped block\n");
+  *a1++ = 0xCC;
+
+  // this one isn't an exception.
+  a2 = (char *) region2;
+  printf("Checking MMU exception 4: Read from readonly block\n");
+  a = *a2++;
+
+  printf("Checking MMU exception 5: Write to readonly block  \n");
+  *a2++ = 0xCC;
+
+  printf(  "\n\n*** End of mmtest2 ***\n" );
+  exit( 0 );
+}
diff --git a/testsuites/libtests/mmtest2/mmtest2.doc b/testsuites/libtests/mmtest2/mmtest2.doc
new file mode 100644
index 0000000..b2ec16c
--- /dev/null
+++ b/testsuites/libtests/mmtest2/mmtest2.doc
@@ -0,0 +1,7 @@
+This test case try to do the following : 
+
+Install entries with specific memory attributes (e.g read only region).
+Check for memory protection violations (writing to read only blocks).
+Reading from read only blocks.
+Write/Read to/from unmapped region (error!).
+Write to a valid entry that was installed and then uninstalled (error!).
diff --git a/testsuites/libtests/mmtest2/mmtests.scn b/testsuites/libtests/mmtest2/mmtests.scn
new file mode 100644
index 0000000..d9f9b23
--- /dev/null
+++ b/testsuites/libtests/mmtest2/mmtests.scn
@@ -0,0 +1,12 @@
+tart of mmtest2 ***
+
+Region1 starts at 0xXXXXX 
+Region 2 starts at 0xXXXXX
+Test 1: set Region1  as write enabled
+Test 2: set Region2  as read only
+Test 3: Write to write enabled block
+Checking MMU exception 1: Read from Unmapped block
+Checking MMU exception 2: Write to Unmapped block
+Checking MMU exception 4: Read from readonly block
+Checking MMU exception 5: Write to readonly block  
+Internal Exception Occured
diff --git a/testsuites/libtests/mmtest2/system.h b/testsuites/libtests/mmtest2/system.h
new file mode 100644
index 0000000..5fddcf4
--- /dev/null
+++ b/testsuites/libtests/mmtest2/system.h
@@ -0,0 +1,39 @@
+/* system.h
+ *
+ * COPYRIGHT (c) 2013 Gedare Bloom.
+ *
+ * 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.
+ */
+
+#include <rtems.h>
+
+/* functions */
+rtems_task Init(
+  rtems_task_argument argument
+);
+
+static void fatal_extension(
+  rtems_fatal_source source,
+  bool is_internal,
+  rtems_fatal_code error
+);
+/* configuration information */
+
+#include <bsp.h> /* for device driver prototypes */
+
+/* NOTICE: the clock driver is explicitly disabled */
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1 
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
+
+#define CONFIGURE_INITIAL_EXTENSIONS { .fatal = fatal_extension }
+
+#include <rtems/confdefs.h>
+/* end of include file */
-- 
1.8.3.1




More information about the devel mailing list