Skip to content

Commit d362b9d

Browse files
authored
Merge pull request #309 from Infineon/DESMAKERS-3803-new-hil-setup
Desmakers 3803 new hil setup
2 parents c60baba + c8d7be4 commit d362b9d

File tree

3 files changed

+293
-16
lines changed

3 files changed

+293
-16
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
name: Hil unity library checks
2+
3+
# on which event should we start push, pull request or schedule dispatches
4+
on:
5+
- push
6+
- pull_request
7+
8+
env:
9+
TEST_VERSION: 1.0.0
10+
11+
# This template runes multiple workflows
12+
jobs:
13+
14+
15+
#############################################################################
16+
# This action sets common variables for the flow and
17+
# identifies the libs to compile
18+
setup:
19+
20+
# we run this on self hosted runner, use labels to be more specific
21+
# add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones
22+
runs-on:
23+
- self-hosted
24+
- X64
25+
- Linux
26+
27+
steps:
28+
# checkout the latest github action code
29+
- name: Checkout actions
30+
uses: actions/checkout@v4
31+
32+
# checkout the latest arduino-cli compiler
33+
- name: Setup Arduino CLI
34+
uses: arduino/setup-arduino-cli@master
35+
36+
# Update the arduino code. Attention this does not setup XMC packages as this are set inside the self hosted runner
37+
# the arduino board support packages can be updated automatically
38+
# the XMC board support package is only linked inside the self hosted runner, which allows
39+
# to use none official and beta versions
40+
# arduino-cli core install "infineon:xmc"
41+
- name: Install/Update Arduino Platform
42+
run: |
43+
arduino-cli core update-index
44+
arduino-cli core install "arduino:avr"
45+
46+
# Fetch variables and move them to the GITHUB_OUTPUT and fetch HIL information
47+
- id: startup
48+
run: |
49+
# switch on the HIL
50+
cd /opt/runner_support/
51+
REPO="$(basename "$GITHUB_REPOSITORY")"
52+
./py_checkusb.py --switch repo --namelist $REPO --onoff on
53+
54+
# set the hil-unity-checks
55+
hil=$(./py_checkusb.py --readyaml $GITHUB_WORKSPACE/tests/Unity/hil-unity-checklist.yaml --json)
56+
echo "hil=${hil}" >> $GITHUB_OUTPUT
57+
58+
# fetch unity libraries
59+
readarray -t data < <(echo $hil | jq -r '.|keys[]')
60+
export dev=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${data[@]}")
61+
echo "devices=${dev}" >> $GITHUB_OUTPUT
62+
echo "devices=${dev}"
63+
64+
# Connect the GITHUB_OUTPUT to the variables and the workflow output mechanism
65+
outputs:
66+
hil: ${{ steps.startup.outputs.hil }}
67+
devices: ${{ steps.startup.outputs.devices }}
68+
69+
70+
#############################################################################
71+
# This step allows HIL (Hardware in the loop), therefore
72+
# is searches for the given board/sensor combination and tries to find the actual port
73+
# on the self hosted runner. (see documentation for the board2port finder)
74+
flash:
75+
76+
# We need a successful build before we can run the deploy
77+
needs: [setup]
78+
79+
# we run this on self hosted runner, use labels to be more specific
80+
# add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones
81+
runs-on:
82+
- self-hosted
83+
- X64
84+
- Linux
85+
86+
# do not stop if a single job fails
87+
continue-on-error: true
88+
89+
strategy:
90+
91+
# the code to flash
92+
matrix:
93+
# the serials of the hardware boards
94+
device: ${{ fromJson(needs.setup.outputs.devices) }}
95+
96+
# These are the steps which should run for each combination of fqbn and lib code
97+
steps:
98+
# checkout the latest github action code
99+
- name: Checkout actions
100+
uses: actions/checkout@v4
101+
102+
# setup environment
103+
- name: Environment
104+
run: |
105+
cd $HOME
106+
rm -rf ~/.arduino15/packages/Infineon/hardware/xmc/*
107+
ln -s $GITHUB_WORKSPACE ~/.arduino15/packages/Infineon/hardware/xmc/$TEST_VERSION
108+
109+
hil=${{ toJson(needs.setup.outputs.hil) }}
110+
REPO="$(basename "$GITHUB_REPOSITORY")"
111+
DEVICE="$(basename ${{ matrix.device }} )"
112+
LIBRARY=$(echo $hil | jq ".\"${DEVICE}\"" -r --compact-output)
113+
FQBN=`tr '.' ':' <<<"${DEVICE}"`
114+
115+
echo "repo=$REPO" >> $GITHUB_ENV
116+
echo "device=$DEVICE" >> $GITHUB_ENV
117+
echo "version=$TEST_VERSION" >> $GITHUB_ENV
118+
echo "library=$LIBRARY" >> $GITHUB_ENV
119+
echo "fqbn=$FQBN" >> $GITHUB_ENV
120+
121+
echo "Repo " $REPO
122+
echo "Device " $DEVICE
123+
echo "Library " $LIBRARY
124+
echo "FQBN " $FQBN
125+
echo "Version " ${TEST_VERSION}
126+
127+
# Build the test code with make and flash it to the board
128+
# runs via nested loops:
129+
# - first loop over the libraries mentioned for a device in the yaml file
130+
# - selects the serial ids and ports for all devices connected with this device and library
131+
# - second loop over the examples mentioned below the selected device for a library in the yaml file
132+
# - third loop over the tests mentioned below the selected example for a device and library in the yaml file
133+
# - fourth loop over the make commands mentioned below the selected test for a device, example and library in the yaml file
134+
135+
- name: Build
136+
run: |
137+
export TMPDIR=$HOME/tmp
138+
mkdir -p $TMPDIR
139+
rm -rf $HOME/artefact
140+
mkdir -p $HOME/artefact
141+
142+
lib=${{ toJson(env.library) }}
143+
readarray -t LIBS < <(echo ${lib} | jq ".|keys[]" -r --compact-output)
144+
145+
# loop over all libs in the unity test yaml
146+
for LIB in "${LIBS[@]}"; do
147+
cd /opt/runner_support/
148+
readarray -t SERIALS < <(echo $(./py_checkusb.py --type ${LIB} --json) | jq ".\"${LIB}\".\"${{ env.device }}\"|keys[]" -r)
149+
150+
# check if we have one or more serial numbers for this lib or stop here
151+
if [[ -z $SERIALS ]]; then
152+
echo "No serial or library information found"
153+
exit 0
154+
fi
155+
156+
# loop over all serials and fetch the ports
157+
declare -a PORTS
158+
for SERIAL in "${SERIALS[@]}"; do
159+
PORTS+=($(/opt/runner_support/find_usb.sh $SERIAL))
160+
done
161+
162+
# loop over all examples for one library
163+
readarray -t EXAMPLES < <(echo $lib | jq ".\"${LIB}\"|keys[]" -r --compact-output)
164+
for EXAMPLE in "${EXAMPLES[@]}"; do
165+
echo "=============================================================================================================="
166+
echo "Run for EXAMPLE: ${EXAMPLE} under LIB: ${LIB}"
167+
echo "=============================================================================================================="
168+
169+
# loop over all tests for one example and compile7flash the devices
170+
readarray -t TESTS < <(echo $lib | jq ".\"${LIB}\".\"${EXAMPLE}\"[]" -r --compact-output)
171+
for ((idx=0; idx<${#TESTS[@]}; ++idx)); do
172+
cd $GITHUB_WORKSPACE/tests/Unity/
173+
echo "=============================================================================================================="
174+
echo "Run on index $idx for TEST: ${TESTS[idx]} under EXAMPLE: ${EXAMPLE} and LIB: ${LIB}"
175+
echo "=============================================================================================================="
176+
make FQBN=${{ env.fqbn }} PORT=${PORTS[idx]} UNITY_PATH=/opt/runner_support/Unity_github ${TESTS[idx]}
177+
mkdir -p ~/artefact/${LIB}/${EXAMPLE}/${TESTS[idx]}/
178+
mv ./build/build/* ~/artefact/${LIB}/${EXAMPLE}/${TESTS[idx]}/.
179+
echo "=============================================================================================================="
180+
done # end of TEST loop flash
181+
182+
# loop over all tests for one example and monitor the serial output
183+
for ((idx=0; idx<${#TESTS[@]}; ++idx)); do
184+
echo "=============================================================================================================="
185+
echo "Monitor on index $idx for TEST: ${TESTS[idx]} under EXAMPLE: ${EXAMPLE} and LIB: ${LIB}"
186+
timeout 1m \
187+
/opt/runner_support/py_console.py \
188+
--port ${PORTS[idx]} \
189+
--baud 115200 \
190+
--report ~/artefact/${LIB}/${EXAMPLE}/${TESTS[idx]}/${{ env.device }}/report.json
191+
192+
echo "=============================================================================================================="
193+
done # end of TEST loop monitor
194+
195+
done # end of EXAMPLE loop
196+
done # end of LIB loop
197+
198+
# Upload the compiled HEX files to the GitHub server
199+
- name: Artefact
200+
uses: actions/upload-artifact@v4
201+
with:
202+
name: ${{ env.device }}
203+
path: ~/artefact/*
204+
if-no-files-found: ignore
205+
206+
207+
#############################################################################
208+
# Switch off the HIL after all tests are done
209+
post:
210+
211+
# we run this no matter if before fails
212+
if: always()
213+
# wait on first setup run before starting main function
214+
needs: [setup, flash]
215+
216+
# we run this on self hosted runner, use labels to be more specific
217+
# add specific names if there are some, otherwise self-hosted, X64, Linux are the default ones
218+
runs-on:
219+
- self-hosted
220+
- X64
221+
- Linux
222+
223+
steps:
224+
- name: Switch off HIL
225+
run: |
226+
cd /opt/runner_support/
227+
REPO="$(basename "$GITHUB_REPOSITORY")"
228+
./py_checkusb.py --switch repo --namelist $REPO --onoff off
229+

tests/Unity/Makefile

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $(info BAUD_RATE : $(BAUD_RATE))
1212

1313
TESTS_CONNECTED=-DTEST_CAN_CONNECTED
1414
TESTS_NOT_CONNECTED=-DTEST_CAN
15-
15+
1616
CAN: TESTS=-DTEST_CAN
1717
CAN_connected: TESTS=-DTEST_CAN -DTEST_CAN_CONNECTED
1818
CAN_connected_node1: TESTS=-DTEST_CAN_CONNECTED_NODE1
@@ -40,16 +40,16 @@ arduino: clean
4040
# find src -name '*.[hc]*' -a \( \! -name '*mtb*' \) -print -exec cp {} build \;
4141
.PHONY: CANReceiver CANReceiverCallback CANSender CANLoopBack
4242
CANReceiver: arduino
43-
cp examples/CANReceiver/CANReceiver.ino build/build.ino
43+
cp examples/CANReceiver/CANReceiver.ino build/build.ino
4444

4545
CANReceiverCallback: arduino
46-
cp examples/CANReceiverCallback/CANReceiverCallback.ino build/build.ino
46+
cp examples/CANReceiverCallback/CANReceiverCallback.ino build/build.ino
4747

4848
CANSender: arduino
49-
cp examples/CANSender/CANSender.ino build/build.ino
49+
cp examples/CANSender/CANSender.ino build/build.ino
5050

5151
CANLoopBack: arduino
52-
cp examples/CANLoopBack/CANLoopBack.ino build/build.ino
52+
cp examples/CANLoopBack/CANLoopBack.ino build/build.ino
5353

5454

5555
# install Unity from https://www.throwtheswitch.org/unity or git
@@ -82,8 +82,15 @@ ifeq ($(FQBN),)
8282
$(error "Must set variable FQBN in order to be able to compile Arduino sketches !")
8383
else
8484
# CAUTION : only use '=' when assigning values to vars, not '+='
85-
arduino-cli.exe compile --clean --log --warnings all --fqbn $(FQBN) --build-property "compiler.c.extra_flags=\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
86-
--build-property compiler.cpp.extra_flags="$(TESTS)" build
85+
arduino-cli.exe compile \
86+
--clean \
87+
--log \
88+
--warnings all \
89+
--fqbn $(FQBN) \
90+
--build-property "compiler.c.extra_flags=\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
91+
--build-property compiler.cpp.extra_flags="$(TESTS)" \
92+
--export-binaries \
93+
build
8794
endif
8895

8996

@@ -93,13 +100,18 @@ ifeq ($(FQBN),)
93100
else
94101
# compiler.c.extra_flags : switch to -std=c23 whenever XMCLib is conforming; currently neither c99 nor c11 work !
95102
# CAUTION : only use '=' when assigning values to vars, not '+='
96-
arduino-cli.exe compile --clean --log --warnings all --fqbn $(FQBN) \
97-
--build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\" -DNDEBUG -flto -fno-fat-lto-objects -Wextra -Wall -Wfloat-equal -Wconversion -Wredundant-decls -Wswitch-default -Wdouble-promotion -Wpedantic -Wunreachable-code -fanalyzer -std=c20 " \
98-
--build-property compiler.cpp.extra_flags="$(TESTS) -DNDEBUG -flto -fno-fat-lto-objects -Wextra -Wall -Wfloat-equal -Wconversion -Wredundant-decls -Wswitch-default -Wdouble-promotion -Wpedantic -Wunreachable-code -fanalyzer -std=c++20 " \
99-
--build-property compiler.ar.cmd=arm-none-eabi-gcc-ar \
100-
--build-property compiler.libraries.ldflags=-lstdc++ \
101-
--build-property compiler.arm.cmsis.path="-isystem{compiler.xmclib_include.path}/XMCLib/inc -isystem{compiler.dsp_include.path} -isystem{compiler.nn_include.path} -isystem{compiler.cmsis_include.path} -isystem{compiler.xmclib_include.path}/LIBS -isystem{build.variant.path} -isystem{build.variant.config_path}" \
102-
--build-property compiler.usb.path="-isystem{runtime.platform.path}/cores/usblib -isystem{runtime.platform.path}/cores/usblib/Common -isystem{runtime.platform.path}/cores/usblib/Class -isystem{runtime.platform.path}/cores/usblib/Class/Common -isystem{runtime.platform.path}/cores/usblib/Class/Device -isystem{runtime.platform.path}/cores/usblib/Core -isystem{runtime.platform.path}/cores/usblib/Core/XMC4000" \
103+
arduino-cli.exe compile \
104+
--clean \
105+
--log \
106+
--warnings all \
107+
--fqbn $(FQBN) \
108+
--build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\" -DNDEBUG -flto -fno-fat-lto-objects -Wextra -Wall -Wfloat-equal -Wconversion -Wredundant-decls -Wswitch-default -Wdouble-promotion -Wpedantic -Wunreachable-code -fanalyzer -std=c20 " \
109+
--build-property compiler.cpp.extra_flags="$(TESTS) -DNDEBUG -flto -fno-fat-lto-objects -Wextra -Wall -Wfloat-equal -Wconversion -Wredundant-decls -Wswitch-default -Wdouble-promotion -Wpedantic -Wunreachable-code -fanalyzer -std=c++20 " \
110+
--build-property compiler.ar.cmd=arm-none-eabi-gcc-ar \
111+
--build-property compiler.libraries.ldflags=-lstdc++ \
112+
--build-property compiler.arm.cmsis.path="-isystem{compiler.xmclib_include.path}/XMCLib/inc -isystem{compiler.dsp_include.path} -isystem{compiler.nn_include.path} -isystem{compiler.cmsis_include.path} -isystem{compiler.xmclib_include.path}/LIBS -isystem{build.variant.path} -isystem{build.variant.config_path}" \
113+
--build-property compiler.usb.path="-isystem{runtime.platform.path}/cores/usblib -isystem{runtime.platform.path}/cores/usblib/Common -isystem{runtime.platform.path}/cores/usblib/Class -isystem{runtime.platform.path}/cores/usblib/Class/Common -isystem{runtime.platform.path}/cores/usblib/Class/Device -isystem{runtime.platform.path}/cores/usblib/Core -isystem{runtime.platform.path}/cores/usblib/Core/XMC4000" \
114+
--export-binaries \
103115
build
104116
endif
105117

@@ -111,7 +123,11 @@ endif
111123
ifeq ($(FQBN),)
112124
$(error "Must set variable FQBN in order to be able to flash Arduino sketches !")
113125
else
114-
arduino-cli.exe upload -p $(PORT) --fqbn $(FQBN) --verbose build
126+
arduino-cli.exe upload \
127+
-p $(PORT) \
128+
--fqbn $(FQBN) \
129+
--verbose \
130+
build
115131
endif
116132

117133

@@ -125,6 +141,9 @@ endif
125141
ifeq ($(FQBN),)
126142
$(error "Must set variable FQBN in order to be able to flash Arduino sketches !")
127143
else
128-
arduino-cli.exe monitor -c baudrate=$(BAUD_RATE) -p $(PORT) --fqbn $(FQBN)
144+
arduino-cli.exe monitor \
145+
-c baudrate=$(BAUD_RATE) \
146+
-p $(PORT) \
147+
--fqbn $(FQBN)
129148
endif
130149

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Infineon.xmc.XMC4700_Relax_Kit:
2+
CAN:
3+
1:
4+
- "CAN_connected_node1"
5+
- "CAN_connected_node2"
6+
2:
7+
- CAN
8+
9+
Wire:
10+
1:
11+
- "I2C"
12+
2:
13+
- "I2C"
14+
15+
16+
Infineon.xmc.XMC1400_XMC2GO:
17+
CAN:
18+
1:
19+
- "CAN_connected_node1"
20+
- "CAN_connected_node2"
21+
2:
22+
- CAN
23+
24+
Infineon.xmc.XMC1100_XMC2GO:
25+
Wire:
26+
1:
27+
- "I2C"
28+
2:
29+
- "I2C"

0 commit comments

Comments
 (0)