Skip to content

Commit dd7d2bb

Browse files
committed
apps/netutils: Modify the MQTT compilation file to enable MQTT testing
Modify the build and test files to make the MQTT test cases run. Signed-off-by: zhangshuai39 <[email protected]>
1 parent 8cb7dd0 commit dd7d2bb

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

netutils/mqttc/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,24 @@ if(CONFIG_NETUTILS_MQTTC)
124124
mqttc)
125125
endif()
126126
endif()
127+
128+
if(CONFIG_NETUTILS_MQTTC_TEST)
129+
set(MQTT_TEST_CFLAGS ${CFLAGS} -Dopen_nb_socket=test_open_nb_socket
130+
-Dpublish_callback=test_publish_callback)
131+
132+
nuttx_add_application(
133+
NAME
134+
cmocka_mqttc_test
135+
STACKSIZE
136+
${CONFIG_NETUTILS_MQTTC_TEST_STACKSIZE}
137+
PRIORITY
138+
${SCHED_PRIORITY_DEFAULT}
139+
SRCS
140+
${MQTTC_DIR}/tests.c
141+
COMPILE_FLAGS
142+
${MQTT_TEST_CFLAGS}
143+
DEPENDS
144+
cmocka
145+
mqttc)
146+
endif()
127147
endif()

netutils/mqttc/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ config NETUTILS_MQTTC_EXAMPLE
1717
---help---
1818
Enable MQTT-C example
1919

20+
config NETUTILS_MQTTC_TEST
21+
tristate "Enable MQTT-C test"
22+
default n
23+
2024
if NETUTILS_MQTTC_EXAMPLE
2125

2226
config NETUTILS_MQTTC_EXAMPLE_STACKSIZE
@@ -25,6 +29,14 @@ config NETUTILS_MQTTC_EXAMPLE_STACKSIZE
2529

2630
endif
2731

32+
if NETUTILS_MQTTC_TEST
33+
34+
config NETUTILS_MQTTC_TEST_STACKSIZE
35+
int "Task's stack size"
36+
default 8192
37+
38+
endif
39+
2840
config NETUTILS_MQTTC_WITH_MBEDTLS
2941
bool "Enable MQTT-C with mbedtls"
3042
default n

netutils/mqttc/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,17 @@ endif
8383

8484
endif
8585

86+
ifneq ($(CONFIG_NETUTILS_MQTTC_TEST),)
87+
$(MQTTC_UNPACK)$(DELIM)tests.c_CFLAGS += \
88+
-I$(APPDIR)$(DELIM)testing$(DELIM)cmocka$(DELIM)cmocka$(DELIM)include \
89+
-Dopen_nb_socket=test_open_nb_socket \
90+
-Dpublish_callback=test_publish_callback
91+
92+
PRIORITY = SCHED_PRIORITY_DEFAULT
93+
STACKSIZE = $(CONFIG_NETUTILS_MQTTC_TEST_STACKSIZE)
94+
MODULE = $(CONFIG_NETUTILS_MQTTC_TEST)
95+
MAINSRC += $(MQTTC_UNPACK)$(DELIM)tests.c
96+
PROGNAME += cmocka_mqttc_test
97+
endif
98+
8699
include $(APPDIR)/Application.mk

0 commit comments

Comments
 (0)