source: rtems/testsuites/sptests/spassoc01/init.c @ 6c0301d

4.115
Last change on this file since 6c0301d was 6c0301d, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:21

tests/sptests: Use <rtems/test.h>

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
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.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <tmacros.h>
15#include "test_support.h"
16
17#include <stdio.h>
18#include <rtems/assoc.h>
19
20const char rtems_test_name[] = "SPASSOC 1";
21
22/* forward declarations to avoid warnings */
23rtems_task Init(rtems_task_argument argument);
24
25const rtems_assoc_t assoc_table_null[] =
26  {
27    { NULL       , 0 , 0  },
28    { "zero"     , 1 , 8  },
29    { "one"      , 2 , 4  },
30    { "two"      , 4 , 2  },
31    { "three"    , 8 , 1  },
32    { NULL       , -1, -1 }
33  };
34
35const rtems_assoc_t assoc_table_default[] =
36  {
37    { "(default)", 0 , 0  },
38    { "zero"     , 1 , 8  },
39    { "one"      , 2 , 4  },
40    { "two"      , 4 , 2  },
41    { "three"    , 8 , 1  },
42    { NULL       , -1, -1 }
43  };
44
45const rtems_assoc_t assoc_table[] =
46  {
47    { "zero" , 1 , 8  },
48    { "one"  , 2 , 4  },
49    { "two"  , 4 , 2  },
50    { "three", 8 , 1  },
51    { NULL   , -1, -1 }
52  };
53
54uint32_t local;
55uint32_t remote;
56const rtems_assoc_t *assoc_item;
57char *name;
58
59static void reset_name( void )
60{
61  memset( name, 0, 40 );
62}
63
64rtems_task Init(
65  rtems_task_argument argument
66)
67{
68  name = malloc(40);
69  TEST_BEGIN();
70
71  puts( "Init - get local by name -- OK" );
72  local = rtems_assoc_local_by_name( assoc_table, "zero" );
73  rtems_test_assert( local == 1 );
74
75  puts( "Init - get local by name -- expect 0" );
76  local = rtems_assoc_local_by_name( assoc_table, "four" );
77  rtems_test_assert( local == 0 );
78
79  puts( "Init - get local by remote bitfield -- OK" );
80  local = rtems_assoc_local_by_remote_bitfield( assoc_table, 1 );
81  rtems_test_assert( local == 8 );
82
83  puts( "Init - get local by remote bitfield -- expect 0" );
84  local = rtems_assoc_local_by_remote_bitfield( assoc_table, 0 );
85  rtems_test_assert( local == 0 );
86
87  puts( "Init - get local by remote -- OK" );
88  local = rtems_assoc_local_by_remote( assoc_table, 1 );
89  rtems_test_assert( local == 8 );
90
91  puts( "Init - get local by remote -- expect 0" );
92  local = rtems_assoc_local_by_remote( assoc_table, 0 );
93  rtems_test_assert( local == 0 );
94
95  reset_name();
96  puts( "Init - get name by local bitfield -- OK" );
97  name = rtems_assoc_name_by_local_bitfield( assoc_table, 1, name );
98  rtems_test_assert ( !strcmp( name, "zero" ) );
99
100  reset_name();
101  puts( "Init - get name by local bitfield -- OK" );
102  name = rtems_assoc_name_by_local_bitfield( assoc_table, 3, name );
103  rtems_test_assert ( !strcmp( name, "zero one" ) );
104
105  reset_name();
106  puts( "Init - get name by local bitfield -- expect\"\"" );
107  name = rtems_assoc_name_by_local_bitfield( assoc_table, 0, name );
108  rtems_test_assert ( !strcmp( name, "" ) );
109 
110  reset_name();
111  puts( "Init - get name by local -- OK" );
112  rtems_test_assert( !strcmp( rtems_assoc_name_by_local( assoc_table, 1 ),
113                              "zero" ) );
114 
115  reset_name();
116  puts( "Init - get name by local -- using bad value" );
117  puts( rtems_assoc_name_by_local( assoc_table, 0 ) );
118
119  reset_name();
120  puts( "Init - get name by remote bitfield -- OK" );
121  name =
122    rtems_assoc_name_by_remote_bitfield( assoc_table, 1, name );
123  rtems_test_assert ( !strcmp( name, "three" ) );
124
125  reset_name();
126  puts( "Init - get name by remote bitfield -- OK" );
127  name =
128    rtems_assoc_name_by_remote_bitfield( assoc_table, 3, name );
129  rtems_test_assert ( !strcmp( name, "three two" ) );
130
131  reset_name();
132  puts( "Init - get name by remote bitfield -- expect\"\"" );
133  name =
134    rtems_assoc_name_by_remote_bitfield( assoc_table, 0, name );
135  rtems_test_assert ( !strcmp( name, "" ) );
136 
137  reset_name();
138  puts( "Init - get name by remote -- OK" );
139  rtems_test_assert( !strcmp( rtems_assoc_name_by_remote( assoc_table, 1 ),
140                              "three" ) );
141 
142  reset_name();
143  puts( "Init - get name by remote -- using bad value" );
144  puts( rtems_assoc_name_by_remote( assoc_table, 0 ) );
145
146  puts( "Init - get ptr by local -- OK" );
147  assoc_item = rtems_assoc_ptr_by_local( assoc_table, 1 );
148  rtems_test_assert( assoc_item == assoc_table );
149
150  puts( "Init - get ptr by local -- expect NULL" );
151  assoc_item = rtems_assoc_ptr_by_local( assoc_table, 0 );
152  rtems_test_assert( assoc_item == 0 );
153
154  puts( "Init - get ptr by remote -- OK" );
155  assoc_item = rtems_assoc_ptr_by_remote( assoc_table, 8 );
156  rtems_test_assert( assoc_item == assoc_table );
157
158  puts( "Init - get ptr by remote -- expect NULL" );
159  assoc_item = rtems_assoc_ptr_by_remote( assoc_table, 0 );
160  rtems_test_assert( assoc_item == 0 );
161
162  puts( "Init - get ptr by name -- OK" );
163  assoc_item = rtems_assoc_ptr_by_name( assoc_table, "zero" );
164  rtems_test_assert( assoc_item == assoc_table );
165
166  puts( "Init - get ptr by name -- expect NULL" );
167  assoc_item = rtems_assoc_ptr_by_name( assoc_table, "six" );
168  rtems_test_assert( assoc_item == 0 );
169
170  puts( "Init - get remote by local bitfield -- OK" );
171  remote = rtems_assoc_remote_by_local_bitfield( assoc_table, 1 );
172  rtems_test_assert( remote == 8 );
173
174  puts( "Init - get remote by local bitfield -- expect 0" );
175  remote = rtems_assoc_remote_by_local_bitfield( assoc_table, 0 );
176  rtems_test_assert( remote == 0 );
177
178  puts( "Init - get remote by local -- OK" );
179  remote = rtems_assoc_remote_by_local( assoc_table, 1 );
180  rtems_test_assert( remote == 8 );
181
182  puts( "Init - get remote by local -- expect 0" );
183  remote = rtems_assoc_remote_by_local( assoc_table, 0 );
184  rtems_test_assert( remote == 0 );
185
186  puts( "Init - get remote by name -- OK" );
187  remote = rtems_assoc_remote_by_name( assoc_table, "zero" );
188  rtems_test_assert( remote == 8 );
189
190  puts( "Init - get remote by name -- expect 0" );
191  remote = rtems_assoc_remote_by_name( assoc_table, "six" );
192  rtems_test_assert( remote == 0 );
193
194  puts( "Init - get ptr by name -- expect (default)" );
195  assoc_item = rtems_assoc_ptr_by_name( assoc_table_default, "six" );
196  rtems_test_assert( assoc_item == assoc_table_default );
197
198  puts( "Init - get ptr by local -- expect (default)" );
199  assoc_item = rtems_assoc_ptr_by_local( assoc_table_default, 0 );
200  rtems_test_assert( assoc_item == assoc_table_default );
201
202  puts( "Init - get ptr by remote -- expect (default)" );
203  assoc_item = rtems_assoc_ptr_by_remote( assoc_table_default, 0 );
204  rtems_test_assert( assoc_item == assoc_table_default );
205
206  puts( "Init - get ptr by name -- expect NULL" );
207  assoc_item = rtems_assoc_ptr_by_name( assoc_table_null, "six" );
208  rtems_test_assert( assoc_item == 0 );
209
210  puts( "Init - get ptr by local -- expect NULL" );
211  assoc_item = rtems_assoc_ptr_by_local( assoc_table_null, 0 );
212  rtems_test_assert( assoc_item == 0 );
213
214  puts( "Init - get ptr by remote -- expect NULL" );
215  assoc_item = rtems_assoc_ptr_by_remote( assoc_table_null, 0 );
216  rtems_test_assert( assoc_item == 0 );
217
218  free( name );
219
220  TEST_END();
221
222  rtems_test_exit(0);
223}
224
225/* configuration information */
226
227#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
228#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
229
230#define CONFIGURE_MAXIMUM_TASKS             1
231#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
232
233#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
234
235#define CONFIGURE_INIT
236
237#include <rtems/confdefs.h>
238/* end of file */
Note: See TracBrowser for help on using the repository browser.