source: rtems/testsuites/psxtests/psxconfig01/init.c @ 3a5c71d

Last change on this file since 3a5c71d was 3a5c71d, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 10, 2019 at 7:10:17 AM

psxconfig01: Fix pre-processor conditions

Do not rely on compiler optimizations to throw away empty loops.

Close #3673.

  • Property mode set to 100644
File size: 13.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup psxtests
5 *
6 * @brief Test that the workspace size estimate is correct.
7 */
8
9/*
10 * Copyright (c) 2014. On-Line Applications Research Corporation (OAR).
11 * Copyright (c) 2011-2014 embedded brains GmbH.  All rights reserved.
12 *
13 *  embedded brains GmbH
14 *  Dornierstr. 4
15 *  82178 Puchheim
16 *  Germany
17 *  <rtems@embedded-brains.de>
18 *
19 * The license and distribution terms for this file may be
20 * found in the file LICENSE in this distribution or at
21 * http://www.rtems.org/license/LICENSE.
22 */
23
24#ifdef HAVE_CONFIG_H
25  #include "config.h"
26#endif
27
28#define _GNU_SOURCE
29
30#include <rtems/test.h>
31#include <tmacros.h>
32
33#include <sys/stat.h>
34#include <fcntl.h>
35#include <inttypes.h>
36#include <mqueue.h>
37#include <pthread.h>
38#include <semaphore.h>
39#include <signal.h>
40#include <stdio.h>
41#include <time.h>
42#include <limits.h>
43
44#include <rtems/libcsupport.h>
45
46const char rtems_test_name[] = "PSXCONFIG 1";
47
48#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
49
50#define CONFIGURE_MAXIMUM_POSIX_KEYS 23
51#if CONFIGURE_MAXIMUM_POSIX_KEYS > 0
52  #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS CONFIGURE_MAXIMUM_POSIX_KEYS
53#endif
54
55#define CONFIGURE_MAXIMUM_BARRIERS 2
56#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 7
57#define CONFIGURE_MAXIMUM_PARTITIONS 37
58#define CONFIGURE_MAXIMUM_PERIODS 41
59#define CONFIGURE_MAXIMUM_REGIONS 43
60#define CONFIGURE_MAXIMUM_SEMAPHORES 47
61#define CONFIGURE_MAXIMUM_TASKS 11
62#define CONFIGURE_MAXIMUM_TIMERS 59
63#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 17
64
65#define POSIX_MQ_COUNT 5
66#ifdef RTEMS_POSIX_API
67#define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 7
68#endif
69#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 41
70#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
71
72#define CONFIGURE_MINIMUM_POSIX_THREAD_STACK_SIZE CPU_STACK_MINIMUM_SIZE
73
74#define CONFIGURE_MAXIMUM_POSIX_THREADS 3
75#ifdef RTEMS_POSIX_API
76#define CONFIGURE_MAXIMUM_POSIX_TIMERS 47
77#endif
78
79#ifndef CONFIGURE_MAXIMUM_TASKS
80  #define CONFIGURE_MAXIMUM_TASKS 1
81#endif
82
83#if CONFIGURE_MAXIMUM_MESSAGE_QUEUES > 0
84  #define MQ_0_COUNT 2
85  #define MQ_1_COUNT 3
86  #define MQ_2_COUNT 5
87  #define MQ_3_COUNT 7
88  #define MQ_4_COUNT 11
89  #define MQ_5_COUNT 13
90  #define MQ_6_COUNT 17
91
92  #define MQ_0_SIZE 101
93  #define MQ_1_SIZE 103
94  #define MQ_2_SIZE 107
95  #define MQ_3_SIZE 109
96  #define MQ_4_SIZE 113
97  #define MQ_5_SIZE 127
98  #define MQ_6_SIZE 131
99
100  #define MQ_BUFFER_MEMORY \
101    (CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_0_COUNT, MQ_0_SIZE) \
102      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_1_COUNT, MQ_1_SIZE) \
103      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_2_COUNT, MQ_2_SIZE) \
104      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_3_COUNT, MQ_3_SIZE) \
105      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_4_COUNT, MQ_4_SIZE) \
106      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_5_COUNT, MQ_5_SIZE) \
107      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_6_COUNT, MQ_6_SIZE))
108
109  static const uint8_t mq_counts [CONFIGURE_MAXIMUM_MESSAGE_QUEUES] = {
110    MQ_0_COUNT,
111    MQ_1_COUNT,
112    MQ_2_COUNT,
113    MQ_3_COUNT,
114    MQ_4_COUNT,
115    MQ_5_COUNT,
116    MQ_6_COUNT
117  };
118
119  static const uint8_t mq_sizes [CONFIGURE_MAXIMUM_MESSAGE_QUEUES] = {
120    MQ_0_SIZE,
121    MQ_1_SIZE,
122    MQ_2_SIZE,
123    MQ_3_SIZE,
124    MQ_4_SIZE,
125    MQ_5_SIZE,
126    MQ_6_SIZE
127  };
128#else
129  #define MQ_BUFFER_MEMORY 0
130#endif
131
132#if POSIX_MQ_COUNT > 0
133  #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES POSIX_MQ_COUNT
134
135  #define POSIX_MQ_0_COUNT 2
136  #define POSIX_MQ_1_COUNT 3
137  #define POSIX_MQ_2_COUNT 5
138  #define POSIX_MQ_3_COUNT 7
139  #define POSIX_MQ_4_COUNT 11
140
141  #define POSIX_MQ_0_SIZE 137
142  #define POSIX_MQ_1_SIZE 139
143  #define POSIX_MQ_2_SIZE 149
144  #define POSIX_MQ_3_SIZE 151
145  #define POSIX_MQ_4_SIZE 157
146
147  #define POSIX_MQ_BUFFER_MEMORY \
148    (CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(POSIX_MQ_0_COUNT, POSIX_MQ_0_SIZE) \
149      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(POSIX_MQ_1_COUNT, POSIX_MQ_1_SIZE) \
150      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(POSIX_MQ_2_COUNT, POSIX_MQ_2_SIZE) \
151      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(POSIX_MQ_3_COUNT, POSIX_MQ_3_SIZE) \
152      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(POSIX_MQ_4_COUNT, POSIX_MQ_4_SIZE))
153
154  static const uint8_t posix_mq_counts [POSIX_MQ_COUNT] = {
155    POSIX_MQ_0_COUNT,
156    POSIX_MQ_1_COUNT,
157    POSIX_MQ_2_COUNT,
158    POSIX_MQ_3_COUNT,
159    POSIX_MQ_4_COUNT
160  };
161
162  static const uint8_t posix_mq_sizes [POSIX_MQ_COUNT] = {
163    POSIX_MQ_0_SIZE,
164    POSIX_MQ_1_SIZE,
165    POSIX_MQ_2_SIZE,
166    POSIX_MQ_3_SIZE,
167    POSIX_MQ_4_SIZE
168  };
169#else
170  #define POSIX_MQ_BUFFER_MEMORY 0
171#endif
172
173#define CONFIGURE_MESSAGE_BUFFER_MEMORY \
174  (MQ_BUFFER_MEMORY + POSIX_MQ_BUFFER_MEMORY)
175
176#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
177#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
178
179#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
180
181#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
182
183#define CONFIGURE_INIT
184
185static rtems_task Init(rtems_task_argument argument);
186
187#include <rtems/confdefs.h>
188
189typedef struct {
190  uint64_t data [16];
191} area;
192
193#if CONFIGURE_MAXIMUM_PARTITIONS > 0
194  static area partition_areas [CONFIGURE_MAXIMUM_PARTITIONS];
195#endif
196
197#if CONFIGURE_MAXIMUM_REGIONS > 0
198  static area region_areas [CONFIGURE_MAXIMUM_REGIONS];
199#endif
200
201static char posix_name [_POSIX_PATH_MAX + 1];
202
203static char *get_posix_name(char a, char b, char c, int i)
204{
205  posix_name [_POSIX_PATH_MAX - 4] = a;
206  posix_name [_POSIX_PATH_MAX - 3] = b;
207  posix_name [_POSIX_PATH_MAX - 2] = c;
208  posix_name [_POSIX_PATH_MAX - 1] = 'A' + i;
209
210  return posix_name;
211}
212
213static void *posix_thread(void *arg RTEMS_UNUSED)
214{
215  rtems_test_assert(0);
216}
217
218static void posix_key_dtor(void *key RTEMS_UNUSED)
219{
220  /* Do nothing */
221}
222
223static void print_info(void)
224{
225  Heap_Information_block info;
226  bool ok = rtems_workspace_get_information(&info);
227  rtems_test_assert(ok);
228
229  printf(
230    "used blocks = %" PRIuPTR ", "
231    "largest used block = %" PRIuPTR ", "
232    "used space = %" PRIuPTR "\n"
233    "free blocks = %" PRIuPTR ", "
234    "largest free block = %" PRIuPTR ", "
235    "free space = %" PRIuPTR "\n",
236    info.Used.number,
237    info.Used.largest,
238    info.Used.total,
239    info.Free.number,
240    info.Free.largest,
241    info.Free.total
242  );
243}
244
245static rtems_task Init(rtems_task_argument argument)
246{
247  rtems_status_code sc = RTEMS_SUCCESSFUL;
248  int eno = 0;
249  rtems_id id = RTEMS_ID_NONE;
250  rtems_name name = rtems_build_name('C', 'O', 'N', 'F');
251  rtems_extensions_table table;
252  rtems_resource_snapshot snapshot;
253  int i = 0;
254  pthread_key_t key;
255
256  TEST_BEGIN();
257
258  memset(posix_name, 'P', sizeof(posix_name) - 1);
259
260  print_info();
261
262  rtems_resource_snapshot_take(&snapshot);
263  rtems_test_assert(rtems_resource_snapshot_equal(&snapshot, &snapshot));
264  rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
265
266#if CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS > 0
267  for (i = 3; i < CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS; ++i) {
268    int oflag = O_WRONLY | O_CREAT | O_TRUNC;
269    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
270    char path [] = { 'F', 'I', 'L', 'E', 'A' + i, '\0' };
271    int fd = open(path, oflag, mode);
272    rtems_test_assert(fd == i);
273  }
274  rtems_resource_snapshot_take(&snapshot);
275  rtems_test_assert(
276    snapshot.open_files == CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS
277  );
278#endif
279
280#if CONFIGURE_MAXIMUM_USER_EXTENSIONS > 0
281  memset(&table, 0, sizeof(table));
282  for (i = 0; i < CONFIGURE_MAXIMUM_USER_EXTENSIONS; ++i) {
283    sc = rtems_extension_create(name, &table, &id);
284    directive_failed(sc, "rtems_extension_create");
285  }
286  rtems_resource_snapshot_take(&snapshot);
287  rtems_test_assert(
288    snapshot.rtems_api.active_extensions == CONFIGURE_MAXIMUM_USER_EXTENSIONS
289  );
290#endif
291
292#if CONFIGURE_MAXIMUM_POSIX_KEYS > 0
293  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_KEYS; ++i) {
294    eno = pthread_key_create(&key, posix_key_dtor);
295    rtems_test_assert(eno == 0);
296
297    eno = pthread_setspecific(key, (void *) (uintptr_t)(i + 1));
298    rtems_test_assert(eno == 0);
299  }
300  eno = pthread_key_create(&key, posix_key_dtor);
301  rtems_test_assert(eno == EAGAIN);
302  rtems_resource_snapshot_take(&snapshot);
303  rtems_test_assert(
304    snapshot.active_posix_keys == _CONFIGURE_POSIX_KEYS
305  );
306  rtems_test_assert(
307    snapshot.active_posix_key_value_pairs == CONFIGURE_MAXIMUM_POSIX_KEYS
308  );
309#else
310  (void) key;
311#endif
312
313#if CONFIGURE_MAXIMUM_BARRIERS > 0
314  for (i = 0; i < CONFIGURE_MAXIMUM_BARRIERS; ++i) {
315    sc = rtems_barrier_create(name, RTEMS_DEFAULT_ATTRIBUTES, 1, &id);
316    directive_failed(sc, "rtems_barrier_create");
317  }
318  rtems_resource_snapshot_take(&snapshot);
319  rtems_test_assert(
320    snapshot.rtems_api.active_barriers == CONFIGURE_MAXIMUM_BARRIERS
321  );
322#endif
323
324#if CONFIGURE_MAXIMUM_MESSAGE_QUEUES > 0
325  for (i = 0; i < CONFIGURE_MAXIMUM_MESSAGE_QUEUES; ++i) {
326    sc = rtems_message_queue_create(
327      name,
328      mq_counts [i],
329      mq_sizes [i],
330      RTEMS_DEFAULT_ATTRIBUTES,
331      &id
332    );
333    directive_failed(sc, "rtems_message_queue_create");
334  }
335  rtems_resource_snapshot_take(&snapshot);
336  rtems_test_assert(
337    snapshot.rtems_api.active_message_queues
338      == CONFIGURE_MAXIMUM_MESSAGE_QUEUES
339  );
340#endif
341
342#if CONFIGURE_MAXIMUM_PARTITIONS > 0
343  for (i = 0; i < CONFIGURE_MAXIMUM_PARTITIONS; ++i) {
344    sc = rtems_partition_create(
345      name,
346      partition_areas + i,
347      sizeof(partition_areas [0]),
348      sizeof(partition_areas [0]),
349      RTEMS_DEFAULT_ATTRIBUTES,
350      &id
351    );
352    directive_failed(sc, "rtems_partition_create");
353  }
354  rtems_resource_snapshot_take(&snapshot);
355  rtems_test_assert(
356    snapshot.rtems_api.active_partitions == CONFIGURE_MAXIMUM_PARTITIONS
357  );
358#endif
359
360#if CONFIGURE_MAXIMUM_PERIODS > 0
361  for (i = 0; i < CONFIGURE_MAXIMUM_PERIODS; ++i) {
362    sc = rtems_rate_monotonic_create(name, &id);
363    directive_failed(sc, "rtems_rate_monotonic_create");
364  }
365  rtems_resource_snapshot_take(&snapshot);
366  rtems_test_assert(
367    snapshot.rtems_api.active_periods == CONFIGURE_MAXIMUM_PERIODS
368  );
369#endif
370
371#if CONFIGURE_MAXIMUM_REGIONS > 0
372  for (i = 0; i < CONFIGURE_MAXIMUM_REGIONS; ++i) {
373    sc = rtems_region_create(
374      name,
375      region_areas + i,
376      sizeof(region_areas [0]),
377      1,
378      RTEMS_DEFAULT_ATTRIBUTES,
379      &id
380    );
381    directive_failed(sc, "rtems_region_create");
382  }
383  rtems_resource_snapshot_take(&snapshot);
384  rtems_test_assert(
385    snapshot.rtems_api.active_regions == CONFIGURE_MAXIMUM_REGIONS
386  );
387#endif
388
389#if CONFIGURE_MAXIMUM_SEMAPHORES > 0
390  for (i = 0; i < CONFIGURE_MAXIMUM_SEMAPHORES; ++i) {
391    sc = rtems_semaphore_create(
392      name,
393      0,
394      RTEMS_DEFAULT_ATTRIBUTES,
395      0,
396      &id
397    );
398    directive_failed(sc, "rtems_semaphore_create");
399  }
400  rtems_resource_snapshot_take(&snapshot);
401  rtems_test_assert(
402    snapshot.rtems_api.active_semaphores >= CONFIGURE_MAXIMUM_SEMAPHORES
403  );
404#endif
405
406#if CONFIGURE_MAXIMUM_TASKS > 0
407  for (i = 1; i < CONFIGURE_MAXIMUM_TASKS; ++i) {
408    sc = rtems_task_create(
409      name,
410      RTEMS_MINIMUM_PRIORITY,
411      RTEMS_MINIMUM_STACK_SIZE,
412      RTEMS_DEFAULT_MODES,
413      RTEMS_LOCAL | RTEMS_FLOATING_POINT,
414      &id
415    );
416    directive_failed(sc, "rtems_task_create");
417  }
418  rtems_resource_snapshot_take(&snapshot);
419  rtems_test_assert(
420    snapshot.rtems_api.active_tasks == CONFIGURE_MAXIMUM_TASKS
421  );
422#endif
423
424#if CONFIGURE_MAXIMUM_TIMERS > 0
425  for (i = 0; i < CONFIGURE_MAXIMUM_TIMERS; ++i) {
426    sc = rtems_timer_create(name, &id);
427    directive_failed(sc, "rtems_timer_create");
428  }
429  rtems_resource_snapshot_take(&snapshot);
430  rtems_test_assert(
431    snapshot.rtems_api.active_timers == CONFIGURE_MAXIMUM_TIMERS
432  );
433#endif
434
435#if POSIX_MQ_COUNT > 0
436  for (i = 0; i < POSIX_MQ_COUNT; ++i) {
437    int oflag = O_RDWR | O_CREAT | O_EXCL;
438    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
439    struct mq_attr attr = {
440      .mq_maxmsg = posix_mq_counts [i],
441      .mq_msgsize = posix_mq_sizes [i]
442    };
443    char *path = get_posix_name('M', 'S', 'Q', i);
444    mqd_t mq = mq_open(path, oflag, mode, &attr);
445    rtems_test_assert(mq >= 0);
446  }
447  rtems_resource_snapshot_take(&snapshot);
448  rtems_test_assert(
449    snapshot.posix_api.active_message_queues
450      == CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES
451  );
452#endif
453
454#if CONFIGURE_MAXIMUM_POSIX_SEMAPHORES > 0
455  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; ++i) {
456    int oflag = O_RDWR | O_CREAT | O_EXCL;
457    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
458    unsigned int value = 0;
459    char *path = get_posix_name('S', 'E', 'M', i);
460    sem_t *sem = sem_open(path, oflag, mode, value);
461    rtems_test_assert(sem != SEM_FAILED);
462  }
463  rtems_resource_snapshot_take(&snapshot);
464  rtems_test_assert(
465    snapshot.posix_api.active_semaphores == CONFIGURE_MAXIMUM_POSIX_SEMAPHORES
466  );
467#endif
468
469#if CONFIGURE_MAXIMUM_POSIX_THREADS > 0
470  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_THREADS; ++i) {
471    pthread_t thread;
472    pthread_attr_t attr;
473    size_t stack_size;
474
475    eno = pthread_create(&thread, NULL, posix_thread, NULL);
476    rtems_test_assert(eno == 0);
477
478    eno = pthread_getattr_np(thread, &attr);
479    rtems_test_assert(eno == 0);
480
481    eno = pthread_attr_getstacksize(&attr, &stack_size);
482    rtems_test_assert(eno == 0);
483    rtems_test_assert(stack_size == CPU_STACK_MINIMUM_SIZE);
484
485    eno = pthread_attr_destroy(&attr);
486    rtems_test_assert(eno == 0);
487  }
488  rtems_resource_snapshot_take(&snapshot);
489  rtems_test_assert(
490    snapshot.posix_api.active_threads == CONFIGURE_MAXIMUM_POSIX_THREADS
491  );
492#endif
493
494#if CONFIGURE_MAXIMUM_POSIX_TIMERS > 0
495  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_TIMERS; ++i) {
496    timer_t timer_id;
497    int rv;
498
499    rv = timer_create(CLOCK_REALTIME, NULL, &timer_id);
500    rtems_test_assert(rv == 0);
501  }
502  rtems_resource_snapshot_take(&snapshot);
503  rtems_test_assert(
504    snapshot.posix_api.active_timers == CONFIGURE_MAXIMUM_POSIX_TIMERS
505  );
506#endif
507
508  printf("object creation done\n");
509  print_info();
510
511  TEST_END();
512
513  rtems_test_exit(0);
514}
Note: See TracBrowser for help on using the repository browser.