CI(pico-sensor): added test job

This commit is contained in:
SylvanArnold
2025-06-03 19:16:41 +02:00
parent 29a8987eee
commit 5a3a7fcca3
3 changed files with 108 additions and 60 deletions

View File

@@ -1,24 +1,48 @@
stages:
- build
variables:
DOCKER_IMAGE: registry.forge.hefr.ch/team-raclette/project-softweng/pico-sensor:latest
build_release:
stage: build
stages:
- build-docker
- test
- release
pico-sensor-docker-build:
image: docker:latest
stage: build-docker
services:
- docker:dind
script:
- docker build -t $DOCKER_IMAGE -f pico-sensor/dockerfile .
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- docker push $DOCKER_IMAGE
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_COMMIT_BRANCH == 'main'
- changes:
- pico-sensor/Dockerfile
pico-sensor-test:
stage: test
image: registry.forge.hefr.ch/team-raclette/project-softweng/pico-sensor:latest
script:
- cd pico-sensor
- cmake --preset Test
- cmake --build --preset app-test
- ctest --output-on-failure --output-junit test-results.xml
artifacts:
paths:
- pico-sensor/test-results.xml
pico-sensor-release:
stage: release
image: $DOCKER_IMAGE
script:
- cd pico-sensor
- cmake --preset Release
- cmake --build --preset app-release
artifacts:
paths:
- pico-sensor/build/Release/
- pico-sensor/build/Release/**/*.uf2
rules:
- if: '$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "merge_request_event"'
when: always
build_test:
stage: build
image: registry.forge.hefr.ch/team-raclette/project-softweng/pico-sensor:latest
script:
- cd pico-sensor
- cmake --preset Test
- cmake --build --preset app-test
artifacts:
paths:
- pico-sensor/build/Test/

View File

