[PATCH 2/4] testsuites: add test cases for libmm

Gedare Bloom gedare at rtems.org
Thu Oct 11 19:10:21 UTC 2012


From: Hesham AL-Matary <heshamelmatary at gmail.com>

---
 testsuites/libtests/Makefile.am         |    1 +
 testsuites/libtests/configure.ac        |    2 +
 testsuites/libtests/mmtest1/Makefile.am |   17 +++
 testsuites/libtests/mmtest1/init.c      |  215 +++++++++++++++++++++++++++++++
 testsuites/libtests/mmtest1/mmtests.scn |   30 +++++
 testsuites/libtests/mmtest1/system.h    |   39 ++++++
 testsuites/libtests/mmtest2/Makefile.am |   17 +++
 testsuites/libtests/mmtest2/init.c      |  148 +++++++++++++++++++++
 testsuites/libtests/mmtest2/mmtest2.scn |   24 ++++
 testsuites/libtests/mmtest2/system.h    |   38 ++++++
 10 files changed, 531 insertions(+), 0 deletions(-)
 create mode 100644 testsuites/libtests/mmtest1/Makefile.am
 create mode 100644 testsuites/libtests/mmtest1/init.c
 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.scn
 create mode 100644 testsuites/libtests/mmtest2/system.h

diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am
index 69f4e8d..583c575 100644
--- a/testsuites/libtests/Makefile.am
+++ b/testsuites/libtests/Makefile.am
@@ -17,6 +17,7 @@ SUBDIRS += bspcmdline01 cpuuse devfs01 devfs02 devfs03 devfs04 \
     block08 block09 block10 block11 block12 stringto01 \
     tar01 tar02 tar03 \
     math mathf mathl complex \
+		mmtest1 mmtest2 \
     mouse01
 
 if NETTESTS
diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac
index a29c7f8..1922912 100644
--- a/testsuites/libtests/configure.ac
+++ b/testsuites/libtests/configure.ac
@@ -47,6 +47,8 @@ block14/Makefile
 block13/Makefile
 rbheap01/Makefile
 syscall01/Makefile
+mmtest1/Makefile
+mmtest2/Makefile
 flashdisk01/Makefile
 block01/Makefile
 block02/Makefile
