Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test to cicd #28

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,6 @@ jobs:
kill $(cat server.pid)
rm server.pid

- name: Remove latest installed platform version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that these steps are not really necessary as they are taking care by the arduino-cli installation or?

run: |
cd ~/.arduino15/packages/infineon/hardware/psoc
rm -rf *

- name: copy/link repository to arduino path
run: |
mkdir ~/.arduino15/packages/infineon/hardware/psoc/0.0.0
cp -a ./* ~/.arduino15/packages/infineon/hardware/psoc/0.0.0
cd ~/.arduino15/packages/infineon/hardware/psoc/0.0.0

- name: copy/link arduino core api path
run: |
mkdir ~/.arduino15/packages/infineon/hardware/psoc/0.0.0/cores/psoc/api
cp -a ~/.arduino15/packages/infineon/hardware/psoc/0.0.0/extras/arduino-core-api/api/* ~/.arduino15/packages/infineon/hardware/psoc/0.0.0/cores/psoc/api

# Compile the sample code for the selected board and board support package with the arduino compiler
- name: Compile Sketch
run: |
Expand Down
165 changes: 165 additions & 0 deletions .github/workflows/hil_unity_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
name: Hil unity library checks

# on which event should we start push, pull request or schedule dispatches
on:
- push
- pull_request

env:
TEST_VERSION: 1.0.0

jobs:

# The build job compiles the sample code for different boards
tests:

#############################################################################
# This action sets common variables for the flow and
# identifies the libs to compile
runs-on:
- self-hosted
- X64
- Linux
- PSoC

# which combination of sample code and boards should run
# for this example of 2 sample codes and 3 boards a total of 2x3=6 runners have to work.
# if we have only 4 runner then these 4 are started and the last 2 are waiting until they can start
strategy:

matrix:
# List of all examples in the lib to compile
example: [
examples/testSketch/testSketch.ino
]

# board packages we want to run
# attention the matrix spans over the fqbn not platform so that we can choose different boards
# this example compiles each sample code for Arduino Uno, XMC2Go and XMC4700 boards
fqbn: [
"infineon:psoc:cy8ckit_062s2_ai"
]

# include additional information for each fqbn, in this case the platform name to install
include:
- fqbn: "infineon:psoc:cy8ckit_062s2_ai"
platform: "infineon:psoc"

# These are the steps which should run for each combination of fqbn and example code
steps:

- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

- name: Generate package json
run: |
python ./tools/release.py build-local

- name: Start local HTTP server
run: |
cd pkg_build
nohup python -m http.server 8000 & echo $! > server.pid

- name: Install/Update Arduino Platform
run: |
arduino-cli core update-index
arduino-cli core install ${{ matrix.platform }} --additional-urls http://localhost:8000/package_psoc_index.json
arduino-cli core list

- name: Kill local HTTP server
run: |
cd pkg_build
kill $(cat server.pid)
rm server.pid

- name: Remove latest installed platform version
run: |
cd ~/.arduino15/packages/infineon/hardware/psoc
rm -rf *

- name: copy/link repository to arduino path
run: |
mkdir ~/.arduino15/packages/infineon/hardware/psoc/$TEST_VERSION
cp -a ./* ~/.arduino15/packages/infineon/hardware/psoc/$TEST_VERSION
cd ~/.arduino15/packages/infineon/hardware/psoc/$TEST_VERSION

- name: copy/link arduino core api path
run: |
mkdir ~/.arduino15/packages/infineon/hardware/psoc/$TEST_VERSION/cores/psoc/api
cp -a ~/.arduino15/packages/infineon/hardware/psoc/$TEST_VERSION/extras/arduino-core-api/api/* ~/.arduino15/packages/infineon/hardware/psoc/$TEST_VERSION/cores/psoc/api

# Fetch variables and move them to the GITHUB_OUTPUT and fetch HIL information
- id: startup
run: |
# switch on the HIL
cd /opt/runner_support/

# set the hil-unity-checks
hil=$(./py_checkusb.py --readyaml ~/.arduino15/packages/infineon/hardware/psoc/$TEST_VERSION/tests/unity/hil-unity-checklist.yaml --json)
echo "hil=${hil}" >> $GITHUB_OUTPUT
echo "hil=${hil}"

# fetch unity libraries
readarray -t data < <(echo $hil | jq -r '.|keys[]')
export dev=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${data[@]}")
echo "devices=${dev}" >> $GITHUB_OUTPUT
echo "devices=${dev}"

# setup environment
- name: Environment
run: |
hil=${{ toJson(steps.startup.outputs.hil) }}
REPO="$(basename "$GITHUB_REPOSITORY")"
DEVICE=${{ steps.startup.outputs.devices }}
DEVICE=$(echo $DEVICE | tr -d '[]')
FQBN=$(echo $DEVICE | tr -d '[]')
DEVICE=`tr ':' '.' <<<"${DEVICE}"`

echo "repo=$REPO" >> $GITHUB_ENV
echo "device=$DEVICE" >> $GITHUB_ENV
echo "version=$TEST_VERSION" >> $GITHUB_ENV
echo "fqbn=$FQBN" >> $GITHUB_ENV

echo "Repo " $REPO
echo "Device " $DEVICE
echo "FQBN " $FQBN
echo "Version " ${TEST_VERSION}

- name: Build
run: |
export TMPDIR=$HOME/tmp
mkdir -p $TMPDIR
rm -rf $HOME/artefact
mkdir -p $HOME/artefact

cd ~/.arduino15/packages/infineon/hardware/psoc/$TEST_VERSION/tests/unity/
echo "=============================================================================================================="
echo "Run Tests"
echo "=============================================================================================================="
make FQBN=${{ env.fqbn }} PORT=/dev/ttyACM0 single_hardware_connected
mkdir -p ~/artefact/unit_tests/${{ env.device }}
mv ./build/* ~/artefact/unit_tests/.
echo "=============================================================================================================="



echo "=============================================================================================================="
echo "Monitor"
timeout 1m \
/opt/runner_support/py_console.py \
--port /dev/ttyACM0 \
--baud 115200 \
--report ~/artefact/unit_tests/${{ env.device }}/report.json

echo "=============================================================================================================="


# Upload the compiled HEX files to the GitHub server
- name: Artefact
uses: actions/upload-artifact@v4
with:
name: ${{ env.device }}
path: ~/artefact/*
if-no-files-found: ignore
27 changes: 17 additions & 10 deletions Makefile.arduino.mk → tests/unity/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
FQBN ?=
PORT ?=
TESTS ?=
UNITY_PATH ?= ../../extras/unity
BAUD_RATE ?= 115200

$(info FQBN : $(FQBN))
$(info PORT : $(PORT))

UNITY_PATH = ./extras/unity
$(info UNITY_PATH : $(UNITY_PATH))
$(info BAUD_RATE : $(BAUD_RATE))

TESTS_SINGLE_HARDWARE_CONNECTED=-DTEST_SINGLE_HARDWARE_CONNECTED


TESTS_MULTI_HARDWARE_CONNECTED=-DTEST_MULTI_HARDWARE_CONNECTED


Expand Down Expand Up @@ -44,8 +45,8 @@ ifeq ($(UNITY_PATH),)
$(error "Must set variable UNITY_PATH in order to be able to compile Arduino unit tests !")
else
find $(UNITY_PATH) -name '*.[hc]' \( -path '*extras*' -a -path '*src*' -or -path '*src*' -a \! -path '*example*' \) -exec \cp {} build \;
find test/unit -name '*.[hc]*' -a \! -path '*mtb*' -a \! -path '*applibs*' -exec \cp {} build \;
cp test/unit/src/test_main.ino build/build.ino
find src -name '*.[hc]*' -a \! -path '*mtb*' -a \! -path '*applibs*' -exec \cp {} build \;
cp src/test_main.ino build/build.ino
endif


Expand All @@ -57,7 +58,7 @@ ifeq ($(FQBN),)
$(error "Must set variable FQBN in order to be able to compile Arduino sketches !")
else
# CAUTION : only use '=' when assigning values to vars, not '+='
arduino-cli compile --clean --log --warnings all --fqbn $(FQBN) --build-property "compiler.c.extra_flags=\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
arduino-cli compile --clean --verbose --log --warnings all --fqbn $(FQBN) --build-property "compiler.c.extra_flags=\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
--build-property compiler.cpp.extra_flags="$(TESTS)" build
endif

Expand All @@ -79,19 +80,22 @@ else
endif


upload:
upload: compile
ifeq ($(PORT),)
$(error "Must set variable PORT (Windows port naming convention, ie COM16) in order to be able to flash Arduino sketches !")
endif
ifeq ($(FQBN),)
$(error "Must set variable FQBN in order to be able to flash Arduino sketches !")
else
arduino-cli upload -p $(PORT) --fqbn $(FQBN) build
arduino-cli upload \
-p $(PORT) \
--fqbn $(FQBN) \
--verbose \
build
endif


flash: compile upload
flashLTO: compileLTO upload


monitor:
Expand All @@ -101,6 +105,9 @@ endif
ifeq ($(FQBN),)
$(error "Must set variable FQBN in order to be able to flash Arduino sketches !")
else
arduino-cli monitor -c baudrate=115200 -p $(PORT) --fqbn $(FQBN)
arduino-cli monitor \
-c baudrate=$(BAUD_RATE) \
-p $(PORT) \
--fqbn $(FQBN)
endif

2 changes: 1 addition & 1 deletion Makefile.test → tests/unity/Makefile.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

######################### tests runnable with a single board "talking to itself" #########################

make -f Makefile.arduino.mk FQBN=infineon:psoc:cy8ckit_062s2_ai PORT=/dev/ttyACM0 single_hardware_connected monitor
make FQBN=infineon:psoc:cy8ckit_062s2_ai PORT=/dev/ttyACM0 single_hardware_connected monitor

######################### tests runnable with 2 boards and some wires #########################
7 changes: 7 additions & 0 deletions tests/unity/hil-unity-checklist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
infineon:psoc:cy8ckit_062s2_ai:
math:
1:
- "math"



File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading