source: rtems/testsuites/sptests/spconfig02/init.c @ 3899bc1a

5
Last change on this file since 3899bc1a was 3899bc1a, checked in by Sebastian Huber <sebastian.huber@…>, on 11/24/18 at 10:51:28

score: Optimize object lookup

Use the maximum ID for the ID to object translation. Using the maximum
ID gets rid of an additional load from the object information in
_Objects_Get(). In addition, object lookups fail for every ID in case
the object information is cleared to zero. This makes it a bit more
robust during system startup (see new tests in spconfig02).

The local table no longer needs a NULL pointer entry at array index
zero. Adjust all the object iteration loops accordingly.

Remove Objects_Information::minimum_id since it contains only redundant
information. Add _Objects_Get_minimum_id() to get the minimum ID.

Update #3621.

  • Property mode set to 100644
File size: 10.5 KB
Line 
1/*
2 * Copyright (c) 2018 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems.h>
20#include <rtems/score/objectimpl.h>
21#include <rtems/sysinit.h>
22
23#include <tmacros.h>
24
25const char rtems_test_name[] = "SPCONFIG 2";
26
27static const rtems_name name = rtems_build_name('N', 'A', 'M', 'E');
28
29static void test_barrier_create(void)
30{
31  rtems_status_code sc;
32  rtems_id id;
33
34  sc = rtems_barrier_create(name, RTEMS_DEFAULT_ATTRIBUTES, 1, &id);
35  rtems_test_assert(sc == RTEMS_TOO_MANY);
36}
37
38static void test_barrier_delete(void)
39{
40  rtems_status_code sc;
41  rtems_id id;
42
43  sc = rtems_barrier_delete(0);
44  rtems_test_assert(sc == RTEMS_INVALID_ID);
45
46  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS, 1, 0);
47  sc = rtems_barrier_delete(id);
48  rtems_test_assert(sc == RTEMS_INVALID_ID);
49}
50
51static void test_barrier_get(void)
52{
53  rtems_status_code sc;
54  rtems_id id;
55
56  sc = rtems_barrier_wait(0, RTEMS_NO_TIMEOUT);
57  rtems_test_assert(sc == RTEMS_INVALID_ID);
58
59  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS, 1, 0);
60  sc = rtems_barrier_wait(id, RTEMS_NO_TIMEOUT);
61  rtems_test_assert(sc == RTEMS_INVALID_ID);
62}
63
64static void test_message_queue_create(void)
65{
66  rtems_status_code sc;
67  rtems_id id;
68
69  sc = rtems_message_queue_create(
70    name,
71    1,
72    1,
73    RTEMS_DEFAULT_ATTRIBUTES,
74    &id
75  );
76  rtems_test_assert(sc == RTEMS_TOO_MANY);
77}
78
79static void test_message_queue_delete(void)
80{
81  rtems_status_code sc;
82  rtems_id id;
83
84  sc = rtems_message_queue_delete(0);
85  rtems_test_assert(sc == RTEMS_INVALID_ID);
86
87  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_MESSAGE_QUEUES, 1, 0);
88  sc = rtems_message_queue_delete(id);
89  rtems_test_assert(sc == RTEMS_INVALID_ID);
90}
91
92static void test_message_queue_get(void)
93{
94  rtems_status_code sc;
95  rtems_id id;
96  uint32_t count;
97
98  sc = rtems_message_queue_flush(0, &count);
99  rtems_test_assert(sc == RTEMS_INVALID_ID);
100
101  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_MESSAGE_QUEUES, 1, 0);
102  sc = rtems_message_queue_flush(id, &count);
103  rtems_test_assert(sc == RTEMS_INVALID_ID);
104}
105
106static void test_partition_create(void)
107{
108  rtems_status_code sc;
109  rtems_id id;
110  long buf[32];
111
112  sc = rtems_partition_create(
113    name,
114    buf,
115    sizeof(buf),
116    sizeof(buf),
117    RTEMS_DEFAULT_ATTRIBUTES,
118    &id
119  );
120  rtems_test_assert(sc == RTEMS_TOO_MANY);
121}
122
123static void test_partition_delete(void)
124{
125  rtems_status_code sc;
126  rtems_id id;
127
128  sc = rtems_partition_delete(0);
129  rtems_test_assert(sc == RTEMS_INVALID_ID);
130
131  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PARTITIONS, 1, 0);
132  sc = rtems_partition_delete(id);
133  rtems_test_assert(sc == RTEMS_INVALID_ID);
134}
135
136static void test_partition_get(void)
137{
138  rtems_status_code sc;
139  rtems_id id;
140
141  sc = rtems_partition_return_buffer(0, NULL);
142  rtems_test_assert(sc == RTEMS_INVALID_ID);
143
144  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PARTITIONS, 1, 0);
145  sc = rtems_partition_return_buffer(id, NULL);
146  rtems_test_assert(sc == RTEMS_INVALID_ID);
147}
148
149static void test_rate_monotonic_create(void)
150{
151  rtems_status_code sc;
152  rtems_id id;
153
154  sc = rtems_rate_monotonic_create(name, &id);
155  rtems_test_assert(sc == RTEMS_TOO_MANY);
156}
157
158static void test_rate_monotonic_delete(void)
159{
160  rtems_status_code sc;
161  rtems_id id;
162
163  sc = rtems_rate_monotonic_delete(0);
164  rtems_test_assert(sc == RTEMS_INVALID_ID);
165
166  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PERIODS, 1, 0);
167  sc = rtems_rate_monotonic_delete(id);
168  rtems_test_assert(sc == RTEMS_INVALID_ID);
169}
170
171static void test_rate_monotonic_get(void)
172{
173  rtems_status_code sc;
174  rtems_id id;
175
176  sc = rtems_rate_monotonic_cancel(0);
177  rtems_test_assert(sc == RTEMS_INVALID_ID);
178
179  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PERIODS, 1, 0);
180  sc = rtems_rate_monotonic_cancel(id);
181  rtems_test_assert(sc == RTEMS_INVALID_ID);
182}
183
184static void test_region_create(void)
185{
186  rtems_status_code sc;
187  rtems_id id;
188  long buf[32];
189
190  sc = rtems_region_create(
191    name,
192    buf,
193    sizeof(buf),
194    1,
195    RTEMS_DEFAULT_ATTRIBUTES,
196    &id
197  );
198  rtems_test_assert(sc == RTEMS_TOO_MANY);
199}
200
201static void test_region_delete(void)
202{
203  rtems_status_code sc;
204  rtems_id id;
205
206  sc = rtems_region_delete(0);
207  rtems_test_assert(sc == RTEMS_INVALID_ID);
208
209  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_REGIONS, 1, 0);
210  sc = rtems_region_delete(id);
211  rtems_test_assert(sc == RTEMS_INVALID_ID);
212}
213
214static void test_region_get(void)
215{
216  rtems_status_code sc;
217  rtems_id id;
218
219  sc = rtems_region_return_segment(0, NULL);
220  rtems_test_assert(sc == RTEMS_INVALID_ID);
221
222  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_REGIONS, 1, 0);
223  sc = rtems_region_return_segment(id, NULL);
224  rtems_test_assert(sc == RTEMS_INVALID_ID);
225}
226
227static void test_semaphore_create(void)
228{
229  rtems_status_code sc;
230  rtems_id id;
231
232  sc = rtems_semaphore_create(
233    name,
234    0,
235    RTEMS_DEFAULT_ATTRIBUTES,
236    0,
237    &id
238  );
239  rtems_test_assert(sc == RTEMS_TOO_MANY);
240}
241
242static void test_semaphore_delete(void)
243{
244  rtems_status_code sc;
245  rtems_id id;
246
247  sc = rtems_semaphore_delete(0);
248  rtems_test_assert(sc == RTEMS_INVALID_ID);
249
250  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_SEMAPHORES, 1, 0);
251  sc = rtems_semaphore_delete(id);
252  rtems_test_assert(sc == RTEMS_INVALID_ID);
253}
254
255static void test_semaphore_get(void)
256{
257  rtems_status_code sc;
258  rtems_id id;
259
260  sc = rtems_semaphore_release(0);
261  rtems_test_assert(sc == RTEMS_INVALID_ID);
262
263  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_SEMAPHORES, 1, 0);
264  sc = rtems_semaphore_release(id);
265  rtems_test_assert(sc == RTEMS_INVALID_ID);
266}
267
268static void test_task_create(void)
269{
270  rtems_status_code sc;
271  rtems_id id;
272
273  sc = rtems_task_create(
274    name,
275    1,
276    RTEMS_MINIMUM_STACK_SIZE,
277    RTEMS_DEFAULT_MODES,
278    RTEMS_DEFAULT_ATTRIBUTES,
279    &id
280  );
281  rtems_test_assert(sc == RTEMS_TOO_MANY);
282}
283
284static void test_task_delete(void)
285{
286  rtems_status_code sc;
287  rtems_id id;
288
289  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS, 1, 0);
290  sc = rtems_task_delete(id);
291  rtems_test_assert(sc == RTEMS_INVALID_ID);
292}
293
294static void test_task_get(void)
295{
296  rtems_status_code sc;
297  rtems_id id;
298
299  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS, 1, 0);
300  sc = rtems_task_resume(id);
301  rtems_test_assert(sc == RTEMS_INVALID_ID);
302}
303
304static void test_timer_create(void)
305{
306  rtems_status_code sc;
307  rtems_id id;
308
309  sc = rtems_timer_create(name, &id);
310  rtems_test_assert(sc == RTEMS_TOO_MANY);
311}
312
313static void test_timer_delete(void)
314{
315  rtems_status_code sc;
316  rtems_id id;
317
318  sc = rtems_timer_delete(0);
319  rtems_test_assert(sc == RTEMS_INVALID_ID);
320
321  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS, 1, 0);
322  sc = rtems_timer_delete(id);
323  rtems_test_assert(sc == RTEMS_INVALID_ID);
324}
325
326static void test_timer_get(void)
327{
328  rtems_status_code sc;
329  rtems_id id;
330
331  sc = rtems_timer_reset(0);
332  rtems_test_assert(sc == RTEMS_INVALID_ID);
333
334  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS, 1, 0);
335  sc = rtems_timer_reset(id);
336  rtems_test_assert(sc == RTEMS_INVALID_ID);
337}
338
339static void test_user_extensions_create(void)
340{
341  rtems_status_code sc;
342  rtems_id id;
343  rtems_extensions_table table;
344
345  memset(&table, 0, sizeof(table));
346  sc = rtems_extension_create(name, &table, &id);
347  rtems_test_assert(sc == RTEMS_TOO_MANY);
348}
349
350static void test_user_extensions_delete(void)
351{
352  rtems_status_code sc;
353  rtems_id id;
354
355  sc = rtems_extension_delete(0);
356  rtems_test_assert(sc == RTEMS_INVALID_ID);
357
358  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_EXTENSIONS, 1, 0);
359  sc = rtems_extension_delete(id);
360  rtems_test_assert(sc == RTEMS_INVALID_ID);
361}
362
363static void test_id_to_name(rtems_id api, rtems_id cls, rtems_id idx, bool *found)
364{
365  rtems_status_code sc;
366  rtems_id id;
367  rtems_name name_of_id;
368
369  id = rtems_build_id(api, cls, 1, idx);
370  sc = rtems_object_get_classic_name(id, &name_of_id);
371
372  if (sc == RTEMS_SUCCESSFUL) {
373    if (name_of_id == rtems_build_name('U', 'I', '1', ' ')) {
374      rtems_test_assert(id == rtems_task_self());
375      rtems_test_assert(!found[0]);
376      found[0] = true;
377    } else {
378      rtems_test_assert(name_of_id == rtems_build_name('I', 'D', 'L', 'E'));
379      rtems_test_assert(!found[1]);
380      found[1] = true;
381    }
382  } else {
383    rtems_test_assert(sc == RTEMS_INVALID_ID);
384  }
385}
386
387static void test_some_id_to_name(void)
388{
389  rtems_id api;
390  bool found[2];
391
392  found[0] = false;
393  found[1] = false;
394
395  for (api = 0; api < 8; ++api) {
396    rtems_id cls;
397
398    for (cls = 0; cls < 32; ++cls) {
399      test_id_to_name(api, cls, 0, found);
400      test_id_to_name(api, cls, 1, found);
401      test_id_to_name(api, cls, 2, found);
402      test_id_to_name(api, cls, 65534, found);
403      test_id_to_name(api, cls, 65535, found);
404    }
405  }
406
407  rtems_test_assert(found[0]);
408  rtems_test_assert(found[1]);
409}
410
411static void Init(rtems_task_argument arg)
412{
413  test_barrier_create();
414  test_barrier_delete();
415  test_barrier_get();
416  test_message_queue_create();
417  test_message_queue_delete();
418  test_message_queue_get();
419  test_partition_create();
420  test_partition_delete();
421  test_partition_get();
422  test_rate_monotonic_create();
423  test_rate_monotonic_delete();
424  test_rate_monotonic_get();
425  test_region_create();
426  test_region_delete();
427  test_region_get();
428  test_semaphore_create();
429  test_semaphore_delete();
430  test_semaphore_get();
431  test_task_create();
432  test_task_delete();
433  test_task_get();
434  test_timer_create();
435  test_timer_delete();
436  test_timer_get();
437  test_user_extensions_create();
438  test_user_extensions_delete();
439  test_some_id_to_name();
440  TEST_END();
441  rtems_test_exit(0);
442}
443
444static void before_object_information_initialization(void)
445{
446  rtems_print_printer_printk(&rtems_test_printer);
447  TEST_BEGIN();
448  test_barrier_get();
449  test_message_queue_get();
450  test_partition_get();
451  test_rate_monotonic_get();
452  test_semaphore_get();
453  test_task_get();
454  test_timer_get();
455}
456
457RTEMS_SYSINIT_ITEM(
458  before_object_information_initialization,
459  RTEMS_SYSINIT_INITIAL_EXTENSIONS,
460  RTEMS_SYSINIT_ORDER_LAST
461);
462
463#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
464
465#define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
466
467#define CONFIGURE_DISABLE_NEWLIB_REENTRANCY
468
469#define CONFIGURE_MAXIMUM_TASKS 1
470
471#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
472
473#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
474
475#define CONFIGURE_INIT
476
477#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.