Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MQTT regression test. #215

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .github/workflows/regression_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ jobs:
cmake_path: ./test/cmake/web
result_affix: Web
skip_deploy: true
MQTT:
permissions:
contents: read
issues: read
checks: write
pull-requests: write
pages: write
id-token: write
uses: azure-rtos/threadx/.github/workflows/regression_template.yml@master
with:
build_script: ./scripts/build_mqtt.sh
test_script: ./scripts/test_mqtt.sh
cmake_path: ./test/cmake/mqtt
result_affix: MQTT
skip_deploy: true
Deploy:
permissions:
contents: read
Expand All @@ -51,8 +66,8 @@ jobs:
pull-requests: write
pages: write
id-token: write
needs: [NetXDuo, Web]
needs: [NetXDuo, Web, MQTT]
uses: azure-rtos/threadx/.github/workflows/regression_template.yml@master
with:
skip_test: true
deploy_list: "NetXDuo Web"
deploy_list: "NetXDuo Web MQTT"
3 changes: 3 additions & 0 deletions scripts/build_mqtt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

$(dirname `realpath $0`)/../test/cmake/mqtt/run.sh build all
3 changes: 3 additions & 0 deletions scripts/test_mqtt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

CTEST_PARALLEL_LEVEL=4 $(dirname `realpath $0`)/../test/cmake/mqtt/run.sh test all
106 changes: 106 additions & 0 deletions test/cmake/mqtt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0057 NEW)
cmake_policy(SET CMP0077 NEW)

project(mqtt_test LANGUAGES C)

# Set build configurations
set(BUILD_CONFIGURATIONS
default_build_coverage secure_build_coverage require_secure_build queue_depth_build
cloud_default_build_coverage cloud_secure_build_coverage
cloud_require_secure_build cloud_queue_depth_build
websocket_secure_build)
set(CMAKE_CONFIGURATION_TYPES
${BUILD_CONFIGURATIONS}
CACHE STRING "list of supported configuration types" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
${CMAKE_CONFIGURATION_TYPES})
list(GET CMAKE_CONFIGURATION_TYPES 0 BUILD_TYPE)
if((NOT CMAKE_BUILD_TYPE) OR (NOT ("${CMAKE_BUILD_TYPE}" IN_LIST
CMAKE_CONFIGURATION_TYPES)))
set(CMAKE_BUILD_TYPE
"${BUILD_TYPE}"
CACHE STRING "Build Type of the project" FORCE)
endif()

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")

set(SECURE -DNX_SECURE_ENABLE)
set(REQUIRE_TLS -DNXD_MQTT_REQUIRE_TLS)
set(QUEUE_DEPTH -DNXD_MQTT_MAXIMUM_TRANSMIT_QUEUE_DEPTH=20)
set(CLOUD -DNXD_MQTT_CLOUD_ENABLE)
set(WEBSOCKET -DNXD_MQTT_OVER_WEBSOCKET)

set(default_build_coverage)
set(secure_build_coverage ${SECURE})
set(require_secure_build ${SECURE} ${REQUIRE_TLS})
set(queue_depth_build ${QUEUE_DEPTH})

set(cloud_default_build_coverage ${CLOUD})
set(cloud_secure_build_coverage ${SECURE} ${CLOUD})
set(cloud_require_secure_build ${SECURE} ${REQUIRE_TLS} ${CLOUD})
set(cloud_queue_depth_build ${CLOUD} ${QUEUE_DEPTH})

set(websocket_secure_build ${WEBSOCKET} ${SECURE} -DNX_ENABLE_EXTENDED_NOTIFY_SUPPORT)

add_compile_options(
-m32
-ggdb
-g3
-gdwarf-2
-fdiagnostics-color
-DTX_INCLUDE_USER_DEFINE_FILE
${${CMAKE_BUILD_TYPE}})
add_link_options(-m32)

enable_testing()

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../.. netxduo)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/regression regression)

# Coverage
if(CMAKE_BUILD_TYPE MATCHES ".*_coverage")
target_compile_options(netxduo PRIVATE -fprofile-arcs -ftest-coverage)
target_link_options(netxduo PRIVATE -fprofile-arcs -ftest-coverage)
endif()

