Changeset ebc5cfd in rtems for testsuites


Ignore:
Timestamp:
06/18/18 05:06:01 (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5, master
Children:
718a84af
Parents:
fe46647e
git-author:
Sebastian Huber <sebastian.huber@…> (06/18/18 05:06:01)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/21/18 09:27:29)
Message:

spmisc01: Add test cases for basedefs.h stuff

Location:
testsuites/sptests/spmisc01
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • testsuites/sptests/spmisc01/init.c

    rfe46647e rebc5cfd  
    1818
    1919#include <rtems.h>
     20#include <string.h>
    2021
    2122#include <tmacros.h>
     
    2324const char rtems_test_name[] = "SPMISC 1";
    2425
     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
    2593RTEMS_DECLARE_GLOBAL_SYMBOL(a_global_symbol);
    2694
    2795RTEMS_DEFINE_GLOBAL_SYMBOL(a_global_symbol, 0xabc);
    2896
     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
    29188static void Init(rtems_task_argument arg)
    30189{
    31190  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);
    32205  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);
    33232  TEST_END();
    34233  rtems_test_exit(0);
Note: See TracChangeset for help on using the changeset viewer.