[PATCH 2/2] spmisc01: Add test cases for basedefs.h stuff
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Jun 18 12:42:06 UTC 2018
---
testsuites/sptests/spmisc01/init.c | 199 +++++++++++++++++++++++++++++++
testsuites/sptests/spmisc01/spmisc01.doc | 28 +++++
2 files changed, 227 insertions(+)
diff --git a/testsuites/sptests/spmisc01/init.c b/testsuites/sptests/spmisc01/init.c
index 4ff6365eeb..d6c6cbeab9 100644
--- a/testsuites/sptests/spmisc01/init.c
+++ b/testsuites/sptests/spmisc01/init.c
@@ -17,19 +17,218 @@
#endif
#include <rtems.h>
+#include <string.h>
#include <tmacros.h>
const char rtems_test_name[] = "SPMISC 1";
+RTEMS_INLINE_ROUTINE int inline_func(void)
+{
+ return 123;
+}
+
+RTEMS_NO_INLINE static int noinline_func(void)
+{
+ return 456;
+}
+
+RTEMS_NO_RETURN void noreturn_func(void);
+
+RTEMS_PURE static int pure_func(void)
+{
+ return 789;
+}
+
+RTEMS_SECTION(".rtemsroset.test") static int section_variable = 101112;
+
+RTEMS_USED static int used_func(void)
+{
+ return 131415;
+}
+
+RTEMS_USED static int used_variable;
+
+static int unused_arg_and_variable_func(RTEMS_UNUSED int arg)
+{
+ RTEMS_UNUSED int variable;
+
+ return 161718;
+}
+
+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);
+
+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 222324;
+}
+
+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 = 282930;
+ int *p;
+
+ p = RTEMS_DECONST(int *, &i);
+ return *p;
+}
+
+static int devolatile(void)
+{
+ volatile int i = 313233;
+ int *p;
+
+ p = RTEMS_DEVOLATILE(int *, &i);
+ return *p;
+}
+
+static int dequalify(void)
+{
+ volatile const int i = 343536;
+ 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 373839;
+}
+
+#define CON con
+
+#define CAT cat
+
+#define STR ing
+
static void Init(rtems_task_argument arg)
{
TEST_BEGIN();
+ rtems_test_assert(inline_func() == 123);
+ RTEMS_COMPILER_MEMORY_BARRIER();
+ rtems_test_assert(noinline_func() == 456);
+ rtems_test_assert(pure_func() == 789);
+ rtems_test_assert(section_variable == 101112);
+ rtems_test_assert(unused_arg_and_variable_func(192021) == 161718);
+ rtems_test_assert(sizeof(packed_struct) == 5);
+ rtems_test_assert(alias_func() == 456);
+ rtems_test_assert(weak_alias_func() == 456);
+ 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) == 222324);
+ rtems_test_assert(obfuscate_variable(252627) == 252627);
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() == 282930);
+ rtems_test_assert(devolatile() == 313233);
+ rtems_test_assert(dequalify() == 343536);
+ 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)() == 373839);
+ rtems_test_assert(RTEMS_XCONCAT(CON, CAT)() == 373839);
+ rtems_test_assert(strcmp(RTEMS_STRING(str), "str") == 0);
+ rtems_test_assert(strcmp(RTEMS_XSTRING(STR), "ing") == 0);
TEST_END();
rtems_test_exit(0);
}
diff --git a/testsuites/sptests/spmisc01/spmisc01.doc b/testsuites/sptests/spmisc01/spmisc01.doc
index 2654788f02..cad97b08bf 100644
--- a/testsuites/sptests/spmisc01/spmisc01.doc
+++ b/testsuites/sptests/spmisc01/spmisc01.doc
@@ -4,8 +4,36 @@ test set name: spbasedefs01
directives:
+ - RTEMS_ALIAS()
+ - RTEMS_ALIGNED()
+ - RTEMS_ARRAY_SIZE()
+ - RTEMS_COMPILER_MEMORY_BARRIER()
+ - RTEMS_CONCAT()
+ - RTEMS_CONTAINER_OF()
- RTEMS_DECLARE_GLOBAL_SYMBOL()
+ - RTEMS_DECONST()
- RTEMS_DEFINE_GLOBAL_SYMBOL()
+ - RTEMS_DEPRECATED
+ - RTEMS_DEQUALIFY()
+ - RTEMS_DEQUALIFY_DEPTHX()
+ - RTEMS_DEVOLATILE()
+ - RTEMS_HAVE_MEMBER_SAME_TYPE()
+ - RTEMS_NO_INLINE
+ - RTEMS_NO_RETURN
+ - RTEMS_OBFUSCATE_VARIABLE()
+ - RTEMS_PACKED
+ - RTEMS_PRINTFLIKE()
+ - RTEMS_PURE
+ - RTEMS_SECTION()
+ - RTEMS_STATIC_ASSERT()
+ - RTEMS_STRING()
+ - RTEMS_TYPEOF_REFX()
+ - RTEMS_UNREACHABLE()
+ - RTEMS_UNUSED
+ - RTEMS_USED
+ - RTEMS_WEAK_ALIAS()
+ - RTEMS_XCONCAT()
+ - RTEMS_XSTRING()
concepts:
--
2.13.7
More information about the devel
mailing list