1 | /* |
---|
2 | * Copyright (c) 2015, 2016 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include "tmacros.h" |
---|
20 | |
---|
21 | #include "splinkersets01.h" |
---|
22 | |
---|
23 | const char rtems_test_name[] = "SPLINKERSETS 1"; |
---|
24 | |
---|
25 | RTEMS_LINKER_RWSET(test_rw_i, const int *); |
---|
26 | |
---|
27 | RTEMS_LINKER_ROSET(test_ro_i, const int *); |
---|
28 | |
---|
29 | RTEMS_LINKER_RWSET_DECLARE(test_rw_i, const int *); |
---|
30 | |
---|
31 | RTEMS_LINKER_ROSET_DECLARE(test_ro_i, const int *); |
---|
32 | |
---|
33 | const int a[4]; |
---|
34 | |
---|
35 | const int ca[5]; |
---|
36 | |
---|
37 | RTEMS_LINKER_RWSET_ITEM(test_rw, const int *, a3) = &a[3]; |
---|
38 | RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw, const int *, a2, 2) = &a[2]; |
---|
39 | RTEMS_LINKER_RWSET_ITEM_REFERENCE(test_rw, const int *, a1); |
---|
40 | RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw, const int *, a0, 0) = &a[0]; |
---|
41 | |
---|
42 | /* Items are ordered lexicographically */ |
---|
43 | RTEMS_LINKER_RWSET_ITEM(test_rw_i, const int *, a3) = &a[3]; |
---|
44 | RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw_i, const int *, a2, 2) = &a[2]; |
---|
45 | RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw_i, const int *, a1, 11) = &a[1]; |
---|
46 | RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw_i, const int *, a0, 0) = &a[0]; |
---|
47 | |
---|
48 | #define OZ OA |
---|
49 | |
---|
50 | RTEMS_LINKER_ROSET_ITEM(test_ro, const int *, ca4) = &ca[4]; |
---|
51 | RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro, const int *, ca3, OD) = &ca[3]; |
---|
52 | RTEMS_LINKER_ROSET_ITEM_REFERENCE(test_ro, const int *, ca2); |
---|
53 | RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro, const int *, ca1, OB) = &ca[1]; |
---|
54 | RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro, const int *, ca0, OZ) = &ca[0]; |
---|
55 | |
---|
56 | RTEMS_LINKER_ROSET_ITEM(test_ro_i, const int *, ca4) = &ca[4]; |
---|
57 | RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca3, OD) = &ca[3]; |
---|
58 | RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca2, OC) = &ca[2]; |
---|
59 | RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca1, OB) = &ca[1]; |
---|
60 | RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca0, OZ) = &ca[0]; |
---|
61 | |
---|
62 | /* |
---|
63 | * Demonstrate safe (= define must exist) order definitions, otherwise typos |
---|
64 | * are undetected and may lead to an unpredictable order. See also above OB |
---|
65 | * vs. OZ. |
---|
66 | */ |
---|
67 | |
---|
68 | #define SAFE_ORDER_A 00000 |
---|
69 | #define SAFE_ORDER_B 00001 |
---|
70 | #define SAFE_ORDER_C 00002 |
---|
71 | |
---|
72 | #define ITEM(i, o) \ |
---|
73 | enum { test_ro_s_##i = o - o }; \ |
---|
74 | RTEMS_LINKER_RWSET_ITEM_ORDERED(test_ro_s, const int *, i, o) = &i |
---|
75 | |
---|
76 | RTEMS_LINKER_RWSET(test_ro_s, const int *); |
---|
77 | |
---|
78 | static const int s0; |
---|
79 | static const int s1; |
---|
80 | static const int s2; |
---|
81 | |
---|
82 | ITEM(s2, SAFE_ORDER_C); |
---|
83 | ITEM(s1, SAFE_ORDER_B); |
---|
84 | ITEM(s0, SAFE_ORDER_A); |
---|
85 | |
---|
86 | static void test(void) |
---|
87 | { |
---|
88 | const int **b; |
---|
89 | const int **e; |
---|
90 | const int * const *cb; |
---|
91 | const int * const *ce; |
---|
92 | const int **bi; |
---|
93 | const int **ei; |
---|
94 | const int * const *cbi; |
---|
95 | const int * const *cei; |
---|
96 | const int * const *sb; |
---|
97 | const int * const *se; |
---|
98 | size_t i; |
---|
99 | |
---|
100 | RTEMS_LINKER_SET_ASSIGN_BEGIN(test_rw, b); |
---|
101 | RTEMS_LINKER_SET_ASSIGN_END(test_rw, e); |
---|
102 | RTEMS_LINKER_SET_ASSIGN_BEGIN(test_ro, cb); |
---|
103 | RTEMS_LINKER_SET_ASSIGN_END(test_ro, ce); |
---|
104 | RTEMS_LINKER_SET_ASSIGN_BEGIN(test_rw_i, bi); |
---|
105 | RTEMS_LINKER_SET_ASSIGN_END(test_rw_i, ei); |
---|
106 | RTEMS_LINKER_SET_ASSIGN_BEGIN(test_ro_i, cbi); |
---|
107 | RTEMS_LINKER_SET_ASSIGN_END(test_ro_i, cei); |
---|
108 | RTEMS_LINKER_SET_ASSIGN_BEGIN(test_ro_s, sb); |
---|
109 | RTEMS_LINKER_SET_ASSIGN_END(test_ro_s, se); |
---|
110 | |
---|
111 | rtems_test_assert((size_t) (e - b) == RTEMS_ARRAY_SIZE(a)); |
---|
112 | rtems_test_assert((size_t) (ce - cb) == RTEMS_ARRAY_SIZE(ca)); |
---|
113 | rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_rw) == RTEMS_ARRAY_SIZE(a)); |
---|
114 | rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_ro) == RTEMS_ARRAY_SIZE(ca)); |
---|
115 | |
---|
116 | rtems_test_assert((size_t) (ei - bi) == RTEMS_ARRAY_SIZE(a)); |
---|
117 | rtems_test_assert((size_t) (cei - cbi) == RTEMS_ARRAY_SIZE(ca)); |
---|
118 | rtems_test_assert((size_t) (se - sb) == 3); |
---|
119 | rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_rw_i) == RTEMS_ARRAY_SIZE(a)); |
---|
120 | rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_ro_i) == RTEMS_ARRAY_SIZE(ca)); |
---|
121 | rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_ro_s) == 3); |
---|
122 | |
---|
123 | for (i = 0; i < RTEMS_ARRAY_SIZE(a); ++i) { |
---|
124 | rtems_test_assert(&a[i] == b[i]); |
---|
125 | } |
---|
126 | |
---|
127 | for (i = 0; i < RTEMS_ARRAY_SIZE(ca); ++i) { |
---|
128 | rtems_test_assert(&ca[i] == cb[i]); |
---|
129 | } |
---|
130 | |
---|
131 | for (i = 0; i < RTEMS_ARRAY_SIZE(a); ++i) { |
---|
132 | rtems_test_assert(&a[i] == bi[i]); |
---|
133 | } |
---|
134 | |
---|
135 | for (i = 0; i < RTEMS_ARRAY_SIZE(ca); ++i) { |
---|
136 | rtems_test_assert(&ca[i] == cbi[i]); |
---|
137 | } |
---|
138 | |
---|
139 | rtems_test_assert(&s0 == sb[0]); |
---|
140 | rtems_test_assert(&s1 == sb[1]); |
---|
141 | rtems_test_assert(&s2 == sb[2]); |
---|
142 | } |
---|
143 | |
---|
144 | static void test_content(void) |
---|
145 | { |
---|
146 | const char *b_rw; |
---|
147 | const char *e_rw; |
---|
148 | const char *b_ro; |
---|
149 | const char *e_ro; |
---|
150 | |
---|
151 | RTEMS_LINKER_SET_ASSIGN_BEGIN(test_content_rw, b_rw); |
---|
152 | RTEMS_LINKER_SET_ASSIGN_END(test_content_rw, e_rw); |
---|
153 | RTEMS_LINKER_SET_ASSIGN_BEGIN(test_content_ro, b_ro); |
---|
154 | RTEMS_LINKER_SET_ASSIGN_END(test_content_ro, e_ro); |
---|
155 | |
---|
156 | rtems_test_assert((uintptr_t) &content_rw_1 >= (uintptr_t) b_rw); |
---|
157 | rtems_test_assert((uintptr_t) &content_rw_2 >= (uintptr_t) b_rw); |
---|
158 | rtems_test_assert((uintptr_t) &content_rw_3 >= (uintptr_t) b_rw); |
---|
159 | rtems_test_assert((uintptr_t) &content_rw_1 <= (uintptr_t) e_rw); |
---|
160 | rtems_test_assert((uintptr_t) &content_rw_2 <= (uintptr_t) e_rw); |
---|
161 | rtems_test_assert((uintptr_t) &content_rw_3 <= (uintptr_t) e_rw); |
---|
162 | |
---|
163 | rtems_test_assert((uintptr_t) &content_ro_1 >= (uintptr_t) b_ro); |
---|
164 | rtems_test_assert((uintptr_t) &content_ro_2 >= (uintptr_t) b_ro); |
---|
165 | rtems_test_assert((uintptr_t) &content_ro_3 >= (uintptr_t) b_ro); |
---|
166 | rtems_test_assert((uintptr_t) &content_ro_1 <= (uintptr_t) e_ro); |
---|
167 | rtems_test_assert((uintptr_t) &content_ro_2 <= (uintptr_t) e_ro); |
---|
168 | rtems_test_assert((uintptr_t) &content_ro_3 <= (uintptr_t) e_ro); |
---|
169 | } |
---|
170 | |
---|
171 | static void Init(rtems_task_argument arg) |
---|
172 | { |
---|
173 | TEST_BEGIN(); |
---|
174 | |
---|
175 | test(); |
---|
176 | test_content(); |
---|
177 | |
---|
178 | TEST_END(); |
---|
179 | rtems_test_exit(0); |
---|
180 | } |
---|
181 | |
---|
182 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
183 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
184 | |
---|
185 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
186 | |
---|
187 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
188 | |
---|
189 | #define CONFIGURE_INIT |
---|
190 | |
---|
191 | #include <rtems/confdefs.h> |
---|