source: rtems/testsuites/sptests/spassoc01/init.c @ 32e8fc3

5
Last change on this file since 32e8fc3 was 32e8fc3, checked in by Sebastian Huber <sebastian.huber@…>, on 01/19/18 at 08:57:05

spassoc01: Use floating-point task

This test uses sprintf().

  • Property mode set to 100644
File size: 8.2 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
64static void test_assoc_32_to_string( void )
65{
66  static const rtems_assoc_32_pair pairs[] = {
67    { 1, "A" },
68    { 2, "LOOOOONG" },
69    { 4, "C" }
70  };
71  char buf[4];
72  size_t len;
73
74  len = rtems_assoc_32_to_string(
75    0,
76    buf,
77    sizeof( buf ),
78    pairs,
79    RTEMS_ARRAY_SIZE( pairs ),
80    ":",
81    "D"
82  );
83  rtems_test_assert( len == 1 );
84  rtems_test_assert( strcmp( buf, "D" ) == 0 );
85
86  len = rtems_assoc_32_to_string(
87    1,
88    buf,
89    sizeof( buf ),
90    pairs,
91    RTEMS_ARRAY_SIZE( pairs ),
92    ":",
93    "D"
94  );
95  rtems_test_assert( len == 1 );
96  rtems_test_assert( strcmp( buf, "A" ) == 0 );
97
98  len = rtems_assoc_32_to_string(
99    5,
100    buf,
101    sizeof( buf ),
102    pairs,
103    RTEMS_ARRAY_SIZE( pairs ),
104    ":",
105    "D"
106  );
107  rtems_test_assert( len == 3 );
108  rtems_test_assert( strcmp( buf, "A:C" ) == 0 );
109
110  len = rtems_assoc_32_to_string(
111    7,
112    buf,
113    sizeof( buf ),
114    pairs,
115    RTEMS_ARRAY_SIZE( pairs ),
116    ":",
117    "D"
118  );
119  rtems_test_assert( len == 12 );
120  rtems_test_assert( strcmp( buf, "A:L" ) == 0 );
121}
122
123rtems_task Init(
124  rtems_task_argument argument
125)
126{
127  name = malloc(40);
128  TEST_BEGIN();
129
130  puts( "Init - get local by name -- OK" );
131  local = rtems_assoc_local_by_name( assoc_table, "zero" );
132  rtems_test_assert( local == 1 );
133
134  puts( "Init - get local by name -- expect 0" );
135  local = rtems_assoc_local_by_name( assoc_table, "four" );
136  rtems_test_assert( local == 0 );
137
138  puts( "Init - get local by remote bitfield -- OK" );
139  local = rtems_assoc_local_by_remote_bitfield( assoc_table, 1 );
140  rtems_test_assert( local == 8 );
141
142  puts( "Init - get local by remote bitfield -- expect 0" );
143  local = rtems_assoc_local_by_remote_bitfield( assoc_table, 0 );
144  rtems_test_assert( local == 0 );
145
146  puts( "Init - get local by remote -- OK" );
147  local = rtems_assoc_local_by_remote( assoc_table, 1 );
148  rtems_test_assert( local == 8 );
149
150  puts( "Init - get local by remote -- expect 0" );
151  local = rtems_assoc_local_by_remote( assoc_table, 0 );
152  rtems_test_assert( local == 0 );
153
154  reset_name();
155  puts( "Init - get name by local bitfield -- OK" );
156  name = rtems_assoc_name_by_local_bitfield( assoc_table, 1, name );
157  rtems_test_assert ( !strcmp( name, "zero" ) );
158
159  reset_name();
160  puts( "Init - get name by local bitfield -- OK" );
161  name = rtems_assoc_name_by_local_bitfield( assoc_table, 3, name );
162  rtems_test_assert ( !strcmp( name, "zero one" ) );
163
164  reset_name();
165  puts( "Init - get name by local bitfield -- expect\"\"" );
166  name = rtems_assoc_name_by_local_bitfield( assoc_table, 0, name );
167  rtems_test_assert ( !strcmp( name, "" ) );
168 
169  reset_name();
170  puts( "Init - get name by local -- OK" );
171  rtems_test_assert( !strcmp( rtems_assoc_name_by_local( assoc_table, 1 ),
172                              "zero" ) );
173 
174  reset_name();
175  puts( "Init - get name by local -- using bad value" );
176  puts( rtems_assoc_name_by_local( assoc_table, 0 ) );
177
178  reset_name();
179  puts( "Init - get name by remote bitfield -- OK" );
180  name =
181    rtems_assoc_name_by_remote_bitfield( assoc_table, 1, name );
182  rtems_test_assert ( !strcmp( name, "three" ) );
183
184  reset_name();
185  puts( "Init - get name by remote bitfield -- OK" );
186  name =
187    rtems_assoc_name_by_remote_bitfield( assoc_table, 3, name );
188  rtems_test_assert ( !strcmp( name, "three two" ) );
189
190  reset_name();
191  puts( "Init - get name by remote bitfield -- expect\"\"" );
192  name =
193    rtems_assoc_name_by_remote_bitfield( assoc_table, 0, name );
194  rtems_test_assert ( !strcmp( name, "" ) );
195 
196  reset_name();
197  puts( "Init - get name by remote -- OK" );
198  rtems_test_assert( !strcmp( rtems_assoc_name_by_remote( assoc_table, 1 ),
199                              "three" ) );
200 
201  reset_name();
202  puts( "Init - get name by remote -- using bad value" );
203  puts( rtems_assoc_name_by_remote( assoc_table, 0 ) );
204
205  puts( "Init - get ptr by local -- OK" );
206  assoc_item = rtems_assoc_ptr_by_local( assoc_table, 1 );
207  rtems_test_assert( assoc_item == assoc_table );
208
209  puts( "Init - get ptr by local -- expect NULL" );
210  assoc_item = rtems_assoc_ptr_by_local( assoc_table, 0 );
211  rtems_test_assert( assoc_item == 0 );
212
213  puts( "Init - get ptr by remote -- OK" );
214  assoc_item = rtems_assoc_ptr_by_remote( assoc_table, 8 );
215  rtems_test_assert( assoc_item == assoc_table );
216
217  puts( "Init - get ptr by remote -- expect NULL" );
218  assoc_item = rtems_assoc_ptr_by_remote( assoc_table, 0 );
219  rtems_test_assert( assoc_item == 0 );
220
221  puts( "Init - get ptr by name -- OK" );
222  assoc_item = rtems_assoc_ptr_by_name( assoc_table, "zero" );
223  rtems_test_assert( assoc_item == assoc_table );
224
225  puts( "Init - get ptr by name -- expect NULL" );
226  assoc_item = rtems_assoc_ptr_by_name( assoc_table, "six" );
227  rtems_test_assert( assoc_item == 0 );
228
229  puts( "Init - get remote by local bitfield -- OK" );
230  remote = rtems_assoc_remote_by_local_bitfield( assoc_table, 1 );
231  rtems_test_assert( remote == 8 );
232
233  puts( "Init - get remote by local bitfield -- expect 0" );
234  remote = rtems_assoc_remote_by_local_bitfield( assoc_table, 0 );
235  rtems_test_assert( remote == 0 );
236
237  puts( "Init - get remote by local -- OK" );
238  remote = rtems_assoc_remote_by_local( assoc_table, 1 );
239  rtems_test_assert( remote == 8 );
240
241  puts( "Init - get remote by local -- expect 0" );
242  remote = rtems_assoc_remote_by_local( assoc_table, 0 );
243  rtems_test_assert( remote == 0 );
244
245  puts( "Init - get remote by name -- OK" );
246  remote = rtems_assoc_remote_by_name( assoc_table, "zero" );
247  rtems_test_assert( remote == 8 );
248
249  puts( "Init - get remote by name -- expect 0" );
250  remote = rtems_assoc_remote_by_name( assoc_table, "six" );
251  rtems_test_assert( remote == 0 );
252
253  puts( "Init - get ptr by name -- expect (default)" );
254  assoc_item = rtems_assoc_ptr_by_name( assoc_table_default, "six" );
255  rtems_test_assert( assoc_item == assoc_table_default );
256
257  puts( "Init - get ptr by local -- expect (default)" );
258  assoc_item = rtems_assoc_ptr_by_local( assoc_table_default, 0 );
259  rtems_test_assert( assoc_item == assoc_table_default );
260
261  puts( "Init - get ptr by remote -- expect (default)" );
262  assoc_item = rtems_assoc_ptr_by_remote( assoc_table_default, 0 );
263  rtems_test_assert( assoc_item == assoc_table_default );
264
265  puts( "Init - get ptr by name -- expect NULL" );
266  assoc_item = rtems_assoc_ptr_by_name( assoc_table_null, "six" );
267  rtems_test_assert( assoc_item == 0 );
268
269  puts( "Init - get ptr by local -- expect NULL" );
270  assoc_item = rtems_assoc_ptr_by_local( assoc_table_null, 0 );
271  rtems_test_assert( assoc_item == 0 );
272
273  puts( "Init - get ptr by remote -- expect NULL" );
274  assoc_item = rtems_assoc_ptr_by_remote( assoc_table_null, 0 );
275  rtems_test_assert( assoc_item == 0 );
276
277  free( name );
278
279  test_assoc_32_to_string();
280
281  TEST_END();
282
283  rtems_test_exit(0);
284}
285
286/* configuration information */
287
288#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
289#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
290
291#define CONFIGURE_MAXIMUM_TASKS             1
292#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
293
294#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
295#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
296
297#define CONFIGURE_INIT
298
299#include <rtems/confdefs.h>
300/* end of file */
Note: See TracBrowser for help on using the repository browser.