[rtems commit] score: Fix watchdog removal
Sebastian Huber
sebh at rtems.org
Mon Dec 21 07:37:27 UTC 2015
Module: rtems
Branch: master
Commit: a48b7c442db1a49acddf7a2adc07239ddb303020
Changeset: http://git.rtems.org/rtems/commit/?id=a48b7c442db1a49acddf7a2adc07239ddb303020
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Sun Dec 20 21:47:12 2015 +0100
score: Fix watchdog removal
Under certain conditions a new watchdog was inserted with a wrong and
very large delta interval due to an incomplete iterator update.
Bug was introduced by 1ccbd052910ed16131c74b0d5595c8a94066942d.
Close #2501.
---
cpukit/score/src/watchdogremove.c | 11 ++++++-
testsuites/sptests/spwatchdog/init.c | 62 +++++++++++++++++++++++++++++++++---
2 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/cpukit/score/src/watchdogremove.c b/cpukit/score/src/watchdogremove.c
index 03c0c5f..2aa72a4 100644
--- a/cpukit/score/src/watchdogremove.c
+++ b/cpukit/score/src/watchdogremove.c
@@ -61,7 +61,16 @@ static void _Watchdog_Remove_it(
}
if ( iterator->current == &the_watchdog->Node ) {
- iterator->current = _Chain_Previous( &the_watchdog->Node );
+ Chain_Node *previous = _Chain_Previous( &the_watchdog->Node );
+
+ iterator->current = previous;
+
+ if ( previous != _Chain_Head( &header->Watchdogs ) ) {
+ Watchdog_Control *previous_watchdog;
+
+ previous_watchdog = (Watchdog_Control *) previous;
+ iterator->delta_interval += previous_watchdog->delta_interval;
+ }
}
iterator_node = _Chain_Next( iterator_node );
diff --git a/testsuites/sptests/spwatchdog/init.c b/testsuites/sptests/spwatchdog/init.c
index b96b680..d99c558 100644
--- a/testsuites/sptests/spwatchdog/init.c
+++ b/testsuites/sptests/spwatchdog/init.c
@@ -36,7 +36,7 @@ static void test_watchdog_routine( Objects_Id id, void *arg )
static void init_watchdogs(
Watchdog_Header *header,
- Watchdog_Control watchdogs[3]
+ Watchdog_Control watchdogs[4]
)
{
Watchdog_Control *a = &watchdogs[0];
@@ -105,23 +105,23 @@ static void test_watchdog_insert_and_remove( void )
/* Remove next watchdog of iterator */
_Watchdog_Remove( &header, c );
- rtems_test_assert( i.delta_interval == 2 );
+ rtems_test_assert( i.delta_interval == 4 );
rtems_test_assert( i.current == &b->Node );
/* Remove watchdog before the current watchdog of iterator */
_Watchdog_Remove( &header, a );
- rtems_test_assert( i.delta_interval == 4 );
+ rtems_test_assert( i.delta_interval == 6 );
rtems_test_assert( i.current == &b->Node );
/* Remove current (= last) watchdog of iterator */
_Watchdog_Remove( &header, b );
- rtems_test_assert( i.delta_interval == 4 );
+ rtems_test_assert( i.delta_interval == 6 );
rtems_test_assert( i.current == _Chain_Head( &header.Watchdogs ) );
/* Insert first watchdog */
a->initial = 1;
_Watchdog_Insert( &header, a );
- rtems_test_assert( i.delta_interval == 4 );
+ rtems_test_assert( i.delta_interval == 6 );
rtems_test_assert( i.current == _Chain_Head( &header.Watchdogs ) );
destroy_watchdogs( &header );
@@ -147,6 +147,57 @@ static void test_watchdog_insert_and_remove( void )
destroy_watchdogs( &header );
}
+static void init_watchdogs_remove_second_and_insert_first(
+ Watchdog_Header *header,
+ Watchdog_Control watchdogs[3]
+)
+{
+ Watchdog_Control *a = &watchdogs[0];
+ Watchdog_Control *b = &watchdogs[1];
+ Watchdog_Control *c = &watchdogs[2];
+
+ _Watchdog_Preinitialize( a );
+ _Watchdog_Preinitialize( b );
+ _Watchdog_Preinitialize( c );
+
+ _Watchdog_Header_initialize( header );
+
+ a->initial = 6;
+ _Watchdog_Insert( header, a );
+ rtems_test_assert( a->delta_interval == 6 );
+
+ b->initial = 8;
+ _Watchdog_Insert( header, b );
+ rtems_test_assert( a->delta_interval == 6 );
+ rtems_test_assert( b->delta_interval == 2 );
+}
+
+static void test_watchdog_remove_second_and_insert_first( void )
+{
+ Watchdog_Header header;
+ Watchdog_Control watchdogs[3];
+ Watchdog_Control *a = &watchdogs[0];
+ Watchdog_Control *b = &watchdogs[1];
+ Watchdog_Control *c = &watchdogs[2];
+ Watchdog_Iterator i;
+
+ init_watchdogs_remove_second_and_insert_first( &header, watchdogs );
+ add_iterator( &header, &i, b );
+
+ _Watchdog_Remove( &header, b );
+ rtems_test_assert( i.delta_interval == 8 );
+ rtems_test_assert( i.current == &a->Node );
+
+ c->initial = 4;
+ _Watchdog_Insert( &header, c );
+ rtems_test_assert( a->delta_interval == 2 );
+ rtems_test_assert( c->delta_interval == 4 );
+ rtems_test_assert( i.delta_interval == 4 );
+ rtems_test_assert( i.current == &a->Node );
+
+ destroy_watchdogs( &header );
+}
+
static void test_watchdog_static_init( void )
{
#if defined(RTEMS_USE_16_BIT_OBJECT)
@@ -184,6 +235,7 @@ rtems_task Init(
test_watchdog_static_init();
test_watchdog_insert_and_remove();
+ test_watchdog_remove_second_and_insert_first();
build_time( &time, 12, 31, 1988, 9, 0, 0, 0 );
More information about the vc
mailing list