source: rtems/testsuites/sptests/spmisc01/init.c @ 6f94a83

Last change on this file since 6f94a83 was 6f94a83, checked in by Sebastian Huber <sebastian.huber@…>, on 04/08/20 at 08:20:51

score: Add RTEMS_WEAK

Update #4032.

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