File indexing completed on 2025-05-11 08:24:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031
0032 #include <rtems.h>
0033 #include <string.h>
0034
0035 #include <tmacros.h>
0036
0037 #include "spmisc01.h"
0038
0039 const char rtems_test_name[] = "SPMISC 1";
0040
0041 RTEMS_INLINE_ROUTINE int inline_func(void)
0042 {
0043 return 7;
0044 }
0045
0046 RTEMS_NO_INLINE static int noinline_func(void)
0047 {
0048 return 14;
0049 }
0050
0051 RTEMS_NO_RETURN void noreturn_func(void);
0052
0053 RTEMS_PURE static int pure_func(void)
0054 {
0055 return 21;
0056 }
0057
0058 RTEMS_CONST static int const_func(void)
0059 {
0060 return 23;
0061 }
0062
0063 RTEMS_SECTION(".rtemsroset.test") static int section_variable = 28;
0064
0065 RTEMS_NOINIT static int noinit_variable;
0066
0067 RTEMS_USED static int used_func(void)
0068 {
0069 return 35;
0070 }
0071
0072 RTEMS_USED static int used_variable;
0073
0074 static int unused_arg_and_variable_func(RTEMS_UNUSED int arg)
0075 {
0076 RTEMS_UNUSED int variable;
0077
0078 return 42;
0079 }
0080
0081 typedef struct {
0082 uint8_t c;
0083 uint32_t i;
0084 } RTEMS_PACKED packed_struct;
0085
0086 static int alias_func(void) RTEMS_ALIAS(noinline_func);
0087
0088 int weak_alias_func(void) RTEMS_WEAK_ALIAS(noinline_func);
0089
0090 RTEMS_WEAK int weak_or_strong(void)
0091 {
0092 return 99;
0093 }
0094
0095 RTEMS_WEAK int weak_2(void)
0096 {
0097 return 111;
0098 }
0099
0100 static char aligned_variable RTEMS_ALIGNED(64);
0101
0102 typedef struct {
0103 uint8_t c;
0104 uint8_t aligned_member RTEMS_ALIGNED(64);
0105 } aligned_member_struct;
0106
0107 static void unreachable(void)
0108 {
0109 if (0) {
0110 RTEMS_UNREACHABLE();
0111 }
0112 }
0113
0114 RTEMS_PRINTFLIKE(1, 2) static int printflike_func(const char *fmt, ...)
0115 {
0116 return 56;
0117 }
0118
0119 static int obfuscate_variable(int i)
0120 {
0121 RTEMS_OBFUSCATE_VARIABLE(i);
0122 return i;
0123 }
0124
0125 static int global_symbol_base;
0126
0127 RTEMS_DECLARE_GLOBAL_SYMBOL(a_global_symbol);
0128
0129 RTEMS_DEFINE_GLOBAL_SYMBOL(
0130 a_global_symbol,
0131 RTEMS_SYMBOL_NAME(global_symbol_base) + 0xabc
0132 );
0133
0134 RTEMS_STATIC_ASSERT(0 != 1, zero_neq_one);
0135
0136 static int array[3];
0137
0138 typedef struct {
0139 uint32_t i;
0140 uint32_t j[RTEMS_ZERO_LENGTH_ARRAY];
0141 } zero_length_array_struct;
0142
0143 typedef struct {
0144 int a;
0145 int b;
0146 } container_of_struct;
0147
0148 static void container_of(void)
0149 {
0150 container_of_struct s;
0151 int *b;
0152
0153 b = &s.b;
0154 rtems_test_assert(RTEMS_CONTAINER_OF(b, container_of_struct, b) == &s);
0155 }
0156
0157 static int deconst(void)
0158 {
0159 const int i = 70;
0160 int *p;
0161
0162 p = RTEMS_DECONST(int *, &i);
0163 return *p;
0164 }
0165
0166 static int devolatile(void)
0167 {
0168 volatile int i = 77;
0169 int *p;
0170
0171 p = RTEMS_DEVOLATILE(int *, &i);
0172 return *p;
0173 }
0174
0175 static int dequalify(void)
0176 {
0177 volatile const int i = 84;
0178 int *p;
0179
0180 p = RTEMS_DEQUALIFY(int *, &i);
0181 return *p;
0182 }
0183
0184 typedef struct {
0185 char a;
0186 int b;
0187 } same_member_type_struct;
0188
0189 typedef struct {
0190 char c;
0191 int d;
0192 } same_member_type_struct_2;
0193
0194 RTEMS_STATIC_ASSERT(
0195 RTEMS_HAVE_MEMBER_SAME_TYPE(
0196 same_member_type_struct,
0197 b,
0198 same_member_type_struct_2,
0199 d
0200 ),
0201 same_member_type_struct_eq
0202 );
0203
0204 RTEMS_STATIC_ASSERT(
0205 !RTEMS_HAVE_MEMBER_SAME_TYPE(
0206 same_member_type_struct,
0207 b,
0208 same_member_type_struct_2,
0209 c
0210 ),
0211 same_member_type_struct_neq
0212 );
0213
0214 static int concat(void)
0215 {
0216 return 91;
0217 }
0218
0219 #define CON con
0220
0221 #define CAT cat
0222
0223 #define STR ing
0224
0225 static void Init(rtems_task_argument arg)
0226 {
0227 void *p;
0228 int v;
0229
0230 TEST_BEGIN();
0231 rtems_test_assert(inline_func() == 7);
0232 RTEMS_COMPILER_MEMORY_BARRIER();
0233 rtems_test_assert(noinline_func() == 14);
0234 rtems_test_assert(pure_func() == 21);
0235 rtems_test_assert(const_func() == 23);
0236 rtems_test_assert(section_variable == 28);
0237 v = noinit_variable;
0238 RTEMS_OBFUSCATE_VARIABLE(v);
0239 rtems_test_assert(unused_arg_and_variable_func(49) == 42);
0240 rtems_test_assert(sizeof(packed_struct) == 5);
0241 rtems_test_assert(alias_func() == 14);
0242 rtems_test_assert(weak_alias_func() == 14);
0243 pull_in_strong();
0244 rtems_test_assert(weak_or_strong() == 77);
0245 rtems_test_assert(weak_2() == 111);
0246 rtems_test_assert(((uintptr_t) &aligned_variable) % 64 == 0);
0247 rtems_test_assert(offsetof(aligned_member_struct, aligned_member) % 64 == 0);
0248 unreachable();
0249 rtems_test_assert(printflike_func("%i", 0) == 56);
0250 rtems_test_assert(obfuscate_variable(63) == 63);
0251 rtems_test_assert(
0252 (uintptr_t) a_global_symbol - (uintptr_t) &global_symbol_base == 0xabc
0253 );
0254 rtems_test_assert(RTEMS_ARRAY_SIZE(array) == 3);
0255 rtems_test_assert(sizeof(zero_length_array_struct) == 4);
0256 container_of();
0257 rtems_test_assert(deconst() == 70);
0258 rtems_test_assert(devolatile() == 77);
0259 rtems_test_assert(dequalify() == 84);
0260 rtems_test_assert(
0261 RTEMS_HAVE_MEMBER_SAME_TYPE(
0262 same_member_type_struct,
0263 b,
0264 same_member_type_struct_2,
0265 d
0266 )
0267 );
0268 rtems_test_assert(
0269 !RTEMS_HAVE_MEMBER_SAME_TYPE(
0270 same_member_type_struct,
0271 b,
0272 same_member_type_struct_2,
0273 c
0274 )
0275 );
0276 rtems_test_assert(RTEMS_CONCAT(con, cat)() == 91);
0277 rtems_test_assert(RTEMS_XCONCAT(CON, CAT)() == 91);
0278 rtems_test_assert(strcmp(RTEMS_STRING(str), "str") == 0);
0279 rtems_test_assert(strcmp(RTEMS_XSTRING(STR), "ing") == 0);
0280
0281 if (RTEMS_PREDICT_TRUE(true)) {
0282 rtems_test_assert(true);
0283 } else {
0284 rtems_test_assert(false);
0285 }
0286
0287 if (RTEMS_PREDICT_FALSE(true)) {
0288 rtems_test_assert(true);
0289 } else {
0290 rtems_test_assert(false);
0291 }
0292
0293 if (RTEMS_PREDICT_TRUE(false)) {
0294 rtems_test_assert(false);
0295 } else {
0296 rtems_test_assert(true);
0297 }
0298
0299 if (RTEMS_PREDICT_FALSE(false)) {
0300 rtems_test_assert(false);
0301 } else {
0302 rtems_test_assert(true);
0303 }
0304
0305 p = RTEMS_RETURN_ADDRESS();
0306 (void) p;
0307
0308 TEST_END();
0309 rtems_test_exit(0);
0310 }
0311
0312 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0313
0314 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0315
0316 #define CONFIGURE_MAXIMUM_TASKS 1
0317
0318 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0319
0320 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0321
0322 #define CONFIGURE_INIT
0323
0324 #include <rtems/confdefs.h>