summaryrefslogtreecommitdiffstats
path: root/testsuites/sptests/spassoc01/init.c
blob: 4a5f80c441377ff3d39a38b22d21c36fa455804b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
 *  COPYRIGHT (c) 1989-2012.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <tmacros.h>
#include "test_support.h"

#include <stdio.h>
#include <rtems/assoc.h>

/* forward declarations to avoid warnings */
rtems_task Init(rtems_task_argument argument);

const rtems_assoc_t assoc_table_null[] = 
  {
    { NULL       , 0 , 0  },
    { "zero"     , 1 , 8  },
    { "one"      , 2 , 4  },
    { "two"      , 4 , 2  },
    { "three"    , 8 , 1  },
    { NULL       , -1, -1 }
  };

const rtems_assoc_t assoc_table_default[] = 
  {
    { "(default)", 0 , 0  },
    { "zero"     , 1 , 8  },
    { "one"      , 2 , 4  },
    { "two"      , 4 , 2  },
    { "three"    , 8 , 1  },
    { NULL       , -1, -1 }
  };

const rtems_assoc_t assoc_table[] = 
  {
    { "zero" , 1 , 8  },
    { "one"  , 2 , 4  },
    { "two"  , 4 , 2  },
    { "three", 8 , 1  },
    { NULL   , -1, -1 }
  };

uint32_t local;
uint32_t remote;
const rtems_assoc_t *assoc_item;
char *name;

static void reset_name( void )
{
  memset( name, 0, 40 );
}

