tests: Improve RTEMS_DEFINE_GLOBAL_SYMBOL() tests

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

Update #4953.
This commit is contained in:
Sebastian Huber
2023-09-13 07:45:35 +02:00
parent 0add2d2edc
commit d7a6e80398
2 changed files with 24 additions and 5 deletions
+9 -2
View File
@@ -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();
+15 -3
View File
@@ -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
);
}
/**