Skip to content

Commit 025ba86

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 025ba86

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

netutils/mqttc/CMakeLists.txt

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
############################################################################
1+
# ##############################################################################
22
# apps/netutils/mqttc/CMakeLists.txt
33
#
44
# SPDX-License-Identifier: Apache-2.0
55
#
6-
# Licensed to the Apache Software Foundation (ASF) under one or more
7-
# contributor license agreements. See the NOTICE file distributed with
8-
# this work for additional information regarding copyright ownership. The
9-
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10-
# "License"); you may not use this file except in compliance with the
11-
# License. You may obtain a copy of the License at
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
1212
#
13-
# http://www.apache.org/licenses/LICENSE-2.0
13+
# http://www.apache.org/licenses/LICENSE-2.0
1414
#
1515
# Unless required by applicable law or agreed to in writing, software
1616
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
1717
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18-
# License for the specific language governing permissions and limitations
19-
# under the License.
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
2020
#
21-
############################################################################
21+
# ##############################################################################
2222

2323
if(CONFIG_NETUTILS_MQTTC)
2424

@@ -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)