Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:47

0001 /*
0002  * Copyright (C) 2015, 2016 embedded brains GmbH & Co. KG
0003  *
0004  * The license and distribution terms for this file may be
0005  * found in the file LICENSE in this distribution or at
0006  * http://www.rtems.com/license/LICENSE.
0007  */
0008 
0009 #ifdef HAVE_CONFIG_H
0010 #include "config.h"
0011 #endif
0012 
0013 #include "tmacros.h"
0014 
0015 #include "splinkersets01.h"
0016 
0017 const char rtems_test_name[] = "SPLINKERSETS 1";
0018 
0019 RTEMS_LINKER_RWSET(test_rw_i, const int *);
0020 
0021 RTEMS_LINKER_ROSET(test_ro_i, const int *);
0022 
0023 RTEMS_LINKER_RWSET_DECLARE(test_rw_i, const int *);
0024 
0025 RTEMS_LINKER_ROSET_DECLARE(test_ro_i, const int *);
0026 
0027 const int a[4];
0028 
0029 const int ca[5];
0030 
0031 RTEMS_LINKER_RWSET_ITEM(test_rw, const int *, a3) = &a[3];
0032 RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw, const int *, a2, 2) = &a[2];
0033 RTEMS_LINKER_RWSET_ITEM_REFERENCE(test_rw, const int *, a1);
0034 RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw, const int *, a0, 0) = &a[0];
0035 
0036 /* Items are ordered lexicographically */
0037 RTEMS_LINKER_RWSET_ITEM(test_rw_i, const int *, a3) = &a[3];
0038 RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw_i, const int *, a2, 2) = &a[2];
0039 RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw_i, const int *, a1, 11) = &a[1];
0040 RTEMS_LINKER_RWSET_ITEM_ORDERED(test_rw_i, const int *, a0, 0) = &a[0];
0041 
0042 #define OZ OA
0043 
0044 RTEMS_LINKER_ROSET_ITEM(test_ro, const int *, ca4) = &ca[4];
0045 RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro, const int *, ca3, OD) = &ca[3];
0046 RTEMS_LINKER_ROSET_ITEM_REFERENCE(test_ro, const int *, ca2);
0047 RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro, const int *, ca1, OB) = &ca[1];
0048 RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro, const int *, ca0, OZ) = &ca[0];
0049 
0050 RTEMS_LINKER_ROSET_ITEM(test_ro_i, const int *, ca4) = &ca[4];
0051 RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca3, OD) = &ca[3];
0052 RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca2, OC) = &ca[2];
0053 RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca1, OB) = &ca[1];
0054 RTEMS_LINKER_ROSET_ITEM_ORDERED(test_ro_i, const int *, ca0, OZ) = &ca[0];
0055 
0056 /*
0057  * Demonstrate safe (= define must exist) order definitions, otherwise typos
0058  * are undetected and may lead to an unpredictable order.  See also above OB
0059  * vs. OZ.
0060  */
0061 
0062 #define SAFE_ORDER_A 00000
0063 #define SAFE_ORDER_B 00001
0064 #define SAFE_ORDER_C 00002
0065 
0066 #define ITEM(i, o) \
0067   enum { test_ro_s_##i = o - o }; \
0068   RTEMS_LINKER_RWSET_ITEM_ORDERED(test_ro_s, const int *, i, o) = &i
0069 
0070 RTEMS_LINKER_RWSET(test_ro_s, const int *);
0071 
0072 static const int s0;
0073 static const int s1;
0074 static const int s2;
0075 
0076 ITEM(s2, SAFE_ORDER_C);
0077 ITEM(s1, SAFE_ORDER_B);
0078 ITEM(s0, SAFE_ORDER_A);
0079 
0080 RTEMS_LINKER_RWSET(test_rw_empty, const int *);
0081 
0082 RTEMS_LINKER_ROSET(test_ro_empty, const int *);
0083 
0084 static void test(void)
0085 {
0086   const int **b;
0087   const int **e;
0088   const int * const *cb;
0089   const int * const *ce;
0090   const int **bi;
0091   const int **ei;
0092   const int * const *cbi;
0093   const int * const *cei;
0094   const int * const *sb;
0095   const int * const *se;
0096   size_t i;
0097   const int **item;
0098 
0099   b = RTEMS_LINKER_SET_BEGIN(test_rw);
0100   e = RTEMS_LINKER_SET_END(test_rw);
0101   cb = RTEMS_LINKER_SET_BEGIN(test_ro);
0102   ce = RTEMS_LINKER_SET_END(test_ro);
0103   bi = RTEMS_LINKER_SET_BEGIN(test_rw_i);
0104   ei = RTEMS_LINKER_SET_END(test_rw_i);
0105   cbi = RTEMS_LINKER_SET_BEGIN(test_ro_i);
0106   cei = RTEMS_LINKER_SET_END(test_ro_i);
0107   sb = RTEMS_LINKER_SET_BEGIN(test_ro_s);
0108   se = RTEMS_LINKER_SET_END(test_ro_s);
0109   RTEMS_OBFUSCATE_VARIABLE(b);
0110   RTEMS_OBFUSCATE_VARIABLE(e);
0111   RTEMS_OBFUSCATE_VARIABLE(cb);
0112   RTEMS_OBFUSCATE_VARIABLE(ce);
0113   RTEMS_OBFUSCATE_VARIABLE(bi);
0114   RTEMS_OBFUSCATE_VARIABLE(ei);
0115   RTEMS_OBFUSCATE_VARIABLE(cbi);
0116   RTEMS_OBFUSCATE_VARIABLE(cei);
0117   RTEMS_OBFUSCATE_VARIABLE(sb);
0118   RTEMS_OBFUSCATE_VARIABLE(se);
0119 
0120   rtems_test_assert((size_t) (e - b) == RTEMS_ARRAY_SIZE(a));
0121   rtems_test_assert((size_t) (ce - cb) == RTEMS_ARRAY_SIZE(ca));
0122   rtems_test_assert(
0123     RTEMS_LINKER_SET_SIZE(test_rw)
0124       == sizeof(const int *) * RTEMS_ARRAY_SIZE(a)
0125   );
0126   rtems_test_assert(
0127     RTEMS_LINKER_SET_SIZE(test_ro)
0128       == sizeof(const int *) * RTEMS_ARRAY_SIZE(ca)
0129   );
0130   rtems_test_assert(
0131     RTEMS_LINKER_SET_ITEM_COUNT(test_rw) == RTEMS_ARRAY_SIZE(a)
0132   );
0133   rtems_test_assert(
0134     RTEMS_LINKER_SET_ITEM_COUNT(test_ro) == RTEMS_ARRAY_SIZE(ca)
0135   );
0136   rtems_test_assert(!RTEMS_LINKER_SET_IS_EMPTY(test_rw));
0137   rtems_test_assert(!RTEMS_LINKER_SET_IS_EMPTY(test_ro));
0138 
0139   rtems_test_assert((size_t) (ei - bi) == RTEMS_ARRAY_SIZE(a));
0140   rtems_test_assert((size_t) (cei - cbi) == RTEMS_ARRAY_SIZE(ca));
0141   rtems_test_assert((size_t) (se - sb) == 3);
0142   rtems_test_assert(
0143     RTEMS_LINKER_SET_SIZE(test_rw_i)
0144       == sizeof(const int *) * RTEMS_ARRAY_SIZE(a)
0145   );
0146   rtems_test_assert(
0147     RTEMS_LINKER_SET_SIZE(test_ro_i)
0148       == sizeof(const int *) * RTEMS_ARRAY_SIZE(ca)
0149   );
0150   rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_ro_s) == 3 * sizeof(int *));
0151   rtems_test_assert(
0152     RTEMS_LINKER_SET_ITEM_COUNT(test_rw_i) == RTEMS_ARRAY_SIZE(a)
0153   );
0154   rtems_test_assert(
0155     RTEMS_LINKER_SET_ITEM_COUNT(test_ro_i) == RTEMS_ARRAY_SIZE(ca)
0156   );
0157   rtems_test_assert(RTEMS_LINKER_SET_ITEM_COUNT(test_ro_s) == 3);
0158   rtems_test_assert(!RTEMS_LINKER_SET_IS_EMPTY(test_rw_i));
0159   rtems_test_assert(!RTEMS_LINKER_SET_IS_EMPTY(test_ro_i));
0160   rtems_test_assert(!RTEMS_LINKER_SET_IS_EMPTY(test_ro_s));
0161 
0162   rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_rw_empty) == 0);
0163   rtems_test_assert(RTEMS_LINKER_SET_SIZE(test_ro_empty) == 0);
0164   rtems_test_assert(RTEMS_LINKER_SET_ITEM_COUNT(test_rw_empty) == 0);
0165   rtems_test_assert(RTEMS_LINKER_SET_ITEM_COUNT(test_ro_empty) == 0);
0166   rtems_test_assert(RTEMS_LINKER_SET_IS_EMPTY(test_rw_empty));
0167   rtems_test_assert(RTEMS_LINKER_SET_IS_EMPTY(test_ro_empty));
0168 
0169   for (i = 0; i < RTEMS_ARRAY_SIZE(a); ++i) {
0170     rtems_test_assert(&a[i] == b[i]);
0171   }
0172 
0173   for (i = 0; i < RTEMS_ARRAY_SIZE(ca); ++i) {
0174     rtems_test_assert(&ca[i] == cb[i]);
0175   }
0176 
0177   for (i = 0; i < RTEMS_ARRAY_SIZE(a); ++i) {
0178     rtems_test_assert(&a[i] == bi[i]);
0179   }
0180 
0181   for (i = 0; i < RTEMS_ARRAY_SIZE(ca); ++i) {
0182     rtems_test_assert(&ca[i] == cbi[i]);
0183   }
0184 
0185   i = 0;
0186   RTEMS_LINKER_SET_FOREACH(test_rw, item) {
0187     rtems_test_assert(&a[i] == *item);
0188     ++i;
0189   }
0190   rtems_test_assert(i == RTEMS_ARRAY_SIZE(a));
0191 
0192   i = 0;
0193   RTEMS_LINKER_SET_FOREACH(test_ro, item) {
0194     rtems_test_assert(&ca[i] == *item);
0195     ++i;
0196   }
0197   rtems_test_assert(i == RTEMS_ARRAY_SIZE(ca));
0198 
0199   i = 0;
0200   RTEMS_LINKER_SET_FOREACH(test_rw_i, item) {
0201     rtems_test_assert(&a[i] == *item);
0202     ++i;
0203   }
0204   rtems_test_assert(i == RTEMS_ARRAY_SIZE(a));
0205 
0206   i = 0;
0207   RTEMS_LINKER_SET_FOREACH(test_ro_i, item) {
0208     rtems_test_assert(&ca[i] == *item);
0209     ++i;
0210   }
0211   rtems_test_assert(i == RTEMS_ARRAY_SIZE(ca));
0212 
0213   rtems_test_assert(&s0 == sb[0]);
0214   rtems_test_assert(&s1 == sb[1]);
0215   rtems_test_assert(&s2 == sb[2]);
0216 
0217   i = 0;
0218   RTEMS_LINKER_SET_FOREACH(test_rw_empty, item) {
0219     ++i;
0220   }
0221   rtems_test_assert(i == 0);
0222 
0223   i = 0;
0224   RTEMS_LINKER_SET_FOREACH(test_ro_empty, item) {
0225     ++i;
0226   }
0227   rtems_test_assert(i == 0);
0228 }
0229 
0230 static void test_content(void)
0231 {
0232   const char *b_rw;
0233   const char *e_rw;
0234   const char *b_ro;
0235   const char *e_ro;
0236 
0237   b_rw = RTEMS_LINKER_SET_BEGIN(test_content_rw);
0238   e_rw = RTEMS_LINKER_SET_END(test_content_rw);
0239   b_ro = RTEMS_LINKER_SET_BEGIN(test_content_ro);
0240   e_ro = RTEMS_LINKER_SET_END(test_content_ro);
0241   RTEMS_OBFUSCATE_VARIABLE(b_rw);
0242   RTEMS_OBFUSCATE_VARIABLE(e_rw);
0243   RTEMS_OBFUSCATE_VARIABLE(b_ro);
0244   RTEMS_OBFUSCATE_VARIABLE(e_ro);
0245 
0246   rtems_test_assert((uintptr_t) &content_rw_1 >= (uintptr_t) b_rw);
0247   rtems_test_assert((uintptr_t) &content_rw_2 >= (uintptr_t) b_rw);
0248   rtems_test_assert((uintptr_t) &content_rw_3 >= (uintptr_t) b_rw);
0249   rtems_test_assert((uintptr_t) &content_rw_1 <= (uintptr_t) e_rw);
0250   rtems_test_assert((uintptr_t) &content_rw_2 <= (uintptr_t) e_rw);
0251   rtems_test_assert((uintptr_t) &content_rw_3 <= (uintptr_t) e_rw);
0252 
0253   rtems_test_assert((uintptr_t) &content_ro_1 >= (uintptr_t) b_ro);
0254   rtems_test_assert((uintptr_t) &content_ro_2 >= (uintptr_t) b_ro);
0255   rtems_test_assert((uintptr_t) &content_ro_3 >= (uintptr_t) b_ro);
0256   rtems_test_assert((uintptr_t) &content_ro_1 <= (uintptr_t) e_ro);
0257   rtems_test_assert((uintptr_t) &content_ro_2 <= (uintptr_t) e_ro);
0258   rtems_test_assert((uintptr_t) &content_ro_3 <= (uintptr_t) e_ro);
0259 }
0260 
0261 static void Init(rtems_task_argument arg)
0262 {
0263   TEST_BEGIN();
0264 
0265   test();
0266   test_content();
0267 
0268   TEST_END();
0269   rtems_test_exit(0);
0270 }
0271 
0272 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0273 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0274 
0275 #define CONFIGURE_MAXIMUM_TASKS 1
0276 
0277 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0278 
0279 #define CONFIGURE_INIT
0280 
0281 #include <rtems/confdefs.h>