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: variables:
- build DOCKER_IMAGE: registry.forge.hefr.ch/team-raclette/project-softweng/pico-sensor:latest
build_release: stages:
stage: build - 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 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: script:
- cd pico-sensor - cd pico-sensor
- cmake --preset Release - cmake --preset Release
- cmake --build --preset app-release - cmake --build --preset app-release
artifacts: artifacts:
paths: 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 FROM mcr.microsoft.com/devcontainers/cpp:dev-ubuntu24.04
# folder for downloaded files
WORKDIR /apps WORKDIR /apps
RUN mkdir -p /apps
# Install prerequisites # Install prerequisites
RUN apt-get update && \ RUN \
apt-get install -y --no-install-recommends \ apt update \
git python3 wget unzip \ && apt install -y git python3 wget unzip \
cmake build-essential ninja-build \ && apt install -y 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/*
# Install ARM toolchain # Install nano editor
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 && \ RUN apt-get install -y nano
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
# Use the ARM gcov for coverage # Install doxygen and graphviz
RUN rm /usr/bin/gcov && \ RUN apt-get install -y doxygen graphviz
ln -s /opt/gcc-arm-none-eabi-13.2.1-1.1/bin/arm-none-eabi-gcov /usr/bin/gcov
# Install SEGGER J-Link # Install ping utility
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" && \ RUN apt-get update && apt-get install -y iputils-ping
dpkg --unpack JLink_Linux_V810g_x86_64.deb && \
rm -f /var/lib/dpkg/info/jlink.postinst && \ # Install curl and others, needed to get SEGGER files
dpkg --configure jlink && \ RUN apt-get install -y apt-transport-https ca-certificates curl software-properties-common
apt-get install -yf && \ 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
rm JLink_Linux_V810g_x86_64.deb 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 # Install Pico SDK
RUN git clone https://github.com/raspberrypi/pico-sdk.git --branch master && \ RUN \
cd pico-sdk && \ cd /apps \
git checkout tags/2.0.0 && \ && git clone https://github.com/raspberrypi/pico-sdk.git --branch master \
git submodule update --init && 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/ ENV PICO_SDK_PATH=/apps/pico-sdk/
# Patch the SDK for semihosting file I/O (needed for gcov) # 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 COPY newlib_interface.c.patched ${PICO_SDK_PATH}/src/rp2_common/pico_clib_interface/newlib_interface.c
# Build picotool # Build picotool so we don't have to build it for the project
RUN git clone https://github.com/raspberrypi/picotool.git --branch master && \ RUN \
cd picotool && \ cd /apps \
git checkout tags/2.0.0 && \ && git clone https://github.com/raspberrypi/picotool.git --branch master \
git submodule update --init && \ && cd picotool/ \
mkdir build && cd build && cmake ../ && make -j8 && \ && git checkout tags/2.0.0 \
cmake --install . && 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 # 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( add_test(
NAME Led NAME Led