diff --git a/testsuites/libtests/mmtest1/Makefile.am b/testsuites/libtests/mmtest1/Makefile.am
new file mode 100644
index 0000000..65e1096
--- /dev/null
+++ b/testsuites/libtests/mmtest1/Makefile.am
@@ -0,0 +1,17 @@
+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..cc21754
--- /dev/null
+++ b/testsuites/libtests/mmtest1/init.c
@@ -0,0 +1,215 @@
+/*  Init
+ *
+ *  This routine is the initialization task for this test program.
+ *  It is called from init_exec and has the responsibility for creating
+ *  and starting the tasks that make up the test.  If the time of day
+ *  clock is required for the test, it should also be set to a known
+ *  value by this function.
+ *
+ *  Input parameters:  NONE
+ *
+ *  Output parameters:  NONE
+ *
+ *  COPYRIGHT (c) 1989-1999.
+ *  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.
+ *
+ */
+
+#define CONFIGURE_INIT
+#include "system.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <rtems/libmm.h>
+
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  rtems_status_code status;
+  uint32_t access;
+  size_t  blocksize;
+  int i;
+  unsigned char *a1;
+  unsigned char *a2;
+  char  *a;
+  void *alut_search_addr1;
+  void *alut_search_addr2;
+  rtems_memory_management_entry *mpe;
+
+  alut_search_addr1 = (char*) 0x00180000;
+  alut_search_addr2 = (char*) 0x01000000;
+
+  rtems_memory_management_region_descriptor r1 = {
+    .name = "Valid Entry-1",
+    .base = 0x00100000,
+    .size = 0x200000
+  };
+  rtems_memory_management_region_descriptor r2 = {
+    .name = "Valid Entry-2",
+    .base = 0x00400000,
+    .size = 0x100000
+  };
+
+  rtems_memory_management_region_descriptor r5 = {
+    .name = "Valid entry",
+    .base = 0x00600000,
+    .size = 0x100000
+  };
+  rtems_memory_management_region_descriptor r3 = {
+    .name = "faulty - size",
+    .base = 0x00500000,
+    .size = 0x00001001
+  };
+
+  rtems_memory_management_region_descriptor r4 = {
+    .name = "faulty - overlapping",
+    .base = 0x00100000,
+    .size = 0x00100000
+  };
+
+
+
+  puts( "\n\n*** LIBMM HIGH/MID LEVEL TEST BEGINS ***\n" );
+  puts( "initialize the memory protect manager\n");
+
+  rtems_memory_management_install_alut();
+
+  status = rtems_memory_management_initialize ( );
+
+  if(status != RTEMS_SUCCESSFUL)
+  {
+    printf("Failed:initialize the memory protect manager failed; status = %d\n",status);
+    exit(0);
+  }
+  printf("ALUT created\n");
+
+
+  printf("Test 1 : Adding entry with invalid block size\n");
+  status = rtems_memory_management_create_entry(r3, &mpe);
+  if(status == RTEMS_SUCCESSFUL){
+    printf("Failed : Invalid block size and still entry added\n");
+  }
+  else{
+    printf("Passed : Entry addition failed, status = %d\n",status);
+  }
+
+  printf("Test 2 : Adding entry with block size not a multiple of 2\n");
+  status = rtems_memory_management_create_entry(r3, &mpe);
+  if(status == RTEMS_SUCCESSFUL){
+    printf("Failed : Invalid block size and still entry successfully added\n");
+  }
+  else{
+    printf("Passed : Entry adding failed, status = %d\n",status);
+  }
+
+  printf("Test 3 : Adding valid Entry-1 into ALUT\n");
+  status = rtems_memory_management_create_entry(r1, &mpe);
+  if(status == RTEMS_SUCCESSFUL){
+    printf("Passed : Entry Added\n");
+  }
+  else{
+    printf("Failed : Entry addition failed, status = %d\n",status);
+  }
+
+  printf("Test 4 : Installing Entry-1 into HW\n");
+  status = rtems_memory_management_install_entry(mpe);
+
+  if(status == RTEMS_SUCCESSFUL){
+     printf("Passed : Installing Entry-1 into HW = %d\n",status);
+   }
+   else{
+     printf("Failed : to Install Entry-1 into HW = %d\n",status);
+   }
+
+  printf("Test 5 : Set Read only for installed Entry-1 permissions \n");
+  status = rtems_memory_management_set_read_only(mpe);
+
+  if(status == RTEMS_SUCCESSFUL){
+     printf("Passed : Set Read only permissions = %d\n",status);
+   }
+   else{
+     printf("Failed : to Set Read only permissions = %d\n",status);
+   }
+
+  printf("Test 6 : Adding overlapping  address value\n");
+  status = rtems_memory_management_create_entry(r4, &mpe);
+  if(status == RTEMS_SUCCESSFUL){
+    printf("Failed : Addition passed inspite of address overlap\n");
+  }
+  else{
+    printf("Passed : Successful detection of address overlap and ignored, status = %d\n",status);
+  }
+
+  printf("Test 7 : Adding another valid Entry-2\n");
+
+  status = rtems_memory_management_create_entry(r2, &mpe);
+  if(status == RTEMS_SUCCESSFUL){
+    printf("Passed : Entry-2 successfully added, status = %d\n",status);
+  }
+  else{
+    printf("Failed : Entry adding failed, status = %d\n",status);
+  }
+  printf("Test 8 : Installing Entry-2 into HW\n");
+  status = rtems_memory_management_install_entry(mpe);
+
+  if(status == RTEMS_SUCCESSFUL){
+     printf("Passed : Installing Entry into HW = %d\n",status);
+   }
+   else{
+     printf("Failed : to Install Entry into HW = %d\n",status);
+   }
+  status = rtems_memory_management_install_entry(mpe);
+
+  printf("Test 9 : Set Write permission for installed Entry-2 \n");
+  status = rtems_memory_management_set_write(mpe);
+
+  if(status == RTEMS_SUCCESSFUL){
+     printf("Passed : Set Write permissions = %d\n",status);
+   }
+   else{
+     printf("Failed : to Set Write permissions = %d\n",status);
+   }
+
+   /* Adding a new entry to alut when it's full */
+
+  printf("Test 10 : Adding an entry to a full alut \n");
+  status = rtems_memory_management_create_entry(r5, &mpe);
+  if(status == RTEMS_SUCCESSFUL){
+    printf("Failed : Entry-3 successfully added despite exceeding alut size, status = %d\n",status);
+  }
+  else{
+    printf("Passed : Entry adding failed because alut is full, status = %d\n",status);
+  }
+  /* Now that the ALUT is created and populated, start testing for
+   *  search operations over particular address values
+   */
+  printf("Test 11: Get access attributes for address 0x%x\n", alut_search_addr1);
+  status = rtems_memory_management_find_entry(alut_search_addr1, &mpe);
+  if(status != RTEMS_SUCCESSFUL){
+    printf("Failed : Cannot find the entry including this address in ALUT, status = %d\n",status);
+  }
+  status = rtems_memory_management_get_size(mpe,&blocksize);
+  if(status != RTEMS_SUCCESSFUL){
+    printf("Failed : Access Attribute not found, status = %d\n",status);
+  }
+  else {
+    printf("Passed : the size of the entry including the request address is 0x%x\n", blocksize);
+  }
+
+
+  printf("Test 12: Get attribute for unmapped address 0x%x\n", alut_search_addr2);
+  status = rtems_memory_management_find_entry(alut_search_addr2, &mpe);
+  if(status == RTEMS_SUCCESSFUL){
+    printf("Failed : Find the entry including this address in ALUT, status = %d\n",status);
+  }
+  else printf("Passed : Failed to find unmapped address in ALUT, status = %d\n",status);
+  printf(  "\n\n*** LIBMM HIGH/MID LEVEL TEST ENDS ***\n" );
+ 
+  a = (char *) 0x00100008;
+  *a = 5;
+  exit( 0 );
+}
diff --git a/testsuites/libtests/mmtest1/mmtests.scn b/testsuites/libtests/mmtest1/mmtests.scn
new file mode 100644
index 0000000..59a8dc3
--- /dev/null
+++ b/testsuites/libtests/mmtest1/mmtests.scn
@@ -0,0 +1,30 @@
+*** LIBMM HIGH/MID LEVEL TEST BEGINS ***
+
+initialize the memory protect manager
+
+ALUT created
+Test 1 : Adding entry with invalid block size
+Passed : Entry addition failed, status = 10
+Test 2 : Adding entry with block size not a multiple of 2
+Passed : Entry adding failed, status = 10
+Test 3 : Adding valid Entry-1 into ALUT
+Passed : Entry Added
+Test 4 : Installing Entry-1 into HW
+Passed : Installing Entry-1 into HW = 0
+Test 5 : Set Read only for installed Entry-1 permissions 
+Passed : Set Read only permissions = 0
+Test 6 : Adding overlapping  address value
+Passed : Successful detection of address overlap and ignored, status = 9
+Test 7 : Adding another valid Entry-2
+Failed : Entry adding failed, status = 9
+Test 8 : Installing Entry-2 into HW
+Passed : Installing Entry into HW = 0
+Test 9 : Set Write permission for installed Entry-2 
+Passed : Set Write permissions = 0
+Test 10: Get access attributes for address 0x18000
+Passed :the size of the entry including the request address is 0x200000
+Test 11: Get attribute for unmapped address 0x1000000
+Passed : Failed to find unmapped address in ALUT, status = 13
+
+
+*** LIBMM HIGH/MID LEVEL TEST ENDS ***
diff --git a/testsuites/libtests/mmtest1/system.h b/testsuites/libtests/mmtest1/system.h
new file mode 100644
index 0000000..2ddd985
--- /dev/null
+++ b/testsuites/libtests/mmtest1/system.h
@@ -0,0 +1,39 @@
+/*  system.h
+ *
+ *  This include file contains information that is included in every
+ *  function in the test set.
+ *
+ *  COPYRIGHT (c) 1989-1999.
+ *  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.
+ */
+
+#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
+#define CONFIGURE_LIBMM_ALUT_SIZE 2 
+
+#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..2d5cf13
--- /dev/null
+++ b/testsuites/libtests/mmtest2/init.c
@@ -0,0 +1,148 @@
+/*  Init
+ *
+ *  This routine is the initialization task for this test program.
+ *  It is called from init_exec and has the responsibility for creating
+ *  and starting the tasks that make up the test.  If the time of day
+ *  clock is required for the test, it should also be set to a known
+ *  value by this function.
+ *
+ *  Input parameters:  NONE
+ *
+ *  Output parameters:  NONE
+ *
+ *  COPYRIGHT (c) 1989-1999.
+ *  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.
+ *
+ */
+
+#define CONFIGURE_INIT
+#include "system.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <rtems/libmm.h>
+
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  rtems_status_code status;
+  uint32_t access;
+  size_t  blocksize;
+  int i;
+  unsigned char *a1;
+  unsigned char *a2;
+  char a;
+  void *alut_search_addr1;
+  void *alut_search_addr2;
+  rtems_memory_management_entry *mpe;
+
+  alut_search_addr1 = (char*) 0xffffffff;
+  alut_search_addr2 = (char*) 0x00100000;
+
+  rtems_memory_management_region_descriptor r1 = {
+    .name = "Valid Entry-1",
+    .base = 0x00100000,
+    .size = 0x200000
+  };
+  rtems_memory_management_region_descriptor r2 = {
+    .name = "Valid Entry-2",
+    .base = 0x00400000,
+    .size = 0x100000
+  };
+
+  puts( "\n\n*** LIBMM LOW LEVEL (BSP) TEST BEGINS ***\n" );
+  puts( "initialize the memory protect manager\n");
+
+  rtems_memory_management_install_alut();
+
+  status = rtems_memory_management_initialize ( );
+
+  if(status != RTEMS_SUCCESSFUL)
+  {
+    printf("Failed:initialize the memory protect manager failed; status = %d\n",status);
+    exit(0);
+  }
+  printf("ALUT created\n");
+
+  printf("Test 1 : Adding valid Entry-1 into ALUT\n");
+  status = rtems_memory_management_create_entry(r1, &mpe);
+  if(status == RTEMS_SUCCESSFUL){
+    printf("Passed : Entry Added\n");
+  }
+  else{
+    printf("Failed : Entry addition failed, status = %d\n",status);
+  }
+
+  printf("Test 2 : Installing Entry-1 into HW\n");
+  status = rtems_memory_management_install_entry(mpe);
+
+  if(status == RTEMS_SUCCESSFUL){
+     printf("Passed : Installing Entry-1 into HW = %d\n",status);
+   }
+   else{
+     printf("Failed : to Install Entry-1 into HW = %d\n",status);
+   }
+
+  printf("Test 3 : Set Read only for installed Entry-1 permissions \n");
+  status = rtems_memory_management_set_read_only(mpe);
+
+  if(status == RTEMS_SUCCESSFUL){
+     printf("Passed : Set Read only permissions = %d\n",status);
+   }
+   else{
+     printf("Failed : to Set Read only permissions = %d\n",status);
+   }
+
+  printf("Test 4 : Adding another valid Entry-2\n");
+
+  status = rtems_memory_management_create_entry(r2, &mpe);
+  if(status == RTEMS_SUCCESSFUL){
+    printf("Passed : Entry-2 successfully added, status = %d\n",status);
+  }
+  else{
+    printf("Failed : Entry adding failed, status = %d\n",status);
+  }
+  printf("Test 5 : Installing Entry-2 into HW\n");
+  status = rtems_memory_management_install_entry(mpe);
+
+  if(status == RTEMS_SUCCESSFUL){
+     printf("Passed : Installing Entry into HW = %d\n",status);
+   }
+   else{
+     printf("Failed : to Install Entry into HW = %d\n",status);
+   }
+  status = rtems_memory_management_install_entry(mpe);
+
+  printf("Test 6 : Set Write permission for installed Entry-2 \n");
+  status = rtems_memory_management_set_write(mpe);
+
+  if(status == RTEMS_SUCCESSFUL){
+     printf("Passed : Set Write permissions = %d\n",status);
+   }
+   else{
+     printf("Failed : to Set Write permissions = %d\n",status);
+   }
+
+  a1 = alut_search_addr2;
+  printf("Checking MMU exception 1:Read from Unmapped block\n");
+  a = *a1++;
+
+  a1 = alut_search_addr2 + 0x2000;
+  printf("Checking MMU exception 2: Write to Unmapped block\n");
+  //*a1++ = 0xCC;
+
+  // this one isn't an exception.
+  a2 = r1.base;
+  printf("Checking MMU exception 3: Read from readonly block\n");
+    a = *a2++;
+
+  printf("Checking MMU exception 4: Write to readonly block  \n");
+   *a2++ = 0xCC;
+
+  printf(  "\n\n*** LIBMM LOW LEVEL (BSP) TEST ENDS ***\n" );
+  exit( 0 );
+}
diff --git a/testsuites/libtests/mmtest2/mmtest2.scn b/testsuites/libtests/mmtest2/mmtest2.scn
new file mode 100644
index 0000000..9e459cf
--- /dev/null
+++ b/testsuites/libtests/mmtest2/mmtest2.scn
@@ -0,0 +1,24 @@
+*** LIBMM LOW LEVEL (BSP) TEST BEGINS ***
+
+initialize the memory protect manager
+
+ALUT created
+Test 1 : Adding valid Entry-1 into ALUT
+Passed : Entry Added
+Test 2 : Installing Entry-1 into HW
+Passed : Installing Entry-1 into HW = 0
+Test 3 : Set Read only for installed Entry-1 permissions 
+Passed : Set Read only permissions = 0
+Test 4 : Adding another valid Entry-2
+Passed : Entry-2 successfully added, status = 0
+Test 5 : Installing Entry-2 into HW
+Passed : Installing Entry into HW = 0
+Test 6 : Set Write permission for installed Entry-2 
+Passed : Set Write permissions = 0
+Checking MMU exception 1:Read from Unmapped block
+Checking MMU exception 2: Write to Unmapped block
+Checking MMU exception 3: Read from readonly block
+Checking MMU exception 4: Write to readonly block  
+
+
+*** LIBMM LOW LEVEL (BSP) TEST ENDS ***
diff --git a/testsuites/libtests/mmtest2/system.h b/testsuites/libtests/mmtest2/system.h
new file mode 100644
index 0000000..db04113
--- /dev/null
+++ b/testsuites/libtests/mmtest2/system.h
@@ -0,0 +1,38 @@
+/*  system.h
+ *
+ *  This include file contains information that is included in every
+ *  function in the test set.
+ *
+ *  COPYRIGHT (c) 1989-1999.
+ *  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.
+ */
+
+#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.7.1




More information about the devel mailing list