From 0bb52a3a077697f66b1833a18f5270fa67f85543 Mon Sep 17 00:00:00 2001 From: SylvanArnold <89144178+SylvanArnold@users.noreply.github.com> Date: Wed, 4 Jun 2025 10:51:17 +0200 Subject: [PATCH] doc(pico-sensor): updated readme with remote tests informations --- pico-sensor/README.md | 57 ++++++++++++++++++------ pico-sensor/src/tests/test_mqtt_client.c | 0 pico-sensor/src/tests/test_mqtt_client.h | 0 pico-sensor/src/tests/test_sensors.c | 27 +++++++++++ pico-sensor/src/tests/test_sensors.h | 11 +++++ pico-sensor/src/tests/tests.c | 18 +++----- 6 files changed, 88 insertions(+), 25 deletions(-) create mode 100644 pico-sensor/src/tests/test_mqtt_client.c create mode 100644 pico-sensor/src/tests/test_mqtt_client.h create mode 100644 pico-sensor/src/tests/test_sensors.c create mode 100644 pico-sensor/src/tests/test_sensors.h diff --git a/pico-sensor/README.md b/pico-sensor/README.md index 4189716..c1d4195 100644 --- a/pico-sensor/README.md +++ b/pico-sensor/README.md @@ -1,11 +1,11 @@ # TSM_PicoW_Sensor -Project using the PicoW board. It publish sensors values (humidity, temperature) to an MQTT broker. +This project uses the PicoW board to publish sensor values (humidity and temperature) to an MQTT broker. -## Configuration +## Target Configuration -You have to use the serial terminal (Baud rate of 115200) to configure the board by sending commands. The application will then store the parameters in flash memory. You have to restart the device to update the changes. +Use a serial terminal (baud rate: 115200) to configure the board by sending commands. The application stores the parameters in flash memory. You must restart the device to apply any changes. -### Wifi +### Wi-Fi ```shell McuMinINI write settings.ini WiFi ssid "YOUR_SSID" @@ -14,7 +14,7 @@ McuMinINI write settings.ini WiFi pass "YOUR_PASSWORD" ### MQTT -Broker informations: +Broker information: ```shell McuMinINI write settings.ini MQTT broker "BROKER_NAME" McuMinINI write settings.ini MQTT user "USERNAME" @@ -30,29 +30,60 @@ McuMinINI write settings.ini MQTT topic_send_measurement "// ## Build Project has `Debug`, `Release` and `Test` targets, using CMake Presets. -Configure: -``` +**Configure:** +```shell cmake --list-presets cmake --preset Debug cmake --preset Release cmake --preset Test ``` -Build: -``` +**Build:** +```shell cmake --build --list-presets cmake --build --preset app-debug cmake --build --preset app-release cmake --build --preset app-test ``` -Test: -``` +**Test:** +```shell ctest --list-presets ctest --test-dir build/Test -R Led_1 ``` -Worflow: -``` +**Workflow:** +```shell cmake --workflow --list-presets ``` + +## Running Tests on Another Machine + +To run tests on a target connected to another machine (e.g., in a GitLab CI pipeline), follow these steps: + +### On the Host Machine + +Set up a J-Link tunnel to make the target accessible from anywhere: + +```shell +JLinkRemoteServerCL -UseTunnel -TunnelBySN +``` + +The terminal output should look like this: + +``` +2025-06-04 08:43:57 - Remote Server started +2025-06-04 08:43:57 - Connected to J-Link with S/N 801000372 +2025-06-04 08:43:57 - Resolving tunnel server name (jlink-europe.segger.com)... +2025-06-04 08:43:57 - Tunnel server IP: 185.162.249.2 +2025-06-04 08:43:57 - Registered at tunnel server +2025-06-04 08:43:57 - Waiting for client connection +``` + +`801000372` is the tunnel ID required to reach the target. Include it in your CMake command: + +```shell +cmake --preset Test -DTUNNEL_ID=801000372 +``` + +When you run the tests, they will automatically execute on the host machine. \ No newline at end of file diff --git a/pico-sensor/src/tests/test_mqtt_client.c b/pico-sensor/src/tests/test_mqtt_client.c new file mode 100644 index 0000000..e69de29 diff --git a/pico-sensor/src/tests/test_mqtt_client.h b/pico-sensor/src/tests/test_mqtt_client.h new file mode 100644 index 0000000..e69de29 diff --git a/pico-sensor/src/tests/test_sensors.c b/pico-sensor/src/tests/test_sensors.c new file mode 100644 index 0000000..106c12b --- /dev/null +++ b/pico-sensor/src/tests/test_sensors.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025, Sylvan Arnold + * + */ +#include "platform.h" +#if PL_CONFIG_USE_UNIT_TESTS +#include "test_sensors.h" +#include "unity.h" +#include "sensor.h" + +void TestSensors_Test(void) { + float temp, hum; + + /* Test that initial sensor values are within a reasonable range */ + temp = Sensor_GetTemperature(); + hum = Sensor_GetHumidity(); + + /* Check temperature is within plausible sensor range (-40°C to 125°C) */ + TEST_ASSERT_TRUE_MESSAGE(temp > -50.0f && temp < 130.0f, "Temperature out of range"); + + /* Check humidity is within plausible sensor range (0% to 100%) */ + TEST_ASSERT_TRUE_MESSAGE(hum >= 0.0f && hum <= 100.0f, "Humidity out of range"); + + /* Optionally, check that values are not both zero (unless sensor is uninitialized) */ + TEST_ASSERT_FALSE_MESSAGE(temp == 0.0f && hum == 0.0f, "Sensor values are both zero, possible init error"); +} +# endif \ No newline at end of file diff --git a/pico-sensor/src/tests/test_sensors.h b/pico-sensor/src/tests/test_sensors.h new file mode 100644 index 0000000..7d8dac1 --- /dev/null +++ b/pico-sensor/src/tests/test_sensors.h @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2025, Sylvan Arnold + * + */ + +#ifndef _TEST_SENSORS_H__ +#define _TEST_SENSORS_H__ + +void TestSensors_Test(void); + +#endif /* _TEST_SENSORS_H__ */ \ No newline at end of file diff --git a/pico-sensor/src/tests/tests.c b/pico-sensor/src/tests/tests.c index 2298453..f3057da 100644 --- a/pico-sensor/src/tests/tests.c +++ b/pico-sensor/src/tests/tests.c @@ -14,10 +14,10 @@ #include "McuRTT.h" #include "McuUtility.h" #include "McuLog.h" -//#include "test_sensor.h" -//#include "test_leds.h" +#include "test_sensors.h" #include "test_dns_resolver.h" + static void TestArgFailed(void) { TEST_ASSERT_MESSAGE(false, "wrong test_arg value"); } @@ -36,18 +36,12 @@ void Tests_Run(void) { nofBytes = McuUnity_RTT_GetArgs(buf, sizeof(buf)); UNITY_BEGIN(); if (nofBytes>0) { - if (McuUtility_strcmp(buf, "led")==0) { - //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); + if (McuUtility_strcmp(buf, "dummy")==0) { + RUN_TEST(TestDummy); + } else if (McuUtility_strcmp(buf, "sensors")==0) { + RUN_TEST(TestSensors_Test); } else if (McuUtility_strcmp(buf, "dns")==0) { RUN_TEST(TestDnsResolver_Test); - } - else if (McuUtility_strcmp(buf, "dummy")==0) { - RUN_TEST(TestDummy); } else { RUN_TEST(TestArgFailed);