[37cff02] | 1 | /* |
---|
[9e15e9b] | 2 | * COPYRIGHT (c) 1989-2011. |
---|
[37cff02] | 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 | |
---|
[7d3f9c6] | 12 | #ifdef HAVE_CONFIG_H |
---|
| 13 | #include "config.h" |
---|
| 14 | #endif |
---|
| 15 | |
---|
[37cff02] | 16 | #include <tmacros.h> |
---|
| 17 | #include <rtems/chain.h> |
---|
| 18 | |
---|
[469e71d] | 19 | #define EVENT RTEMS_EVENT_13 |
---|
| 20 | #define TIMEOUT 1 |
---|
| 21 | |
---|
[37cff02] | 22 | typedef struct { |
---|
| 23 | rtems_chain_node Node; |
---|
| 24 | int id; |
---|
| 25 | } test_node; |
---|
| 26 | |
---|
[fb01c022] | 27 | static 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 | |
---|
| 34 | static 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 | ); |
---|
[719f4dd] | 42 | rtems_test_assert( |
---|
| 43 | sizeof(rtems_chain_control) |
---|
| 44 | == 3 * sizeof(rtems_chain_node *) |
---|
| 45 | ); |
---|
[fb01c022] | 46 | rtems_test_assert( &chain.Head.Node.previous == &chain.Tail.Node.next ); |
---|
| 47 | } |
---|
| 48 | |
---|
[469e71d] | 49 | static 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 | |
---|
[b431b66] | 62 | static 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 | |
---|
[469e71d] | 81 | static void test_chain_with_notification(void) |
---|
| 82 | { |
---|
| 83 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
| 84 | rtems_chain_control chain; |
---|
| 85 | rtems_chain_node a; |
---|
[4cdce0e] | 86 | rtems_chain_node b; |
---|
[469e71d] | 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 ); |
---|
[9e15e9b] | 92 | sc = rtems_chain_append_with_notification( |
---|
| 93 | &chain, |
---|
| 94 | &a, |
---|
| 95 | rtems_task_self(), |
---|
| 96 | EVENT |
---|
| 97 | ); |
---|
[469e71d] | 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 | |
---|
[9d5f600] | 103 | rtems_chain_initialize_empty( &chain ); |
---|
| 104 | |
---|
| 105 | rtems_chain_append( &chain, &b ); |
---|
[9e15e9b] | 106 | sc = rtems_chain_append_with_notification( |
---|
| 107 | &chain, |
---|
| 108 | &a, |
---|
| 109 | rtems_task_self(), |
---|
| 110 | EVENT |
---|
| 111 | ); |
---|
[9d5f600] | 112 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
| 113 | rtems_test_assert( p == &a ); |
---|
| 114 | |
---|
[469e71d] | 115 | puts( "INIT - Verify rtems_chain_prepend_with_notification" ); |
---|
| 116 | rtems_chain_initialize_empty( &chain ); |
---|
[9e15e9b] | 117 | sc = rtems_chain_prepend_with_notification( |
---|
| 118 | &chain, |
---|
| 119 | &a, |
---|
| 120 | rtems_task_self(), |
---|
| 121 | EVENT |
---|
| 122 | ); |
---|
[469e71d] | 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 | |
---|
[9d5f600] | 128 | rtems_chain_prepend( &chain, &b ); |
---|
[9e15e9b] | 129 | sc = rtems_chain_prepend_with_notification( |
---|
| 130 | &chain, |
---|
| 131 | &a, |
---|
| 132 | rtems_task_self(), |
---|
| 133 | EVENT |
---|
| 134 | ); |
---|
[9d5f600] | 135 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
| 136 | rtems_test_assert( p == &a ); |
---|
| 137 | |
---|
| 138 | puts( "INIT - Verify rtems_chain_prepend_with_notification" ); |
---|
[469e71d] | 139 | puts( "INIT - Verify rtems_chain_get_with_notification" ); |
---|
| 140 | rtems_chain_initialize_empty( &chain ); |
---|
[4cdce0e] | 141 | |
---|
| 142 | rtems_chain_append( &chain, &b ); |
---|
[469e71d] | 143 | rtems_chain_append( &chain, &a ); |
---|
[4cdce0e] | 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); |
---|
[469e71d] | 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 | |
---|
| 162 | static 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 ); |
---|
[4cdce0e] | 183 | empty = rtems_chain_prepend_with_empty_check( &chain, &b ); |
---|
| 184 | rtems_test_assert( !empty ); |
---|
[469e71d] | 185 | |
---|
| 186 | puts( "INIT - Verify rtems_chain_get_with_empty_check" ); |
---|
| 187 | rtems_chain_initialize_empty( &chain ); |
---|
[4cdce0e] | 188 | empty = rtems_chain_get_with_empty_check( &chain, &p ); |
---|
| 189 | rtems_test_assert( empty ); |
---|
| 190 | |
---|
[469e71d] | 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 | |
---|
[37cff02] | 201 | rtems_task Init( |
---|
| 202 | rtems_task_argument ignored |
---|
| 203 | ) |
---|
| 204 | { |
---|
[b1274bd9] | 205 | rtems_chain_control chain1; |
---|
[37cff02] | 206 | rtems_chain_node *p; |
---|
[b1274bd9] | 207 | test_node node1, node2; |
---|
[37cff02] | 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 | |
---|
[ae78019] | 222 | for ( p = rtems_chain_first(&chain1), id = 1 ; |
---|
[37cff02] | 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 | |
---|
[b431b66] | 236 | test_chain_first_and_last(); |
---|
[469e71d] | 237 | test_chain_with_empty_check(); |
---|
| 238 | test_chain_with_notification(); |
---|
| 239 | test_chain_get_with_wait(); |
---|
[fb01c022] | 240 | test_chain_control_layout(); |
---|
| 241 | test_chain_control_initializer(); |
---|
[469e71d] | 242 | |
---|
[84b7a968] | 243 | puts( "*** END OF RTEMS CHAIN API TEST ***" ); |
---|
[37cff02] | 244 | rtems_test_exit(0); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | /* configuration information */ |
---|
| 248 | |
---|
| 249 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
[469e71d] | 250 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
[37cff02] | 251 | |
---|
[84b7a968] | 252 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 253 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
[37cff02] | 254 | |
---|
| 255 | #define CONFIGURE_INIT |
---|
| 256 | #include <rtems/confdefs.h> |
---|
| 257 | |
---|
| 258 | /* global variables */ |
---|