source: rtems/testsuites/sptests/spmisc01/init.c @ ebc5cfd

5
Last change on this file since ebc5cfd was ebc5cfd, checked in by Sebastian Huber <sebastian.huber@…>, on 06/18/18 at 05:06:01

spmisc01: Add test cases for basedefs.h stuff

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