Skip to content

Commit 047c5ea

Browse files
author
Felipe Torrezan
authored
Add tests (#16)
* Added CMake Modules testing scripts
1 parent 64d82d8 commit 047c5ea

8 files changed

Lines changed: 343 additions & 4 deletions

File tree

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
_builds
2-
hello-world
3-
Testing
4-
1+
_build*
2+
hello-world
3+
Testing
4+

tests/CMakeLists.txt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
set(TOOLKIT_DIR $ENV{TOOLKIT_DIR})
4+
set(CMAKE_GENERATOR "Ninja Multi-Config")
5+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
6+
list(APPEND CMAKE_CONFIGURATION_TYPES Debug Release RelWithDebInfo MinSizeRel)
7+
8+
project(IAR-test LANGUAGES C CXX ASM)
9+
10+
set(LINKER_MAP --map $<CONFIG>/$<TARGET_PROPERTY:NAME>.map)
11+
12+
# arch-specific
13+
if(TARGET_ARCH STREQUAL arm)
14+
set(LINKER_OPTS "SHELL:--config ${TOOLKIT_DIR}/config/generic.icf")
15+
elseif(TARGET_ARCH STREQUAL avr)
16+
set(ICC_OPTS -v3 --enhanced_core -ms)
17+
set(ASM_OPTS -D__IASMAVR__)
18+
set(LINKER_OPTS -f ${TOOLKIT_DIR}/src/template/lnk3s.xcl -rt -s __program_start ${TOOLKIT_DIR}/lib/dlib/dlAVR-3s-ec_mul-n.r90)
19+
set(LINKER_MAP -l $<CONFIG>/$<TARGET_PROPERTY:NAME>.map)
20+
elseif(TARGET_ARCH STREQUAL 430)
21+
set(ASM_OPTS -D__IASM430__)
22+
set(LINKER_OPTS -D_STACK_SIZE=0x40 -D_DATA16_HEAP_SIZE=0x40 -D_DATA20_HEAP_SIZE=0x40)
23+
set(LINKER_OPTS ${LINKER_OPTS} "SHELL:-f ${TOOLKIT_DIR}/config/linker/lnk430f149.xcl -f ${TOOLKIT_DIR}/config/linker/multiplier.xcl")
24+
set(LINKER_OPTS ${LINKER_OPTS} -s __program_start -rt ${TOOLKIT_DIR}/lib/dlib/dl430fn.r43)
25+
set(LINKER_MAP -l $<CONFIG>/$<TARGET_PROPERTY:NAME>.map)
26+
elseif(TARGET_ARCH STREQUAL 8051)
27+
set(ASM_OPTS -D__IASM8051__ -D__CORE__=1 -D__CODE_MODEL=1 -D__DATA_MODEL__=1 -D__CALLING_CONVENTION__=2)
28+
set(ICC_OPTS --core=plain --dptr=16,1 --data_model=large --code_model=near)
29+
set(ICC_OPTS ${ICC_OPTS} --calling_convention=xdata_reentrant --place_constants=data --nr_virtual_regs 8)
30+
set(ICC_OPTS ${ICC_OPTS} --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl8051Normal.h)
31+
set(LINKER_OPTS -f ${TOOLKIT_DIR}/config/devices/_generic/lnk51ew_8052.xcl -rt -s __program_start ${TOOLKIT_DIR}/lib/dlib/dl-pli-nlxd-1e16x01n.r51)
32+
set(LINKER_OPTS ${LINKER_OPTS} -D_NR_OF_VIRTUAL_REGISTERS=8 -D?PBANK=0xA0 -D?CBANK=0xF0 )
33+
set(LINKER_OPTS ${LINKER_OPTS} -D?CBANK_MASK=0x30 -e?BCALL_30=?BCALL -e?BRET_30=?BRET -e?BDISPATCH_30=?BDISPATCH -D_CODEBANK_START=0x8000 )
34+
set(LINKER_OPTS ${LINKER_OPTS} -D_CODEBANK_END=0xFFFF -D_NR_OF_BANKS=0x03 )
35+
set(LINKER_OPTS ${LINKER_OPTS} -D_IDATA_STACK_SIZE=0x40 -D?ESP=0 -D?ESP_MASK=0 -D_EXTENDED_STACK_START=0 -D_EXTENDED_STACK_SIZE=0 )
36+
set(LINKER_OPTS ${LINKER_OPTS} -D_PDATA_STACK_SIZE=0x80 -D_XDATA_STACK_SIZE=0xEFF -D_XDATA_HEAP_SIZE=0xFF -D_FAR_HEAP_SIZE=0xFFF )
37+
set(LINKER_OPTS ${LINKER_OPTS} -D_HUGE_HEAP_SIZE=0xFFF -D_FAR22_HEAP_SIZE=0xFFF )
38+
set(LINKER_MAP -l $<CONFIG>/$<TARGET_PROPERTY:NAME>.map)
39+
elseif(TARGET_ARCH MATCHES "(riscv|rx)")
40+
set(LINKER_OPTS "SHELL:--config_def CSTACK_SIZE=0x1000 --config_def HEAP_SIZE=0x1000 --debug_lib")
41+
elseif(TARGET_ARCH STREQUAL rh850)
42+
set(LINKER_OPTS "SHELL:--config_def CSTACK_SIZE=0x1000 --config_def HEAP_SIZE=0x1000 --config_def _SELF_SIZE=0x20000
43+
--config ${TOOLKIT_DIR}/config/lnkr7f701401.icf")
44+
elseif(TARGET_ARCH STREQUAL rl78)
45+
set(LINKER_OPTS "SHELL:--config_def _STACK_SIZE=256 --config_def _NEAR_HEAP_SIZE=0x400 --config_def
46+
_FAR_HEAP_SIZE=4096 --config_def _HUGE_HEAP_SIZE=0 --config_def _NEAR_CONST_LOCATION_START=0x2000 --config_def
47+
_NEAR_CONST_LOCATION_SIZE=0x6F00 --define_symbol _NEAR_CONST_LOCATION=0 --debug_lib --config ${TOOLKIT_DIR}/config/lnkrl78_s3.icf")
48+
elseif(TARGET_ARCH STREQUAL rx)
49+
set(LINKER_OPTS "SHELL:--config_def _USTACK_SIZE=0x1000 --config_def _ISTACK_SIZE=0x1000 _HEAP_SIZE=0x1000 --debug_lib")
50+
elseif(TARGET_ARCH STREQUAL stm8)
51+
set(LINKER_OPTS "SHELL:--config_def _CSTACK_SIZE=0x100 --config_def _HEAP_SIZE=0x100")
52+
endif()
53+
54+
# Test the IAR C Compiler
55+
add_executable(test-c)
56+
target_sources(test-c PRIVATE module.c)
57+
target_compile_options(test-c PRIVATE $<$<CONFIG:Debug>:-Ol> -e ${ICC_OPTS})
58+
target_compile_definitions(test-c PRIVATE CSYMBOL=32)
59+
target_link_options(test-c PRIVATE
60+
${LINKER_MAP}
61+
${LINKER_OPTS}
62+
)
63+
64+
# Test the IAR C++ Compiler
65+
add_executable(test-cxx)
66+
target_sources(test-cxx PRIVATE module.cxx)
67+
target_compile_options(test-cxx PRIVATE $<$<CONFIG:Debug>:-Om> -e ${ICC_OPTS})
68+
target_compile_definitions(test-cxx PRIVATE CXXSYM=64)
69+
target_link_options(test-cxx PRIVATE
70+
${LINKER_MAP}
71+
${LINKER_OPTS}
72+
)
73+
74+
# Test the IAR Assembler
75+
add_executable(test-asm)
76+
target_sources(test-asm PRIVATE module.asm)
77+
target_compile_definitions(test-asm PRIVATE ASMSYM=16 ${ASM_OPTS})
78+
target_link_options(test-asm PRIVATE
79+
${LINKER_MAP}
80+
${LINKER_OPTS}
81+
)
82+

tests/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Tests for the IAR toolchains on CMake
2+
The tests in this directory are for the CMake Modules for the IAR Toolchains (e.g., `/path/to/share/cmake-x.xx/Modules/Compiler/IAR-*.cmake`).
3+
4+
The `run-tests.sh` script will...
5+
- build one executable for each supported language (`C`, `CXX` and `ASM`) using...
6+
- the the default CMake build configurations (`Debug`, `Release`, `DebWithRelInfo` and `MinSizeRel`).
7+
8+
## Environment
9+
The following GNU Bash environments were used:
10+
- MINGW64 (e.g., https://gitforwindows.org)
11+
- WSL2 (IAR Build Tools for Linux)
12+
13+
## Instructions
14+
- Export the `$IAR_TOOL_ROOT` environment variable.
15+
```bash
16+
export IAR_TOOL_ROOT=/path/to/IAR/tools/top/level
17+
```
18+
> __Note__ Make `$IAR_TOOL_ROOT` point to the top-level location in which all the IAR toolchains are installed.
19+
20+
| Examples | Effect |
21+
| :---------------------------- | :-------------------------------------------------------------------- |
22+
| `/c/IAR_Systems` | Perform tests on all toolchains found on the top-level directory. |
23+
| `/c/IAR_Systems/EW/ARM` | Perform tests only using the toolchains found in the `ARM` directory. |
24+
| `/c/IAR_Systems/EW/ARM/[7-9]*` | Perform tests on "Embedded Workbench for Arm" from V7 to V9. |
25+
| `/c/IAR_Systems/EW/ARM/9.30.1` | Perform tests only using "Embedded Workbench 9.30.1". |
26+
27+
> __Note__ Optionally export `IAR_LMS2_SERVER_IP` if client's 1st-time license setup is required. (Applies to `-GL` and `-NW`).
28+
29+
- Execute `run-tests.sh`.

tests/module.asm

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#if defined(__IASM8051__) || defined(__IASM430__)
2+
NAME main
3+
#else
4+
MODULE main
5+
#endif
6+
7+
PUBLIC main
8+
PUBLIC __iar_program_start
9+
PUBLIC __program_start
10+
11+
#if defined(__IASMSTM8__)
12+
EXTERN CSTACK$$Limit
13+
SECTION `.near_func.text`:CODE:NOROOT(0)
14+
#elif defined(__IASMAVR__)
15+
ORG $0
16+
RJMP main
17+
RSEG CODE
18+
#elif defined(__IASM8051__)
19+
ORG 0FFFEh
20+
DC16 main
21+
RSEG RCODE
22+
?cmain:
23+
#elif defined(__IASM430__)
24+
ORG 0FFFEh
25+
DC16 init
26+
RSEG CSTACK
27+
RSEG CODE
28+
init:
29+
MOV #SFE(CSTACK), SP
30+
#else
31+
EXTERN __iar_static_base$$GPREL
32+
SECTION CSTACK:DATA:NOROOT(4)
33+
SECTION `.cstartup`:CODE(2)
34+
CODE
35+
#endif
36+
37+
__program_start:
38+
__iar_program_start:
39+
main:
40+
NOP
41+
END

tests/module.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "module.h"
2+
__root int i;
3+
__root int main() {
4+
i = INTERNAL;
5+
return i;
6+
}
7+

tests/module.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "module.h"
2+
__root int i;
3+
__root int main() {
4+
i = INTERNAL;
5+
return i;
6+
}
7+

tests/module.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef __MODULE_H__
2+
#define __MODULE_H__
3+
4+
#if defined(__cplusplus)
5+
#define INTERNAL CXXSYM
6+
#elif !defined(__cplusplus) && defined(__IAR_SYSTEMS_ICC__)
7+
#define INTERNAL CSYMBOL
8+
#elif defined(__IAR_SYSTEMS_ASM__)
9+
#define INTERNAL ASMSYM
10+
#else
11+
#error "Unable to determine INTERNAL symbol."
12+
#endif /* __IAR_SYSTEMS_ICC */
13+
14+
#endif /* __MODULE_H__ */

tests/run-tests.sh

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2022 IAR Systems AB
4+
#
5+
# Test CMake with the IAR Build Tools
6+
#
7+
# See LICENSE for detailed license information
8+
#
9+
10+
# Environment variables that can be set for this script
11+
# IAR_TOOL_ROOT
12+
# Top-level location in which the IAR toolchains are installed
13+
# MINGW64: with the full path (e.g.,) `/c/IAR_Systems/`
14+
# Default: /opt/iarsystems
15+
# IAR_LMS2_SERVER_IP
16+
# If defined, automatic license setup will be performed
17+
18+
BUILD_CFGS=(Debug RelWithDebInfo Release MinSizeRel)
19+
20+
if ! ((${#IAR_TOOL_ROOT[@]})); then
21+
IAR_TOOL_ROOT=/opt/iarsystems
22+
fi
23+
24+
if [ "$MSYSTEM" = "MINGW64" ]; then
25+
EXT=.exe;
26+
fi
27+
28+
function lms2-setup() {
29+
if [ ! -z $IAR_LMS2_SERVER_IP ]; then
30+
LLM=$(dirname ${p})/../../common/bin/LightLicenseManager;
31+
if [ -f $LLM ]; then
32+
HAS_SETUP=$(${LLM} | grep setup);
33+
if [ ! -z $HAS_SETUP ]; then
34+
SETUP_CMD=setup;
35+
else
36+
SETUP_CMD="";
37+
fi
38+
$LLM $SETUP_CMD -s $IAR_LMS2_SERVER_IP;
39+
fi
40+
fi
41+
}
42+
43+
44+
function find_icc() {
45+
if [ "$MSYSTEM" = "MINGW64" ]; then
46+
export CC=$(cygpath -m "${p}");
47+
export CXX=$CC;
48+
else
49+
export CC="${p}";
50+
export CXX="${p}";
51+
fi
52+
export TOOLKIT_DIR=$(dirname $(dirname $CC))
53+
echo "Using CC: $CC";
54+
echo "Using CXX: $CXX";
55+
}
56+
57+
function find_ilink() {
58+
if [ "$MSYSTEM" = "MINGW64" ]; then
59+
export ASM=$(cygpath -m $(dirname ${p})/iasm${a}${EXT});
60+
else
61+
export ASM=$(dirname ${p})/iasm${a};
62+
fi
63+
echo "Using ASM: $ASM";
64+
}
65+
66+
function find_xlink() {
67+
if [ "$MSYSTEM" = "MINGW64" ]; then
68+
export ASM=$(cygpath -m $(dirname ${p})/a${a}${EXT});
69+
else
70+
export ASM=$(dirname ${p})/a${a};
71+
fi
72+
echo "Using ASM_COMPILER: $ASM";
73+
}
74+
75+
function cmake_configure() {
76+
rm -rf _builds;
77+
if [ "$MSYSTEM" = "MINGW64" ]; then
78+
CMAKE_MAKE_PRG=$(cygpath -m $(which ninja));
79+
else
80+
CMAKE_MAKE_PRG=$(which ninja);
81+
fi
82+
if [ ! $CMAKE_MAKE_PRG ]; then
83+
echo "FATAL ERROR: Ninja not found.";
84+
exit 1;
85+
fi
86+
cmake -B _builds -G "Ninja Multi-Config" \
87+
-DCMAKE_MAKE_PROGRAM=$CMAKE_MAKE_PRG \
88+
-DTARGET_ARCH=${a} \
89+
-DTOOLKIT_DIR=${TOOLKIT_DIR};
90+
if [ $? -ne 0 ]; then
91+
echo "FAIL: CMake configuration phase.";
92+
exit 1;
93+
fi
94+
}
95+
96+
function check_output() {
97+
if [ -f _builds/${cfg}/test-c.${OUTPUT_FORMAT,,} ]; then
98+
echo "+${cfg}:C ${OUTPUT_FORMAT} built successfully.";
99+
else
100+
echo "-${cfg}:C ${OUTPUT_FORMAT} not built.";
101+
fi
102+
if [ -f _builds/${cfg}/test-cxx.${OUTPUT_FORMAT,,} ]; then
103+
echo "+${cfg}:CXX ${OUTPUT_FORMAT} built successfully.";
104+
else
105+
echo "-${cfg}:CXX ${OUTPUT_FORMAT} not built.";
106+
fi
107+
if [ -f _builds/${cfg}/test-asm.${OUTPUT_FORMAT,,} ]; then
108+
echo "+${cfg}:ASM ${OUTPUT_FORMAT} built successfully.";
109+
else
110+
echo "-${cfg}:ASM ${OUTPUT_FORMAT} not built.";
111+
fi
112+
}
113+
114+
function cmake_build() {
115+
for cfg in ${BUILD_CFGS[@]}; do
116+
echo "===== Build configuration: [${cfg}]";
117+
cmake --build _builds --config ${cfg} --verbose;
118+
if [ $? -ne 0 ]; then
119+
echo "FAIL: CMake building phase (${cfg}).";
120+
exit 1;
121+
fi
122+
check_output;
123+
done
124+
}
125+
126+
127+
echo "----------- ilink tools";
128+
ILINK_TOOL=(arm riscv rh850 rl78 rx stm8);
129+
OUTPUT_FORMAT=ELF;
130+
for r in ${IAR_TOOL_ROOT[@]}; do
131+
for a in ${ILINK_TOOL[@]}; do
132+
for b in $(find ${r} -path "*/${a}/bin"); do
133+
for p in $(find ${b} -executable -name icc${a}${EXT}); do
134+
find_icc;
135+
find_ilink;
136+
lms2-setup;
137+
cmake_configure;
138+
cmake_build;
139+
done
140+
done
141+
done
142+
done
143+
144+
echo "----------- xlink tools";
145+
XLINK_TOOL=(8051 430 avr);
146+
OUTPUT_FORMAT=BIN;
147+
for r in ${IAR_TOOL_ROOT[@]}; do
148+
for a in ${XLINK_TOOL[@]}; do
149+
for b in $(find ${r} -path "*/${a}/bin"); do
150+
for p in $(find ${b} -executable -name icc${a}${EXT}); do
151+
find_icc;
152+
find_xlink;
153+
lms2-setup;
154+
cmake_configure;
155+
cmake_build;
156+
done
157+
done
158+
done
159+
done

0 commit comments

Comments
 (0)