source: rtems/testsuites/sptests/spsysinit01/init.c @ ba74ebde

Last change on this file since ba74ebde was ba74ebde, checked in by Sebastian Huber <sebastian.huber@…>, on Feb 14, 2020 at 6:09:56 PM

libio: Add POSIX user environment pointer to TCB

The IO library used a POSIX key to store an optional POSIX user
environment pointer. This pulled in the POSIX keys support in every
application configuration. Add a user environment pointer to the thread
control block (TCB) instead. Applications which do not need the POSIX
user environment will just get an overhead of one pointer per thread.

Close #3882.

  • Property mode set to 100644
File size: 21.7 KB
Line 
1/*
2 * Copyright (c) 2015, 2020 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 "tmacros.h"
20
21#include <sys/types.h>
22#include <sys/mman.h>
23#include <sys/stat.h>
24
25#include <assert.h>
26#include <fcntl.h>
27#include <mqueue.h>
28#include <pthread.h>
29#include <semaphore.h>
30#include <signal.h>
31#include <stdlib.h>
32#include <string.h>
33#include <time.h>
34#include <unistd.h>
35
36#include <rtems.h>
37#include <rtems/ioimpl.h>
38#include <rtems/libio_.h>
39#include <rtems/sysinit.h>
40
41#include <rtems/extensionimpl.h>
42#include <rtems/posix/barrierimpl.h>
43#include <rtems/posix/mqueueimpl.h>
44#include <rtems/posix/muteximpl.h>
45#ifdef RTEMS_POSIX_API
46#include <rtems/posix/psignalimpl.h>
47#endif /* RTEMS_POSIX_API */
48#include <rtems/posix/pthreadimpl.h>
49#include <rtems/posix/rwlockimpl.h>
50#include <rtems/posix/semaphoreimpl.h>
51#include <rtems/posix/shmimpl.h>
52#ifdef RTEMS_POSIX_API
53#include <rtems/posix/timerimpl.h>
54#endif /* RTEMS_POSIX_API */
55#include <rtems/posix/keyimpl.h>
56#include <rtems/rtems/barrierimpl.h>
57#include <rtems/rtems/dpmemimpl.h>
58#include <rtems/rtems/messageimpl.h>
59#include <rtems/rtems/partimpl.h>
60#include <rtems/rtems/ratemonimpl.h>
61#include <rtems/rtems/regionimpl.h>
62#include <rtems/rtems/semimpl.h>
63#include <rtems/rtems/tasksimpl.h>
64#include <rtems/rtems/timerimpl.h>
65#include <rtems/score/apimutex.h>
66#include <rtems/score/chainimpl.h>
67#include <rtems/score/sysstate.h>
68#include <rtems/score/userextimpl.h>
69#include <rtems/score/wkspace.h>
70
71const char rtems_test_name[] = "SPSYSINIT 1";
72
73typedef enum {
74  WORKSPACE_PRE,
75  WORKSPACE_POST,
76  BSP_START_PRE,
77  BSP_START_POST,
78  CPU_COUNTER_PRE,
79  CPU_COUNTER_POST,
80  INITIAL_EXTENSIONS_PRE,
81  INITIAL_EXTENSIONS_POST,
82  DATA_STRUCTURES_PRE,
83  DATA_STRUCTURES_POST,
84  USER_EXTENSIONS_PRE,
85  USER_EXTENSIONS_POST,
86  CLASSIC_TASKS_PRE,
87  CLASSIC_TASKS_POST,
88  CLASSIC_TIMER_PRE,
89  CLASSIC_TIMER_POST,
90  CLASSIC_MESSAGE_QUEUE_PRE,
91  CLASSIC_MESSAGE_QUEUE_POST,
92  CLASSIC_SEMAPHORE_PRE,
93  CLASSIC_SEMAPHORE_POST,
94  CLASSIC_PARTITION_PRE,
95  CLASSIC_PARTITION_POST,
96  CLASSIC_REGION_PRE,
97  CLASSIC_REGION_POST,
98  CLASSIC_DUAL_PORTED_MEMORY_PRE,
99  CLASSIC_DUAL_PORTED_MEMORY_POST,
100  CLASSIC_RATE_MONOTONIC_PRE,
101  CLASSIC_RATE_MONOTONIC_POST,
102  CLASSIC_BARRIER_PRE,
103  CLASSIC_BARRIER_POST,
104#ifdef RTEMS_POSIX_API
105  POSIX_SIGNALS_PRE,
106  POSIX_SIGNALS_POST,
107#endif /* RTEMS_POSIX_API */
108  POSIX_THREADS_PRE,
109  POSIX_THREADS_POST,
110  POSIX_MESSAGE_QUEUE_PRE,
111  POSIX_MESSAGE_QUEUE_POST,
112  POSIX_SEMAPHORE_PRE,
113  POSIX_SEMAPHORE_POST,
114#ifdef RTEMS_POSIX_API
115  POSIX_TIMER_PRE,
116  POSIX_TIMER_POST,
117#endif /* RTEMS_POSIX_API */
118  POSIX_SHM_PRE,
119  POSIX_SHM_POST,
120  POSIX_KEYS_PRE,
121  POSIX_KEYS_POST,
122  POSIX_CLEANUP_PRE,
123  POSIX_CLEANUP_POST,
124  IDLE_THREADS_PRE,
125  IDLE_THREADS_POST,
126  LIBIO_PRE,
127  LIBIO_POST,
128  USER_ENVIRONMENT_PRE,
129  USER_ENVIRONMENT_POST,
130  ROOT_FILESYSTEM_PRE,
131  ROOT_FILESYSTEM_POST,
132  BSP_PRE_DRIVERS_PRE,
133  BSP_PRE_DRIVERS_POST,
134  DEVICE_DRIVERS_PRE,
135  DEVICE_DRIVERS_POST,
136  CLASSIC_USER_TASKS_PRE,
137  CLASSIC_USER_TASKS_POST,
138  POSIX_USER_THREADS_PRE,
139  POSIX_USER_THREADS_POST,
140  STD_FILE_DESCRIPTORS_PRE,
141  STD_FILE_DESCRIPTORS_POST,
142  LAST_FIRST,
143  LAST_SECOND,
144  LAST_THIRD,
145  LAST_FOURTH,
146  LAST_FIFTH,
147  LAST_SIXTH,
148  LAST_SEVENTH,
149  LAST_EIGHTH,
150  LAST_NINETH,
151  LAST_TENTH,
152  LAST_MIDDLE,
153  LAST_LAST_BUT_9,
154  LAST_LAST_BUT_8,
155  LAST_LAST_BUT_7,
156  LAST_LAST_BUT_6,
157  LAST_LAST_BUT_5,
158  LAST_LAST_BUT_4,
159  LAST_LAST_BUT_3,
160  LAST_LAST_BUT_2,
161  LAST_LAST_BUT_1,
162  LAST_LAST,
163  INIT_TASK,
164  DONE
165} init_step;
166
167#define FIRST(x) \
168  static void x##_first(void); \
169  RTEMS_SYSINIT_ITEM( \
170    x##_first, \
171    x, \
172    RTEMS_SYSINIT_ORDER_FIRST \
173  ); \
174  static void x##_first(void)
175
176#define LAST(x) \
177  static void x##_last(void); \
178  RTEMS_SYSINIT_ITEM( \
179    x##_last, \
180    x, \
181    RTEMS_SYSINIT_ORDER_LAST_BUT_1 \
182  ); \
183  static void x##_last(void)
184
185#define LAST_STEP(x) \
186  static void last_##x(void) \
187  { \
188    next_step(LAST_##x); \
189  } \
190  RTEMS_SYSINIT_ITEM( \
191    last_##x, \
192    RTEMS_SYSINIT_LAST, \
193    RTEMS_SYSINIT_ORDER_##x \
194  )
195
196static init_step step;
197
198static void next_step(init_step expected)
199{
200  assert(step == expected);
201  step = expected + 1;
202}
203
204static bool info_not_init(const Objects_Information *info)
205{
206  return _Chain_Is_empty(&info->Inactive);
207}
208
209static bool info_is_init(const Objects_Information *info, size_t count)
210{
211  return _Chain_Node_count_unprotected(&info->Inactive) == count;
212}
213
214FIRST(RTEMS_SYSINIT_WORKSPACE)
215{
216  assert(_Workspace_Area.area_begin == 0);
217  next_step(WORKSPACE_PRE);
218}
219
220LAST(RTEMS_SYSINIT_WORKSPACE)
221{
222  assert(_Workspace_Area.area_begin != 0);
223  next_step(WORKSPACE_POST);
224}
225
226FIRST(RTEMS_SYSINIT_BSP_START)
227{
228  /*
229   * Since the work performed here is BSP-specific, there is no way to test pre
230   * and post conditions.
231   */
232  next_step(BSP_START_PRE);
233}
234
235LAST(RTEMS_SYSINIT_BSP_START)
236{
237  /*
238   * Some BSPs initialize the printk() support in bsp_start().  So, print begin
239   * of test after bsp_start().
240   */
241  TEST_BEGIN();
242
243  next_step(BSP_START_POST);
244}
245
246FIRST(RTEMS_SYSINIT_CPU_COUNTER)
247{
248  /*
249   * Since the work performed here is BSP-specific, there is no way to test pre
250   * and post conditions.
251   */
252  next_step(CPU_COUNTER_PRE);
253}
254
255LAST(RTEMS_SYSINIT_CPU_COUNTER)
256{
257  next_step(CPU_COUNTER_POST);
258}
259
260FIRST(RTEMS_SYSINIT_INITIAL_EXTENSIONS)
261{
262  assert(_Chain_Is_empty(&_User_extensions_Switches_list));
263  next_step(INITIAL_EXTENSIONS_PRE);
264}
265
266LAST(RTEMS_SYSINIT_INITIAL_EXTENSIONS)
267{
268  assert(!_Chain_Is_empty(&_User_extensions_Switches_list));
269  next_step(INITIAL_EXTENSIONS_POST);
270}
271
272FIRST(RTEMS_SYSINIT_DATA_STRUCTURES)
273{
274  assert(info_not_init(&_Thread_Information.Objects));
275  next_step(DATA_STRUCTURES_PRE);
276}
277
278LAST(RTEMS_SYSINIT_DATA_STRUCTURES)
279{
280  assert(info_is_init(&_Thread_Information.Objects, 1));
281  next_step(DATA_STRUCTURES_POST);
282}
283
284FIRST(RTEMS_SYSINIT_USER_EXTENSIONS)
285{
286  assert(info_not_init(&_Extension_Information));
287  next_step(USER_EXTENSIONS_PRE);
288}
289
290LAST(RTEMS_SYSINIT_USER_EXTENSIONS)
291{
292  assert(info_is_init(&_Extension_Information, 1));
293  next_step(USER_EXTENSIONS_POST);
294}
295
296FIRST(RTEMS_SYSINIT_CLASSIC_TASKS)
297{
298  assert(info_not_init(&_RTEMS_tasks_Information.Objects));
299  next_step(CLASSIC_TASKS_PRE);
300}
301
302LAST(RTEMS_SYSINIT_CLASSIC_TASKS)
303{
304  assert(info_is_init(&_RTEMS_tasks_Information.Objects, 2));
305  next_step(CLASSIC_TASKS_POST);
306}
307
308FIRST(RTEMS_SYSINIT_CLASSIC_TIMER)
309{
310  assert(info_not_init(&_Timer_Information));
311  next_step(CLASSIC_TIMER_PRE);
312}
313
314LAST(RTEMS_SYSINIT_CLASSIC_TIMER)
315{
316  assert(info_is_init(&_Timer_Information, 1));
317  next_step(CLASSIC_TIMER_POST);
318}
319
320FIRST(RTEMS_SYSINIT_CLASSIC_MESSAGE_QUEUE)
321{
322  assert(info_not_init(&_Message_queue_Information));
323  next_step(CLASSIC_MESSAGE_QUEUE_PRE);
324}
325
326LAST(RTEMS_SYSINIT_CLASSIC_MESSAGE_QUEUE)
327{
328  assert(info_is_init(&_Message_queue_Information, 1));
329  next_step(CLASSIC_MESSAGE_QUEUE_POST);
330}
331
332FIRST(RTEMS_SYSINIT_CLASSIC_SEMAPHORE)
333{
334  assert(_Semaphore_Information.initial_objects[0].id == 0);
335  next_step(CLASSIC_SEMAPHORE_PRE);
336}
337
338LAST(RTEMS_SYSINIT_CLASSIC_SEMAPHORE)
339{
340  assert(_Semaphore_Information.initial_objects[0].id != 0);
341  next_step(CLASSIC_SEMAPHORE_POST);
342}
343
344FIRST(RTEMS_SYSINIT_CLASSIC_PARTITION)
345{
346  assert(info_not_init(&_Partition_Information));
347  next_step(CLASSIC_PARTITION_PRE);
348}
349
350LAST(RTEMS_SYSINIT_CLASSIC_PARTITION)
351{
352  assert(info_is_init(&_Partition_Information, 1));
353  next_step(CLASSIC_PARTITION_POST);
354}
355
356FIRST(RTEMS_SYSINIT_CLASSIC_REGION)
357{
358  assert(info_not_init(&_Region_Information));
359  next_step(CLASSIC_REGION_PRE);
360}
361
362LAST(RTEMS_SYSINIT_CLASSIC_REGION)
363{
364  assert(info_is_init(&_Region_Information, 1));
365  next_step(CLASSIC_REGION_POST);
366}
367
368FIRST(RTEMS_SYSINIT_CLASSIC_DUAL_PORTED_MEMORY)
369{
370  assert(info_not_init(&_Dual_ported_memory_Information));
371  next_step(CLASSIC_DUAL_PORTED_MEMORY_PRE);
372}
373
374LAST(RTEMS_SYSINIT_CLASSIC_DUAL_PORTED_MEMORY)
375{
376  assert(info_is_init(&_Dual_ported_memory_Information, 1));
377  next_step(CLASSIC_DUAL_PORTED_MEMORY_POST);
378}
379
380FIRST(RTEMS_SYSINIT_CLASSIC_RATE_MONOTONIC)
381{
382  assert(info_not_init(&_Rate_monotonic_Information));
383  next_step(CLASSIC_RATE_MONOTONIC_PRE);
384}
385
386LAST(RTEMS_SYSINIT_CLASSIC_RATE_MONOTONIC)
387{
388  assert(info_is_init(&_Rate_monotonic_Information, 1));
389  next_step(CLASSIC_RATE_MONOTONIC_POST);
390}
391
392FIRST(RTEMS_SYSINIT_CLASSIC_BARRIER)
393{
394  assert(info_not_init(&_Barrier_Information));
395  next_step(CLASSIC_BARRIER_PRE);
396}
397
398LAST(RTEMS_SYSINIT_CLASSIC_BARRIER)
399{
400  assert(info_is_init(&_Barrier_Information, 1));
401  next_step(CLASSIC_BARRIER_POST);
402}
403
404#ifdef RTEMS_POSIX_API
405FIRST(RTEMS_SYSINIT_POSIX_SIGNALS)
406{
407  assert(
408    memcmp(
409      &_POSIX_signals_Vectors,
410      _POSIX_signals_Default_vectors,
411      sizeof(_POSIX_signals_Vectors)
412    ) != 0
413  );
414  next_step(POSIX_SIGNALS_PRE);
415}
416
417LAST(RTEMS_SYSINIT_POSIX_SIGNALS)
418{
419  assert(
420    memcmp(
421      &_POSIX_signals_Vectors,
422      _POSIX_signals_Default_vectors,
423      sizeof(_POSIX_signals_Vectors)
424    ) == 0
425  );
426  next_step(POSIX_SIGNALS_POST);
427}
428#endif /* RTEMS_POSIX_API */
429
430FIRST(RTEMS_SYSINIT_POSIX_THREADS)
431{
432  assert(info_not_init(&_POSIX_Threads_Information.Objects));
433  next_step(POSIX_THREADS_PRE);
434}
435
436LAST(RTEMS_SYSINIT_POSIX_THREADS)
437{
438  assert(info_is_init(&_POSIX_Threads_Information.Objects, 1));
439  next_step(POSIX_THREADS_POST);
440}
441
442FIRST(RTEMS_SYSINIT_POSIX_MESSAGE_QUEUE)
443{
444  assert(info_not_init(&_POSIX_Message_queue_Information));
445  next_step(POSIX_MESSAGE_QUEUE_PRE);
446}
447
448LAST(RTEMS_SYSINIT_POSIX_MESSAGE_QUEUE)
449{
450  assert(info_is_init(&_POSIX_Message_queue_Information, 1));
451  next_step(POSIX_MESSAGE_QUEUE_POST);
452}
453
454FIRST(RTEMS_SYSINIT_POSIX_SEMAPHORE)
455{
456  assert(info_not_init(&_POSIX_Semaphore_Information));
457  next_step(POSIX_SEMAPHORE_PRE);
458}
459
460LAST(RTEMS_SYSINIT_POSIX_SEMAPHORE)
461{
462  assert(info_is_init(&_POSIX_Semaphore_Information, 1));
463  next_step(POSIX_SEMAPHORE_POST);
464}
465
466#ifdef RTEMS_POSIX_API
467FIRST(RTEMS_SYSINIT_POSIX_TIMER)
468{
469  assert(info_not_init(&_POSIX_Timer_Information));
470  next_step(POSIX_TIMER_PRE);
471}
472
473LAST(RTEMS_SYSINIT_POSIX_TIMER)
474{
475  assert(info_is_init(&_POSIX_Timer_Information, 1));
476  next_step(POSIX_TIMER_POST);
477}
478#endif /* RTEMS_POSIX_API */
479
480FIRST(RTEMS_SYSINIT_POSIX_SHM)
481{
482  assert(info_not_init(&_POSIX_Shm_Information));
483  next_step(POSIX_SHM_PRE);
484}
485
486LAST(RTEMS_SYSINIT_POSIX_SHM)
487{
488  assert(info_is_init(&_POSIX_Shm_Information, 1));
489  next_step(POSIX_SHM_POST);
490}
491
492static size_t user_extensions_pre_posix_cleanup;
493
494FIRST(RTEMS_SYSINIT_POSIX_CLEANUP)
495{
496  user_extensions_pre_posix_cleanup =
497    _Chain_Node_count_unprotected(&_User_extensions_List.Active);
498  next_step(POSIX_CLEANUP_PRE);
499}
500
501LAST(RTEMS_SYSINIT_POSIX_CLEANUP)
502{
503  assert(
504    user_extensions_pre_posix_cleanup + 1 ==
505      _Chain_Node_count_unprotected(&_User_extensions_List.Active)
506  );
507  next_step(POSIX_CLEANUP_POST);
508}
509
510FIRST(RTEMS_SYSINIT_POSIX_KEYS)
511{
512  assert(info_not_init(&_POSIX_Keys_Information));
513  next_step(POSIX_KEYS_PRE);
514}
515
516LAST(RTEMS_SYSINIT_POSIX_KEYS)
517{
518  assert(info_is_init(&_POSIX_Keys_Information, 1));
519  next_step(POSIX_KEYS_POST);
520}
521
522FIRST(RTEMS_SYSINIT_IDLE_THREADS)
523{
524  assert(_System_state_Is_before_initialization(_System_state_Get()));
525  next_step(IDLE_THREADS_PRE);
526}
527
528LAST(RTEMS_SYSINIT_IDLE_THREADS)
529{
530  assert(_System_state_Is_before_multitasking(_System_state_Get()));
531  next_step(IDLE_THREADS_POST);
532}
533
534FIRST(RTEMS_SYSINIT_LIBIO)
535{
536  assert(rtems_libio_iop_free_head == NULL);
537  next_step(LIBIO_PRE);
538}
539
540LAST(RTEMS_SYSINIT_LIBIO)
541{
542  assert(rtems_libio_iop_free_head == &rtems_libio_iops[0]);
543  next_step(LIBIO_POST);
544}
545
546static size_t user_extensions_pre_user_env;
547
548FIRST(RTEMS_SYSINIT_USER_ENVIRONMENT)
549{
550  user_extensions_pre_user_env =
551    _Chain_Node_count_unprotected(&_User_extensions_List.Active);
552  next_step(USER_ENVIRONMENT_PRE);
553}
554
555LAST(RTEMS_SYSINIT_USER_ENVIRONMENT)
556{
557  assert(
558    user_extensions_pre_user_env + 1 ==
559      _Chain_Node_count_unprotected(&_User_extensions_List.Active)
560  );
561  next_step(USER_ENVIRONMENT_POST);
562}
563
564FIRST(RTEMS_SYSINIT_ROOT_FILESYSTEM)
565{
566  struct stat st;
567  int rv;
568
569  rv = stat("/", &st);
570  assert(rv == -1);
571  next_step(ROOT_FILESYSTEM_PRE);
572}
573
574LAST(RTEMS_SYSINIT_ROOT_FILESYSTEM)
575{
576  struct stat st;
577  int rv;
578
579  rv = stat("/", &st);
580  assert(rv == 0);
581  next_step(ROOT_FILESYSTEM_POST);
582}
583
584FIRST(RTEMS_SYSINIT_BSP_PRE_DRIVERS)
585{
586  /*
587   * Since the work performed here is BSP-specific, there is no way to test pre
588   * and post conditions.
589   */
590  next_step(BSP_PRE_DRIVERS_PRE);
591}
592
593LAST(RTEMS_SYSINIT_BSP_PRE_DRIVERS)
594{
595  next_step(BSP_PRE_DRIVERS_POST);
596}
597
598FIRST(RTEMS_SYSINIT_DEVICE_DRIVERS)
599{
600  assert(!_IO_All_drivers_initialized);
601  next_step(DEVICE_DRIVERS_PRE);
602}
603
604LAST(RTEMS_SYSINIT_DEVICE_DRIVERS)
605{
606  assert(_IO_All_drivers_initialized);
607  next_step(DEVICE_DRIVERS_POST);
608}
609
610FIRST(RTEMS_SYSINIT_CLASSIC_USER_TASKS)
611{
612  _Objects_Allocator_lock();
613  assert(_Objects_Active_count(&_RTEMS_tasks_Information.Objects) == 0);
614  _Objects_Allocator_unlock();
615  next_step(CLASSIC_USER_TASKS_PRE);
616}
617
618LAST(RTEMS_SYSINIT_CLASSIC_USER_TASKS)
619{
620  _Objects_Allocator_lock();
621  assert(_Objects_Active_count(&_RTEMS_tasks_Information.Objects) == 1);
622  _Objects_Allocator_unlock();
623  next_step(CLASSIC_USER_TASKS_POST);
624}
625
626FIRST(RTEMS_SYSINIT_POSIX_USER_THREADS)
627{
628  _Objects_Allocator_lock();
629  assert(_Objects_Active_count(&_POSIX_Threads_Information.Objects) == 0);
630  _Objects_Allocator_unlock();
631  next_step(POSIX_USER_THREADS_PRE);
632}
633
634LAST(RTEMS_SYSINIT_POSIX_USER_THREADS)
635{
636  _Objects_Allocator_lock();
637  assert(_Objects_Active_count(&_POSIX_Threads_Information.Objects) == 1);
638  _Objects_Allocator_unlock();
639  next_step(POSIX_USER_THREADS_POST);
640}
641
642FIRST(RTEMS_SYSINIT_STD_FILE_DESCRIPTORS)
643{
644  struct stat st;
645  int rv;
646
647  rv = fstat(0, &st);
648  assert(rv == -1);
649  next_step(STD_FILE_DESCRIPTORS_PRE);
650}
651
652LAST(RTEMS_SYSINIT_STD_FILE_DESCRIPTORS)
653{
654  struct stat st;
655  int rv;
656
657  rv = fstat(0, &st);
658  assert(rv == 0);
659  next_step(STD_FILE_DESCRIPTORS_POST);
660}
661
662LAST_STEP(FIRST);
663LAST_STEP(SECOND);
664LAST_STEP(THIRD);
665LAST_STEP(FOURTH);
666LAST_STEP(FIFTH);
667LAST_STEP(SIXTH);
668LAST_STEP(SEVENTH);
669LAST_STEP(EIGHTH);
670LAST_STEP(NINETH);
671LAST_STEP(TENTH);
672LAST_STEP(MIDDLE);
673LAST_STEP(LAST_BUT_9);
674LAST_STEP(LAST_BUT_8);
675LAST_STEP(LAST_BUT_7);
676LAST_STEP(LAST_BUT_6);
677LAST_STEP(LAST_BUT_5);
678LAST_STEP(LAST_BUT_4);
679LAST_STEP(LAST_BUT_3);
680LAST_STEP(LAST_BUT_2);
681LAST_STEP(LAST_BUT_1);
682LAST_STEP(LAST);
683
684static void do_barrier_create(void)
685{
686  rtems_status_code sc;
687  rtems_id id;
688
689  sc = rtems_barrier_create(
690    rtems_build_name('T', 'E', 'S', 'T'),
691    RTEMS_DEFAULT_ATTRIBUTES,
692    1,
693    &id
694  );
695  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
696
697  sc = rtems_barrier_delete(id);
698  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
699}
700
701static void do_extensions_create(void)
702{
703  rtems_status_code sc;
704  rtems_id id;
705  rtems_extensions_table table;
706
707  memset(&table, 0, sizeof(table));
708  sc = rtems_extension_create(
709    rtems_build_name('T', 'E', 'S', 'T'),
710    &table,
711    &id
712  );
713  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
714
715  sc = rtems_extension_delete(id);
716  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
717}
718
719static void do_message_queue_create(void)
720{
721  rtems_status_code sc;
722  rtems_id id;
723
724  sc = rtems_message_queue_create(
725    rtems_build_name('T', 'E', 'S', 'T'),
726    1,
727    1,
728    RTEMS_DEFAULT_ATTRIBUTES,
729    &id
730  );
731  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
732
733  sc = rtems_message_queue_delete(id);
734  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
735}
736
737static void do_partition_create(void)
738{
739  rtems_status_code sc;
740  rtems_id id;
741  long buf[32];
742
743  sc = rtems_partition_create(
744    rtems_build_name('T', 'E', 'S', 'T'),
745    buf,
746    sizeof(buf),
747    sizeof(buf),
748    RTEMS_DEFAULT_ATTRIBUTES,
749    &id
750  );
751  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
752
753  sc = rtems_partition_delete(id);
754  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
755}
756
757static void do_period_create(void)
758{
759  rtems_status_code sc;
760  rtems_id id;
761
762  sc = rtems_rate_monotonic_create(
763    rtems_build_name('T', 'E', 'S', 'T'),
764    &id
765  );
766  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
767
768  sc = rtems_rate_monotonic_delete(id);
769  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
770}
771
772static void do_port_create(void)
773{
774  rtems_status_code sc;
775  rtems_id id;
776
777  sc = rtems_port_create(
778    rtems_build_name('T', 'E', 'S', 'T'),
779    NULL,
780    NULL,
781    1,
782    &id
783  );
784  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
785
786  sc = rtems_port_delete(id);
787  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
788}
789
790static void do_region_create(void)
791{
792  rtems_status_code sc;
793  rtems_id id;
794  long buf[32];
795
796  sc = rtems_region_create(
797    rtems_build_name('T', 'E', 'S', 'T'),
798    buf,
799    sizeof(buf),
800    1,
801    RTEMS_DEFAULT_ATTRIBUTES,
802    &id
803  );
804  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
805
806  sc = rtems_region_delete(id);
807  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
808}
809
810static void do_semaphore_create(void)
811{
812  rtems_status_code sc;
813  rtems_id id;
814
815  sc = rtems_semaphore_create(
816    rtems_build_name('T', 'E', 'S', 'T'),
817    0,
818    RTEMS_DEFAULT_ATTRIBUTES,
819    0,
820    &id
821  );
822  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
823
824  sc = rtems_semaphore_delete(id);
825  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
826}
827
828static void do_task_create(void)
829{
830  rtems_status_code sc;
831  rtems_id id;
832
833  sc = rtems_task_create(
834    rtems_build_name('T', 'E', 'S', 'T'),
835    1,
836    RTEMS_MINIMUM_STACK_SIZE,
837    RTEMS_DEFAULT_MODES,
838    RTEMS_DEFAULT_ATTRIBUTES,
839    &id
840  );
841  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
842
843  sc = rtems_task_delete(id);
844  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
845}
846
847static void do_timer_create(void)
848{
849  rtems_status_code sc;
850  rtems_id id;
851
852  sc = rtems_timer_create(rtems_build_name('T', 'E', 'S', 'T'), &id);
853  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
854
855  sc = rtems_timer_delete(id);
856  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
857}
858
859static void do_cleanup_push_pop(void)
860{
861  pthread_cleanup_push(NULL, NULL);
862  pthread_cleanup_pop(0);
863}
864
865static void do_posix_key_create(void)
866{
867  pthread_key_t key;
868  int eno;
869
870  eno = pthread_key_create(&key, NULL);
871  rtems_test_assert(eno == 0);
872
873  eno = pthread_key_delete(key);
874  rtems_test_assert(eno == 0);
875}
876
877static void do_posix_mq_open(void)
878{
879  struct mq_attr attr;
880  mqd_t mq;
881  int rv;
882
883  memset(&attr, 0, sizeof(attr));
884  attr.mq_maxmsg = 1;
885  attr.mq_msgsize = 1;
886  mq = mq_open("mq", O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO, &attr);
887  rtems_test_assert(mq != (mqd_t) -1);
888
889  rv = mq_close(mq);
890  rtems_test_assert(rv == 0);
891
892  rv = mq_unlink("mq");
893  rtems_test_assert(rv == 0);
894}
895
896static void do_posix_sem_open(void)
897{
898  sem_t *sem;
899  int rv;
900
901  sem = sem_open("sem", O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO);
902  rtems_test_assert(sem != SEM_FAILED);
903
904  rv = sem_close(sem);
905  rtems_test_assert(rv == 0);
906
907  rv = sem_unlink("sem");
908  rtems_test_assert(rv == 0);
909}
910
911static void do_posix_shm_open(void)
912{
913  int fd;
914  int rv;
915
916  fd = shm_open("/shm", O_CREAT | O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO);
917  rtems_test_assert(fd >= 0);
918
919  rv = close(fd);
920  rtems_test_assert(rv == 0);
921
922  rv = shm_unlink("/shm");
923  rtems_test_assert(rv == 0);
924}
925
926static void do_posix_timer_create(void)
927{
928#ifdef RTEMS_POSIX_API
929  int rv;
930  timer_t timer;
931
932  rv = timer_create(CLOCK_REALTIME, NULL, &timer);
933  rtems_test_assert(rv == 0);
934
935  rv = timer_delete(timer);
936  rtems_test_assert(rv == 0);
937#endif /* RTEMS_POSIX_API */
938}
939
940static void check_config(void)
941{
942  const rtems_api_configuration_table *config;
943
944  config = rtems_configuration_get_rtems_api_configuration();
945
946  rtems_test_assert(!config->notepads_enabled);
947  rtems_test_assert(config->maximum_tasks == 2);
948  rtems_test_assert(config->maximum_timers == 1);
949  rtems_test_assert(config->maximum_semaphores == 1);
950  rtems_test_assert(config->maximum_message_queues == 1);
951  rtems_test_assert(config->maximum_partitions == 1);
952  rtems_test_assert(config->maximum_regions == 1);
953  rtems_test_assert(config->maximum_ports == 1);
954  rtems_test_assert(config->maximum_periods == 1);
955  rtems_test_assert(config->maximum_barriers == 1);
956  rtems_test_assert(config->number_of_initialization_tasks == 1);
957  rtems_test_assert(config->User_initialization_tasks_table != NULL);
958}
959
960static void do_use_global_user_env(void)
961{
962  rtems_libio_use_global_env();
963}
964
965static void Init(rtems_task_argument arg)
966{
967  next_step(INIT_TASK);
968  do_barrier_create();
969  do_extensions_create();
970  do_message_queue_create();
971  do_partition_create();
972  do_period_create();
973  do_port_create();
974  do_region_create();
975  do_semaphore_create();
976  do_task_create();
977  do_timer_create();
978  do_cleanup_push_pop();
979  do_posix_key_create();
980  do_posix_mq_open();
981  do_posix_sem_open();
982  do_posix_shm_open();
983  do_posix_timer_create();
984  do_use_global_user_env();
985  check_config();
986  TEST_END();
987  exit(0);
988}
989
990static void *POSIX_Init(void *arg)
991{
992  return NULL;
993}
994
995#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
996
997#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
998
999#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
1000
1001#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
1002
1003#define CONFIGURE_MAXIMUM_BARRIERS 1
1004
1005#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1
1006
1007#define CONFIGURE_MAXIMUM_PARTITIONS 1
1008
1009#define CONFIGURE_MAXIMUM_PERIODS 1
1010
1011#define CONFIGURE_MAXIMUM_PORTS 1
1012
1013#define CONFIGURE_MAXIMUM_REGIONS 1
1014
1015#define CONFIGURE_MAXIMUM_SEMAPHORES 1
1016
1017#define CONFIGURE_MAXIMUM_TASKS 2
1018
1019#define CONFIGURE_MAXIMUM_TIMERS 1
1020
1021#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 1
1022
1023#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 1
1024
1025#define CONFIGURE_MAXIMUM_POSIX_SHMS 1
1026
1027#ifdef RTEMS_POSIX_API
1028#define CONFIGURE_MAXIMUM_POSIX_TIMERS 1
1029#endif /* RTEMS_POSIX_API */
1030
1031#define CONFIGURE_MAXIMUM_POSIX_THREADS 1
1032
1033#define CONFIGURE_POSIX_INIT_THREAD_TABLE
1034
1035#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
1036
1037#define CONFIGURE_MESSAGE_BUFFER_MEMORY \
1038  CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(1, 1)
1039
1040#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
1041
1042#define CONFIGURE_STACK_CHECKER_ENABLED
1043
1044#define CONFIGURE_VERBOSE_SYSTEM_INITIALIZATION
1045
1046#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
1047
1048#define CONFIGURE_INIT
1049
1050#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.