From bbb1fbe0e3d3596afd0b7be98716743f023228d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= <gaetan.harter@fu-berlin.de>
Date: Mon, 16 Jul 2018 08:54:01 +0200
Subject: [PATCH] cortexm_common_ldscript: add a test that checks if ROM_LEN is
 used

Trigger an overflow by 1 byte to detect in ROM_LEN is indeed used.
---
 tests/cortexm_common_ldscript/Makefile | 37 ++++++++++++++++++++++++++
 tests/cortexm_common_ldscript/main.c   | 25 +++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 tests/cortexm_common_ldscript/Makefile
 create mode 100644 tests/cortexm_common_ldscript/main.c

diff --git a/tests/cortexm_common_ldscript/Makefile b/tests/cortexm_common_ldscript/Makefile
new file mode 100644
index 0000000000..e4a7c7c9f4
--- /dev/null
+++ b/tests/cortexm_common_ldscript/Makefile
@@ -0,0 +1,37 @@
+BOARD ?= samr21-xpro
+include ../Makefile.tests_common
+
+
+# Normally all boards using `cortexm_common/ldscripts/cortexm.ld` linkerscript
+# Only tested on these ones for the moment
+BOARD_WHITELIST += iotlab-a8-m3
+BOARD_WHITELIST += iotlab-m3
+BOARD_WHITELIST += samr21-xpro
+
+include $(RIOTBASE)/Makefile.include
+
+
+# # # # # # # # # # # # # # # # # # #
+# Compile time tests for ROM_OFFSET #
+# # # # # # # # # # # # # # # # # # #
+
+COMPILE_TESTS = test-elffile-overflow
+
+all: compile-tests
+
+compile-tests: $(COMPILE_TESTS)
+.PHONY: compile-tests $(COMPILE_TESTS)
+
+
+# test-elffile-overflow depends on $(BINFILE) to prevent:
+# * ROM_LEN to be passed to $(ELFFILE) generation
+# * dummy error message of wc not finding the .bin file (ELFFILE is not enough)
+test-elffile-overflow: $(BINFILE) _test-elffile-overflow-runtest
+
+.PHONY: _test-elffile-overflow-runtest
+_test-elffile-overflow-runtest: ROM_LEN=$(firstword $(shell wc -c $(BINFILE)))-1+$(if $(ROM_OFFSET),$(ROM_OFFSET),0)
+_test-elffile-overflow-runtest: $(BINFILE)
+	$(Q)echo -n "Test rom offset 1 byte overflow detection: "
+	$(Q)\
+	{ $(_LINK) -o /dev/null  2>&1 | grep -q "region \`rom' overflowed by 1 byte" ; } \
+	  && echo [OK] || { echo [ERROR] Compilation should have failed >&2; exit 1; }
diff --git a/tests/cortexm_common_ldscript/main.c b/tests/cortexm_common_ldscript/main.c
new file mode 100644
index 0000000000..59d2d4dcce
--- /dev/null
+++ b/tests/cortexm_common_ldscript/main.c
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2018 Freie Universität Berlin
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser General
+ * Public License v2.1. See the file LICENSE in the top level directory for more
+ * details.
+ */
+
+/**
+ * @ingroup     tests
+ * @{
+ *
+ * @file
+ * @brief       Empty main file
+ *
+ * @author      Gaëtan Harter <gaetan.harter@fu-berlin.de>
+ *
+ * @}
+ */
+
+int main(void)
+{
+    /* The important rules are in the Makefile */
+    return 0;
+}
-- 
GitLab