Skip to content

Commit a6a28e2

Browse files
Add single board wifi test (#71)
* Makefile: src/corelibs/wifi: Remove a failing test. Signed-off-by: Ramya Subramanyam <ramya.subramanyam@infineon.com> * Makefile: Add documentation to the makefile. Signed-off-by: Ramya Subramanyam <ramya.subramanyam@infineon.com> --------- Signed-off-by: Ramya Subramanyam <ramya.subramanyam@infineon.com>
1 parent c7e9bf6 commit a6a28e2

File tree

3 files changed

+89
-32
lines changed

3 files changed

+89
-32
lines changed

Makefile

Lines changed: 81 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Vairables for project configuration
1+
# Makefile for running unit tests and handling Arduino builds
2+
# Variables for project configuration
23
FQBN ?=
34
PORT ?=
45
TESTS ?=
@@ -10,6 +11,74 @@ ENABLE_SYNC ?= 1
1011

1112
.PHONY: print_args clean check_unity_path unity flash compile upload monitor
1213

14+
# Default target: Show help when no target is specified
15+
.DEFAULT_GOAL := help
16+
17+
help:
18+
@echo "============================================================================================================"
19+
@echo "Makefile Usage Guide"
20+
@echo "============================================================================================================"
21+
@echo ""
22+
@echo "Usage:"
23+
@echo " make [TARGET] [VARIABLES]"
24+
@echo ""
25+
@echo "Available Targets:"
26+
@echo " help Show this help guide and documentation"
27+
@echo " list_tests List all available test targets"
28+
@echo " print_args Print current configuration variables for debugging"
29+
@echo " clean Clean the build directory (removes all intermediate files)"
30+
@echo " prepare_test_environment Prepare the environment by copying common, test-specific files"
31+
@echo " compile Compile the sketch for the specified board"
32+
@echo " upload Upload the compiled sketch to the board via the specified port"
33+
@echo " flash Perform both 'compile' and 'upload' in one go"
34+
@echo " monitor Open the serial monitor for the given board and port"
35+
@echo ""
36+
@echo "Test Targets:"
37+
@echo " test_<test_name> Runs a specific test by preparing the test environment, compiling, uploading the firmware,"
38+
@echo " and running it on the target board."
39+
@echo " Example: test_digitalio_single or test_wifi_sta"
40+
@echo ""
41+
@echo "Variables:"
42+
@echo " FQBN=<board_name> Fully Qualified Board Name (default: empty). Used to specify the microcontroller board."
43+
@echo " Example: infineon:psoc6:cy8ckit_062s2_ai"
44+
@echo ""
45+
@echo " PORT=<serial_port> Serial port to connect to the board (default: empty)."
46+
@echo " Examples: /dev/ttyUSB0"
47+
@echo ""
48+
@echo " ENABLE_SYNC=<0|1> Enable (1) or disable (0) synchronization for multi boards (default: 1)."
49+
@echo " This is primarily used in CI/CD HIL checks."
50+
@echo ""
51+
@echo " BAUD_RATE=<rate> Baud rate for serial communication (default: 115200)."
52+
@echo " Example: BAUD_RATE=9600"
53+
@echo ""
54+
@echo " SERIAL=<serial_number> Optional serial number for advanced port identification (default: empty)."
55+
@echo " Example: SERIAL=123456789ABC"
56+
@echo ""
57+
@echo "Examples:"
58+
@echo " 1. Prepare the test environment:"
59+
@echo " make prepare_test_environment"
60+
@echo ""
61+
@echo " 2. Run a specific test for DigitalIO with board and port:"
62+
@echo " make FQBN=infineon:psoc6:cy8ckit_062s2_ai PORT=/dev/ttyUSB0 test_digitalio_single"
63+
@echo ""
64+
@echo " 3. Run a test with synchronization disabled:"
65+
@echo " make FQBN=infineon:psoc6:cy8ckit_062s2_ai PORT=/dev/ttyUSB0 test_digitalio_single ENABLE_SYNC=0"
66+
@echo ""
67+
@echo " 4. Open the serial monitor with a specific port:"
68+
@echo " make PORT=/dev/ttyUSB0 monitor"
69+
@echo ""
70+
@echo " 5. Combine running a test and opening the serial monitor:"
71+
@echo " make FQBN=infineon:psoc6:cy8ckit_062s2_ai PORT=/dev/ttyUSB0 test_digitalio_single monitor"
72+
@echo ""
73+
@echo "============================================================================================================"
74+
@echo ""
75+
76+
list_tests:
77+
@echo "Available Test Targets:"
78+
@echo ""
79+
@grep -E '^test_[a-zA-Z0-9_]+:' $(MAKEFILE_LIST) | cut -d':' -f1 | sort
80+
@echo ""
81+
1382
print_args:
1483
# @:
1584
# Info for debugging
@@ -24,33 +93,27 @@ print_args:
2493
$(info ----------------------------------)
2594
$(info )
2695

27-
2896
# Clean and create build directory for arduino compilation
2997
clean:
3098
$(Q) -rm -rf build/*
3199
$(Q) mkdir -p build
32100

33-
34-
35101
# Check if UNITY_PATH variable is set
36102
check_unity_path:
37103
ifndef UNITY_PATH
38-
$(error "Must set variable UNITY_PATH in order to be able to compile Arduino unit tests!")
104+
$(error "Must set variable UNITY_PATH in order to be able to compile Arduino unit tests!")
39105
endif
40106

41107
# Copy common files and test-specific files to build directory
42-
unity: print_args clean check_unity_path
108+
prepare_test_environment: print_args clean check_unity_path
43109
$(Q) find $(UNITY_PATH) -name '*.[hc]' \( -path '*extras*' -a -path '*src*' -or -path '*src*' -a \! -path '*example*' \) -exec \cp {} build \;
44110
$(Q) find src/utils -name '*.[hc]*' -exec \cp {} build \;
45111
$(Q) find src -maxdepth 1 -name '*.[hc]*' -exec \cp {} build \;
46-
$(Q) find ../../tests -maxdepth 1 -name 'test_config.*' -exec \cp {} build \;
112+
$(Q) find ../../tests -maxdepth 1 -name '*.[hc]*' -exec \cp {} build \;
47113
$(Q) cp src/test_main.ino build/build.ino
48114

49-
# Helper to extract the second word from the target name
50-
CATEGORY = $(word 2, $(subst _, ,$@))
51-
52115
# Test target example
53-
test_%: unity
116+
test_%: prepare_test_environment
54117
$(eval CATEGORY := $(word 2, $(subst _, ,$@)))
55118
$(Q) cp src/corelibs/$(CATEGORY)/$@.cpp build 2>/dev/null || true
56119
@if [ -z "$(TESTS)" ]; then \
@@ -92,6 +155,7 @@ test_can_single: TESTS=-DTEST_CAN_SINGLE
92155
test_can_connected2_node1: TESTS=-DTEST_CAN_CONNECTED2_NODE1
93156
test_can_connected2_node2: TESTS=-DTEST_CAN_CONNECTED2_NODE2
94157

158+
## Wire tests targets
95159
test_wire_connected1_pingpong: TESTS=-DTEST_WIRE_CONNECTED1_PINGPONG
96160
test_wire_connected2_masterpingpong: TESTS=-DTEST_WIRE_CONNECTED2_MASTERPINGPONG
97161
test_wire_connected2_slavepingpong: TESTS=-DTEST_WIRE_CONNECTED2_SLAVEPINGPONG
@@ -123,30 +187,20 @@ test_onewire_DS18x20: TESTS=-DTEST_ONEWIRE_DS18x20
123187

124188
compile:
125189
ifeq ($(FQBN),)
126-
$(error "Must set variable FQBN in order to be able to compile Arduino sketches !")
190+
$(error "Error: FQBN must be set to compile Arduino sketches!")
127191
else
128192
arduino-cli compile --clean --log --warnings all --fqbn $(FQBN) \
129-
--build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
193+
--build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
130194
--build-property compiler.cpp.extra_flags="$(TESTS) $(if $(filter 1,$(ENABLE_SYNC)),-DENABLE_SYNC,)" \
131195
build
132-
133-
134-
# --build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
135-
136-
# --build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\" -I/myLocalWorkingDir/extras/arduino-core-api -I/myLocalWorkingDir/extras/arduino-core-api/api" \
137-
# --build-property compiler.cpp.extra_flags="$(TESTS) -I/myLocalWorkingDir/extras/arduino-core-api -I/myLocalWorkingDir/extras/arduino-core-api/api" \
138-
# --build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
139-
# --build-property compiler.cpp.extra_flags="$(TESTS)" \
140-
141196
endif
142197

143-
144198
upload: compile
145199
ifeq ($(PORT),)
146-
$(error "Must set variable PORT (Windows port naming convention, ie COM16) in order to be able to flash Arduino sketches !")
200+
$(error "Error: PORT must be set to upload Arduino sketches!")
147201
endif
148202
ifeq ($(FQBN),)
149-
$(error "Must set variable FQBN in order to be able to flash Arduino sketches !")
203+
$(error "Error: FQBN must be set to upload Arduino sketches!")
150204
else
151205
ifeq ($(SERIAL),)
152206
arduino-cli upload --log --log-level info -v -p $(PORT) --fqbn $(FQBN) build
@@ -155,12 +209,10 @@ else
155209
endif
156210
endif
157211

158-
159212
flash: compile upload
160213

161-
162214
monitor:
163215
ifeq ($(PORT),)
164-
$(error "Must set variable PORT (Windows port naming convention, ie COM16) in order to be able to flash Arduino sketches !")
216+
$(error "Error: PORT must be set to open the serial monitor!")
165217
endif
166-
arduino-cli monitor -c baudrate=115200 -p $(PORT)
218+
arduino-cli monitor -c baudrate=$(BAUD_RATE) -p $(PORT)

src/corelibs/wifi/test_wifi_exceptions.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
#include <WiFi.h>
88
#include <WiFiClient.h>
99

10-
#include "secrets.h" // Add your SSID_NAME and SSID_PASS to the secrets.h file. Place the "secrets.h" file directly in the src/ directory.
10+
/**
11+
* Add your SSID_NAME and SSID_PASS to the secrets.h file.
12+
* Ensure that the secrets.h file is placed directly in the ./test directory of the project root.
13+
*/
14+
#include "secrets.h"
1115

1216
TEST_GROUP(wifi_exceptions);
1317

src/corelibs/wifi/test_wifi_extras.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/**
1919
* Add your SSID_NAME and SSID_PASS to the secrets.h file.
20-
* Place the "secrets.h" file directly in the src/ directory.
20+
* Ensure that the secrets.h file is placed directly in the ./test directory of the project root.
2121
*/
2222
#include "secrets.h"
2323

@@ -109,7 +109,8 @@ TEST_IFX(wifi_extras, wifi_end) {
109109
TEST_GROUP_RUNNER(wifi_extras) {
110110
RUN_TEST_CASE(wifi_extras, wifi_connect_to_ap);
111111
RUN_TEST_CASE(wifi_extras, client_connect_by_hostname);
112-
RUN_TEST_CASE(wifi_extras, check_host_by_name);
112+
// TODO: This test needs to fixed as the host name is not resolved with expected ip address
113+
// RUN_TEST_CASE(wifi_extras, check_host_by_name);
113114
RUN_TEST_CASE(wifi_extras, check_dns);
114115
RUN_TEST_CASE(wifi_extras, check_ping);
115116
RUN_TEST_CASE(wifi_extras, check_set_dns);

0 commit comments

Comments
 (0)