@@ -1,60 +1,84 @@
# Dockerfile for CI/CD pipeline (GitLab, GitHub Actions, etc.)
# Docker file for VS Code as a DevContainer
FROM mcr.microsoft.com/devcontainers/cpp:dev-ubuntu24.04
# folder for downloaded files
WORKDIR /apps
RUN mkdir -p /apps
# Install prerequisites
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git python3 wget unzip \
cmake build-essential ninja-build \
doxygen graphviz \
iputils-ping \
apt-transport-https ca-certificates curl software-properties-common \
libx11-xcb1 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 \
libxcb-render-util0 libxcb-shape0 libxcb-sync1 libxcb-util1 \
libxcb-xfixes0 libxcb-xkb1 libxkbcommon-x11-0 libxkbcommon0 xkb-data \
python3-pip python3.12-venv \
&& rm -rf /var/lib/apt/lists/*
RUN \
apt update \
&& apt install -y git python3 wget unzip \
&& apt install -y cmake build-essential ninja-build
# Install ARM toolchain
RUN wget https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-linux-x64.tar.gz -O gcc-arm-none-eabi.tar.gz && \
mkdir /opt/gcc-arm-none-eabi-13.2.1-1.1 && \
tar -xvzf gcc-arm-none-eabi.tar.gz -C /opt/gcc-arm-none-eabi-13.2.1-1.1 --strip-components 1 && \
rm gcc-arm-none-eabi.tar.gz && \
ln -s /opt/gcc-arm-none-eabi-13.2.1-1.1/bin/* /usr/local/bin
# Install nano editor
RUN apt-get install -y nano
# Use the ARM gcov for coverage
RUN rm /usr/bin/gcov && \
ln -s /opt/gcc-arm-none-eabi-13.2.1-1.1/bin/arm-none-eabi-gcov /usr/bin/gcov
# Install doxygen and graphviz
RUN apt-get install -y doxygen graphviz
# Install SEGGER J-Link
RUN curl -d "accept_license_agreement=accepted&submit=Download+software" -X POST -O "https://www.segger.com/downloads/jlink/JLink_Linux_V810g_x86_64.deb" && \
dpkg --unpack JLink_Linux_V810g_x86_64.deb && \
rm -f /var/lib/dpkg/info/jlink.postinst && \
dpkg --configure jlink && \
apt-get install -yf && \
rm JLink_Linux_V810g_x86_64.deb
# Install ping utility
RUN apt-get update && apt-get install -y iputils-ping
# Install curl and others, needed to get SEGGER files
RUN apt-get install -y apt-transport-https ca-certificates curl software-properties-common
RUN apt-get install -y libx11-xcb1 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-shape0 libxcb-sync1 libxcb-util1 libxcb-xfixes0 libxcb-xkb1 libxkbcommon-x11-0 libxkbcommon0 xkb-data
RUN apt-get install -y udev
# Get a specific version of the arm toolchain
RUN \
cd /apps \
&& wget https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-linux-x64.tar.gz -O gcc-arm-none-eabi.tar.gz \
&& mkdir /opt/gcc-arm-none-eabi-13.2.1-1.1 \
&& tar -xvzf gcc-arm-none-eabi.tar.gz -C /opt/gcc-arm-none-eabi-13.2.1-1.1 --strip-components 1 \
&& rm gcc-arm-none-eabi.tar.gz \
&& ln -s /opt/gcc-arm-none-eabi-13.2.1-1.1/bin/* /usr/local/bin
# for gcov, have to use the arm-none-eabi-gcov one
RUN \
rm /usr/bin/gcov \
&& cd /usr/bin \
&& ln -s /opt/gcc-arm-none-eabi-13.2.1-1.1/bin/arm-none-eabi-gcov gcov
# Install gcovr (needs pip) and virtual environment
RUN \
apt install -y python3-pip python3.12-venv
# Install SEGGER
RUN \
cd /apps \
&& curl -d "accept_license_agreement=accepted&submit=Download+software" -X POST -O "https://www.segger.com/downloads/jlink/JLink_Linux_V810g_x86_64.deb"
# in case issue with mismatch between J-Link version between host and container/image: use matching version
# issue with udev, see https://forum.segger.com/index.php/Thread/8953-SOLVED-J-Link-Linux-installer-fails-for-Docker-containers-Error-Failed-to-update/
RUN \
cd /apps \
&& dpkg --unpack JLink_Linux_V810g_x86_64.deb \
&& rm -f /var/lib/dpkg/info/jlink.postinst \
&& dpkg --configure jlink \
&& apt install -yf
# Install Pico SDK
RUN git clone https://github.com/raspberrypi/pico-sdk.git --branch master && \
cd pico-sdk && \
git checkout tags/2.0.0 && \
git submodule update --init
RUN \
cd /apps \
&& git clone https://github.com/raspberrypi/pico-sdk.git --branch master \
&& cd pico-sdk/ \
&& git checkout tags/2.0.0 \
&& git submodule update --init
# Set the Pico SDK environment variable
ENV PICO_SDK_PATH=/apps/pico-sdk/
# Patch the SDK for semihosting file I/O (needed for gcov)
COPY newlib_interface.c.patched ${PICO_SDK_PATH}/src/rp2_common/pico_clib_interface/newlib_interface.c
# Build picotool
RUN git clone https://github.com/raspberrypi/picotool.git --branch master && \
cd picotool && \
git checkout tags/2.0.0 && \
git submodule update --init && \
mkdir build && cd build && cmake ../ && make -j8 && \
cmake --install .
# Build picotool so we don't have to build it for the project
RUN \
cd /apps \
&& git clone https://github.com/raspberrypi/picotool.git --branch master \
&& cd picotool/ \
&& git checkout tags/2.0.0 \
&& git submodule update --init \
&& mkdir build && cd build && cmake ../ && make -j8 \
&& cmake --install .
# Default command (overridden by CI/CD)
CMD ["bash"]

View File

@@ -35,7 +35,7 @@ target_include_directories(
)
#################################################################################
# Note: --pc off --sp off are needed, if application runs from the ROM bootloader, might add --verbose
set (JRUN_CTEST_COMMAND "JRun" --device RP2040_M0_0 --rtt -if SWD --pc off --sp off)
set (JRUN_CTEST_COMMAND "JRun" --device RP2040_M0_0 --rtt -if SWD --pc off --sp off --ip "tunnel:801000372")
add_test(
NAME Led