[rtems-central commit] spec: Fix unstable test of clock manager

Sebastian Huber sebh at rtems.org
Fri Jul 23 14:26:45 UTC 2021


Module:    rtems-central
Branch:    master
Commit:    fc3586fe37824e51d47840bb97df827916ddd4d3
Changeset: http://git.rtems.org/rtems-central/commit/?id=fc3586fe37824e51d47840bb97df827916ddd4d3

Author:    Frank Kühndel <frank.kuehndel at embedded-brains.de>
Date:      Fri Jul 23 10:47:35 2021 +0200

spec: Fix unstable test of clock manager

The tests of specification get-tod.yml and set.yml were expecting
that no more than five ticks pass between consecutive calls to
rtems_clock_set() and rtems_clock_get_tod(). Yet, in coverage tests
this limit was exceeded.

* All tests are placed in a test suite without clock driver so that
  all ticks must be triggered by the test suite.

* The grace period of five ticks has been removed.

* Test which require that the realtime clock has not been set
  manipulate RTEMS internal data with `_TOD.is_set = false`.
  The old function get_tod_before_set_tod() has been removed
  in favor of this new solution.

---

 spec/c/req/clock-nanosleep.yml      |  2 ++
 spec/rtems/clock/req/get-tod.yml    | 57 +++++++++----------------------------
 spec/rtems/clock/req/get-uptime.yml |  4 +--
 spec/rtems/clock/req/set.yml        | 31 +++++---------------
 spec/rtems/clock/val/clock.yml      |  6 ++--
 5 files changed, 27 insertions(+), 73 deletions(-)

diff --git a/spec/c/req/clock-nanosleep.yml b/spec/c/req/clock-nanosleep.yml
index fbec98d..912bc1d 100644
--- a/spec/c/req/clock-nanosleep.yml
+++ b/spec/c/req/clock-nanosleep.yml
@@ -359,6 +359,8 @@ test-prepare: |
 test-setup:
   brief: null
   code: |
+    rtems_time_of_day now = { 1988, 1, 1, 0, 0, 0, 0 };
+    T_rsc_success( rtems_clock_set( &now ) );
     SetSelfPriority( PRIO_NORMAL );
     ctx->worker_id = CreateTask( "WORK", PRIO_HIGH );
     StartTask( ctx->worker_id, Worker, ctx );
diff --git a/spec/rtems/clock/req/get-tod.yml b/spec/rtems/clock/req/get-tod.yml
index db64fcb..6eea3b1 100644
--- a/spec/rtems/clock/req/get-tod.yml
+++ b/spec/rtems/clock/req/get-tod.yml
@@ -41,9 +41,9 @@ post-conditions:
       T_eq_u32( ctx->get_tod_value.hour,   ctx->set_tod_value.hour );
       T_eq_u32( ctx->get_tod_value.minute, ctx->set_tod_value.minute );
       T_eq_u32( ctx->get_tod_value.second, ctx->set_tod_value.second );
-      T_ge_u32( ctx->get_tod_value.ticks,  ctx->set_tod_value.ticks );
-      T_lt_u32( ctx->get_tod_value.ticks,
-        ctx->set_tod_value.ticks + ctx->grace_ticks );
+      /* rtems_clock_set() or rtems_clock_get_tod() cause an error of 1 tick */
+      T_ge_u32( ctx->get_tod_value.ticks + 1,  ctx->set_tod_value.ticks );
+      T_le_u32( ctx->get_tod_value.ticks, ctx->set_tod_value.ticks );
     text: |
       The value of the object referenced by the
       ${../if/get-tod:/params[0]/name} parameter shall be set to the value
@@ -87,7 +87,7 @@ pre-conditions:
     test-code: |
       ctx->set_tod_value =
         (rtems_time_of_day) { 2100, 2, 28, 23, 59, 59,
-        rtems_clock_get_ticks_per_second() - ctx->grace_ticks };
+        rtems_clock_get_ticks_per_second() - 1 };
     text: |
       While the ${/glossary/clock-realtime:/term} indicates a
       date for a non-leap year with the value of 28th of February.
@@ -109,7 +109,7 @@ pre-conditions:
     test-code: |
       ctx->set_tod_value =
         (rtems_time_of_day) { 2105, 12, 31, 23, 59, 59,
-        rtems_clock_get_ticks_per_second() - ctx->grace_ticks };
+        rtems_clock_get_ticks_per_second() - 1 };
     text: |
       While the ${/glossary/clock-realtime:/term} indicates the
       oldest date and time accepted (2105-12-31T23:59:59.999999999Z).
@@ -145,10 +145,12 @@ test-action: |
     ctx->set_tod_status = rtems_clock_set( &ctx->set_tod_value );
     ctx->get_tod_status = rtems_clock_get_tod( ctx->get_tod_ref );
   } else {
-    ctx->get_tod_status = get_tod_before_set_tod( ctx->get_tod_ref );
+    UnsetClock();
+    ctx->get_tod_status = rtems_clock_get_tod( ctx->get_tod_ref );
   }
 test-brief: null
-test-cleanup: null
+test-cleanup: |
+  UnsetClock();
 test-context:
 - brief: null
   description: null
@@ -165,9 +167,6 @@ test-context:
 - brief: null
   description: null
   member: rtems_status_code get_tod_status
-- brief: Grace period in tick which may be passed between set and get ToD.
-  description: null
-  member: uint32_t grace_ticks
 - brief: null
   description: null
   member: bool isDef
@@ -177,45 +176,15 @@ test-header: null
 test-includes:
 - rtems.h
 test-local-includes:
-- tc-clock-get-tod.h
+- tx-support.h
 test-prepare: |
     ctx->get_tod_value = (rtems_time_of_day) { 1, 1, 1, 1, 1, 1, 1 };
     ctx->get_tod_ref = &ctx->get_tod_value;
     ctx->set_tod_value = (rtems_time_of_day) { 2023, 4, 5, 6, 7, 8, 0 };
     ctx->isDef = true;
-test-setup:
-  brief: null
-  code: |
-    /* Call rtems_clock_get_tod() once before rtems_clock_set() gets called */
-    get_tod_before_set_tod( NULL );
-
-    ctx->grace_ticks = rtems_clock_get_ticks_per_second() * GRACE_PERIOD / 1000;
-  description: null
+test-setup: null
 test-stop: null
-test-support: |
-  rtems_status_code get_tod_before_set_tod( rtems_time_of_day *time_of_day )
-  {
-    static rtems_time_of_day tod_buf = { 1, 1, 1, 1, 1, 1, 1 };
-    static rtems_status_code status;
-    static bool has_been_called = false;
-
-    if ( ! has_been_called ) {
-      status = rtems_clock_get_tod( &tod_buf );
-      has_been_called = true;
-    }
-
-    if ( NULL != time_of_day ) {
-      *time_of_day = tod_buf;
-    }
-
-    return status;
-  }
-
-  /*
-   * How much time may pass between a call to rtems_clock_set() and
-   * a follow up call to rtems_clock_get_tod() in milliseconds?
-   */
-  #define GRACE_PERIOD 5
+test-support: null
 test-target: testsuites/validation/tc-clock-get-tod.c
 test-teardown: null
 text: ${.:text-template}
@@ -246,6 +215,7 @@ transition-map:
       - Leap400
       - Youngest
       - Oldest
+      - NotSet
     Param:
       - 'Null'
 - enabled-by: true
@@ -257,5 +227,4 @@ transition-map:
       - NotSet
     Param:
       - Valid
-      - 'Null'
 type: requirement
diff --git a/spec/rtems/clock/req/get-uptime.yml b/spec/rtems/clock/req/get-uptime.yml
index 05ed4a7..b63f734 100644
--- a/spec/rtems/clock/req/get-uptime.yml
+++ b/spec/rtems/clock/req/get-uptime.yml
@@ -28,8 +28,8 @@ post-conditions:
   - name: Set
     test-code: |
       T_eq_ptr( ctx->uptime, &ctx->uptime_value );
-      T_gt_i64( ctx->uptime_value.tv_sec, 0LL );
-      T_gt_long( ctx->uptime_value.tv_nsec, 0L );
+      T_ge_i64( ctx->uptime_value.tv_sec, 0LL );
+      T_ge_long( ctx->uptime_value.tv_nsec, 0L );
       T_lt_long( ctx->uptime_value.tv_nsec, 1000000000L );
     text: |
       The value of the object referenced by the
diff --git a/spec/rtems/clock/req/set.yml b/spec/rtems/clock/req/set.yml
index 216b435..d99550b 100644
--- a/spec/rtems/clock/req/set.yml
+++ b/spec/rtems/clock/req/set.yml
@@ -41,9 +41,9 @@ post-conditions:
       T_eq_u32( ctx->tod_after.hour, ctx->target_tod_value.hour );
       T_eq_u32( ctx->tod_after.minute, ctx->target_tod_value.minute );
       T_eq_u32( ctx->tod_after.second, ctx->target_tod_value.second );
-      T_ge_u32( ctx->tod_after.ticks, ctx->target_tod_value.ticks );
-      T_lt_u32( ctx->tod_after.ticks,
-        ctx->target_tod_value.ticks + ctx->grace_ticks );
+      /* rtems_clock_set() or rtems_clock_get_tod() cause an error of 1 tick */
+      T_ge_u32( ctx->tod_after.ticks + 1, ctx->target_tod_value.ticks );
+      T_le_u32( ctx->tod_after.ticks, ctx->target_tod_value.ticks );
     text: |
       The ${/glossary/clock-realtime:/term} shall be set
       to the values of the object referenced by the
