summaryrefslogtreecommitdiffstats
path: root/testsuites/sptests/splinkersets01/init.c
blob: 28c638437722635b5e48f34e92d8c06e65fd8628 (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
/*
 * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Dornierstr. 4
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * 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 "tmacros.h"

#include "splinkersets01.h"

const char rtems_test_name[] = "SPLINKERSETS 1";

RTEMS_LINKER_RWSET(test_rw_i, const int *);

RTEMS_LINKER_ROSET(test_ro_i, const int *);

RTEMS_LINKER_RWSET_DECLARE(test_rw_i, const int *);

RTEMS_LINKER_ROSET_DECLARE(test_ro_i, const int *);

const int a[4];

const int ca[5];

RTEMS_LINKER_RWSET_ITEM(test_rw, const int *, a3) = &a[3];
RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw, const int *, a2, 2) = &a[2];
RTEMS_LINKER_RWSET_ITEM_REFERENCE(test_rw, const int *, a1);
RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw, const int *, a0, 0) = &a[0];

/* Items are ordered lexicographically */
RTEMS_LINKER_RWSET_ITEM(test_rw_i, const int *, a3) = &a[3];
RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw_i, const int *, a2, 2) = &a[2];
RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw_i, const int *, a1, 11) = &a[1];
RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw_i, const int *, a0, 0) = &a[0];

#define OZ OA

RTEMS_LINKER_ROSET_ITEM(test_ro, const int *, ca4) = &ca[4];
RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro, const int *, ca3, OD) = &ca[3];
RTEMS_LINKER_ROSET_ITEM_REFERENCE(test_ro, const int *, ca2);
RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro, const int *, ca1, OB) = &ca[1];
RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro, const int *, ca0, OZ) = &ca[0];

RTEMS_LINKER_ROSET_ITEM(test_ro_i, const int *, ca4) = &ca[4];
RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca3, OD) = &ca[3];
RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca2, OC) = &ca[2];
RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca1, OB) = &ca[1];
RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca0, OZ) = &ca[0];

/*
 * Demonstrate safe (= define must exist) order definitions, otherwise typos
 * are undetected and may lead to an unpredictable order.  See also above OB
 * vs. OZ.
 */

#define SAFE_ORDER_A 00000
#define SAFE_ORDER_B 00001
#define SAFE_ORDER_C 00002

#define ITEM(i, o) \
  enum { test_ro_s_##i = o - o }; \
  RTEMS_LINKER_RWSET_ITEM_ORDERED(test_ro_s, const int *, i, o) = &i

RTEMS_LINKER_RWSET(test_ro_s, const int *);

static const int s0;
static const int s1;
static const int s2;

ITEM(s2, SAFE_ORDER_C);
ITEM(s1, SAFE_ORDER_B);
ITEM(s0, SAFE_ORDER_A);

static void test(void)
{
  const int * volatile *b = RTEMS_LINKER_SET_BEGIN(test_rw);
  const int * volatile *e = RTEMS_LINKER_SET_END(test_rw);
  const int * volatile const *cb = RTEMS_LINKER_SET_BEGIN(test_ro);
  const int * volatile const *ce = RTEMS_LINKER_SET_END(test_ro);
  const int * volatile *bi = RTEMS_LINKER_SET_BEGIN(test_rw_i);
  const int * volatile *ei = RTEMS_LINKER_SET_END(test_rw_i);
  const int * volatile const *cbi = RTEMS_LINKER_SET_BEGIN(test_ro_i);
  const int * volatile const *cei = RTEMS_LINKER_SET_END(test_ro_i);
  const int * volatile const *sb = RTEMS_LINKER_SET_BEGIN(test_ro_s);
  const int * volatile const *se = RTEMS_LINKER_SET_END(test_ro_s);
  size_t i;

  rtems_test_assert((size_t) (e - b) == RTEMS_ARRAY_SIZE(a));
  rtems_test_assert((size_t) (ce - cb) == RTEMS_ARRAY_SIZE(ca));
  rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_rw) == RTEMS_ARRAY_SIZE(a));
  rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_ro) == RTEMS_ARRAY_SIZE(ca));

  rtems_test_assert((size_t) (ei - bi) == RTEMS_ARRAY_SIZE(a));
  rtems_test_assert((size_t) (cei - cbi) == RTEMS_ARRAY_SIZE(ca));
  rtems_test_assert((size_t) (se - sb) == 3);
  rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_rw_i) == RTEMS_ARRAY_SIZE(a));
  rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_ro_i) == RTEMS_ARRAY_SIZE(ca));
  rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_ro_s) == 3);

  for (i = 0; i < RTEMS_ARRAY_SIZE(a); ++i) {
    rtems_test_assert(&a[i] == b[i]);
  }

  for (i = 0; i < RTEMS_ARRAY_SIZE(ca); ++i) {
    rtems_test_assert(&ca[i] == cb[i]);
  }

  for (i = 0; i < RTEMS_ARRAY_SIZE(a); ++i) {
    rtems_test_assert(&a[i] == bi[i]);
  }

  for (i = 0; i < RTEMS_ARRAY_SIZE(ca); ++i) {
    rtems_test_assert(&ca[i] == cbi[i]);
  }

  rtems_test_assert(&s0 == sb[0]);
  rtems_test_assert(&s1 == sb[1]);
  rtems_test_assert(&s2 == sb[2]);
}

static void test_content(void)
{
  void volatile *b_rw = RTEMS_LINKER_SET_BEGIN(test_content_rw);
  void volatile *e_rw = RTEMS_LINKER_SET_END(test_content_rw);

  void volatile const *b_ro = RTEMS_LINKER_SET_BEGIN(test_content_ro);
  void volatile const *e_ro = RTEMS_LINKER_SET_END(test_content_ro);

  rtems_test_assert(&content_rw_1 >= b_rw);
  rtems_test_assert(&content_rw_2 >= b_rw);
  rtems_test_assert(&content_rw_3 >= b_rw);
  rtems_test_assert(&content_rw_1 <= e_rw);
  rtems_test_assert(&content_rw_2 <= e_rw);
  rtems_test_assert(&content_rw_3 <= e_rw);

  rtems_test_assert(&content_ro_1 >= b_ro);
  rtems_test_assert(&content_ro_2 >= b_ro);
  rtems_test_assert(&content_ro_3 >= b_ro);
  rtems_test_assert(&content_ro_1 <= e_ro);
  rtems_test_assert(&content_ro_2 <= e_ro);
  rtems_test_assert(&content_ro_3 <= e_ro);
}

static void Init(rtems_task_argument arg)
{
  TEST_BEGIN();

  test();
  test_content();

  TEST_END();
  rtems_test_exit(0);
}

#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER

#define CONFIGURE_MAXIMUM_TASKS 1

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_INIT

#include <rtems/confdefs.h>