rtems_task Init(
  rtems_task_argument argument
)
{
  name = malloc(40);
  puts( "\n\n*** TEST ASSOC ROUTINES - 1 ***" );

  puts( "Init - get local by name -- OK" );
  local = rtems_assoc_local_by_name( assoc_table, "zero" );
  rtems_test_assert( local == 1 );

  puts( "Init - get local by name -- expect 0" );
  local = rtems_assoc_local_by_name( assoc_table, "four" );
  rtems_test_assert( local == 0 );

  puts( "Init - get local by remote bitfield -- OK" );
  local = rtems_assoc_local_by_remote_bitfield( assoc_table, 1 );
  rtems_test_assert( local == 8 );

  puts( "Init - get local by remote bitfield -- expect 0" );
  local = rtems_assoc_local_by_remote_bitfield( assoc_table, 0 );
  rtems_test_assert( local == 0 );

  puts( "Init - get local by remote -- OK" );
  local = rtems_assoc_local_by_remote( assoc_table, 1 );
  rtems_test_assert( local == 8 );

  puts( "Init - get local by remote -- expect 0" );
  local = rtems_assoc_local_by_remote( assoc_table, 0 );
  rtems_test_assert( local == 0 );

  reset_name();
  puts( "Init - get name by local bitfield -- OK" );
  name = rtems_assoc_name_by_local_bitfield( assoc_table, 1, name );
  rtems_test_assert ( !strcmp( name, "zero" ) );

  reset_name();
  puts( "Init - get name by local bitfield -- OK" );
  name = rtems_assoc_name_by_local_bitfield( assoc_table, 3, name );
  rtems_test_assert ( !strcmp( name, "zero one" ) );

  reset_name();
  puts( "Init - get name by local bitfield -- expect\"\"" );
  name = rtems_assoc_name_by_local_bitfield( assoc_table, 0, name );
  rtems_test_assert ( !strcmp( name, "" ) );
  
  reset_name();
  puts( "Init - get name by local -- OK" );
  rtems_test_assert( !strcmp( rtems_assoc_name_by_local( assoc_table, 1 ), 
			      "zero" ) );
  
  reset_name();
  puts( "Init - get name by local -- using bad value" );
  puts( rtems_assoc_name_by_local( assoc_table, 0 ) );

  reset_name();
  puts( "Init - get name by remote bitfield -- OK" );
  name = 
    rtems_assoc_name_by_remote_bitfield( assoc_table, 1, name );
  rtems_test_assert ( !strcmp( name, "three" ) );

  reset_name();
  puts( "Init - get name by remote bitfield -- OK" );
  name = 
    rtems_assoc_name_by_remote_bitfield( assoc_table, 3, name );
  rtems_test_assert ( !strcmp( name, "three two" ) );

  reset_name();
  puts( "Init - get name by remote bitfield -- expect\"\"" );
  name = 
    rtems_assoc_name_by_remote_bitfield( assoc_table, 0, name );
  rtems_test_assert ( !strcmp( name, "" ) );
  
  reset_name();
  puts( "Init - get name by remote -- OK" );
  rtems_test_assert( !strcmp( rtems_assoc_name_by_remote( assoc_table, 1 ),
			      "three" ) );
  
  reset_name();
  puts( "Init - get name by remote -- using bad value" );
  puts( rtems_assoc_name_by_remote( assoc_table, 0 ) );

  puts( "Init - get ptr by local -- OK" );
  assoc_item = rtems_assoc_ptr_by_local( assoc_table, 1 );
  rtems_test_assert( assoc_item == assoc_table );

  puts( "Init - get ptr by local -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_local( assoc_table, 0 );
  rtems_test_assert( assoc_item == 0 );

  puts( "Init - get ptr by remote -- OK" );
  assoc_item = rtems_assoc_ptr_by_remote( assoc_table, 8 );
  rtems_test_assert( assoc_item == assoc_table );

  puts( "Init - get ptr by remote -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_remote( assoc_table, 0 );
  rtems_test_assert( assoc_item == 0 );

  puts( "Init - get ptr by name -- OK" );
  assoc_item = rtems_assoc_ptr_by_name( assoc_table, "zero" );
  rtems_test_assert( assoc_item == assoc_table );

  puts( "Init - get ptr by name -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_name( assoc_table, "six" );
  rtems_test_assert( assoc_item == 0 );

  puts( "Init - get remote by local bitfield -- OK" );
  remote = rtems_assoc_remote_by_local_bitfield( assoc_table, 1 );
  rtems_test_assert( remote == 8 );

  puts( "Init - get remote by local bitfield -- expect 0" );
  remote = rtems_assoc_remote_by_local_bitfield( assoc_table, 0 );
  rtems_test_assert( remote == 0 );

  puts( "Init - get remote by local -- OK" );
  remote = rtems_assoc_remote_by_local( assoc_table, 1 );
  rtems_test_assert( remote == 8 );

  puts( "Init - get remote by local -- expect 0" );
  remote = rtems_assoc_remote_by_local( assoc_table, 0 );
  rtems_test_assert( remote == 0 );

  puts( "Init - get remote by name -- OK" );
  remote = rtems_assoc_remote_by_name( assoc_table, "zero" );
  rtems_test_assert( remote == 8 );

  puts( "Init - get remote by name -- expect 0" );
  remote = rtems_assoc_remote_by_name( assoc_table, "six" );
  rtems_test_assert( remote == 0 );

  puts( "Init - get ptr by name -- expect (default)" );
  assoc_item = rtems_assoc_ptr_by_name( assoc_table_default, "six" );
  rtems_test_assert( assoc_item == assoc_table_default );

  puts( "Init - get ptr by local -- expect (default)" );
  assoc_item = rtems_assoc_ptr_by_local( assoc_table_default, 0 );
  rtems_test_assert( assoc_item == assoc_table_default );

  puts( "Init - get ptr by remote -- expect (default)" );
  assoc_item = rtems_assoc_ptr_by_remote( assoc_table_default, 0 );
  rtems_test_assert( assoc_item == assoc_table_default );

  puts( "Init - get ptr by name -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_name( assoc_table_null, "six" );
  rtems_test_assert( assoc_item == 0 );

  puts( "Init - get ptr by local -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_local( assoc_table_null, 0 );
  rtems_test_assert( assoc_item == 0 );

  puts( "Init - get ptr by remote -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_remote( assoc_table_null, 0 );
  rtems_test_assert( assoc_item == 0 );

  free( name );

  puts( "*** END OF TEST ASSOC ROUTINES - 1 ***" );

  rtems_test_exit(0);
}

/* configuration information */

#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

#define CONFIGURE_MAXIMUM_TASKS             1
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_INIT

#include <rtems/confdefs.h>
/* end of file */