summaryrefslogtreecommitdiffstats
path: root/testsuites/sptests/spconfig02/init.c
blob: f25ff5efe787c36eb982a043f5f482fa85c9f5bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
/*
 * Copyright (c) 2018 embedded brains GmbH & Co. KG
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.com/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems.h>
#include <rtems/score/objectimpl.h>
#include <rtems/sysinit.h>

#include <tmacros.h>

const char rtems_test_name[] = "SPCONFIG 2";

static const rtems_name name = rtems_build_name('N', 'A', 'M', 'E');

static void test_barrier_create(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_barrier_create(name, RTEMS_DEFAULT_ATTRIBUTES, 1, &id);
  rtems_test_assert(sc == RTEMS_TOO_MANY);
}

static void test_barrier_delete(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_barrier_delete(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS, 1, 0);
  sc = rtems_barrier_delete(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_barrier_get(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_barrier_wait(0, RTEMS_NO_TIMEOUT);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_BARRIERS, 1, 0);
  sc = rtems_barrier_wait(id, RTEMS_NO_TIMEOUT);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_message_queue_create(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_message_queue_create(
    name,
    1,
    1,
    RTEMS_DEFAULT_ATTRIBUTES,
    &id
  );
  rtems_test_assert(sc == RTEMS_TOO_MANY);
}

static void test_message_queue_delete(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_message_queue_delete(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_MESSAGE_QUEUES, 1, 0);
  sc = rtems_message_queue_delete(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_message_queue_get(void)
{
  rtems_status_code sc;
  rtems_id id;
  uint32_t count;

  sc = rtems_message_queue_flush(0, &count);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_MESSAGE_QUEUES, 1, 0);
  sc = rtems_message_queue_flush(id, &count);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_partition_create(void)
{
  rtems_status_code sc;
  rtems_id id;
  long buf[32];

  sc = rtems_partition_create(
    name,
    buf,
    sizeof(buf),
    sizeof(buf),
    RTEMS_DEFAULT_ATTRIBUTES,
    &id
  );
  rtems_test_assert(sc == RTEMS_TOO_MANY);
}

static void test_partition_delete(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_partition_delete(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PARTITIONS, 1, 0);
  sc = rtems_partition_delete(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_partition_get(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_partition_return_buffer(0, NULL);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PARTITIONS, 1, 0);
  sc = rtems_partition_return_buffer(id, NULL);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_rate_monotonic_create(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_rate_monotonic_create(name, &id);
  rtems_test_assert(sc == RTEMS_TOO_MANY);
}

static void test_rate_monotonic_delete(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_rate_monotonic_delete(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PERIODS, 1, 0);
  sc = rtems_rate_monotonic_delete(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_rate_monotonic_get(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_rate_monotonic_cancel(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_PERIODS, 1, 0);
  sc = rtems_rate_monotonic_cancel(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_region_create(void)
{
  rtems_status_code sc;
  rtems_id id;
  long buf[32];

  sc = rtems_region_create(
    name,
    buf,
    sizeof(buf),
    1,
    RTEMS_DEFAULT_ATTRIBUTES,
    &id
  );
  rtems_test_assert(sc == RTEMS_TOO_MANY);
}

static void test_region_delete(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_region_delete(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_REGIONS, 1, 0);
  sc = rtems_region_delete(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_region_get(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_region_return_segment(0, NULL);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_REGIONS, 1, 0);
  sc = rtems_region_return_segment(id, NULL);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_semaphore_create(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_semaphore_create(
    name,
    0,
    RTEMS_DEFAULT_ATTRIBUTES,
    0,
    &id
  );
  rtems_test_assert(sc == RTEMS_TOO_MANY);
}

static void test_semaphore_delete(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_semaphore_delete(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_SEMAPHORES, 1, 0);
  sc = rtems_semaphore_delete(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_semaphore_get(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_semaphore_release(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_SEMAPHORES, 1, 0);
  sc = rtems_semaphore_release(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_task_create(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_task_create(
    name,
    1,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &id
  );
  rtems_test_assert(sc == RTEMS_TOO_MANY);
}

static void test_task_delete(void)
{
  rtems_status_code sc;
  rtems_id id;

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS, 1, 0);
  sc = rtems_task_delete(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_task_get(void)
{
  rtems_status_code sc;
  rtems_id id;

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TASKS, 1, 0);
  sc = rtems_task_resume(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_timer_create(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_timer_create(name, &id);
  rtems_test_assert(sc == RTEMS_TOO_MANY);
}

static void test_timer_delete(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_timer_delete(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS, 1, 0);
  sc = rtems_timer_delete(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_timer_get(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_timer_reset(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_TIMERS, 1, 0);
  sc = rtems_timer_reset(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_user_extensions_create(void)
{
  rtems_status_code sc;
  rtems_id id;
  rtems_extensions_table table;

  memset(&table, 0, sizeof(table));
  sc = rtems_extension_create(name, &table, &id);
  rtems_test_assert(sc == RTEMS_TOO_MANY);
}

static void test_user_extensions_delete(void)
{
  rtems_status_code sc;
  rtems_id id;

  sc = rtems_extension_delete(0);
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  id = rtems_build_id(OBJECTS_CLASSIC_API, OBJECTS_RTEMS_EXTENSIONS, 1, 0);
  sc = rtems_extension_delete(id);
  rtems_test_assert(sc == RTEMS_INVALID_ID);
}

static void test_id_to_name(rtems_id api, rtems_id cls, rtems_id idx, bool *found)
{
  rtems_status_code sc;
  rtems_id id;
  rtems_name name_of_id;

  id = rtems_build_id(api, cls, 1, idx);
  sc = rtems_object_get_classic_name(id, &name_of_id);

  if (sc == RTEMS_SUCCESSFUL) {
    if (name_of_id == rtems_build_name('U', 'I', '1', ' ')) {
      rtems_test_assert(id == rtems_task_self());
      rtems_test_assert(!found[0]);
      found[0] = true;
    } else {
      rtems_test_assert(name_of_id == rtems_build_name('I', 'D', 'L', 'E'));
      rtems_test_assert(!found[1]);
      found[1] = true;
    }
  } else {
    rtems_test_assert(sc == RTEMS_INVALID_ID);
  }
}

static void test_some_id_to_name(void)
{
  rtems_id api;
  bool found[2];

  found[0] = false;
  found[1] = false;

  for (api = 0; api < 8; ++api) {
    rtems_id cls;

    for (cls = 0; cls < 32; ++cls) {
      test_id_to_name(api, cls, 0, found);
      test_id_to_name(api, cls, 1, found);
      test_id_to_name(api, cls, 2, found);
      test_id_to_name(api, cls, 65534, found);
      test_id_to_name(api, cls, 65535, found);
    }
  }

  rtems_test_assert(found[0]);
  rtems_test_assert(found[1]);
}

static void Init(rtems_task_argument arg)
{
  test_barrier_create();
  test_barrier_delete();
  test_barrier_get();
  test_message_queue_create();
  test_message_queue_delete();
  test_message_queue_get();
  test_partition_create();
  test_partition_delete();
  test_partition_get();
  test_rate_monotonic_create();
  test_rate_monotonic_delete();
  test_rate_monotonic_get();
  test_region_create();
  test_region_delete();
  test_region_get();
  test_semaphore_create();
  test_semaphore_delete();
  test_semaphore_get();
  test_task_create();
  test_task_delete();
  test_task_get();
  test_timer_create();
  test_timer_delete();
  test_timer_get();
  test_user_extensions_create();
  test_user_extensions_delete();
  test_some_id_to_name();
  TEST_END();
  rtems_test_exit(0);
}

static void before_object_information_initialization(void)
{
  rtems_print_printer_printk(&rtems_test_printer);
  TEST_BEGIN();
  test_barrier_get();
  test_message_queue_get();
  test_partition_get();
  test_rate_monotonic_get();
  test_semaphore_get();
  test_task_get();
  test_timer_get();
}

RTEMS_SYSINIT_ITEM(
  before_object_information_initialization,
  RTEMS_SYSINIT_INITIAL_EXTENSIONS,
  RTEMS_SYSINIT_ORDER_LAST
);

#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER

#define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM

#define CONFIGURE_DISABLE_NEWLIB_REENTRANCY

#define CONFIGURE_MAXIMUM_TASKS 1

#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_INIT

#include <rtems/confdefs.h>