source: rtems/testsuites/sptests/spmisc01/init.c @ 2df9541

Last change on this file since 2df9541 was 2df9541, checked in by Sebastian Huber <sebastian.huber@…>, on 04/30/21 at 14:22:02

spmisc01: Test RTEMS_NOINIT

Close #3866.

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*
2 * Copyright (C) 2018, 2019 embedded brains GmbH
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.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems.h>
20#include <string.h>
21
22#include <tmacros.h>
23
24#include "spmisc01.h"
25
26const char rtems_test_name[] = "SPMISC 1";
27
28RTEMS_INLINE_ROUTINE int inline_func(void)
29{
30  return 7;
31}
32
33RTEMS_NO_INLINE static int noinline_func(void)
34{
35  return 14;
36}
37
38RTEMS_NO_RETURN void noreturn_func(void);
39
40RTEMS_PURE static int pure_func(void)
41{
42  return 21;
43}
44
45RTEMS_CONST static int const_func(void)
46{
47  return 23;
48}
49
50RTEMS_SECTION(".rtemsroset.test") static int section_variable = 28;
51
52RTEMS_NOINIT static int noinit_variable;
53
54RTEMS_USED static int used_func(void)
55{
56  return 35;
57}
58
59RTEMS_USED static int used_variable;
60
61static int unused_arg_and_variable_func(RTEMS_UNUSED int arg)
62{
63  RTEMS_UNUSED int variable;
64
65  return 42;
66}
67
68typedef struct {
69  uint8_t c;
70  uint32_t i;
71} RTEMS_PACKED packed_struct;
72
73static int alias_func(void) RTEMS_ALIAS(noinline_func);
74
75int weak_alias_func(void) RTEMS_WEAK_ALIAS(noinline_func);
76
77RTEMS_WEAK int weak_or_strong(void)
78{
79  return 99;
80}
81
82RTEMS_WEAK int weak_2(void)
83{
84  return 111;
85}
86
87static char aligned_variable RTEMS_ALIGNED(64);
88
89typedef struct {
90  uint8_t c;
91  uint8_t aligned_member RTEMS_ALIGNED(64);
92} aligned_member_struct;
93
94static void unreachable(void)
95{
96  if (0) {
97    RTEMS_UNREACHABLE();
98  }
99}
100
101RTEMS_PRINTFLIKE(1, 2) static int printflike_func(const char *fmt, ...)
102{
103  return 56;
104}
105
106static int obfuscate_variable(int i)
107{
108  RTEMS_OBFUSCATE_VARIABLE(i);
109  return i;
110}
111
112RTEMS_DECLARE_GLOBAL_SYMBOL(a_global_symbol);
113
114RTEMS_DEFINE_GLOBAL_SYMBOL(a_global_symbol, 0xabc);
115
116RTEMS_STATIC_ASSERT(0 != 1, zero_neq_one);
117
118static int array[3];
119
120typedef struct {
121  uint32_t i;
122  uint32_t j[RTEMS_ZERO_LENGTH_ARRAY];
123} zero_length_array_struct;
124
125typedef struct {
126  int a;
127  int b;
128} container_of_struct;
129
130static void container_of(void)
131{
132  container_of_struct s;
133  int *b;
134
135  b = &s.b;
136  rtems_test_assert(RTEMS_CONTAINER_OF(b, container_of_struct, b) == &s);
137}
138
139static int deconst(void)
140{
141  const int i = 70;
142  int *p;
143
144  p = RTEMS_DECONST(int *, &i);
145  return *p;
146}
147
148static int devolatile(void)
149{
150  volatile int i = 77;
151  int *p;
152
153  p = RTEMS_DEVOLATILE(int *, &i);
154  return *p;
155}
156
157static int dequalify(void)
158{
159  volatile const int i = 84;
160  int *p;
161
162  p = RTEMS_DEQUALIFY(int *, &i);
163  return *p;
164}
165
166typedef struct {
167  char a;
168  int b;
169} same_member_type_struct;
170
171typedef struct {
172  char c;
173  int d;
174} same_member_type_struct_2;
175
176RTEMS_STATIC_ASSERT(
177  RTEMS_HAVE_MEMBER_SAME_TYPE(
178    same_member_type_struct,
179    b,
180    same_member_type_struct_2,
181    d
182  ),
183  same_member_type_struct_eq
184);
185
186RTEMS_STATIC_ASSERT(
187  !RTEMS_HAVE_MEMBER_SAME_TYPE(
188    same_member_type_struct,
189    b,
190    same_member_type_struct_2,
191    c
192  ),
193  same_member_type_struct_neq
194);
195
196static int concat(void)
197{
198  return 91;
199}
200
201#define CON con
202
203#define CAT cat
204
205#define STR ing
206
207static void Init(rtems_task_argument arg)
208{
209  void *p;
210  int   v;
211
212  TEST_BEGIN();
213  rtems_test_assert(inline_func() == 7);
214  RTEMS_COMPILER_MEMORY_BARRIER();
215  rtems_test_assert(noinline_func() == 14);
216  rtems_test_assert(pure_func() == 21);
217  rtems_test_assert(const_func() == 23);
218  rtems_test_assert(section_variable == 28);
219  v = noinit_variable;
220  RTEMS_OBFUSCATE_VARIABLE(v);
221  rtems_test_assert(unused_arg_and_variable_func(49) == 42);
222  rtems_test_assert(sizeof(packed_struct) == 5);
223  rtems_test_assert(alias_func() == 14);
224  rtems_test_assert(weak_alias_func() == 14);
225  pull_in_strong();
226  rtems_test_assert(weak_or_strong() == 77);
227  rtems_test_assert(weak_2() == 111);
228  rtems_test_assert(((uintptr_t) &aligned_variable) % 64 == 0);
229  rtems_test_assert(offsetof(aligned_member_struct, aligned_member) % 64 == 0);
230  unreachable();
231  rtems_test_assert(printflike_func("%i", 0) == 56);
232  rtems_test_assert(obfuscate_variable(63) == 63);
233  rtems_test_assert((uintptr_t)a_global_symbol == 0xabc);
234  rtems_test_assert(RTEMS_ARRAY_SIZE(array) == 3);
235  rtems_test_assert(sizeof(zero_length_array_struct) == 4);
236  container_of();
237  rtems_test_assert(deconst() == 70);
238  rtems_test_assert(devolatile() == 77);
239  rtems_test_assert(dequalify() == 84);
240  rtems_test_assert(
241    RTEMS_HAVE_MEMBER_SAME_TYPE(
242      same_member_type_struct,
243      b,
244      same_member_type_struct_2,
245      d
246    )
247  );
248  rtems_test_assert(
249    !RTEMS_HAVE_MEMBER_SAME_TYPE(
250      same_member_type_struct,
251      b,
252      same_member_type_struct_2,
253      c
254    )
255  );
256  rtems_test_assert(RTEMS_CONCAT(con, cat)() == 91);
257  rtems_test_assert(RTEMS_XCONCAT(CON, CAT)() == 91);
258  rtems_test_assert(strcmp(RTEMS_STRING(str), "str") == 0);
259  rtems_test_assert(strcmp(RTEMS_XSTRING(STR), "ing") == 0);
260
261  if (RTEMS_PREDICT_TRUE(true)) {
262    rtems_test_assert(true);
263  } else {
264    rtems_test_assert(false);
265  }
266
267  if (RTEMS_PREDICT_FALSE(true)) {
268    rtems_test_assert(true);
269  } else {
270    rtems_test_assert(false);
271  }
272
273  if (RTEMS_PREDICT_TRUE(false)) {
274    rtems_test_assert(false);
275  } else {
276    rtems_test_assert(true);
277  }
278
279  if (RTEMS_PREDICT_FALSE(false)) {
280    rtems_test_assert(false);
281  } else {
282    rtems_test_assert(true);
283  }
284
285  p = RTEMS_RETURN_ADDRESS();
286  (void) p;
287
288  TEST_END();
289  rtems_test_exit(0);
290}
291
292#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
293
294#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
295
296#define CONFIGURE_MAXIMUM_TASKS 1
297
298#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
299
300#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
301
302#define CONFIGURE_INIT
303
304#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.