<div dir="ltr"><div>I accidentally add c/src/lib/libbsp/powerpc/<wbr>acinclude.m4 into the comment.<br></div>Now ticket 2885 should be close. The previous patch has a typo in the comment I hotfix in this patch.<br></div><div class="gmail_extra"><br><div class="gmail_quote">2017-01-26 18:02 GMT+01:00 Kuan-Hsun Chen <span dir="ltr"><<a href="mailto:c0066c@gmail.com" target="_blank">c0066c@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">Prepare a precondition to prevent the potential integer overflow.<br>
<br>
Remove one redundant parameter in _Rate_monotonic_Renew_<wbr>deadline().<br>
<br>
sptests/sp78: Create<br>
A test case for checking the overflow condition of postponed_jobs<br>
in rtems_rate_monotonic_period_<wbr>status.<br>
<br>
Close #2885.<br>
---<br>
 c/src/lib/libbsp/powerpc/<wbr>acinclude.m4 |   4 +-<br>
 cpukit/rtems/src/<wbr>ratemontimeout.c     |  11 ++--<br>
 testsuites/sptests/Makefile.am        |   2 +-<br>
 testsuites/sptests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.<wbr>ac</a>       |   1 +<br>
 testsuites/sptests/sp78/<wbr>Makefile.am   |  22 +++++++<br>
 testsuites/sptests/sp78/init.c        | 120 ++++++++++++++++++++++++++++++<wbr>++++<br>
 testsuites/sptests/sp78/sp78.<wbr>doc      |  18 +++++<br>
 testsuites/sptests/sp78/sp78.<wbr>scn      |   9 +++<br>
 8 files changed, 180 insertions(+), 7 deletions(-)<br>
 create mode 100644 testsuites/sptests/sp78/<wbr>Makefile.am<br>
 create mode 100644 testsuites/sptests/sp78/init.c<br>
 create mode 100644 testsuites/sptests/sp78/sp78.<wbr>doc<br>
 create mode 100644 testsuites/sptests/sp78/sp78.<wbr>scn<br>
<br>
diff --git a/c/src/lib/libbsp/powerpc/<wbr>acinclude.m4 b/c/src/lib/libbsp/powerpc/<wbr>acinclude.m4<br>
index 4c83475..edc67b5 100644<br>
--- a/c/src/lib/libbsp/powerpc/<wbr>acinclude.m4<br>
+++ b/c/src/lib/libbsp/powerpc/<wbr>acinclude.m4<br>
@@ -32,12 +32,12 @@ AC_DEFUN([RTEMS_CHECK_BSPDIR],<br>
     AC_CONFIG_SUBDIRS([t32mppc]);;<br>
   tqm8xx )<br>
     AC_CONFIG_SUBDIRS([tqm8xx]);;<br>
-  virtex )<br>
-    AC_CONFIG_SUBDIRS([virtex]);;<br>
   virtex4 )<br>
     AC_CONFIG_SUBDIRS([virtex4]);;<br>
   virtex5 )<br>
     AC_CONFIG_SUBDIRS([virtex5]);;<br>
+  virtex )<br>
+    AC_CONFIG_SUBDIRS([virtex]);;<br>
   *)<br>
     AC_MSG_ERROR([Invalid BSP]);;<br>
   esac<br>
diff --git a/cpukit/rtems/src/<wbr>ratemontimeout.c b/cpukit/rtems/src/<wbr>ratemontimeout.c<br>
index bcc4ccf..5a838fd 100644<br>
--- a/cpukit/rtems/src/<wbr>ratemontimeout.c<br>
+++ b/cpukit/rtems/src/<wbr>ratemontimeout.c<br>
@@ -9,7 +9,7 @@<br>
  *  COPYRIGHT (c) 1989-2009.<br>
  *  On-Line Applications Research Corporation (OAR).<br>
  *<br>
- *  COPYRIGHT (c) 2016 Kuan-Hsun Chen.<br>
+ *  COPYRIGHT (c) 2016-2017 Kuan-Hsun Chen.<br>
  *<br>
  *  The license and distribution terms for this file may be<br>
  *  found in the file LICENSE in this distribution or at<br>
