source: rtems/testsuites/sptests/spwatchdog/init.c @ 80fca28

4.11
Last change on this file since 80fca28 was 80fca28, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 13, 2015 at 1:29:04 PM

score: Add _Watchdog_Preinitialize()

Add an assert to ensure that the watchdog is the proper state for a
_Watchdog_Initialize(). This helps to detect invalid initializations
which may lead to a corrupt watchdog chain.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*  Init
2 *
3 *  This routine is the XXX.
4 *
5 *  Input parameters:
6 *    argument - task argument
7 *
8 *  Output parameters:  NONE
9 *
10 *  COPYRIGHT (c) 2008.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#define CONFIGURE_INIT
23#include "system.h"
24
25#include <rtems/score/watchdogimpl.h>
26
27const char rtems_test_name[] = "SPWATCHDOG";
28
29static void test_watchdog_routine( Objects_Id id, void *arg )
30{
31  (void) id;
32  (void) arg;
33
34  rtems_test_assert( 0 );
35}
36
37static void init_watchdogs(
38  Watchdog_Header *header,
39  Watchdog_Control watchdogs[3]
40)
41{
42  Watchdog_Control *a = &watchdogs[0];
43  Watchdog_Control *b = &watchdogs[1];
44  Watchdog_Control *c = &watchdogs[2];
45  Watchdog_Control *d = &watchdogs[3];
46
47  _Watchdog_Header_initialize( header );
48  rtems_test_assert( _Watchdog_Is_empty( header ) );
49  rtems_test_assert( _Chain_Is_empty( &header->Iterators ) );
50
51  _Watchdog_Preinitialize( c );
52  c->initial = 6;
53  _Watchdog_Insert( header, c );
54  rtems_test_assert( c->delta_interval == 6 );
55
56  rtems_test_assert( !_Watchdog_Is_empty( header ) );
57  rtems_test_assert( _Chain_Is_empty( &header->Iterators ) );
58
59  _Watchdog_Preinitialize( a );
60  a->initial = 2;
61  _Watchdog_Insert( header, a );
62  rtems_test_assert( a->delta_interval == 2 );
63  rtems_test_assert( c->delta_interval == 4 );
64
65  _Watchdog_Preinitialize( b );
66  b->initial = 4;
67  _Watchdog_Insert( header, b );
68  rtems_test_assert( a->delta_interval == 2 );
69  rtems_test_assert( b->delta_interval == 2 );
70  rtems_test_assert( c->delta_interval == 2 );
71
72  _Watchdog_Preinitialize( d );
73}
74
75static void destroy_watchdogs(
76  Watchdog_Header *header
77)
78{
79  _ISR_lock_Destroy( &header->Lock );
80}
81
82static void add_iterator(
83  Watchdog_Header *header,
84  Watchdog_Iterator *i,
85  Watchdog_Control *w
86)
87{
88  _Chain_Append_unprotected( &header->Iterators, &i->Node );
89  i->delta_interval = 2;
90  i->current = &w->Node;
91}
92
93static void test_watchdog_insert_and_remove( void )
94{
95  Watchdog_Header header;
96  Watchdog_Control watchdogs[4];
97  Watchdog_Control *a = &watchdogs[0];
98  Watchdog_Control *b = &watchdogs[1];
99  Watchdog_Control *c = &watchdogs[2];
100  Watchdog_Control *d = &watchdogs[3];
101  Watchdog_Iterator i;
102
103  init_watchdogs( &header, watchdogs );
104  add_iterator( &header, &i, c );
105
106  /* Remove next watchdog of iterator */
107  _Watchdog_Remove( &header, c );
108  rtems_test_assert( i.delta_interval == 2 );
109  rtems_test_assert( i.current == &b->Node );
110
111  /* Remove watchdog before the current watchdog of iterator */
112  _Watchdog_Remove( &header, a );
113  rtems_test_assert( i.delta_interval == 4 );
114  rtems_test_assert( i.current == &b->Node );
115
116  /* Remove current (= last) watchdog of iterator */
117  _Watchdog_Remove( &header, b );
118  rtems_test_assert( i.delta_interval == 4 );
119  rtems_test_assert( i.current == _Chain_Head( &header.Watchdogs ) );
120
121  /* Insert first watchdog */
122  a->initial = 1;
123  _Watchdog_Insert( &header, a );
124  rtems_test_assert( i.delta_interval == 4 );
125  rtems_test_assert( i.current == _Chain_Head( &header.Watchdogs ) );
126
127  destroy_watchdogs( &header );
128  init_watchdogs( &header, watchdogs );
129  add_iterator( &header, &i, b );
130
131  /* Insert right before current watchdog of iterator */
132  d->initial = 3;
133  _Watchdog_Insert( &header, d );
134  rtems_test_assert( i.delta_interval == 1 );
135  rtems_test_assert( i.current == &b->Node );
136
137  destroy_watchdogs( &header );
138  init_watchdogs( &header, watchdogs );
139  add_iterator( &header, &i, b );
140
141  /* Insert right after current watchdog of iterator */
142  d->initial = 5;
143  _Watchdog_Insert( &header, d );
144  rtems_test_assert( i.delta_interval == 2 );
145  rtems_test_assert( i.current == &b->Node );
146
147  destroy_watchdogs( &header );
148}
149
150static void test_watchdog_static_init( void )
151{
152  #if defined(RTEMS_USE_16_BIT_OBJECT)
153    #define JUNK_ID 0x1234
154  #else
155    #define JUNK_ID 0x12345678
156  #endif
157
158  static Watchdog_Control a = WATCHDOG_INITIALIZER(
159    test_watchdog_routine,
160    JUNK_ID,
161    (void *) 0xdeadbeef
162  );
163  Watchdog_Control b;
164
165  memset( &b, 0, sizeof( b ) );
166  _Watchdog_Initialize(
167    &b,
168    test_watchdog_routine,
169    JUNK_ID,
170    (void *) 0xdeadbeef
171  );
172
173  rtems_test_assert( memcmp( &a, &b, sizeof( a ) ) == 0 );
174}
175
176rtems_task Init(
177  rtems_task_argument argument
178)
179{
180  rtems_time_of_day  time;
181  rtems_status_code  status;
182
183  TEST_BEGIN();
184
185  test_watchdog_static_init();
186  test_watchdog_insert_and_remove();
187
188  build_time( &time, 12, 31, 1988, 9, 0, 0, 0 );
189
190  status = rtems_clock_set( &time );
191  directive_failed( status, "rtems_clock_set" );
192
193  Task_name[ 1 ]  = rtems_build_name( 'T', 'A', '1', ' ' );
194  Timer_name[ 1 ] = rtems_build_name( 'T', 'M', '1', ' ' );
195
196  status = rtems_task_create(
197    Task_name[ 1 ],
198    1,
199    RTEMS_MINIMUM_STACK_SIZE * 2,
200    RTEMS_DEFAULT_MODES,
201    RTEMS_DEFAULT_ATTRIBUTES,
202    &Task_id[ 1 ]
203  );
204  directive_failed( status, "rtems_task_create of TA1" );
205
206  status = rtems_task_start( Task_id[ 1 ], Task_1, 0 );
207  directive_failed( status, "rtems_task_start of TA1" );
208
209  puts( "INIT - rtems_timer_create - creating timer 1" );
210  status = rtems_timer_create( Timer_name[ 1 ], &Timer_id[ 1 ] );
211  directive_failed( status, "rtems_timer_create" );
212
213  printf( "INIT - timer 1 has id (0x%" PRIxrtems_id ")\n", Timer_id[ 1 ] );
214
215  status = rtems_task_delete( RTEMS_SELF );
216  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
217
218
219  rtems_test_exit( 0 );
220}
Note: See TracBrowser for help on using the repository browser.