[PATCH 1/2] tests: Fix rtems_test_spin_until_next_tick()

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Dec 5 09:21:48 UTC 2018


This bug surfaced due to sporadic failures in sptimecounter02.  Adjust
rtems_test_spin_for_ticks() to include the partial tick in the argument
value.
---
 testsuites/support/include/test_support.h |  5 +++--
 testsuites/support/src/spin.c             | 20 +++++++-------------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/testsuites/support/include/test_support.h b/testsuites/support/include/test_support.h
index 017444ca9d..9525f95116 100644
--- a/testsuites/support/include/test_support.h
+++ b/testsuites/support/include/test_support.h
@@ -28,9 +28,10 @@ const char *Get_Too_Long_Name(void);
 const char *Get_Longest_Name(void);
 
 /*
- *  Spin for specified number of ticks.
+ *  Spin for specified number of ticks.  The first tick we spin through is a
+ *  partial one.
  */
-void rtems_test_spin_for_ticks(int ticks);
+void rtems_test_spin_for_ticks(rtems_interval ticks);
 
 /*
  *  Spin until the next clock tick
diff --git a/testsuites/support/src/spin.c b/testsuites/support/src/spin.c
index 5b6d3d484e..57c4e323d5 100644
--- a/testsuites/support/src/spin.c
+++ b/testsuites/support/src/spin.c
@@ -17,21 +17,15 @@
 /*
  *  Burn CPU for specified number of ticks
  */
-void rtems_test_spin_for_ticks(int ticks)
+void rtems_test_spin_for_ticks(rtems_interval ticks)
 {
-  rtems_interval        start;
-  rtems_interval        now;
+  rtems_interval start;
+  rtems_interval now;
 
   start = rtems_clock_get_ticks_since_boot();
   do {
     now = rtems_clock_get_ticks_since_boot();
-    /*
-     *  Spin for <= ticks so we spin >= number of ticks.
-     *  The first tick we spin through is a partial one.
-     *  So you sping "ticks" number of ticks plus a partial
-     *  one.
-     */
-  } while ( (now-start) <= ticks );
+  } while ( now - start < ticks );
 }
 
 /*
@@ -39,11 +33,11 @@ void rtems_test_spin_for_ticks(int ticks)
  */
 void rtems_test_spin_until_next_tick( void )
 {
-  rtems_interval        start;
-  rtems_interval        now;
+  rtems_interval start;
+  rtems_interval now;
 
   start = rtems_clock_get_ticks_since_boot();
   do {
     now = rtems_clock_get_ticks_since_boot();
-  } while ( now != start );
+  } while ( now == start );
 }
-- 
2.16.4



More information about the devel mailing list