@@ -24,13 +24,16 @@<br>
<br>
 static void _Rate_monotonic_Renew_<wbr>deadline(<br>
   Rate_monotonic_Control *the_period,<br>
-  Thread_Control         *owner,<br>
   ISR_lock_Context       *lock_context<br>
 )<br>
 {<br>
   uint64_t deadline;<br>
<br>
-  ++the_period->postponed_jobs;<br>
+  /* stay at 0xffffffff if postponed_jobs is going to overflow */<br>
+  if ( the_period->postponed_jobs != UINT32_MAX ) {<br>
+    ++the_period->postponed_jobs;<br>
+  }<br>
+<br>
   the_period->state = RATE_MONOTONIC_EXPIRED;<br>
<br>
   deadline = _Watchdog_Per_CPU_insert_<wbr>relative(<br>
@@ -85,6 +88,6 @@ void _Rate_monotonic_Timeout( Watchdog_Control *the_watchdog )<br>
       _Thread_Unblock( owner );<br>
     }<br>
   } else {<br>
-    _Rate_monotonic_Renew_<wbr>deadline( the_period, owner, &lock_context );<br>
+    _Rate_monotonic_Renew_<wbr>deadline( the_period, &lock_context );<br>
   }<br>
 }<br>
diff --git a/testsuites/sptests/Makefile.<wbr>am b/testsuites/sptests/Makefile.<wbr>am<br>
index 5ef87a0..11e9bcd 100644<br>
--- a/testsuites/sptests/Makefile.<wbr>am<br>
+++ b/testsuites/sptests/Makefile.<wbr>am<br>
@@ -10,7 +10,7 @@ _SUBDIRS = \<br>
     sp40 sp41 sp42 sp43 sp44 sp45 sp46 sp47 sp48 sp49 \<br>
     sp50 sp51 sp52 sp53 sp54 sp55 sp56 sp57 sp58 sp59 \<br>
     sp60      sp62 sp63 sp64 sp65 sp66 sp67 sp68 sp69 \<br>
-    sp70 sp71 sp72 sp73 sp74 sp75 sp76 sp77 sp2038 \<br>
+    sp70 sp71 sp72 sp73 sp74 sp75 sp76 sp77 sp78 sp2038 \<br>
     spassoc01 spchain spcoverage spobjgetnext \<br>
     spprintk spprivenv01 sprbtree01 spsize spstkalloc \<br>
     spstkalloc02 spthreadq01 spwatchdog spwkspace \<br>
diff --git a/testsuites/sptests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure<wbr>.ac</a> b/testsuites/sptests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure<wbr>.ac</a><br>
index 77ec512..a2af200 100644<br>
--- a/testsuites/sptests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure<wbr>.ac</a><br>
+++ b/testsuites/sptests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure<wbr>.ac</a><br>
@@ -144,6 +144,7 @@ sp74/Makefile<br>
 sp75/Makefile<br>
 sp76/Makefile<br>
 sp77/Makefile<br>
+sp78/Makefile<br>
 sp2038/Makefile<br>
 spassoc01/Makefile<br>
 spcbssched01/Makefile<br>