@@ -58,9 +58,7 @@ post-conditions:
       T_eq_u32( ctx->tod_after.hour, ctx->tod_before.hour );
       T_eq_u32( ctx->tod_after.minute, ctx->tod_before.minute );
       T_eq_u32( ctx->tod_after.second, ctx->tod_before.second );
-      T_ge_u32( ctx->tod_after.ticks, ctx->tod_before.ticks );
-      T_lt_u32( ctx->tod_after.ticks,
-        ctx->tod_before.ticks + 2 * ctx->grace_ticks );
+      T_eq_u32( ctx->tod_after.ticks, ctx->tod_before.ticks );
     text: |
       The state of the ${/glossary/clock-realtime:/term} shall not be changed
       by the ${../if/set:/name} call.
@@ -76,8 +74,7 @@ post-conditions:
       T_eq_u32( ctx->timer_routine_tod.day, 1 );
       T_eq_u32( ctx->timer_routine_tod.minute, 0 );
       T_eq_u32( ctx->timer_routine_tod.second, 0 );
-      T_ge_u32( ctx->timer_routine_tod.ticks, 0 );
-      T_lt_u32( ctx->timer_routine_tod.ticks, 0 + ctx->grace_ticks );
+      T_eq_u32( ctx->timer_routine_tod.ticks, 0 );
     text: |
       The timer routine shall be executed once after the
       ${/glossary/clock-realtime:/term} has been set and before
@@ -141,7 +138,7 @@ pre-conditions:
     test-code: |
       ctx->target_tod_value =
         (rtems_time_of_day) { 2105, 12, 31, 23, 59, 59,
-        rtems_clock_get_ticks_per_second() - ctx->grace_ticks };
+        rtems_clock_get_ticks_per_second() - 1 };
     text: |
       While the ${../if/set:/params[0]/name} parameter references the
       oldest date and time accepted (2105-12-31T23:59:59.999999999Z).
@@ -312,16 +309,12 @@ test-context:
 - brief: null
   description: null
   member: rtems_time_of_day timer_routine_tod
-- brief: Grace period in tick which may be passed between set and get ToD.
-  description: null
-  member: uint32_t grace_ticks
 test-context-support: null
 test-description: null
 test-header: null
 test-includes:
 - rtems.h
-test-local-includes:
-- tc-clock-get-tod.h
+test-local-includes: []
 test-prepare: |
   rtems_status_code status;
 
@@ -336,10 +329,6 @@ test-setup:
     rtems_name timer_name = rtems_build_name( 'T', 'M', 'R', '0' );
     ctx->timer_id = RTEMS_ID_NONE;
 
-    /* Call rtems_clock_get_tod() once before rtems_clock_set() gets called */
-    get_tod_before_set_tod( NULL );
-
-    ctx->grace_ticks = rtems_clock_get_ticks_per_second() * GRACE_PERIOD / 1000;
     ctx->target_tod = &ctx->target_tod_value;
 
     status = rtems_timer_create( timer_name, &ctx->timer_id );
@@ -347,12 +336,6 @@ test-setup:
   description: null
 test-stop: null
 test-support: |
-  /*
-   * How much time may pass between a call to rtems_clock_set() and
-   * a follow up call to rtems_clock_get_tod() in millisecond?
-   */
-  #define GRACE_PERIOD 5
-
   static rtems_timer_service_routine _TOD_timer_routine(
     rtems_id   timer_id,
     void      *user_data
diff --git a/spec/rtems/clock/val/clock.yml b/spec/rtems/clock/val/clock.yml
index b2689b4..52ff2d8 100644
--- a/spec/rtems/clock/val/clock.yml
+++ b/spec/rtems/clock/val/clock.yml
@@ -12,9 +12,8 @@ test-actions:
     int32_t difference; /* Note: rtems_interval = uint32_t (unsigned!) */
 
     result_0 = rtems_clock_get_ticks_since_boot();
-    do {
-      result_1 = rtems_clock_get_ticks_since_boot();
-    } while( result_0 == result_1 );
+    ClockTick();
+    result_1 = rtems_clock_get_ticks_since_boot();
     /*
      * Because of the ones-complement, the overflow
      * is handled correctly. result_0 = 0xFFFFFFFF will become -1
@@ -59,6 +58,7 @@ test-includes:
 - rtems.h
 test-local-includes:
 - ts-config.h
+- tx-support.h
 test-setup: null
 test-stop: null
 test-support: null



More information about the vc mailing list