[PATCH 2/2] tests: Improve RTEMS_DEFINE_GLOBAL_SYMBOL() tests

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Sep 12 14:44:20 UTC 2023


Use a symbol value relative to an existing symbol address to make the
test work on more code models.

Update #4953.
---
 testsuites/sptests/spmisc01/init.c  | 11 +++++++++--
 testsuites/validation/tc-basedefs.c | 18 +++++++++++++++---
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/testsuites/sptests/spmisc01/init.c b/testsuites/sptests/spmisc01/init.c
index 62b2f69dbc..8c46245af9 100644
--- a/testsuites/sptests/spmisc01/init.c
+++ b/testsuites/sptests/spmisc01/init.c
@@ -122,9 +122,14 @@ static int obfuscate_variable(int i)
   return i;
 }
 
+static int global_symbol_base;
+
 RTEMS_DECLARE_GLOBAL_SYMBOL(a_global_symbol);
 
-RTEMS_DEFINE_GLOBAL_SYMBOL(a_global_symbol, 0xabc);
+RTEMS_DEFINE_GLOBAL_SYMBOL(
+  a_global_symbol,
+  RTEMS_SYMBOL_NAME(global_symbol_base) + 0xabc
+);
 
 RTEMS_STATIC_ASSERT(0 != 1, zero_neq_one);
 
@@ -243,7 +248,9 @@ static void Init(rtems_task_argument arg)
   unreachable();
   rtems_test_assert(printflike_func("%i", 0) == 56);
   rtems_test_assert(obfuscate_variable(63) == 63);
-  rtems_test_assert((uintptr_t)a_global_symbol == 0xabc);
+  rtems_test_assert(
+    (uintptr_t) a_global_symbol - (uintptr_t) &global_symbol_base == 0xabc
+  );
   rtems_test_assert(RTEMS_ARRAY_SIZE(array) == 3);
   rtems_test_assert(sizeof(zero_length_array_struct) == 4);
   container_of();
diff --git a/testsuites/validation/tc-basedefs.c b/testsuites/validation/tc-basedefs.c
index 94600f5241..28c11af505 100644
--- a/testsuites/validation/tc-basedefs.c
+++ b/testsuites/validation/tc-basedefs.c
@@ -527,8 +527,12 @@ RTEMS_COMPILER_PURE_ATTRIBUTE static int compiler_pure_attribute_func( void )
   return 21;
 }
 
+static int global_symbol_base;
+
 RTEMS_DEFINE_GLOBAL_SYMBOL(
-  GLOBAL_SYMBOL, GLOBAL_SYMBOL_VALULE( abc ) );
+  GLOBAL_SYMBOL,
+  RTEMS_SYMBOL_NAME( global_symbol_base ) + GLOBAL_SYMBOL_VALULE( abc )
+);
 
 static int deprecated_func( int i ) RTEMS_DEPRECATED;
 static int deprecated_func( int i )
@@ -1055,7 +1059,11 @@ static void RtemsBasedefsValBasedefs_Action_18( void )
    * which is defined in a file different from the file in which the gobal
    * symbol is defined.
    */
-  T_step_eq_int( 45, basedefs_get_global_symbol(), 0xabc );
+  T_step_eq_uptr(
+    45,
+    basedefs_get_global_symbol() - (uintptr_t) &global_symbol_base,
+    0xabc
+  );
 }
 
 /**
@@ -1089,7 +1097,11 @@ static void RtemsBasedefsValBasedefs_Action_20( void )
    * Check that the RTEMS_DEFINE_GLOBAL_SYMBOL() macro defines a global symbol
    * with the correct value.
    */
-  T_step_eq_int( 49, (uintptr_t) global_symbol, 0xabc );
+  T_step_eq_uptr(
+    49,
+    (uintptr_t) global_symbol - (uintptr_t) &global_symbol_base,
+    0xabc
+  );
 }
 
 /**
-- 
2.35.3



More information about the devel mailing list