[rtems commit] sptests/sprmsched01: Merge and fix

Sebastian Huber sebh at rtems.org
Tue Jan 24 14:37:20 UTC 2017


Module:    rtems
Branch:    master
Commit:    29e08d41f42d68fdafba982061ea7a3d57f75731
Changeset: http://git.rtems.org/rtems/commit/?id=29e08d41f42d68fdafba982061ea7a3d57f75731

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Jan 24 15:34:47 2017 +0100

sptests/sprmsched01: Merge and fix

Merge into one file and fix obvious problems (e.g. out of bounds array
access).

Update #2795.

---

 testsuites/sptests/sprmsched01/Makefile.am |   2 +-
 testsuites/sptests/sprmsched01/init.c      | 133 ++++++++++++++++++++++++-----
 testsuites/sptests/sprmsched01/system.h    |  61 -------------
 testsuites/sptests/sprmsched01/tasks.c     | 112 ------------------------
 4 files changed, 112 insertions(+), 196 deletions(-)

diff --git a/testsuites/sptests/sprmsched01/Makefile.am b/testsuites/sptests/sprmsched01/Makefile.am
index 62d39c8..068bb19 100644
--- a/testsuites/sptests/sprmsched01/Makefile.am
+++ b/testsuites/sptests/sprmsched01/Makefile.am
@@ -1,6 +1,6 @@
 
 rtems_tests_PROGRAMS = sprmsched01
-sprmsched01_SOURCES = init.c tasks.c system.h
+sprmsched01_SOURCES = init.c
 	
 dist_rtems_tests_DATA = sprmsched01.scn
 dist_rtems_tests_DATA += sprmsched01.doc
diff --git a/testsuites/sptests/sprmsched01/init.c b/testsuites/sptests/sprmsched01/init.c
index f353191..2332920 100644
--- a/testsuites/sptests/sprmsched01/init.c
+++ b/testsuites/sptests/sprmsched01/init.c
@@ -1,7 +1,21 @@
 /**
- * @file sprmsched01/init.c
+ * @brief A heuristic example to demonstrate how the postponed jobs are handled.
  *
- * @brief A init task body for sprmsched01 example.
+ * Given two tasks with implicit deadline under fixed-priority scheudling.
+ * Task 1 has (6, 10) and task 2 has (1, 2), where (execution time, deadline/period).
+ * To force deadline misses, we reverse the rate-monotonic priority assignment
+ * and only execute the highest priority task twice.
+ *
+ * In the original implementation in v4.11, no matter how many periods are
+ * expired, RMS manager only releases a job with a shifted deadline assignment
+ * in the watchdog. As the results written in sprmsched01.scn, we can see that
+ * the timeout of task 2 period will be detected right after Job3 of Task2 is finished.
+ * If the overrun handling is correct, the status of task 2 period will return back to
+ * RTEMS_SUCCESSFUL after periodically releasing those postponed jobs (the last one is Job 9).
+ *
+ * Otherwise, we can see that the release time of Job 4 is no longer periodic,
+ * and the RTEMS returns back to RTEMS_SUCCESSFUL right after Job 4 is finished
+ * without releasing all the other postponed jobs.
  *
  */
 
@@ -17,24 +31,89 @@
 #include "config.h"
 #endif
 
