[PATCH 5/5] libmm test cases

Hesham AL-Matary heshamelmatary at gmail.com
Mon Aug 26 00:14:55 UTC 2013


---
 testsuites/libtests/Makefile.am         |  3 +-
 testsuites/libtests/configure.ac        |  2 +
 testsuites/libtests/mmtest1/Makefile.am | 18 ++++++++
 testsuites/libtests/mmtest1/init.c      | 62 ++++++++++++++++++++++++++++
 testsuites/libtests/mmtest1/mmtest1.doc |  1 +
 testsuites/libtests/mmtest1/mmtests.scn |  9 ++++
 testsuites/libtests/mmtest1/system.h    | 33 +++++++++++++++
 testsuites/libtests/mmtest2/Makefile.am | 17 ++++++++
 testsuites/libtests/mmtest2/init.c      | 73 +++++++++++++++++++++++++++++++++
 testsuites/libtests/mmtest2/mmtest2.doc |  7 ++++
 testsuites/libtests/mmtest2/mmtests.scn | 15 +++++++
 testsuites/libtests/mmtest2/system.h    | 32 +++++++++++++++
 12 files changed, 271 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..9e966ba
--- /dev/null
+++ b/testsuites/libtests/mmtest1/init.c
@@ -0,0 +1,62 @@
+/* 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 __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#define CONFIGURE_INIT
+#include "system.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <rtems/score/mm.h>
+
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  size_t size = 0x001000; 
+  uintptr_t *region1 = _Workspace_Allocate(size);
+  uintptr_t *region2 = _Workspace_Allocate(size);
+
+  puts( "\n\n*** Start of mmtest1 ***\n" );
+
+  if (region1 != NULL)
+  {
+    printf("Region 1 successfully allocated from Work Space at address 0x%x \n", \
+region1);
+  } else 
+  {
+    printf("Failed to allocate memory for Region 1 from Work Space ! \n");
+    exit(0);
+  }
+
+  if (region2 != NULL)
+  {
+    printf("Region 2 successfully allocated from Work Space at address 0x%x \n", \
+ region2);
+  } else
+  {
+    printf("Failed to allocate memory for Region 2 from Work Space ! \n");
+    exit(0);
+  }
+
+  printf("Test 1: Set Region1 as read only\n");
+  _Memory_management_Set_attributes( region1, size, RTEMS_MM_REGION_PROTECTION_READ_ONLY);
+
+  printf("Test 2 : Set Region2 as write enabled\n");
+  _Memory_management_Set_attributes( region2, size, RTEMS_MM_REGION_PROTECTION_WRITE);
+
+  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..45ccd6f
--- /dev/null
+++ b/testsuites/libtests/mmtest1/mmtests.scn
@@ -0,0 +1,9 @@
+*** Start of mmtest1 ***
+
+Region 1 successfully allocated from Work Space at address 0x106e20 
+Region 2 successfully allocated from Work Space at address 0x107e28 
+Test 1: Set Region1 as read only
+Test 2 : Set Region2 as write enabled
+
+
+*** End of mmtest1 ***
diff --git a/testsuites/libtests/mmtest1/system.h b/testsuites/libtests/mmtest1/system.h
new file mode 100644
index 0000000..7560e1d
--- /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            9
+
+#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..76612b1
--- /dev/null
+++ b/testsuites/libtests/mmtest2/init.c
@@ -0,0 +1,73 @@
+/* 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 __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#define CONFIGURE_INIT
+#include "system.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <rtems/score/mm.h>
+
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  uint32_t *a1;
+  uint32_t *a2;
+  uint32_t a;
+  size_t size = 0x00100000;
+
+  uint32_t *region1 = (uint32_t *) 0x0C000000U;
+  uint32_t *region2 = (uint32_t *) 0x0C100000U;
+
+  puts( "\n\n*** Start of mmtest2 ***\n" );
+
+  printf("Test 1: set Region1  as read only\n");
+  _Memory_management_Set_attributes( region1, size, RTEMS_MM_REGION_PROTECTION_READ_ONLY);
+
+  printf("Test 2: set Region2  as write enabled\n");
+  _Memory_management_Set_attributes( region2, size, RTEMS_MM_REGION_PROTECTION_WRITE);
+
+  // TODO: Make fatal tests withing exception handler */
+  /* FIXME: make addresses target-independent */
+
+  a1 = region2;
+  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++;
+
+  a1 = 0xffffffffU;
+  printf("Checking MMU exception 2: Write to Unmapped block\n");
+  *a1++ = 0xCC;
+
+  // this one isn't an exception.
+  a2 = (char *) region1;
+  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("Test 6: set region2 with no access attributes \n");
+  _Memory_management_Set_attributes(region2, size, RTEMS_MM_REGION_NO_ACCESS);
+  
+  a1 = (char *) region2;
+  printf("Checking MMU exception 6: Write to uninstalled block \n");
+  *a1 = 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..3a92922
--- /dev/null
+++ b/testsuites/libtests/mmtest2/mmtests.scn
@@ -0,0 +1,15 @@
+*** Start of mmtest2 ***
+Region 1 successfully allocated from Work Space at address 0x106f80 
+Region 2 successfully allocated from Work Space at address 0x106f80 
+Test 1: set Region1  as read only
+Test 2: set Region2  as write enabled
+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  
+Test 6: set region2 with no access attributes 
+Checking MMU exception 6: Write to uninstalled block 
+
+
+*** End of mmtest2 ***
diff --git a/testsuites/libtests/mmtest2/system.h b/testsuites/libtests/mmtest2/system.h
new file mode 100644
index 0000000..8543c9c
--- /dev/null
+++ b/testsuites/libtests/mmtest2/system.h
@@ -0,0 +1,32 @@
+/* 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            9
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
+
+#include <rtems/confdefs.h>
+/* end of include file */
-- 
1.8.3.1




More information about the devel mailing list