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 <zhangshuai39@xiaomi.com>
This commit is contained in:
zhangshuai39 2025-01-10 10:29:46 +08:00 • committed by Xiang Xiao
parent c4da1b5b9f
commit 26a969ac71
3 changed files with 56 additions and 11 deletions

View file

@ -1,24 +1,24 @@
############################################################################
# ##############################################################################
# apps/netutils/mqttc/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# License for the specific language governing permissions and limitations under
# the License.
#
############################################################################
# ##############################################################################
if(CONFIG_NETUTILS_MQTTC)
@ -124,4 +124,24 @@ if(CONFIG_NETUTILS_MQTTC)
mqttc)
endif()
endif()
if(CONFIG_NETUTILS_MQTTC_TEST)
set(MQTT_TEST_CFLAGS ${CFLAGS} -Dopen_nb_socket=test_open_nb_socket
-Dpublish_callback=test_publish_callback)
nuttx_add_application(
NAME
cmocka_mqttc_test
STACKSIZE
${CONFIG_NETUTILS_MQTTC_TEST_STACKSIZE}
PRIORITY
${SCHED_PRIORITY_DEFAULT}
SRCS
${MQTTC_DIR}/tests.c
COMPILE_FLAGS
${MQTT_TEST_CFLAGS}
DEPENDS
cmocka
mqttc)
endif()
endif()

View file

@ -17,6 +17,10 @@ config NETUTILS_MQTTC_EXAMPLE
---help---
Enable MQTT-C example
config NETUTILS_MQTTC_TEST
tristate "Enable MQTT-C test"
default n
if NETUTILS_MQTTC_EXAMPLE
config NETUTILS_MQTTC_EXAMPLE_STACKSIZE
@ -25,6 +29,14 @@ config NETUTILS_MQTTC_EXAMPLE_STACKSIZE
endif
if NETUTILS_MQTTC_TEST
config NETUTILS_MQTTC_TEST_STACKSIZE
int "Task's stack size"
default 8192
endif
config NETUTILS_MQTTC_WITH_MBEDTLS
bool "Enable MQTT-C with mbedtls"
default n

View file

@ -83,4 +83,17 @@ endif
endif
ifneq ($(CONFIG_NETUTILS_MQTTC_TEST),)
$(MQTTC_UNPACK)$(DELIM)tests.c_CFLAGS += \
-I$(APPDIR)$(DELIM)testing$(DELIM)cmocka$(DELIM)cmocka$(DELIM)include \
-Dopen_nb_socket=test_open_nb_socket \
-Dpublish_callback=test_publish_callback
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = $(CONFIG_NETUTILS_MQTTC_TEST_STACKSIZE)
MODULE = $(CONFIG_NETUTILS_MQTTC_TEST)
MAINSRC += $(MQTTC_UNPACK)$(DELIM)tests.c
PROGNAME += cmocka_mqttc_test
endif
include $(APPDIR)/Application.mk