# Build ThreadX library once
execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run.sh build_libs)
add_custom_target(build_libs ALL COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run.sh
build_libs)
add_dependencies(netxduo build_libs)
target_include_directories(netxduo PUBLIC ${CMAKE_BINARY_DIR}/../libs/inc)
add_library(threadx SHARED IMPORTED GLOBAL)
add_library("azrtos::threadx" ALIAS threadx)
set_target_properties(
threadx PROPERTIES IMPORTED_LOCATION
${CMAKE_BINARY_DIR}/../libs/threadx/libthreadx.so)
add_library(filex SHARED IMPORTED GLOBAL)
add_library("azrtos::filex" ALIAS filex)
set_target_properties(
filex PROPERTIES IMPORTED_LOCATION
${CMAKE_BINARY_DIR}/../libs/filex/libfilex.so)
target_link_libraries(netxduo PUBLIC filex)

target_compile_options(
netxduo
PRIVATE -Werror
-std=c99
-Wall
-Wextra
-pedantic
-fmessage-length=0
-fsigned-char
-ffunction-sections
-fdata-sections
-Wunused
-Wuninitialized
-Wmissing-declarations
-Wconversion
-Wpointer-arith
-Wshadow
-Wlogical-op
-Waggregate-return
-Wfloat-equal)
8 changes: 8 additions & 0 deletions test/cmake/mqtt/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e

cd $(dirname $0)
mkdir -p coverage_report/$1
gcovr --object-directory=build/$1/netxduo/CMakeFiles/netxduo.dir/addons/mqtt -r ../../../addons/mqtt --xml-pretty --output coverage_report/$1.xml
gcovr --object-directory=build/$1/netxduo/CMakeFiles/netxduo.dir/addons/mqtt -r ../../../addons/mqtt --html --html-details --output coverage_report/$1/index.html
1 change: 1 addition & 0 deletions test/cmake/mqtt/libs
61 changes: 61 additions & 0 deletions test/cmake/mqtt/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
cmake_policy(SET CMP0057 NEW)

project(regression_test LANGUAGES C)

get_filename_component(SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../regression
ABSOLUTE)

set(mqtt_test_cases
${SOURCE_DIR}/mqtt_test/netx_mqtt_api_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connect_auth_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connect_auth_empty_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connect_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connect_packet_send_failure_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connect_v6_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connect_non_block_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connect_non_block_2_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_null_password_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_publish_qos0_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_publish_qos1_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_receive_qos0_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_receive_qos1_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_subscribe_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_unsubscribe_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connect_will_message_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connect_will_topic_only_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_not_connected_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connect_with_auth_will_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_keepalive_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_keepalive_timeout_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_multiple_receive_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_remaining_length_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_publish_non_zero_packet_id_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_subscribe_non_zero_packet_id_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_packet_leak_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_receive_span_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_publish_packet_chain_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_subscribe_packet_chain_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_connack_error_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_branch_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_transmit_queue_depth_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_websocket_non_block_test.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_websocket_block_test.c)

set(test_utility_files
${SOURCE_DIR}/test/nx_ram_network_driver_test_1500.c
${SOURCE_DIR}/mqtt_test/netx_mqtt_testcontrol.c)

add_library(test_utility ${test_utility_files})
target_link_libraries(test_utility PUBLIC azrtos::netxduo)
target_include_directories(test_utility PUBLIC ${SOURCE_DIR}/test)
target_compile_definitions(test_utility PUBLIC BATCH_TEST CTEST)

foreach(
test_case
${mqtt_test_cases})
get_filename_component(test_name ${test_case} NAME_WE)
add_executable(${test_name} ${test_case})
target_link_libraries(${test_name} PRIVATE test_utility)
add_test(${CMAKE_BUILD_TYPE}::${test_name} ${test_name})
endforeach()
9 changes: 9 additions & 0 deletions test/cmake/mqtt/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

cd $(dirname $0)

# if threadx repo does not exist, clone it
[ -d ../threadx ] || git clone https://github.com/azure-rtos/threadx.git ../threadx --depth 1
[ -d ../filex ] || git clone https://github.com/azure-rtos/filex.git ../filex --depth 1
[ -f .run.sh ] || ln -sf ../threadx/scripts/cmake_bootstrap.sh .run.sh
./.run.sh $*