source: rtems/testsuites/psxtests/psxconfig01/init.c @ 07d71279

5
Last change on this file since 07d71279 was 07d71279, checked in by Sebastian Huber <sebastian.huber@…>, on 02/01/17 at 13:48:17

Prefix confdefs.h internal def with an underscore

Close #2895.

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