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

4.11
Last change on this file since c7dc99ef was c7dc99ef, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 9, 2011 at 4:44:15 PM

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

  • psxconfig01/init.c: Fix due to alignment issue.
  • Property mode set to 100644
File size: 7.0 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 <pthread.h>
34#include <stdio.h>
35#include <inttypes.h>
36
37#define MQ_0_COUNT 2
38#define MQ_1_COUNT 3
39#define MQ_2_COUNT 5
40#define MQ_3_COUNT 7
41#define MQ_4_COUNT 11
42#define MQ_5_COUNT 13
43#define MQ_6_COUNT 17
44
45#define MQ_0_SIZE 101
46#define MQ_1_SIZE 103
47#define MQ_2_SIZE 107
48#define MQ_3_SIZE 109
49#define MQ_4_SIZE 113
50#define MQ_5_SIZE 127
51#define MQ_6_SIZE 131
52
53#define CONFIGURE_MESSAGE_BUFFER_MEMORY \
54  CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_0_COUNT, MQ_0_SIZE) \
55    + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_1_COUNT, MQ_1_SIZE) \
56    + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_2_COUNT, MQ_2_SIZE) \
57    + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_3_COUNT, MQ_3_SIZE) \
58    + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_4_COUNT, MQ_4_SIZE) \
59    + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_5_COUNT, MQ_5_SIZE) \
60    + CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(MQ_6_COUNT, MQ_6_SIZE)
61
62#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 17
63
64#define CONFIGURE_MAXIMUM_BARRIERS 31
65#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 7
66#define CONFIGURE_MAXIMUM_PARTITIONS 37
67#define CONFIGURE_MAXIMUM_PERIODS 41
68#define CONFIGURE_MAXIMUM_REGIONS 43
69#define CONFIGURE_MAXIMUM_SEMAPHORES 47
70#define CONFIGURE_MAXIMUM_TASKS 11
71#define CONFIGURE_MAXIMUM_TASK_VARIABLES 13
72#define CONFIGURE_MAXIMUM_TIMERS 59
73
74#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 29
75#define CONFIGURE_MAXIMUM_POSIX_KEYS 23
76#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 19
77#define CONFIGURE_MAXIMUM_POSIX_THREADS 3
78
79static const uint8_t mq_counts [CONFIGURE_MAXIMUM_MESSAGE_QUEUES] = {
80  MQ_0_COUNT,
81  MQ_1_COUNT,
82  MQ_2_COUNT,
83  MQ_3_COUNT,
84  MQ_4_COUNT,
85  MQ_5_COUNT,
86  MQ_6_COUNT
87};
88
89static const uint8_t mq_sizes [CONFIGURE_MAXIMUM_MESSAGE_QUEUES] = {
90  MQ_0_SIZE,
91  MQ_1_SIZE,
92  MQ_2_SIZE,
93  MQ_3_SIZE,
94  MQ_4_SIZE,
95  MQ_5_SIZE,
96  MQ_6_SIZE
97};
98
99typedef struct {
100  uint64_t data [16];
101} area;
102
103static area partition_areas [CONFIGURE_MAXIMUM_PARTITIONS];
104
105static area region_areas [CONFIGURE_MAXIMUM_REGIONS];
106
107static void *task_var;
108
109static void task_var_dtor(void *var __attribute__((unused)))
110{
111  /* Do nothing */
112}
113
114static void *posix_thread(void *arg __attribute__((unused)))
115{
116  rtems_test_assert(0);
117}
118
119static void posix_key_dtor(void *key __attribute__((unused)))
120{
121  /* Do nothing */
122}
123
124static void print_info(void)
125{
126  Heap_Information_block info;
127  bool ok = rtems_workspace_get_information(&info);
128  rtems_test_assert(ok);
129
130  printf(
131    "used blocks = %" PRIu32 ", "
132    "largest used block = %" PRIu32 ", "
133    "used space = %" PRIu32 "\n"
134    "free blocks = %" PRIu32 ", "
135    "largest free block = %" PRIu32 ", "
136    "free space = %" PRIu32 "\n",
137    info.Used.number,
138    info.Used.largest,
139    info.Used.total,
140    info.Free.number,
141    info.Free.largest,
142    info.Free.total
143  );
144}
145
146rtems_task Init(rtems_task_argument argument)
147{
148  rtems_status_code sc = RTEMS_SUCCESSFUL;
149  rtems_id id = RTEMS_ID_NONE;
150  rtems_name name = rtems_build_name('C', 'O', 'N', 'F');
151  rtems_extensions_table table;
152  int oflag = O_WRONLY | O_CREAT | O_TRUNC;
153  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
154  int fd_a = open("/a", oflag, mode);
155  int fd_b = open("/b", oflag, mode);
156  int i = 0;
157  int eno = 0;
158
159  puts("\n\n*** POSIX TEST CONFIG 01 ***");
160
161  print_info();
162
163  rtems_test_assert(fd_a == 3);
164  rtems_test_assert(fd_b == 4);
165
166  memset(&table, 0, sizeof(table));
167  for (i = 0; i < CONFIGURE_MAXIMUM_USER_EXTENSIONS; ++i) {
168    sc = rtems_extension_create(name, &table, &id);
169    directive_failed(sc, "rtems_extension_create");
170  }
171
172  for (i = 0; i < CONFIGURE_MAXIMUM_BARRIERS; ++i) {
173    sc = rtems_barrier_create(name, RTEMS_DEFAULT_ATTRIBUTES, 1, &id);
174    directive_failed(sc, "rtems_barrier_create");
175  }
176
177  for (i = 0; i < CONFIGURE_MAXIMUM_MESSAGE_QUEUES; ++i) {
178    sc = rtems_message_queue_create(
179      name,
180      mq_counts [i],
181      mq_sizes [i],
182      RTEMS_DEFAULT_ATTRIBUTES,
183      &id
184    );
185    directive_failed(sc, "rtems_message_queue_create");
186  }
187
188  for (i = 0; i < CONFIGURE_MAXIMUM_PARTITIONS; ++i) {
189    sc = rtems_partition_create(
190      name,
191      partition_areas + i,
192      sizeof(partition_areas [0]),
193      sizeof(partition_areas [0]),
194      RTEMS_DEFAULT_ATTRIBUTES,
195      &id
196    );
197    directive_failed(sc, "rtems_partition_create");
198  }
199
200  for (i = 0; i < CONFIGURE_MAXIMUM_PERIODS; ++i) {
201    sc = rtems_rate_monotonic_create(name, &id);
202    directive_failed(sc, "rtems_rate_monotonic_create");
203  }
204
205  for (i = 0; i < CONFIGURE_MAXIMUM_REGIONS; ++i) {
206    sc = rtems_region_create(
207      name,
208      region_areas + i,
209      sizeof(region_areas [0]),
210      1,
211      RTEMS_DEFAULT_ATTRIBUTES,
212      &id
213    );
214    directive_failed(sc, "rtems_region_create");
215  }
216
217  for (i = 0; i < CONFIGURE_MAXIMUM_SEMAPHORES; ++i) {
218    sc = rtems_semaphore_create(
219      name,
220      0,
221      RTEMS_DEFAULT_ATTRIBUTES,
222      0,
223      &id
224    );
225    directive_failed(sc, "rtems_semaphore_create");
226  }
227
228  for (i = 0; i < CONFIGURE_MAXIMUM_TASKS - 1; ++i) {
229    sc = rtems_task_create(
230      name,
231      RTEMS_MINIMUM_PRIORITY,
232      RTEMS_MINIMUM_STACK_SIZE,
233      RTEMS_DEFAULT_MODES,
234      RTEMS_DEFAULT_ATTRIBUTES,
235      &id
236    );
237    directive_failed(sc, "rtems_task_create");
238  }
239
240  for (i = 0; i < CONFIGURE_MAXIMUM_TASK_VARIABLES; ++i) {
241    sc = rtems_task_variable_add(RTEMS_SELF, &task_var, task_var_dtor);
242    directive_failed(sc, "rtems_task_variable_add");
243  }
244
245  for (i = 0; i < CONFIGURE_MAXIMUM_TIMERS; ++i) {
246    sc = rtems_timer_create(name, &id);
247    directive_failed(sc, "rtems_timer_create");
248  }
249
250  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES; ++i) {
251    pthread_cond_t cond;
252    eno = pthread_cond_init(&cond, NULL);
253    rtems_test_assert(eno == 0);
254  }
255
256  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_KEYS; ++i) {
257    pthread_key_t key;
258    eno = pthread_key_create(&key, posix_key_dtor);
259    rtems_test_assert(eno == 0);
260  }
261
262  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_MUTEXES; ++i) {
263    pthread_mutex_t mutex;
264    eno = pthread_mutex_init(&mutex, NULL);
265    rtems_test_assert(eno == 0);
266  }
267
268  for (i = 0; i < CONFIGURE_MAXIMUM_POSIX_THREADS; ++i) {
269    pthread_t thread;
270    eno = pthread_create(&thread, NULL, posix_thread, NULL);
271    rtems_test_assert(eno == 0);
272  }
273
274  printf("object creation done\n");
275  print_info();
276
277  puts("*** END OF POSIX TEST CONFIG 01 ***");
278
279  rtems_test_exit(0);
280}
281
282#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
283#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
284
285#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
286
287#define CONFIGURE_MAXIMUM_DRIVERS 2
288
289#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
290
291#define CONFIGURE_INIT
292
293#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.