summaryrefslogtreecommitdiffstats
path: root/testsuites/sptests/spmisc01/init.c
blob: 6fbc0eeff8dacee6ecb78f06dbd1a04fbe3912ca (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
/*
 * Copyright (C) 2018, 2019 embedded brains GmbH
 *
 *  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.org/license/LICENSE.
 */

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

#include <rtems.h>
#include <string.h>

#include <tmacros.h>

#include "spmisc01.h"

const char rtems_test_name[] = "SPMISC 1";

RTEMS_INLINE_ROUTINE int inline_func(void)
{
  return 7;
}

RTEMS_NO_INLINE static int noinline_func(void)
{
  return 14;
}

RTEMS_NO_RETURN void noreturn_func(void);

RTEMS_PURE static int pure_func(void)
{
  return 21;
}

RTEMS_CONST static int const_func(void)
{
  return 23;
}

RTEMS_SECTION(".rtemsroset.test") static int section_variable = 28;

RTEMS_NOINIT static int noinit_variable;

RTEMS_USED static int used_func(void)
{
  return 35;
}

RTEMS_USED static int used_variable;

static int unused_arg_and_variable_func(RTEMS_UNUSED int arg)
{
  RTEMS_UNUSED int variable;

  return 42;
}

typedef struct {
  uint8_t c;
  uint32_t i;
} RTEMS_PACKED packed_struct;

static int alias_func(void) RTEMS_ALIAS(noinline_func);

int weak_alias_func(void) RTEMS_WEAK_ALIAS(noinline_func);

RTEMS_WEAK int weak_or_strong(void)
{
  return 99;
}

RTEMS_WEAK int weak_2(void)
{
  return 111;
}

static char aligned_variable RTEMS_ALIGNED(64);

typedef struct {
  uint8_t c;
  uint8_t aligned_member RTEMS_ALIGNED(64);
} aligned_member_struct;

static void unreachable(void)
{
  if (0) {
    RTEMS_UNREACHABLE();
  }
}

RTEMS_PRINTFLIKE(1, 2) static int printflike_func(const char *fmt, ...)
{
  return 56;
}

static int obfuscate_variable(int i)
{
  RTEMS_OBFUSCATE_VARIABLE(i);
  return i;
}

RTEMS_DECLARE_GLOBAL_SYMBOL(a_global_symbol);

RTEMS_DEFINE_GLOBAL_SYMBOL(a_global_symbol, 0xabc);

RTEMS_STATIC_ASSERT(0 != 1, zero_neq_one);

static int array[3];

typedef struct {
  uint32_t i;
  uint32_t j[RTEMS_ZERO_LENGTH_ARRAY];
} zero_length_array_struct;

typedef struct {
  int a;
  int b;
} container_of_struct;

static void container_of(void)
{
  container_of_struct s;
  int *b;

  b = &s.b;
  rtems_test_assert(RTEMS_CONTAINER_OF(b, container_of_struct, b) == &s);
}

static int deconst(void)
{
  const int i = 70;
  int *p;

  p = RTEMS_DECONST(int *, &i);
  return *p;
}

static int devolatile(void)
{
  volatile int i = 77;
  int *p;

  p = RTEMS_DEVOLATILE(int *, &i);
  return *p;
}

static int dequalify(void)
{
  volatile const int i = 84;
  int *p;

  p = RTEMS_DEQUALIFY(int *, &i);
  return *p;
}

typedef struct {
  char a;
  int b;
} same_member_type_struct;

typedef struct {
  char c;
  int d;
} same_member_type_struct_2;

RTEMS_STATIC_ASSERT(
  RTEMS_HAVE_MEMBER_SAME_TYPE(
    same_member_type_struct,
    b,
    same_member_type_struct_2,
    d
  ),
  same_member_type_struct_eq
);

RTEMS_STATIC_ASSERT(
  !RTEMS_HAVE_MEMBER_SAME_TYPE(
    same_member_type_struct,
    b,
    same_member_type_struct_2,
    c
  ),
  same_member_type_struct_neq
);

static int concat(void)
{
  return 91;
}

#define CON con

#define CAT cat

#define STR ing

static void Init(rtems_task_argument arg)
{
  void *p;
  int   v;

  TEST_BEGIN();
  rtems_test_assert(inline_func() == 7);
  RTEMS_COMPILER_MEMORY_BARRIER();
  rtems_test_assert(noinline_func() == 14);
  rtems_test_assert(pure_func() == 21);
  rtems_test_assert(const_func() == 23);
  rtems_test_assert(section_variable == 28);
  v = noinit_variable;
  RTEMS_OBFUSCATE_VARIABLE(v);
  rtems_test_assert(unused_arg_and_variable_func(49) == 42);
  rtems_test_assert(sizeof(packed_struct) == 5);
  rtems_test_assert(alias_func() == 14);
  rtems_test_assert(weak_alias_func() == 14);
  pull_in_strong();
  rtems_test_assert(weak_or_strong() == 77);
  rtems_test_assert(weak_2() == 111);
  rtems_test_assert(((uintptr_t) &aligned_variable) % 64 == 0);
  rtems_test_assert(offsetof(aligned_member_struct, aligned_member) % 64 == 0);
  unreachable();
  rtems_test_assert(printflike_func("%i", 0) == 56);
  rtems_test_assert(obfuscate_variable(63) == 63);
  rtems_test_assert((uintptr_t)a_global_symbol == 0xabc);
  rtems_test_assert(RTEMS_ARRAY_SIZE(array) == 3);
  rtems_test_assert(sizeof(zero_length_array_struct) == 4);
  container_of();
  rtems_test_assert(deconst() == 70);
  rtems_test_assert(devolatile() == 77);
  rtems_test_assert(dequalify() == 84);
  rtems_test_assert(
    RTEMS_HAVE_MEMBER_SAME_TYPE(
      same_member_type_struct,
      b,
      same_member_type_struct_2,
      d
    )
  );
  rtems_test_assert(
    !RTEMS_HAVE_MEMBER_SAME_TYPE(
      same_member_type_struct,
      b,
      same_member_type_struct_2,
      c
    )
  );
  rtems_test_assert(RTEMS_CONCAT(con, cat)() == 91);
  rtems_test_assert(RTEMS_XCONCAT(CON, CAT)() == 91);
  rtems_test_assert(strcmp(RTEMS_STRING(str), "str") == 0);
  rtems_test_assert(strcmp(RTEMS_XSTRING(STR), "ing") == 0);

  if (RTEMS_PREDICT_TRUE(true)) {
    rtems_test_assert(true);
  } else {
    rtems_test_assert(false);
  }

  if (RTEMS_PREDICT_FALSE(true)) {
    rtems_test_assert(true);
  } else {
    rtems_test_assert(false);
  }

  if (RTEMS_PREDICT_TRUE(false)) {
    rtems_test_assert(false);
  } else {
    rtems_test_assert(true);
  }

  if (RTEMS_PREDICT_FALSE(false)) {
    rtems_test_assert(false);
  } else {
    rtems_test_assert(true);
  }

  p = RTEMS_RETURN_ADDRESS();
  (void) p;

  TEST_END();
  rtems_test_exit(0);
}

#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER

#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER

#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>