From 03b900d3ed120ea919ea3eded7edbece3488cff3 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 18 Feb 2016 08:36:26 +0100 Subject: score: Replace watchdog handler implementation Use a red-black tree instead of delta chains. Close #2344. Update #2554. Update #2555. Close #2606. --- testsuites/sptests/spwatchdog/init.c | 381 +++++++++++++++-------------------- 1 file changed, 165 insertions(+), 216 deletions(-) (limited to 'testsuites/sptests/spwatchdog/init.c') diff --git a/testsuites/sptests/spwatchdog/init.c b/testsuites/sptests/spwatchdog/init.c index 025295b45b..3b08fb57e5 100644 --- a/testsuites/sptests/spwatchdog/init.c +++ b/testsuites/sptests/spwatchdog/init.c @@ -26,241 +26,192 @@ const char rtems_test_name[] = "SPWATCHDOG"; -static void test_watchdog_routine( Objects_Id id, void *arg ) -{ - (void) id; - (void) arg; - - rtems_test_assert( 0 ); -} +typedef struct { + Watchdog_Control Base; + int counter; +} test_watchdog; -static void init_watchdogs( - Watchdog_Header *header, - Watchdog_Control watchdogs[4] -) +static void test_watchdog_routine( Watchdog_Control *base ) { - Watchdog_Control *a = &watchdogs[0]; - Watchdog_Control *b = &watchdogs[1]; - Watchdog_Control *c = &watchdogs[2]; - Watchdog_Control *d = &watchdogs[3]; - - _Watchdog_Header_initialize( header ); - rtems_test_assert( _Watchdog_Is_empty( header ) ); - rtems_test_assert( _Chain_Is_empty( &header->Iterators ) ); - - _Watchdog_Preinitialize( c ); - c->initial = 6; - _Watchdog_Insert( header, c ); - rtems_test_assert( c->delta_interval == 6 ); - - rtems_test_assert( !_Watchdog_Is_empty( header ) ); - rtems_test_assert( _Chain_Is_empty( &header->Iterators ) ); - - _Watchdog_Preinitialize( a ); - a->initial = 2; - _Watchdog_Insert( header, a ); - rtems_test_assert( a->delta_interval == 2 ); - rtems_test_assert( c->delta_interval == 4 ); - - _Watchdog_Preinitialize( b ); - b->initial = 4; - _Watchdog_Insert( header, b ); - rtems_test_assert( a->delta_interval == 2 ); - rtems_test_assert( b->delta_interval == 2 ); - rtems_test_assert( c->delta_interval == 2 ); - - _Watchdog_Preinitialize( d ); -} + test_watchdog *watchdog = (test_watchdog *) base; -static void destroy_watchdogs( - Watchdog_Header *header -) -{ - _ISR_lock_Destroy( &header->Lock ); + ++watchdog->counter; } -static void add_iterator( - Watchdog_Header *header, - Watchdog_Iterator *i, - Watchdog_Control *w -) +static void test_watchdog_static_init( void ) { - _Chain_Append_unprotected( &header->Iterators, &i->Node ); - i->delta_interval = 2; - i->current = &w->Node; -} + static Watchdog_Control a = WATCHDOG_INITIALIZER( + test_watchdog_routine + ); + Watchdog_Control b; -static void test_watchdog_insert_and_remove( void ) -{ - Watchdog_Header header; - Watchdog_Control watchdogs[4]; - Watchdog_Control *a = &watchdogs[0]; - Watchdog_Control *b = &watchdogs[1]; - Watchdog_Control *c = &watchdogs[2]; - Watchdog_Control *d = &watchdogs[3]; - Watchdog_Iterator i; - - init_watchdogs( &header, watchdogs ); - add_iterator( &header, &i, c ); - - /* Remove next watchdog of iterator */ - _Watchdog_Remove( &header, c ); - 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 == 6 ); - rtems_test_assert( i.current == &b->Node ); - - /* Remove current (= last) watchdog of iterator */ - _Watchdog_Remove( &header, b ); - 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 == 6 ); - rtems_test_assert( i.current == _Chain_Head( &header.Watchdogs ) ); - - destroy_watchdogs( &header ); - init_watchdogs( &header, watchdogs ); - add_iterator( &header, &i, b ); - - /* Insert right before current watchdog of iterator */ - d->initial = 3; - _Watchdog_Insert( &header, d ); - rtems_test_assert( i.delta_interval == 2 ); - rtems_test_assert( i.current == &d->Node ); - - destroy_watchdogs( &header ); - init_watchdogs( &header, watchdogs ); - add_iterator( &header, &i, b ); - - /* Insert right after current watchdog of iterator */ - d->initial = 5; - _Watchdog_Insert( &header, d ); - rtems_test_assert( i.delta_interval == 2 ); - rtems_test_assert( i.current == &b->Node ); - - destroy_watchdogs( &header ); + memset( &b, 0, sizeof( b ) ); + _Watchdog_Preinitialize( &b, _Per_CPU_Get_by_index( 0 ) ); + _Watchdog_Initialize( + &b, + test_watchdog_routine + ); + + rtems_test_assert( memcmp( &a, &b, sizeof( a ) ) == 0 ); } -static void init_watchdogs_remove_second_and_insert_first( - Watchdog_Header *header, - Watchdog_Control watchdogs[3] -) +static bool test_watchdog_is_inactive( test_watchdog *watchdog ) { - 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 ); + return _Watchdog_Get_state( &watchdog->Base ) == WATCHDOG_INACTIVE; } -static void test_watchdog_remove_second_and_insert_first( void ) +static void test_watchdog_init( test_watchdog *watchdog, int counter ) { - 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 == 8 ); - rtems_test_assert( i.current == &c->Node ); - - destroy_watchdogs( &header ); + _Watchdog_Preinitialize( &watchdog->Base, _Per_CPU_Get_snapshot() ); + _Watchdog_Initialize( &watchdog->Base, test_watchdog_routine ); + rtems_test_assert( test_watchdog_is_inactive( watchdog ) ) ; + watchdog->counter = counter; } -static void init_watchdogs_insert_with_iterator( - Watchdog_Header *header, - Watchdog_Control watchdogs[2] -) +static uint64_t test_watchdog_tick( Watchdog_Header *header, uint64_t now ) { - Watchdog_Control *a = &watchdogs[0]; - Watchdog_Control *b = &watchdogs[1]; + ISR_LOCK_DEFINE( , lock, "Test" ) + ISR_lock_Context lock_context; - _Watchdog_Preinitialize( a ); - _Watchdog_Preinitialize( b ); + _ISR_lock_ISR_disable_and_acquire( &lock, &lock_context ); + ++now; + _Watchdog_Tickle( header, now, &lock, &lock_context ); + _ISR_lock_Destroy( &lock ); - _Watchdog_Header_initialize( header ); - - a->initial = 6; - _Watchdog_Insert( header, a ); - rtems_test_assert( a->delta_interval == 6 ); + return now; } -static void test_watchdog_insert_with_iterator( void ) +static void test_watchdog_operations( void ) { Watchdog_Header header; - Watchdog_Control watchdogs[2]; - Watchdog_Control *a = &watchdogs[0]; - Watchdog_Control *b = &watchdogs[1]; - Watchdog_Iterator i; - - init_watchdogs_insert_with_iterator( &header, watchdogs ); - add_iterator( &header, &i, a ); - - b->initial = 4; - _Watchdog_Insert( &header, b ); - rtems_test_assert( a->delta_interval == 2 ); - rtems_test_assert( b->delta_interval == 4 ); - rtems_test_assert( i.delta_interval == 2 ); - rtems_test_assert( i.current == &b->Node ); - - destroy_watchdogs( &header ); -} - -static void test_watchdog_static_init( void ) -{ - #if defined(RTEMS_USE_16_BIT_OBJECT) - #define JUNK_ID 0x1234 - #else - #define JUNK_ID 0x12345678 - #endif - - static Watchdog_Control a = WATCHDOG_INITIALIZER( - test_watchdog_routine, - JUNK_ID, - (void *) 0xdeadbeef - ); - Watchdog_Control b; - - memset( &b, 0, sizeof( b ) ); - _Watchdog_Initialize( - &b, - test_watchdog_routine, - JUNK_ID, - (void *) 0xdeadbeef - ); - - rtems_test_assert( memcmp( &a, &b, sizeof( a ) ) == 0 ); + uint64_t now; + test_watchdog a; + test_watchdog b; + test_watchdog c; + + _Watchdog_Header_initialize( &header ); + rtems_test_assert( _RBTree_Is_empty( &header.Watchdogs ) ); + rtems_test_assert( header.first == NULL ); + + test_watchdog_init( &a, 10 ); + test_watchdog_init( &b, 20 ); + test_watchdog_init( &c, 30 ); + + now = 0; + now = test_watchdog_tick( &header, now ); + + _Watchdog_Insert( &header, &a.Base, now + 1 ); + rtems_test_assert( header.first == &a.Base.Node.RBTree ); + rtems_test_assert( !test_watchdog_is_inactive( &a ) ) ; + rtems_test_assert( a.Base.expire == 2 ); + rtems_test_assert( a.counter == 10 ); + + _Watchdog_Remove( &header, &a.Base ); + rtems_test_assert( header.first == NULL ); + rtems_test_assert( test_watchdog_is_inactive( &a ) ) ; + rtems_test_assert( a.Base.expire == 2 ); + rtems_test_assert( a.counter == 10 ); + + _Watchdog_Remove( &header, &a.Base ); + rtems_test_assert( header.first == NULL ); + rtems_test_assert( test_watchdog_is_inactive( &a ) ) ; + rtems_test_assert( a.Base.expire == 2 ); + rtems_test_assert( a.counter == 10 ); + + _Watchdog_Insert( &header, &a.Base, now + 1 ); + rtems_test_assert( header.first == &a.Base.Node.RBTree ); + rtems_test_assert( !test_watchdog_is_inactive( &a ) ) ; + rtems_test_assert( a.Base.expire == 2 ); + rtems_test_assert( a.counter == 10 ); + + _Watchdog_Insert( &header, &b.Base, now + 1 ); + rtems_test_assert( header.first == &a.Base.Node.RBTree ); + rtems_test_assert( !test_watchdog_is_inactive( &b ) ) ; + rtems_test_assert( b.Base.expire == 2 ); + rtems_test_assert( b.counter == 20 ); + + _Watchdog_Insert( &header, &c.Base, now + 2 ); + rtems_test_assert( header.first == &a.Base.Node.RBTree ); + rtems_test_assert( !test_watchdog_is_inactive( &c ) ) ; + rtems_test_assert( c.Base.expire == 3 ); + rtems_test_assert( c.counter == 30 ); + + _Watchdog_Remove( &header, &a.Base ); + rtems_test_assert( header.first == &b.Base.Node.RBTree ); + rtems_test_assert( test_watchdog_is_inactive( &a ) ) ; + rtems_test_assert( a.Base.expire == 2 ); + rtems_test_assert( a.counter == 10 ); + + _Watchdog_Remove( &header, &b.Base ); + rtems_test_assert( header.first == &c.Base.Node.RBTree ); + rtems_test_assert( test_watchdog_is_inactive( &b ) ) ; + rtems_test_assert( b.Base.expire == 2 ); + rtems_test_assert( b.counter == 20 ); + + _Watchdog_Remove( &header, &c.Base ); + rtems_test_assert( header.first == NULL ); + rtems_test_assert( test_watchdog_is_inactive( &c ) ) ; + rtems_test_assert( c.Base.expire == 3 ); + rtems_test_assert( c.counter == 30 ); + + _Watchdog_Insert( &header, &a.Base, now + 2 ); + rtems_test_assert( header.first == &a.Base.Node.RBTree ); + rtems_test_assert( !test_watchdog_is_inactive( &a ) ) ; + rtems_test_assert( a.Base.expire == 3 ); + rtems_test_assert( a.counter == 10 ); + + _Watchdog_Insert( &header, &b.Base, now + 2 ); + rtems_test_assert( header.first == &a.Base.Node.RBTree ); + rtems_test_assert( !test_watchdog_is_inactive( &b ) ) ; + rtems_test_assert( b.Base.expire == 3 ); + rtems_test_assert( b.counter == 20 ); + + _Watchdog_Insert( &header, &c.Base, now + 3 ); + rtems_test_assert( header.first == &a.Base.Node.RBTree ); + rtems_test_assert( !test_watchdog_is_inactive( &c ) ) ; + rtems_test_assert( c.Base.expire == 4 ); + rtems_test_assert( c.counter == 30 ); + + now = test_watchdog_tick( &header, now ); + rtems_test_assert( !_RBTree_Is_empty( &header.Watchdogs ) ); + rtems_test_assert( header.first == &a.Base.Node.RBTree ); + rtems_test_assert( !test_watchdog_is_inactive( &a ) ) ; + rtems_test_assert( a.Base.expire == 3 ); + rtems_test_assert( a.counter == 10 ); + rtems_test_assert( !test_watchdog_is_inactive( &b ) ) ; + rtems_test_assert( b.Base.expire == 3 ); + rtems_test_assert( b.counter == 20 ); + rtems_test_assert( !test_watchdog_is_inactive( &c ) ) ; + rtems_test_assert( c.Base.expire == 4 ); + rtems_test_assert( c.counter == 30 ); + + now = test_watchdog_tick( &header, now ); + rtems_test_assert( !_RBTree_Is_empty( &header.Watchdogs ) ); + rtems_test_assert( header.first == &c.Base.Node.RBTree ); + rtems_test_assert( test_watchdog_is_inactive( &a ) ) ; + rtems_test_assert( a.Base.expire == 3 ); + rtems_test_assert( a.counter == 11 ); + rtems_test_assert( test_watchdog_is_inactive( &b ) ) ; + rtems_test_assert( b.Base.expire == 3 ); + rtems_test_assert( b.counter == 21 ); + rtems_test_assert( !test_watchdog_is_inactive( &c ) ) ; + rtems_test_assert( c.Base.expire == 4 ); + rtems_test_assert( c.counter == 30 ); + + now = test_watchdog_tick( &header, now ); + rtems_test_assert( _RBTree_Is_empty( &header.Watchdogs ) ); + rtems_test_assert( header.first == NULL ); + rtems_test_assert( test_watchdog_is_inactive( &a ) ) ; + rtems_test_assert( a.Base.expire == 3 ); + rtems_test_assert( a.counter == 11 ); + rtems_test_assert( test_watchdog_is_inactive( &b ) ) ; + rtems_test_assert( b.Base.expire == 3 ); + rtems_test_assert( b.counter == 21 ); + rtems_test_assert( test_watchdog_is_inactive( &c ) ) ; + rtems_test_assert( c.Base.expire == 4 ); + rtems_test_assert( c.counter == 31 ); + + _Watchdog_Header_destroy( &header ); } rtems_task Init( @@ -272,10 +223,8 @@ rtems_task Init( TEST_BEGIN(); + test_watchdog_operations(); test_watchdog_static_init(); - test_watchdog_insert_and_remove(); - test_watchdog_remove_second_and_insert_first(); - test_watchdog_insert_with_iterator(); build_time( &time, 12, 31, 1988, 9, 0, 0, 0 ); -- cgit v1.2.3