diff --git a/testsuites/sptests/sp78/<wbr>Makefile.am b/testsuites/sptests/sp78/<wbr>Makefile.am<br>
new file mode 100644<br>
index 0000000..3e59f3d<br>
--- /dev/null<br>
+++ b/testsuites/sptests/sp78/<wbr>Makefile.am<br>
@@ -0,0 +1,22 @@<br>
+<br>
+rtems_tests_PROGRAMS = sp78<br>
+sp78_SOURCES = init.c ../../support/src/spin.c<br>
+<br>
+dist_rtems_tests_DATA = sp78.scn<br>
+dist_rtems_tests_DATA += sp78.doc<br>
+<br>
+include $(RTEMS_ROOT)/make/custom/@<wbr>RTEMS_BSP@.cfg<br>
+include $(top_srcdir)/../automake/<a href="http://compile.am" rel="noreferrer" target="_blank">comp<wbr>ile.am</a><br>
+include $(top_srcdir)/../automake/<a href="http://leaf.am" rel="noreferrer" target="_blank">leaf<wbr>.am</a><br>
+<br>
+<br>
+AM_CPPFLAGS += -I$(top_srcdir)/../support/<wbr>include<br>
+<br>
+LINK_OBJS = $(sp78_OBJECTS)<br>
+LINK_LIBS = $(sp78_LDLIBS)<br>
+<br>
+sp78$(EXEEXT): $(sp78_OBJECTS) $(sp78_DEPENDENCIES)<br>
+       @rm -f sp69$(EXEEXT)<br>
+       $(make-exe)<br>
+<br>
+include $(top_srcdir)/../automake/<a href="http://local.am" rel="noreferrer" target="_blank">loca<wbr>l.am</a><br>
diff --git a/testsuites/sptests/sp78/<wbr>init.c b/testsuites/sptests/sp78/<wbr>init.c<br>
new file mode 100644<br>
index 0000000..99eec27<br>
--- /dev/null<br>
+++ b/testsuites/sptests/sp78/<wbr>init.c<br>
@@ -0,0 +1,120 @@<br>
+/*<br>
+ *  COPYRIGHT (c) 2017 Kuan-Hsun Chen.<br>
+ *<br>
+ *  The license and distribution terms for this file may be<br>
+ *  found in the file LICENSE in this distribution or at<br>
+ *  <a href="http://www.rtems.org/license/LICENSE" rel="noreferrer" target="_blank">http://www.rtems.org/license/<wbr>LICENSE</a>.<br>
+ */<br>
+<br>
+#ifdef HAVE_CONFIG_H<br>
+#include "config.h"<br>
+#endif<br>
+<br>
+#include <rtems/cpuuse.h><br>
+#include <tmacros.h><br>
+#include <rtems/rtems/ratemonimpl.h><br>
+#include "test_support.h"<br>
+<br>
+const char rtems_test_name[] = "SP 78";<br>
+<br>
+/* forward declarations to avoid warnings */<br>
+rtems_task Init( rtems_task_argument argument );<br>
+static void modify_count( rtems_id id );<br>
+<br>
+static void modify_count(<br>
+  rtems_id            id<br>
+)<br>
+{<br>
+  Rate_monotonic_Control                  *the_period;<br>
+  ISR_lock_Context                        lock_context;<br>
+<br>
+  the_period = _Rate_monotonic_Get( id, &lock_context );<br>
+  _Rate_monotonic_Acquire_<wbr>critical( the_period, &lock_context );<br>
+  the_period->postponed_jobs = UINT32_MAX;<br>
+  _Rate_monotonic_Release( the_period, &lock_context );<br>
+}<br>
+<br>
+rtems_task Init(<br>
+  rtems_task_argument argument<br>
+)<br>
+{<br>
+  rtems_id                                period_id;<br>
+  rtems_name                              period_name;<br>
+  rtems_rate_monotonic_period_<wbr>status      period_status;<br>
+  rtems_status_code                       status;<br>
+  int                                     i;<br>
+<br>
+  period_name = rtems_build_name('P','E','R','<wbr>1');<br>
+<br>
+  TEST_BEGIN();<br>
+<br>
+  /* create period */<br>
+  status = rtems_rate_monotonic_create(<br>
+      period_name,<br>
+      &period_id<br>
+  );<br>
+  directive_failed( status, "rate_monotonic_create" );<br>
+<br>
+  /* modify the count to UINT32_MAX and attempt to miss deadline*/<br>
+  puts( "Testing overflow condition" );<br>
+  rtems_test_spin_until_next_<wbr>tick();<br>
+  status = rtems_rate_monotonic_period( period_id, 50 );<br>
+  directive_failed( status, "rate_monotonic_period above loop" );<br>
+<br>
+  puts( "Modify the count of postponed_job manually" );<br>
+  modify_count( period_id );<br>
+<br>
+  /* Check the status */<br>
+  status = rtems_rate_monotonic_get_<wbr>status( period_id, &period_status );<br>
+  directive_failed( status, "rate_monotonic_get_status" );<br>
+  printf( "Init Postponed jobs = %"PRIu32", and expected %"PRIu32"\n", period_status.postponed_jobs_<wbr>count, UINT32_MAX );<br>
+  rtems_test_assert( period_status.postponed_jobs_<wbr>count == UINT32_MAX );<br>
+<br>
+  for ( i=1 ; i <= 2 ; i++ ) {<br>
+    status = rtems_task_wake_after( 100 );<br>
+    directive_failed( status, "rtems_task_wake_after(100)" );<br>
+    puts( "Task misses its deadline." );<br>
+<br>
+    /* Check the status */<br>
+    status = rtems_rate_monotonic_get_<wbr>status( period_id, &period_status );<br>
+    directive_failed( status, "rate_monotonic_get_status" );<br>
+<br>
</div></div>+    /* print out the count which should keep in UINT32_MAX, since the period still misses its deadline */<br>
<div class="HOEnZb"><div class="h5">+    printf( "Count = %"PRIu32", and expected %"PRIu32"\n", period_status.postponed_jobs_<wbr>count, UINT32_MAX);<br>
+    rtems_test_assert( period_status.postponed_jobs_<wbr>count == UINT32_MAX);<br>
+<br>
+    rtems_test_spin_until_next_<wbr>tick();<br>
+    status = rtems_rate_monotonic_period( period_id, 50 );<br>
+    fatal_directive_status(<br>
+      status,<br>
+      RTEMS_TIMEOUT,<br>
+      "rtems_rate_monotonic_period 2-n"<br>
+    );<br>
+<br>
+<br>
+  }<br>
+<br>
+  TEST_END();<br>
+<br>
+  rtems_test_exit(0);<br>
+}<br>
+<br>
+/* configuration information */<br>
+<br>
+#define CONFIGURE_APPLICATION_NEEDS_<wbr>CONSOLE_DRIVER<br>
+#define CONFIGURE_APPLICATION_NEEDS_<wbr>CLOCK_DRIVER<br>
+<br>
+#define CONFIGURE_MILLISECONDS_PER_<wbr>TICK 1<br>
+<br>
+#define CONFIGURE_MAXIMUM_TASKS             1<br>
+#define CONFIGURE_MAXIMUM_PERIODS           1<br>
+<br>
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION<br>
+<br>
+#define CONFIGURE_RTEMS_INIT_TASKS_<wbr>TABLE<br>
+<br>
+<br>
+#define CONFIGURE_INIT<br>
+<br>
+#include <rtems/confdefs.h><br>
+/* end of file */<br>
diff --git a/testsuites/sptests/sp78/<wbr>sp78.doc b/testsuites/sptests/sp78/<wbr>sp78.doc<br>
new file mode 100644<br>
index 0000000..ad64e4b<br>
--- /dev/null<br>
+++ b/testsuites/sptests/sp78/<wbr>sp78.doc<br>
@@ -0,0 +1,18 @@<br>
+#  COPYRIGHT (c) 2017 Kuan-Hsun Chen.<br>
+#<br>
+#  The license and distribution terms for this file may be<br>
+#  found in the file LICENSE in this distribution or at<br>
+#  <a href="http://www.rtems.org/license/LICENSE" rel="noreferrer" target="_blank">http://www.rtems.org/license/<wbr>LICENSE</a>.<br>
+#<br>
+<br>
+This file describes the directives and concepts tested by this test set.<br>
+<br>
+test set name:  sp78<br>
+<br>
+directives:<br>
+<br>
+  rtems_rate_monotonic_get_<wbr>status<br>
+<br>
+concepts:<br>
+<br>
++ Test the overflow condition for postponed_jobs.<br>
diff --git a/testsuites/sptests/sp78/<wbr>sp78.scn b/testsuites/sptests/sp78/<wbr>sp78.scn<br>
new file mode 100644<br>
index 0000000..4cb71db<br>
--- /dev/null<br>
+++ b/testsuites/sptests/sp78/<wbr>sp78.scn<br>
@@ -0,0 +1,9 @@<br>
+*** BEGIN OF TEST SP 78 ***<br>
+Testing overflow condition<br>
+Modify the count of postponed_job manually<br>
+Init Postponed jobs = 4294967295, and expected 4294967295<br>
+Task misses its deadline.<br>
+Count = 4294967295, and expected 4294967295<br>
+Task misses its deadline.<br>
+Count = 4294967295, and expected 4294967295<br>
+*** END OF TEST SP 78 ***<br>
--<br>
1.9.1<br>
<br>
</div></div></blockquote></div><br></div>