source: rtems/testsuites/psxtests/psxconfig01/init.c @ 73699608

4.115
Last change on this file since 73699608 was 73699608, checked in by Sebastian Huber <sebastian.huber@…>, on 12/13/11 at 10:02:36

2011-12-13 Sebastian Huber <sebastian.huber@…>

  • psxconfig01/init.c: Create more objects.
  • Property mode set to 100644
File size: 11.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) 2011 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.com/license/LICENSE.
21 *
22 * $Id$
23 */
24
25#ifdef HAVE_CONFIG_H
26  #include "config.h"
27#endif
28
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
41#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
42
43#define CONFIGURE_MAXIMUM_PARTITIONS 37
44#define CONFIGURE_MAXIMUM_PERIODS 41
45#define CONFIGURE_MAXIMUM_REGIONS 43
46#define CONFIGURE_MAXIMUM_SEMAPHORES 47
47#define CONFIGURE_MAXIMUM_TASKS 11
48#define CONFIGURE_MAXIMUM_TASK_VARIABLES 13
49#define CONFIGURE_MAXIMUM_TIMERS 59
50#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 17
51
52#define CONFIGURE_MAXIMUM_POSIX_BARRIERS 31
53#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 29
54#define CONFIGURE_MAXIMUM_POSIX_KEYS 23
55#define POSIX_MQ_COUNT 5
56#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 19
57#define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 7
58#define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 31
59#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 41
60#define CONFIGURE_MAXIMUM_POSIX_SPINLOCKS 17
61#define CONFIGURE_MAXIMUM_POSIX_THREADS 3
62#define CONFIGURE_MAXIMUM_POSIX_TIMERS 47
63
64#ifndef CONFIGURE_MAXIMUM_TASKS
65  #define CONFIGURE_MAXIMUM_TASKS 1
66#endif
67
68#ifdef CONFIGURE_MAXIMUM_MESSAGE_QUEUES
69  #define MQ_0_COUNT 2
70  #define MQ_1_COUNT 3
71  #define MQ_2_COUNT 5
72  #define MQ_3_COUNT 7
73  #define MQ_4_COUNT 11
74  #define MQ_5_COUNT 13
75  #define MQ_6_COUNT 17
76
77  #define MQ_0_SIZE 101
78  #define MQ_1_SIZE 103
79  #define MQ_2_SIZE 107
80  #define MQ_3_SIZE 109
81  #define MQ_4_SIZE 113
82  #define MQ_5_SIZE 127
83  #define MQ_6_SIZE 131
84
85  #define MQ_BUFFER_MEMORY \
86    (CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_0_COUNT, MQ_0_SIZE) \
87      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_1_COUNT, MQ_1_SIZE) \
88      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_2_COUNT, MQ_2_SIZE) \
89      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_3_COUNT, MQ_3_SIZE) \
90      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_4_COUNT, MQ_4_SIZE) \
91      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_5_COUNT, MQ_5_SIZE) \
92      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_6_COUNT, MQ_6_SIZE))
93
94  static const uint8_t mq_counts [CONFIGURE_MAXIMUM_MESSAGE_QUEUES] = {
95    MQ_0_COUNT,
96    MQ_1_COUNT,
97    MQ_2_COUNT,
98    MQ_3_COUNT,
99    MQ_4_COUNT,
100    MQ_5_COUNT,
101    MQ_6_COUNT
102  };
103
104  static const uint8_t mq_sizes [CONFIGURE_MAXIMUM_MESSAGE_QUEUES] = {
105    MQ_0_SIZE,
106    MQ_1_SIZE,
107    MQ_2_SIZE,
108    MQ_3_SIZE,
109    MQ_4_SIZE,
110    MQ_5_SIZE,
111    MQ_6_SIZE
112  };
113#else
114  #define MQ_BUFFER_MEMORY 0
115#endif
116
117#ifdef POSIX_MQ_COUNT
118  #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS POSIX_MQ_COUNT
119  #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES POSIX_MQ_COUNT
120
121  #define POSIX_MQ_0_COUNT 2
122  #define POSIX_MQ_1_COUNT 3
123  #define POSIX_MQ_2_COUNT 5
124  #define POSIX_MQ_3_COUNT 7
125  #define POSIX_MQ_4_COUNT 11
126
127  #define POSIX_MQ_0_SIZE 137
128  #define POSIX_MQ_1_SIZE 139
129  #define POSIX_MQ_2_SIZE 149
130  #define POSIX_MQ_3_SIZE 151
131  #define POSIX_MQ_4_SIZE 157
132
133  #define POSIX_MQ_BUFFER_MEMORY \
134    (CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(POSIX_MQ_0_COUNT, POSIX_MQ_0_SIZE) \
135      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(POSIX_MQ_1_COUNT, POSIX_MQ_1_SIZE) \
136      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(POSIX_MQ_2_COUNT, POSIX_MQ_2_SIZE) \
137      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(POSIX_MQ_3_COUNT, POSIX_MQ_3_SIZE) \
138      + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(POSIX_MQ_4_COUNT, POSIX_MQ_4_SIZE))
139
140  static const uint8_t posix_mq_counts [POSIX_MQ_COUNT] = {
141    POSIX_MQ_0_COUNT,
142    POSIX_MQ_1_COUNT,
143    POSIX_MQ_2_COUNT,
144    POSIX_MQ_3_COUNT,
145    POSIX_MQ_4_COUNT
146  };
147
148  static const uint8_t posix_mq_sizes [POSIX_MQ_COUNT] = {
149    POSIX_MQ_0_SIZE,
150    POSIX_MQ_1_SIZE,
151    POSIX_MQ_2_SIZE,
152    POSIX_MQ_3_SIZE,
153    POSIX_MQ_4_SIZE
154  };
155#else
156  #define POSIX_MQ_BUFFER_MEMORY 0
157#endif
158
159#define CONFIGURE_MESSAGE_BUFFER_MEMORY \
160  (MQ_BUFFER_MEMORY + POSIX_MQ_BUFFER_MEMORY)
161
162typedef struct {
163  uint64_t data [16];
164} area;
165
166#ifdef CONFIGURE_MAXIMUM_PARTITIONS
167  static area partition_areas [CONFIGURE_MAXIMUM_PARTITIONS];
168#endif
169
170#ifdef CONFIGURE_MAXIMUM_REGIONS
171  static area region_areas [CONFIGURE_MAXIMUM_REGIONS];
172#endif
173
174static char posix_name [NAME_MAX];
175
176static void *task_var;
177
178static char *get_posix_name(char a, char b, char c, int i)
179{
180  posix_name [NAME_MAX - 5] = a;
181  posix_name [NAME_MAX - 4] = b;
182  posix_name [NAME_MAX - 3] = c;
183  posix_name [NAME_MAX - 2] = 'A' + i;
184
185  return posix_name;
186}
187
188static void task_var_dtor(void *var __attribute__((unused)))
189{
190  /* Do nothing */
191}
192
193static void *posix_thread(void *arg __attribute__((unused)))
194{
195  rtems_test_assert(0);
196}
197
198static void posix_key_dtor(void *key __attribute__((unused)))
199{
200  /* Do nothing */
201}
202
203static void print_info(void)
204{
205  Heap_Information_block info;
206  bool ok = rtems_workspace_get_information(&info);
207  rtems_test_assert(ok);
208
209  printf(
210    "used blocks = %" PRIu32 ", "
211    "largest used block = %" PRIu32 ", "
212    "used space = %" PRIu32 "\n"
213    "free blocks = %" PRIu32 ", "
214    "largest free block = %" PRIu32 ", "
215    "free space = %" PRIu32 "\n",
216    info.Used.number,
217    info.Used.largest,
218    info.Used.total,
219    info.Free.number,
220    info.Free.largest,
221    info.Free.total
222  );
223}
224
225static rtems_task Init(rtems_task_argument argument)
226{
227  rtems_status_code sc = RTEMS_SUCCESSFUL;
228  int eno = 0;
229  int rv = 0;
230  rtems_id id = RTEMS_ID_NONE;
231  rtems_name name = rtems_build_name('C', 'O', 'N', 'F');
232  rtems_extensions_table table;
233  int i = 0;
234
235  puts("\n\n*** POSIX TEST CONFIG 01 ***");
236
237  memset(posix_name, 'P', sizeof(posix_name) - 1);
238
239  print_info();
240
241#ifdef CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS
242  for (i = 3; i < CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS; ++i) {
243    int oflag = O_WRONLY | O_CREAT | O_TRUNC;
244    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
245    char path [] = { 'F', 'I', 'L', 'E', 'A' + i, '\0' };
246    int fd = open(path, oflag, mode);
247    rtems_test_assert(fd == i);
248  }
249#endif
250
251#ifdef CONFIGURE_MAXIMUM_USER_EXTENSIONS
252  memset(&table, 0, sizeof(table));
253  for (i = 0; i < CONFIGURE_MAXIMUM_USER_EXTENSIONS; ++i) {
254    sc = rtems_extension_create(name, &table, &id);
255    directive_failed(sc, "rtems_extension_create");
256  }
257#endif
258
259#ifdef CONFIGURE_MAXIMUM_BARRIERS
260  for (i = 0; i < CONFIGURE_MAXIMUM_BARRIERS; ++i) {
261    sc = rtems_barrier_create(name, RTEMS_DEFAULT_ATTRIBUTES, 1, &id);
262    directive_failed(sc, "rtems_barrier_create");
263  }
264#endif
265
266#ifdef CONFIGURE_MAXIMUM_MESSAGE_QUEUES
267  for (i = 0; i < CONFIGURE_MAXIMUM_MESSAGE_QUEUES; ++i) {
268    sc = rtems_message_queue_create(
269      name,
270      mq_counts [i],
271      mq_sizes [i],
272      RTEMS_DEFAULT_ATTRIBUTES,
273      &id
274    );
275    directive_failed(sc, "rtems_message_queue_create");
276  }
277#endif
278
279#ifdef CONFIGURE_MAXIMUM_PARTITIONS
280  for (i = 0; i < CONFIGURE_MAXIMUM_PARTITIONS; ++i) {
281    sc = rtems_partition_create(
282      name,
283      partition_areas + i,
284      sizeof(partition_areas [0]),
285      sizeof(partition_areas [0]),
286      RTEMS_DEFAULT_ATTRIBUTES,
287      &id
288    );
289    directive_failed(sc, "rtems_partition_create");
290  }
291#endif
292
293#ifdef CONFIGURE_MAXIMUM_PERIODS
294  for (i = 0; i < CONFIGURE_MAXIMUM_PERIODS; ++i) {
295    sc = rtems_rate_monotonic_create(name, &id);
296    directive_failed(sc, "rtems_rate_monotonic_create");
297  }
298#endif
299
300#ifdef CONFIGURE_MAXIMUM_REGIONS
301  for (i = 0; i < CONFIGURE_MAXIMUM_REGIONS; ++i) {
302    sc = rtems_region_create(
303      name,
304      region_areas + i,
305      sizeof(region_areas [0]),
306      1,
307      RTEMS_DEFAULT_ATTRIBUTES,
308      &id
309    );
310    directive_failed(sc, "rtems_region_create");
311  }
312#endif
313
314#ifdef CONFIGURE_MAXIMUM_SEMAPHORES
315  for (i = 0; i < CONFIGURE_MAXIMUM_SEMAPHORES; ++i) {
316    sc = rtems_semaphore_create(
317      name,
318      0,
319      RTEMS_DEFAULT_ATTRIBUTES,
320      0,
321      &id
322    );
323    directive_failed(sc, "rtems_semaphore_create");
324  }
325#endif
326
327#ifdef CONFIGURE_MAXIMUM_TASKS
328  for (i = 1; i < CONFIGURE_MAXIMUM_TASKS; ++i) {
329    sc = rtems_task_create(
330      name,
331      RTEMS_MINIMUM_PRIORITY,
332      RTEMS_MINIMUM_STACK_SIZE,
333      RTEMS_DEFAULT_MODES,
334      RTEMS_DEFAULT_ATTRIBUTES,
335      &id
336    );
337    directive_failed(sc, "rtems_task_create");
338  }
339#endif
340
341#ifdef CONFIGURE_MAXIMUM_TASK_VARIABLES
342  for (i = 0; i < CONFIGURE_MAXIMUM_TASK_VARIABLES; ++i) {
343    sc = rtems_task_variable_add(RTEMS_SELF, &task_var, task_var_dtor);
344    directive_failed(sc, "rtems_task_variable_add");
345  }
346#endif
347
348#ifdef CONFIGURE_MAXIMUM_TIMERS
349  for (i = 0; i < CONFIGURE_MAXIMUM_TIMERS; ++i) {
350    sc = rtems_timer_create(name, &id);
351    directive_failed(sc, "rtems_timer_create");
352  }
353#endif
354
355#ifdef CONFIGURE_MAXIMUM_POSIX_BARRIERS
356  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_BARRIERS; ++i) {
357    pthread_barrier_t barrier;
358    eno = pthread_barrier_init(&barrier, NULL, 1);
359    rtems_test_assert(eno == 0);
360  }
361#endif
362
363#ifdef CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES
364  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES; ++i) {
365    pthread_cond_t cond;
366    eno = pthread_cond_init(&cond, NULL);
367    rtems_test_assert(eno == 0);
368  }
369#endif
370
371#ifdef CONFIGURE_MAXIMUM_POSIX_KEYS
372  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_KEYS; ++i) {
373    pthread_key_t key;
374    eno = pthread_key_create(&key, posix_key_dtor);
375    rtems_test_assert(eno == 0);
376  }
377#endif
378
379#ifdef POSIX_MQ_COUNT
380  for (i = 0; i < POSIX_MQ_COUNT; ++i) {
381    int oflag = O_RDWR | O_CREAT | O_EXCL;
382    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
383    struct mq_attr attr = {
384      .mq_maxmsg = posix_mq_counts [i],
385      .mq_msgsize = posix_mq_sizes [i]
386    };
387    char *path = get_posix_name('M', 'S', 'Q', i);
388    mqd_t mq = mq_open(path, oflag, mode, &attr);
389    rtems_test_assert(mq >= 0);
390  }
391#endif
392
393#ifdef CONFIGURE_MAXIMUM_POSIX_MUTEXES
394  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_MUTEXES; ++i) {
395    pthread_mutex_t mutex;
396    eno = pthread_mutex_init(&mutex, NULL);
397    rtems_test_assert(eno == 0);
398  }
399#endif
400
401#ifdef CONFIGURE_MAXIMUM_POSIX_RWLOCKS
402  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_RWLOCKS; ++i) {
403    pthread_rwlock_t rwlock;
404    eno = pthread_rwlock_init(&rwlock, NULL);
405    rtems_test_assert(eno == 0);
406  }
407#endif
408
409#ifdef CONFIGURE_MAXIMUM_POSIX_SEMAPHORES
410  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_SEMAPHORES; ++i) {
411    int oflag = O_RDWR | O_CREAT | O_EXCL;
412    mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
413    unsigned int value = 0;
414    char *path = get_posix_name('S', 'E', 'M', i);
415    sem_t *sem = sem_open(path, oflag, mode, value);
416    rtems_test_assert(sem != SEM_FAILED);
417  }
418#endif
419
420#ifdef CONFIGURE_MAXIMUM_POSIX_SPINLOCKS
421  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_SPINLOCKS; ++i) {
422    pthread_spinlock_t spinlock;
423    eno = pthread_spin_init(&spinlock, 0);
424    rtems_test_assert(eno == 0);
425  }
426#endif
427
428#ifdef CONFIGURE_MAXIMUM_POSIX_THREADS
429  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_THREADS; ++i) {
430    pthread_t thread;
431    eno = pthread_create(&thread, NULL, posix_thread, NULL);
432    rtems_test_assert(eno == 0);
433  }
434#endif
435
436#ifdef CONFIGURE_MAXIMUM_POSIX_TIMERS
437  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_TIMERS; ++i) {
438    timer_t timer_id;
439    rv = timer_create(CLOCK_REALTIME, NULL, &timer_id);
440    rtems_test_assert(rv == 0);
441  }
442#endif
443
444  printf("object creation done\n");
445  print_info();
446
447  puts("*** END OF POSIX TEST CONFIG 01 ***");
448
449  rtems_test_exit(0);
450}
451
452#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
453#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
454
455#define CONFIGURE_MAXIMUM_DRIVERS 2
456
457#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
458
459#define CONFIGURE_INIT
460
461#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.