CI(pico-sensor): added dockerfile to build pico-sensor image + created ci pipeline with build jobs

This commit is contained in:
SylvanArnold
2025-05-26 20:03:30 +02:00
parent d8f4b9f918
commit 23f11a3b87
6 changed files with 302 additions and 8 deletions

View File

@@ -6,3 +6,4 @@ stages:
include:
- local: gateway/.gitlab-ci.yml
- local: web-app/.gitlab-ci.yml
- local: pico-sensor/.gitlab-ci.yml

View File

@@ -0,0 +1,22 @@
stages:
- build
build_release:
stage: build
image: registry.forge.hefr.ch/team-raclette/project-softweng/pico-sensor:latest
script:
- cmake --preset Release
- cmake --build --preset app-release
artifacts:
paths:
- build/Release/
build_test:
stage: build
image: registry.forge.hefr.ch/team-raclette/project-softweng/pico-sensor:latest
script:
- cmake --preset Test
- cmake --build --preset app-Test
artifacts:
paths:
- build/Test/

60
pico-sensor/dockerfile Normal file
View File

@@ -0,0 +1,60 @@
# Dockerfile for CI/CD pipeline (GitLab, GitHub Actions, etc.)
FROM mcr.microsoft.com/devcontainers/cpp:dev-ubuntu24.04
WORKDIR /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/*
# 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
# 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 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 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
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 .
# Default command (overridden by CI/CD)
CMD ["bash"]

View File

@@ -0,0 +1,211 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/times.h>
#include <time.h>
#include <unistd.h>
#if PICO_ENTER_USB_BOOT_ON_EXIT
#include "pico/bootrom.h"
#endif
#include "pico/time.h"
#include "pico/runtime_init.h"
#if LIB_PICO_PRINTF_PICO
#include "pico/printf.h"
#else
#define weak_raw_printf printf
#define weak_raw_vprintf vprintf
#endif
#if LIB_PICO_STDIO
#include "pico/stdio.h"
#endif
#if PICO_ENTER_USB_BOOT_ON_EXIT
#include "pico/bootrom.h"
#endif
extern char __StackLimit; /* Set by linker. */
#define STDIO_HANDLE_STDIN 0
#define STDIO_HANDLE_STDOUT 1
#define STDIO_HANDLE_STDERR 2
void __attribute__((noreturn)) __weak _exit(__unused int status) {
#if PICO_ENTER_USB_BOOT_ON_EXIT
reset_usb_boot(0,0);
#else
while (1) {
__breakpoint();
}
#endif
}
__weak void *_sbrk(int incr) {
extern char end; /* Set by linker. */
static char *heap_end;
char *prev_heap_end;
if (heap_end == 0)
heap_end = &end;
prev_heap_end = heap_end;
char *next_heap_end = heap_end + incr;
if (__builtin_expect(next_heap_end > (&__StackLimit), false)) {
#if PICO_USE_OPTIMISTIC_SBRK
if (heap_end == &__StackLimit) {
// errno = ENOMEM;
return (char *) -1;
}
next_heap_end = &__StackLimit;
#else
return (char *) -1;
#endif
}
heap_end = next_heap_end;
return (void *) prev_heap_end;
}
static int64_t epoch_time_us_since_boot;
__weak int _gettimeofday (struct timeval *__restrict tv, __unused void *__restrict tz) {
if (tv) {
int64_t us_since_epoch = ((int64_t)to_us_since_boot(get_absolute_time())) - epoch_time_us_since_boot;
tv->tv_sec = (time_t)(us_since_epoch / 1000000);
tv->tv_usec = (suseconds_t)(us_since_epoch % 1000000);
}
return 0;
}
__weak int settimeofday(__unused const struct timeval *tv, __unused const struct timezone *tz) {
if (tv) {
int64_t us_since_epoch = tv->tv_sec * 1000000 + tv->tv_usec;
epoch_time_us_since_boot = (int64_t)to_us_since_boot(get_absolute_time()) - us_since_epoch;
}
return 0;
}
__weak int _times(struct tms *tms) {
#if CLOCKS_PER_SEC >= 1000000
tms->tms_utime = (clock_t)(to_us_since_boot(get_absolute_time()) * (CLOCKS_PER_SEC / 1000000));
#else
tms->tms_utime = (clock_t)(to_us_since_boot(get_absolute_time()) / (1000000 / CLOCKS_PER_SEC));
#endif
tms->tms_stime = 0;
tms->tms_cutime = 0;
tms->tms_cstime = 0;
return 0;
}
__weak pid_t _getpid(void) {
return 0;
}
__weak int _kill(__unused pid_t pid, __unused int sig) {
return -1;
}
#if !McuRdimon_CONFIG_IS_ENABLED
int __attribute__((weak)) _read(int handle, char *buffer, int length) {
#if LIB_PICO_STDIO
if (handle == STDIO_HANDLE_STDIN) {
return stdio_get_until(buffer, length, at_the_end_of_time);
}
#endif
return -1;
}
#endif
#if !McuRdimon_CONFIG_IS_ENABLED
int __attribute__((weak)) _write(int handle, char *buffer, int length) {
#if LIB_PICO_STDIO
if (handle == STDIO_HANDLE_STDOUT || handle == STDIO_HANDLE_STDERR) {
stdio_put_string(buffer, length, false, true);
return length;
}
#endif
return -1;
}
#endif
#if !McuRdimon_CONFIG_IS_ENABLED
int __attribute__((weak)) _open(__unused const char *fn, __unused int oflag, ...) {
return -1;
}
#endif
#if !McuRdimon_CONFIG_IS_ENABLED
int __attribute__((weak)) _close(__unused int fd) {
return -1;
}
#endif
#if !McuRdimon_CONFIG_IS_ENABLED
off_t __attribute__((weak)) _lseek(__unused int fd, __unused off_t pos, __unused int whence) {
return -1;
}
#endif
#if !McuRdimon_CONFIG_IS_ENABLED
int __attribute__((weak)) _fstat(__unused int fd, __unused struct stat *buf) {
return -1;
}
#endif
int __attribute__((weak)) _isatty(int fd) {
return fd == STDIO_HANDLE_STDIN || fd == STDIO_HANDLE_STDOUT || fd == STDIO_HANDLE_STDERR;
}
// exit is not useful... no desire to pull in __call_exitprocs
void exit(int status) {
_exit(status);
}
// incorrect warning from GCC 6
GCC_Pragma("GCC diagnostic push")
GCC_Pragma("GCC diagnostic ignored \"-Wsuggest-attribute=format\"")
void __weak __assert_func(const char *file, int line, const char *func, const char *failedexpr) {
weak_raw_printf("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
failedexpr, file, line, func ? ", function: " : "",
func ? func : "");
_exit(1);
}
GCC_Pragma("GCC diagnostic pop")
void runtime_init(void) {
#ifndef NDEBUG
if (__get_current_exception()) {
// crap; started in exception handler
__breakpoint();
}
#endif
#if !PICO_RUNTIME_SKIP_INIT_PER_CORE_INSTALL_STACK_GUARD
// install core0 stack guard
extern char __StackBottom;
runtime_init_per_core_install_stack_guard(&__StackBottom);
#endif
// todo maybe we want to do this in the future, but it does stuff like register_tm_clones
// which we didn't do in previous SDKs
//extern void __libc_init_array(void);
//__libc_init_array();
// ... so instead just do the __preinit_array
runtime_run_initializers();
// ... and the __init_array
extern void (*__init_array_start)(void);
extern void (*__init_array_end)(void);
for (void (**p)(void) = &__init_array_start; p < &__init_array_end; ++p) {
(*p)();
}
}

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 "$ENV{SEGGER_PATH}/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)
add_test(
NAME Led

View File

@@ -14,8 +14,8 @@
#include "McuRTT.h"
#include "McuUtility.h"
#include "McuLog.h"
#include "test_sensor.h"
#include "test_leds.h"
//#include "test_sensor.h"
//#include "test_leds.h"
#include "test_dns_resolver.h"
static void TestArgFailed(void) {
@@ -32,12 +32,12 @@ void Tests_Run(void) {
UNITY_BEGIN();
if (nofBytes>0) {
if (McuUtility_strcmp(buf, "led")==0) {
RUN_TEST(TestLeds_OnOff);
RUN_TEST(TestLeds_Toggle);
//RUN_TEST(TestLeds_OnOff);
//RUN_TEST(TestLeds_Toggle);
} else if (McuUtility_strcmp(buf, "sensor")==0) {
RUN_TEST(TestSensor_Temperature);
RUN_TEST(TestSensor_Humidity);
RUN_TEST(TestSensor_Both);
//RUN_TEST(TestSensor_Temperature);
//RUN_TEST(TestSensor_Humidity);
//RUN_TEST(TestSensor_Both);
} else if (McuUtility_strcmp(buf, "dns")==0) {
RUN_TEST(TestDnsResolver_Test);
} else {