-#define CONFIGURE_INIT
-#include "system.h"
+#include <rtems/cpuuse.h>
+#include <rtems/counter.h>
+
+#include <stdio.h>
+#include <inttypes.h>
+
+#include "tmacros.h"
+
+const char rtems_test_name[] = "SPRMSCHED 1";
+
+static const uint32_t Periods[] = { 10000, 2000 };
+static const uint32_t Iterations[] = { 6000, 1000 };
+static const rtems_name Task_name[] = {
+  rtems_build_name( 'T', 'A', '1', ' ' ),
+  rtems_build_name( 'T', 'A', '2', ' ' )
+};
+static const rtems_task_priority Prio[3] = { 2, 5 };
+static const uint32_t testnumber = 11; /* stop condition */
+
+static uint32_t tsk_counter[] = { 0, 0 };
+static rtems_id   Task_id[ 2 ];
+
+/**
+ * @brief Task body
+ */
+static rtems_task Task(
+  rtems_task_argument argument
+)
+{
+  rtems_status_code status;
+  rtems_id    RM_period;
+  rtems_id    selfid=rtems_task_self();
+  uint32_t    start, end, flag=0, index;
+  rtems_counter_ticks t0;
 
-#include <rtems/rtems/tasksimpl.h>
-#include <rtems/test.h>
-#include <rtems/status-checks.h>
+  t0 = rtems_counter_nanoseconds_to_ticks( 1000000 ); //1ms ticks counter
+  /*create period*/
+  status = rtems_rate_monotonic_create( Task_name[ argument ], &RM_period );
+  directive_failed( status, "rtems_rate_monotonic_create" );
 
-const char rtems_test_name[] = "Rate Monotonic 01 - Overrun Test";
+  while ( FOREVER ) {
+    status = rtems_rate_monotonic_period( RM_period, Periods[ argument ] );
+    //directive_failed( status, "rtems_rate_monotonic_period" ); let TIMEOUT pass
+    if( argument == 1 && flag == 0 && status == RTEMS_TIMEOUT ){
+      flag = 1;
+      printf( "RTEMS_TIMEOUT\n" );
+    } else if ( flag == 1 && status == RTEMS_SUCCESSFUL ) {
+      flag = 0;
+      printf( "RTEMS_SUCCESSFUL\n" );
+    }
 
-/* Global variables */
-rtems_id   Task_id[ 2 ];         /* array of task ids */
-rtems_name Task_name[ 2 ];       /* array of task names */
-uint32_t tick_per_second;        /* time reference */
-int testnumber = 11;                  /* stop condition */
+    start = rtems_clock_get_ticks_since_boot();
+    if ( argument == 1 )
+      printf( "Job %" PRIu32 " Task %" PRIuPTR " starts at tick %" PRIu32 ".\n", tsk_counter[ argument ]+1, argument, start );
+    else
+      printf( "Task %" PRIuPTR " starts at tick %" PRIu32 ".\n", argument, start );
+    for( index = 0; index < Iterations[ argument ]; index++ ){
+      rtems_counter_delay_ticks( t0 );
+    }
+    end = rtems_clock_get_ticks_since_boot();
+    printf( "					Job %" PRIu32" Task %" PRIuPTR " ends at tick %" PRIu32".\n", tsk_counter[ argument ]+1, argument, end );
+    if( argument == 1 ){
+      if( tsk_counter[ argument ] == testnumber ){
+        TEST_END();
+        status = rtems_rate_monotonic_delete( RM_period );
+        directive_failed( status, "rtems_rate_monotonic_delete" );
+        rtems_test_exit( 0 );
+      }
+    }
 
-rtems_task_priority Prio[3] = { 0, 2, 5 };
+    tsk_counter[ argument ]+=1;
+    if ( argument == 0 ){
+      if( tsk_counter[ argument ] == 2 ){
+        status = rtems_rate_monotonic_delete( RM_period );
+        directive_failed( status, "rtems_rate_monotonic_delete" );
+        status = rtems_task_delete( selfid );
+        directive_failed( status, "rtems_task_delete" );
+      }
+    }
+  }
+}
 
