source: rtems/testsuites/sptests/spchain/init.c @ b431b66

4.115
Last change on this file since b431b66 was b431b66, checked in by Gedare Bloom <gedare@…>, on 11/26/11 at 18:07:52

2011-11-26 Gedare Bloom <gedare@…>

PR 1964

  • spchain/init.c, spchain/spchain.scn: Add testcases for chain is first and last
  • Property mode set to 100644
File size: 7.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <tmacros.h>
17#include <rtems/chain.h>
18
19#define EVENT RTEMS_EVENT_13
20#define TIMEOUT 1
21
22typedef struct {
23  rtems_chain_node Node;
24  int              id;
25} test_node;
26
27static void test_chain_control_initializer(void)
28{
29  rtems_chain_control chain = RTEMS_CHAIN_INITIALIZER_EMPTY( chain );
30  puts( "INIT - Verify rtems_chain_control initializer" );
31  rtems_test_assert( rtems_chain_is_empty( &chain ) );
32}
33
34static void test_chain_control_layout(void)
35{
36  rtems_chain_control chain;
37  puts( "INIT - Verify rtems_chain_control layout" );
38  rtems_test_assert(
39    sizeof(rtems_chain_control)
40      == sizeof(rtems_chain_node) + sizeof(rtems_chain_node *)
41  );
42  rtems_test_assert(
43    sizeof(rtems_chain_control)
44      == 3 * sizeof(rtems_chain_node *)
45  );
46  rtems_test_assert( &chain.Head.Node.previous == &chain.Tail.Node.next );
47}
48
49static void test_chain_get_with_wait(void)
50{
51  rtems_status_code sc = RTEMS_SUCCESSFUL;
52  rtems_chain_control chain;
53  rtems_chain_node *p = (rtems_chain_node *) 1;
54
55  puts( "INIT - Verify rtems_chain_get_with_wait" );
56  rtems_chain_initialize_empty( &chain );
57  sc = rtems_chain_get_with_wait( &chain, EVENT, TIMEOUT, &p );
58  rtems_test_assert( sc == RTEMS_TIMEOUT );
59  rtems_test_assert( p == NULL );
60}
61
62static void test_chain_first_and_last(void)
63{
64  rtems_chain_control   chain;
65  rtems_chain_node      node1, node2;
66  rtems_chain_node     *cnode;
67
68  rtems_chain_initialize_empty( &chain );
69  rtems_chain_append( &chain, &node1 );
70  rtems_chain_insert( &node1, &node2 );
71
72  puts( "INIT - Verify rtems_chain_is_first" );
73  cnode = rtems_chain_first(&chain); 
74  rtems_test_assert( rtems_chain_is_first( cnode ) );
75
76  puts( "INIT - Verify rtems_chain_is_last" );
77  cnode = rtems_chain_last(&chain);
78  rtems_test_assert( rtems_chain_is_last( cnode ) );
79}
80
81static void test_chain_with_notification(void)
82{
83  rtems_status_code sc = RTEMS_SUCCESSFUL;
84  rtems_chain_control chain;
85  rtems_chain_node a;
86  rtems_chain_node b;
87  rtems_chain_node *p = (rtems_chain_node *) 1;
88  rtems_event_set out = 0;
89
90  puts( "INIT - Verify rtems_chain_append_with_notification" );
91  rtems_chain_initialize_empty( &chain );
92  sc = rtems_chain_append_with_notification(
93    &chain,
94    &a,
95    rtems_task_self(),
96    EVENT
97  );
98  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
99  sc = rtems_chain_get_with_wait( &chain, EVENT, TIMEOUT, &p );
100  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
101  rtems_test_assert( p == &a );
102
103  rtems_chain_initialize_empty( &chain );
104
105  rtems_chain_append( &chain, &b );
106  sc = rtems_chain_append_with_notification(
107    &chain,
108    &a,
109    rtems_task_self(),
110    EVENT
111  );
112  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
113  rtems_test_assert( p == &a );
114
115  puts( "INIT - Verify rtems_chain_prepend_with_notification" );
116  rtems_chain_initialize_empty( &chain );
117  sc = rtems_chain_prepend_with_notification(
118    &chain,
119    &a,
120    rtems_task_self(),
121    EVENT
122  );
123  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
124  sc = rtems_chain_get_with_wait( &chain, EVENT, TIMEOUT, &p );
125  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
126  rtems_test_assert( p == &a );
127
128  rtems_chain_prepend( &chain, &b );
129  sc = rtems_chain_prepend_with_notification(
130    &chain,
131    &a,
132    rtems_task_self(),
133    EVENT
134  );
135  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
136  rtems_test_assert( p == &a );
137
138  puts( "INIT - Verify rtems_chain_prepend_with_notification" );
139  puts( "INIT - Verify rtems_chain_get_with_notification" );
140  rtems_chain_initialize_empty( &chain );
141
142  rtems_chain_append( &chain, &b );
143  rtems_chain_append( &chain, &a );
144
145  sc = rtems_chain_get_with_notification(&chain, rtems_task_self(), EVENT, &p);
146  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
147  rtems_test_assert( p == &b );
148
149  sc = rtems_chain_get_with_notification(&chain, rtems_task_self(), EVENT, &p);
150  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
151  rtems_test_assert( p == &a );
152  sc = rtems_event_receive(
153    EVENT,
154    RTEMS_EVENT_ALL | RTEMS_WAIT,
155    TIMEOUT,
156    &out
157  );
158  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
159  rtems_test_assert( out == EVENT );
160}
161
162static void test_chain_with_empty_check(void)
163{
164  rtems_chain_control chain;
165  rtems_chain_node a;
166  rtems_chain_node b;
167  rtems_chain_node *p;
168  bool empty;
169
170  puts( "INIT - Verify rtems_chain_append_with_empty_check" );
171  rtems_chain_initialize_empty( &chain );
172  empty = rtems_chain_append_with_empty_check( &chain, &a );
173  rtems_test_assert( empty );
174  empty = rtems_chain_append_with_empty_check( &chain, &a );
175  rtems_test_assert( !empty );
176
177  puts( "INIT - Verify rtems_chain_prepend_with_empty_check" );
178  rtems_chain_initialize_empty( &chain );
179  empty = rtems_chain_prepend_with_empty_check( &chain, &a );
180  rtems_test_assert( empty );
181  empty = rtems_chain_prepend_with_empty_check( &chain, &a );
182  rtems_test_assert( !empty );
183  empty = rtems_chain_prepend_with_empty_check( &chain, &b );
184  rtems_test_assert( !empty );
185
186  puts( "INIT - Verify rtems_chain_get_with_empty_check" );
187  rtems_chain_initialize_empty( &chain );
188  empty = rtems_chain_get_with_empty_check( &chain, &p );
189  rtems_test_assert( empty );
190
191  rtems_chain_append( &chain, &a );
192  rtems_chain_append( &chain, &b );
193  empty = rtems_chain_get_with_empty_check( &chain, &p );
194  rtems_test_assert( !empty );
195  rtems_test_assert( p == &a );
196  empty = rtems_chain_get_with_empty_check( &chain, &p );
197  rtems_test_assert( empty );
198  rtems_test_assert( p == &b );
199}
200
201rtems_task Init(
202  rtems_task_argument ignored
203)
204{
205  rtems_chain_control  chain1;
206  rtems_chain_node    *p;
207  test_node            node1, node2;
208  int                  id;
209
210  puts( "\n\n*** TEST OF RTEMS CHAIN API ***" );
211
212  puts( "Init - Initialize chain empty" );
213  rtems_chain_initialize_empty( &chain1 );
214
215  /* verify that the chain append and insert work */
216  puts( "INIT - Verify rtems_chain_insert" );
217  node1.id = 1;
218  node2.id = 2;
219  rtems_chain_append( &chain1, &node1.Node );
220  rtems_chain_insert( &node1.Node, &node2.Node );
221
222  for ( p = rtems_chain_first(&chain1), id = 1 ;
223        !rtems_chain_is_tail(&chain1, p) ;
224        p = p->next , id++ ) {
225     test_node *t = (test_node *)p;
226     if ( id > 2 ) {
227       puts( "INIT - TOO MANY NODES ON CHAIN" );
228       rtems_test_exit(0);
229     }
230     if ( t->id != id ) {
231       puts( "INIT - ERROR ON CHAIN ID MISMATCH" );
232       rtems_test_exit(0);
233     }
234  }
235
236  test_chain_first_and_last();
237  test_chain_with_empty_check();
238  test_chain_with_notification();
239  test_chain_get_with_wait();
240  test_chain_control_layout();
241  test_chain_control_initializer();
242
243  puts( "*** END OF RTEMS CHAIN API TEST ***" );
244  rtems_test_exit(0);
245}
246
247/* configuration information */
248
249#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
250#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
251
252#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
253#define CONFIGURE_MAXIMUM_TASKS 1
254
255#define CONFIGURE_INIT
256#include <rtems/confdefs.h>
257
258/* global variables */
Note: See TracBrowser for help on using the repository browser.