test: Prevent test paths from entering the hex file
Use IAR and gcc compiler options to prevent test repository paths from
entering the final hex file.
When building TF-M you get the same result no matter what computer you
build from assuming all the tooling is the same version. The builds
are reproducible in other words. But when building TF-M together with
the tests, e.g. by building the regression test suite you will get a
different binary depending on where in the filesystem the tf-m-tests
repository has been installed.
This is because the TEST_FAIL macro uses the gcc macro _FILE_ which
injects the absolute paths of source files into strings in the binary.
This is a big problem for people using CI systems as a different sized
binary can affect race conditions, flash region usage overflows, etc..
This patch makes builds reproducible.
The simplest solution is to remove __FILE__ from the TEST_FAIL
macro,but this would remove useful information and may also fail in
the future if someone else uses __FILE__.
Using compiler options is the norm for solving this problem. For
instance use a compiler option to replace
"C:/repos/tf-m-tests/source_file.c" with
"TFM_TESTS/source_file.c". For gcc the flag is
-fmacro-prefix-map=<old_string>=<new_string>. For IAR it can remove
all paths from __FILE__ expansions.
For armclang there is no support yet as far as I can tell (2022).
Change-Id: I434c7ac358237c72ea3c8f542e7c45783567a4f1
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
diff --git a/toolchain_IARARM.cmake b/toolchain_IARARM.cmake
index 27f2bf4..67d97e3 100644
--- a/toolchain_IARARM.cmake
+++ b/toolchain_IARARM.cmake
@@ -49,6 +49,7 @@
$<$<COMPILE_LANGUAGE:C,CXX>:-DNO_TYPEOF>
$<$<COMPILE_LANGUAGE:C,CXX>:-D_NO_DEFINITIONS_IN_HEADER_FILES>
$<$<COMPILE_LANGUAGE:C,CXX>:--diag_suppress=Pe546,Pe940,Pa082,Pa084>
+ $<$<COMPILE_LANGUAGE:C,CXX>:--no_path_in_file_macros>
$<$<COMPILE_LANGUAGE:C,CXX,ASM>:--fpu=none>
$<$<AND:$<COMPILE_LANGUAGE:C,CXX,ASM>,$<BOOL:${TFM_DEBUG_SYMBOLS}>,$<CONFIG:Release,MinSizeRel>>:-r>
)