-rtems_task Init(
+static rtems_task Init(
 	rtems_task_argument argument
 )
 {
@@ -43,14 +122,10 @@ rtems_task Init(
 
   TEST_BEGIN();
 
-  tick_per_second = rtems_clock_get_ticks_per_second();
-  printf( "\nTicks per second in your system: %" PRIu32 "\n", tick_per_second );
-
-  Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
-  Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' );
+  printf( "\nTicks per second in your system: %" PRIu32 "\n", rtems_clock_get_ticks_per_second() );
 
   /* Create two tasks */
-  for ( index = 1; index <= 2; index++ ){
+  for ( index = 0; index < RTEMS_ARRAY_SIZE(Task_name); ++index ){
     status = rtems_task_create(
       Task_name[ index ], Prio[index], RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES,
       RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ index ]
@@ -60,7 +135,7 @@ rtems_task Init(
 
 
   /* After creating the periods for tasks, start to run them sequencially. */
-  for ( index = 1; index <= 2; index++ ){
+  for ( index = 0; index < RTEMS_ARRAY_SIZE(Task_name); ++index ){
     status = rtems_task_start( Task_id[ index ], Task, index);
     directive_failed( status, "rtems_task_start loop");
   }
@@ -68,3 +143,17 @@ rtems_task Init(
   directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
 }
 
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_MICROSECONDS_PER_TICK     1000
+#define CONFIGURE_MAXIMUM_TASKS             3
+#define CONFIGURE_MAXIMUM_PERIODS           2
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INITIAL_EXTENSIONS \
+  RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/sptests/sprmsched01/system.h b/testsuites/sptests/sprmsched01/system.h
deleted file mode 100644
index 14a9544..0000000
--- a/testsuites/sptests/sprmsched01/system.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * @file sprmsched01/system.h
- *
- * @brief sprmsched01 example header
- */
-
-/*
- *  COPYRIGHT (c) 1989-2007.
- *  On-Line Applications Research Corporation (OAR).
- *
- *  COPYRIGHT (c) 2016 Kuan-Hsun Chen.
- *
- *  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 <inttypes.h>
-#include <rtems.h>
-
-#include <tmacros.h>
-
-/* function prototypes */
-
-rtems_task Init(
-  rtems_task_argument argument
-);
-
-rtems_task Task(
-  rtems_task_argument argument
-);
-
-
-/*
- *  Keep the names and IDs in global variables so another task can use them.
- */
-
-extern rtems_id   Task_id[ 2 ];         /* array of task ids */
-extern rtems_name Task_name[ 2 ];       /* array of task names */
-extern uint32_t tick_per_second;        /* time reference */
-extern int testnumber;                  /* stop condition */
-
-/* configuration information */
-
-#include <bsp.h> /* for device driver prototypes */
-
-#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
-#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
-#define CONFIGURE_MICROSECONDS_PER_TICK     1000   // NB: 10 and lower gives system failure for erc32 simulator
-#define CONFIGURE_MAXIMUM_TASKS             3
-#define CONFIGURE_MAXIMUM_SEMAPHORES        1
-#define CONFIGURE_MAXIMUM_PRIORITY          15
-#define CONFIGURE_EXTRA_TASK_STACKS         (20 * RTEMS_MINIMUM_STACK_SIZE)
-#define CONFIGURE_MAXIMUM_PERIODS           3
-
-#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
-
-#include <rtems/confdefs.h>
-
-/* end of include file */
diff --git a/testsuites/sptests/sprmsched01/tasks.c b/testsuites/sptests/sprmsched01/tasks.c
deleted file mode 100644
index 82bfd99..0000000
--- a/testsuites/sptests/sprmsched01/tasks.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * @file sprmsched01/tasks.c
- *
- * @brief A heuristic example to demonstrate how the postponed jobs are handled.
- *
- * Given two tasks with implicit deadline under fixed-priority scheudling.
- * Task 1 has (6, 10) and task 2 has (1, 2), where (execution time, deadline/period).
- * To force deadline misses, we reverse the rate-monotonic priority assignment
- * and only execute the highest priority task twice.
- *
- * In the original implementation in v4.11, no matter how many periods are
- * expired, RMS manager only releases a job with a shifted deadline assignment
- * in the watchdog. As the results written in sprmsched01.scn, we can see that
- * the timeout of task 2 period will be detected right after Job3 of Task2 is finished.
- * If the overrun handling is correct, the status of task 2 period will return back to
- * RTEMS_SUCCESSFUL after periodically releasing those postponed jobs (the last one is Job 9).
- *
- * Otherwise, we can see that the release time of Job 4 is no longer periodic,
- * and the RTEMS returns back to RTEMS_SUCCESSFUL right after Job 4 is finished
- * without releasing all the other postponed jobs.
- *
- */
-
-/*
- *  COPYRIGHT (c) 2016 Kuan-Hsun Chen.
- *
- *  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.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "system.h"
-
-/* CPU usage and Rate monotonic manger statistics */
-#include "rtems/cpuuse.h"
-#include "rtems/counter.h"
-
-/* Periods for the various tasks [ticks] */
-uint32_t Periods[3] = { 0, 10000, 2000 };
-uint32_t Iterations[3] = { 0, 6000, 1000 };
-uint32_t tsk_counter[3] = { 0, 0, 0 };
-
-/**
- * @brief Task body
- */
-rtems_task Task(
-  rtems_task_argument argument
-)
-{
-  rtems_status_code status;
-  rtems_id    RM_period;
-  rtems_id    selfid=rtems_task_self();
-  uint32_t    start, end, flag=0, index;
-  rtems_counter_ticks t0;
-
-  t0 = rtems_counter_nanoseconds_to_ticks( 1000000 ); //1ms ticks counter
-  /*create period*/
-  status = rtems_rate_monotonic_create( argument, &RM_period );
-  directive_failed( status, "rtems_rate_monotonic_create" );
-
-  switch ( argument ) {
-    case 1:
-    case 2:
-      while ( FOREVER ) {
-        status = rtems_rate_monotonic_period( RM_period, Periods[ argument ] );
-        //directive_failed( status, "rtems_rate_monotonic_period" ); let TIMEOUT pass
-        if( argument == 2 && flag == 0 && status == RTEMS_TIMEOUT ){
-          flag = 1;
-          printf( "RTEMS_TIMEOUT\n" );
-        } else if ( flag == 1 && status == RTEMS_SUCCESSFUL ) {
-          flag = 0;
-          printf( "RTEMS_SUCCESSFUL\n" );
-        }
-
-        start = rtems_clock_get_ticks_since_boot();
-        if ( argument == 2 )
-          printf( "Job %d Task %d starts at tick %d.\n", tsk_counter[ argument ]+1, argument, start );
-        else
-          printf( "Task %d starts at tick %d.\n", argument, start );
-        for( index = 0; index < Iterations[ argument ]; index++ ){
-          rtems_counter_delay_ticks( t0 );
-        }
-        end = rtems_clock_get_ticks_since_boot();
-        printf( "					Job %d Task %d ends at tick %d.\n", tsk_counter[ argument ]+1, argument, end );
-        if( argument == 2 ){
-          if( tsk_counter[ argument ] == testnumber ){
-            TEST_END();
-            status = rtems_rate_monotonic_delete( RM_period );
-            directive_failed( status, "rtems_rate_monotonic_delete" );
-            rtems_test_exit( 0 );
-          }
-        }
-
-        tsk_counter[ argument ]+=1;
-        if ( argument == 1 ){
-          if( tsk_counter[ argument ] == 2 ){
-				    status = rtems_rate_monotonic_delete( RM_period );
-            directive_failed( status, "rtems_rate_monotonic_delete" );
-            status = rtems_task_delete( selfid );
-            directive_failed( status, "rtems_task_delete" );
-          }
-        }
-      }
-      break;
-
-  }
-}
-




More information about the vc mailing list