Skip to content

Commit fceacf6

Browse files
authored
Add MQTT interoperability test. (#223)
1 parent 050f07b commit fceacf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4206
-2
lines changed

.github/workflows/regression_test.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ jobs:
174174
cmake_path: ./test/cmake/nx_secure_interoperability
175175
result_affix: Secure_Interoperability
176176
skip_deploy: true
177+
MQTT_Interoperability:
178+
permissions:
179+
contents: read
180+
issues: read
181+
checks: write
182+
pull-requests: write
183+
pages: write
184+
id-token: write
185+
uses: azure-rtos/threadx/.github/workflows/regression_template.yml@master
186+
with:
187+
install_script: ./scripts/install_mqtt.sh
188+
build_script: ./scripts/build_mqtt_interoperability.sh
189+
test_script: ./scripts/test_mqtt_interoperability.sh
190+
cmake_path: ./test/cmake/mqtt_interoperability
191+
result_affix: MQTT_Interoperability
192+
skip_deploy: true
177193
Deploy:
178194
permissions:
179195
contents: read
@@ -182,8 +198,8 @@ jobs:
182198
pull-requests: write
183199
pages: write
184200
id-token: write
185-
needs: [NetXDuo, Web, MQTT, NetXDuo64, NetXDuo_Fast, Azure_IoT, Secure, Crypto, Secure_Interoperability]
201+
needs: [NetXDuo, Web, MQTT, NetXDuo64, NetXDuo_Fast, Azure_IoT, Secure, Crypto, Secure_Interoperability, MQTT_Interoperability]
186202
uses: azure-rtos/threadx/.github/workflows/regression_template.yml@master
187203
with:
188204
skip_test: true
189-
deploy_list: "NetXDuo Web MQTT NetXDuo64 NetXDuo_Fast Azure_IoT Secure Crypto Secure_Interoperability"
205+
deploy_list: "NetXDuo Web MQTT NetXDuo64 NetXDuo_Fast Azure_IoT Secure Crypto Secure_Interoperability MQTT_Interoperability"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/bash
2+
3+
$(dirname `realpath $0`)/../test/cmake/mqtt_interoperability/run.sh build all

scripts/install_mqtt.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#! /bin/bash
2+
3+
sudo dpkg --add-architecture i386
4+
5+
sudo apt update
6+
sudo apt install -y \
7+
gcc-multilib \
8+
g++ \
9+
python3-pip \
10+
ninja-build \
11+
unifdef \
12+
dos2unix \
13+
gcovr \
14+
libpcap-dev:i386 libgcc-s1:i386 \
15+
ethtool \
16+
mosquitto \
17+
mosquitto-clients

scripts/test_mqtt_interoperability.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/bash
2+
3+
sudo CTEST_PARALLEL_LEVEL=1 $(dirname `realpath $0`)/../test/cmake/mqtt_interoperability/run.sh test all
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../mqtt/CMakeLists.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../mqtt/coverage.sh

test/cmake/mqtt_interoperability/libs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../libs
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
2+
cmake_policy(SET CMP0057 NEW)
3+
4+
project(regression_test LANGUAGES C)
5+
6+
get_filename_component(
7+
SOURCE_DIR
8+
${CMAKE_CURRENT_LIST_DIR}/../../../regression/interoperability_test/mqtt_test
9+
ABSOLUTE)
10+
11+
if(NOT "-DNXD_MQTT_REQUIRE_TLS" IN_LIST ${CMAKE_BUILD_TYPE})
12+
list(APPEND mqtt_test_cases mqtt_subscriber_test)
13+
set(mqtt_subscriber_test_file_list
14+
${SOURCE_DIR}/linux_mqtt_subscriber_test_entry.c
15+
${SOURCE_DIR}/linux_mqtt_subscriber_test_server.c
16+
${SOURCE_DIR}/linux_mqtt_subscriber_test_publisher.c
17+
${SOURCE_DIR}/netx_mqtt_subscriber_test.c)
18+
list(APPEND mqtt_test_cases mqtt_subscriber_empty_message_test)
19+
set(mqtt_subscriber_empty_message_test_file_list
20+
${SOURCE_DIR}/linux_mqtt_subscriber_test_entry.c
21+
${SOURCE_DIR}/linux_mqtt_subscriber_test_server.c
22+
${SOURCE_DIR}/linux_mqtt_subscriber_empty_message_test_publisher.c
23+
${SOURCE_DIR}/netx_mqtt_subscriber_empty_message_test.c)
24+
endif()
25+
26+
if("-DNX_SECURE_ENABLE" IN_LIST ${CMAKE_BUILD_TYPE})
27+
list(APPEND mqtt_test_cases mqtt_tls_subscriber_twice_test)
28+
set(mqtt_tls_subscriber_twice_test_file_list
29+
${SOURCE_DIR}/linux_mqtt_tls_subscriber_test_entry.c
30+
${SOURCE_DIR}/linux_mqtt_tls_subscriber_test_server.c
31+
${SOURCE_DIR}/linux_mqtt_tls_subscriber_twice_test_publisher.c
32+
${SOURCE_DIR}/netx_mqtt_tls_subscriber_twice_test.c)
33+
34+
list(APPEND mqtt_test_cases mqtt_double_subscribers_test)
35+
set(mqtt_double_subscribers_test_file_list
36+
${SOURCE_DIR}/linux_mqtt_tls_subscriber_test_entry.c
37+
${SOURCE_DIR}/linux_mqtt_tls_subscriber_test_server.c
38+
${SOURCE_DIR}/linux_mqtt_tls_subscriber_test_publisher.c
39+
${SOURCE_DIR}/netx_mqtt_double_subscribers_test.c)
40+
41+
list(APPEND mqtt_test_cases mqtt_tls_subscriber_test)
42+
set(mqtt_tls_subscriber_test_file_list
43+
${SOURCE_DIR}/linux_mqtt_tls_subscriber_test_entry.c
44+
${SOURCE_DIR}/linux_mqtt_tls_subscriber_test_server.c
45+
${SOURCE_DIR}/linux_mqtt_tls_subscriber_test_publisher.c
46+
${SOURCE_DIR}/netx_mqtt_tls_subscriber_test.c)
47+
48+
list(APPEND debug_secure_build_mqtt_test_cases mqtt_tls_debug_test)
49+
set(mqtt_tls_debug_test_file_list
50+
${SOURCE_DIR}/netx_mqtt_tls_subscriber_test.c)
51+
endif()
52+
53+
set(test_utility_files
54+
${SOURCE_DIR}/netxtestcontrol.c
55+
${SOURCE_DIR}/nx_crypto_ciphersuites_regression.c
56+
${SOURCE_DIR}/nx_ram_network_driver_test_1500.c
57+
${SOURCE_DIR}/nx_secure_fips_test_utility.c)
58+
59+
get_filename_component(
60+
UTILITY_SOURCE_DIR
61+
${CMAKE_CURRENT_LIST_DIR}/../../../regression/interoperability_test/test_frame
62+
ABSOLUTE)
63+
add_library(
64+
test_utility
65+
${UTILITY_SOURCE_DIR}/tls_test_get_external_test_process_output.c
66+
${UTILITY_SOURCE_DIR}/tls_test_launch_external_test_process.c
67+
${UTILITY_SOURCE_DIR}/tls_test_launch_external_test_process_in_background.c
68+
${UTILITY_SOURCE_DIR}/tls_test_director_clean_all.c
69+
${UTILITY_SOURCE_DIR}/tls_test_director_cleanup_registered_instances.c
70+
${UTILITY_SOURCE_DIR}/tls_test_director_create.c
71+
${UTILITY_SOURCE_DIR}/tls_test_director_destroy.c
72+
${UTILITY_SOURCE_DIR}/tls_test_director_register_test_instance.c
73+
${UTILITY_SOURCE_DIR}/tls_test_director_test_start.c
74+
${UTILITY_SOURCE_DIR}/tls_test_instance_attributes_access.c
75+
${UTILITY_SOURCE_DIR}/tls_test_instance_append.c
76+
${UTILITY_SOURCE_DIR}/tls_test_instance_create.c
77+
${UTILITY_SOURCE_DIR}/tls_test_instance_destroy.c
78+
${UTILITY_SOURCE_DIR}/tls_test_instance_find_next.c
79+
${UTILITY_SOURCE_DIR}/tls_test_instance_set_exit_status.c
80+
${UTILITY_SOURCE_DIR}/tls_test_instance_shared_buffer_manipulate.c
81+
${UTILITY_SOURCE_DIR}/tls_test_kill_external_test_process.c
82+
${UTILITY_SOURCE_DIR}/tls_test_semaphore_create.c
83+
${UTILITY_SOURCE_DIR}/tls_test_semaphore_destroy.c
84+
${UTILITY_SOURCE_DIR}/tls_test_semaphore_post.c
85+
${UTILITY_SOURCE_DIR}/tls_test_semaphore_wait.c
86+
${UTILITY_SOURCE_DIR}/tls_test_wait_all_child_process.c
87+
${UTILITY_SOURCE_DIR}/tls_test_wait_external_test_process.c
88+
${UTILITY_SOURCE_DIR}/tls_test_uninterruptable_wait.c)
89+
target_link_libraries(test_utility PUBLIC azrtos::netxduo)
90+
target_include_directories(test_utility PUBLIC ${UTILITY_SOURCE_DIR})
91+
92+
include(network_config.cmake)
93+
94+
set(PCAP_SOURCE
95+
${CMAKE_CURRENT_LIST_DIR}/../../../regression/interoperability_test/nx_pcap_network_driver.c
96+
)
97+
foreach(test_case ${mqtt_test_cases})
98+
add_executable(${test_case} ${${test_case}_file_list} ${PCAP_SOURCE})
99+
network_config(${test_case})
100+
target_link_libraries(${test_case} PRIVATE test_utility pcap)
101+
add_test(
102+
NAME ${CMAKE_BUILD_TYPE}::${test_case}
103+
COMMAND
104+
bash -c
105+
"export PATH=${SOURCE_DIR}/test_scripts/:$PATH;
106+
ip link del ${${test_case}_interface}>/dev/null 2>&1;
107+
ip link add ${${test_case}_interface} type veth peer name ${${test_case}_remote_interface} || exit 1;
108+
ifconfig ${${test_case}_interface} up || { ip link del ${${test_case}_interface}; exit 1; };
109+
ifconfig ${${test_case}_remote_interface} ${${test_case}_remote_ip} up netmask ${TEST_NETMASK} || { ip link del ${${test_case}_interface};exit 1; };
110+
ethtool --offload ${${test_case}_remote_interface} tx off || { ip link del ${${test_case}_interface}; exit 1; };
111+
tcpdump -i ${${test_case}_remote_interface} -s 0 -w ${CMAKE_CURRENT_BINARY_DIR}/${test_case}.pcap&
112+
pid=$!
113+
${CMAKE_CURRENT_BINARY_DIR}/${test_case};
114+
exit_code=$?
115+
sleep 1;
116+
kill -TERM $pid
117+
ip link del ${${test_case}_interface} || exit 1;
118+
[[ $exit_code = 0 ]] || [[ $exit_code = 233 ]] || { echo Exit code: $exit_code; exit $exit_code; };"
119+
WORKING_DIRECTORY ${SOURCE_DIR})
120+
endforeach()
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
if(NOT ALLOCATION_PARAMETER)
2+
execute_process(COMMAND bash "-c" "git rev-parse --verify HEAD|cut -c1-1"
3+
OUTPUT_VARIABLE ALLOCATION_PARAMETER)
4+
math(EXPR ALLOCATION_PARAMETER "0x${ALLOCATION_PARAMETER}")
5+
endif()
6+
7+
if(NOT TEST_SUBNET_SIZE)
8+
set(TEST_SUBNET_SIZE 4)
9+
endif()
10+
11+
# NX_MAX_PORT is 0xffff.
12+
math(EXPR PORT_NUMBER "65535 - (${ALLOCATION_PARAMETER} + 1) * 256")
13+
set(INTERFACE_NUMBER ${PORT_NUMBER})
14+
math(EXPR TMP "256 - ${TEST_SUBNET_SIZE}")
15+
set(TEST_NETMASK 255.255.255.${TMP})
16+
17+
set(IP_BYTE_0 10)
18+
set(IP_BYTE_1 10)
19+
set(IP_BYTE_2 ${ALLOCATION_PARAMETER})
20+
set(IP_BYTE_3 1)
21+
set(IP_BYTE_4 2)
22+
23+
macro(network_config target)
24+
target_compile_definitions(
25+
${target}
26+
PRIVATE
27+
-DINTEROPERABILITY_TEST_ENABLE_PARALLEL_PROCESSING
28+
-DTLS_TEST_IP_BYTE_0=${IP_BYTE_0}
29+
-DTLS_TEST_IP_BYTE_1=${IP_BYTE_1}
30+
-DTLS_TEST_IP_BYTE_2=${IP_BYTE_2}
31+
-DTLS_TEST_IP_BYTE_3=${IP_BYTE_3}
32+
-DREMOTE_IP_BYTE_0=${IP_BYTE_0}
33+
-DREMOTE_IP_BYTE_1=${IP_BYTE_1}
34+
-DREMOTE_IP_BYTE_2=${IP_BYTE_2}
35+
-DREMOTE_IP_BYTE_3=${IP_BYTE_4}
36+
-DDEVICE_SERVER_PORT=${PORT_NUMBER}
37+
-DNX_PCAP_SOURCE_NAME=\"veth${INTERFACE_NUMBER}\")
38+
set(${target}_interface veth${INTERFACE_NUMBER})
39+
set(${target}_ip ${IP_BYTE_0}.${IP_BYTE_1}.${IP_BYTE_2}.${IP_BYTE_3})
40+
math(EXPR INTERFACE_NUMBER "${INTERFACE_NUMBER} + 1")
41+
set(${target}_remote_interface veth${INTERFACE_NUMBER})
42+
set(${target}_remote_ip ${IP_BYTE_0}.${IP_BYTE_1}.${IP_BYTE_2}.${IP_BYTE_4})
43+
set(${target}_port ${PORT_NUMBER})
44+
45+
# Increase numbers for next setup
46+
math(EXPR INTERFACE_NUMBER "${INTERFACE_NUMBER} + 1")
47+
math(EXPR IP_BYTE_3 "${IP_BYTE_3} + ${TEST_SUBNET_SIZE}")
48+
if(${IP_BYTE_3} GREATER 253)
49+
math(EXPR IP_BYTE_2 "${IP_BYTE_2} + 1")
50+
set(IP_BYTE_3 1)
51+
endif()
52+
math(EXPR IP_BYTE_4 "${IP_BYTE_3} + 1")
53+
math(EXPR PORT_NUMBER "${PORT_NUMBER} + 1")
54+
55+
endmacro()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
cd $(dirname $0)
4+
5+
# if threadx repo does not exist, clone it
6+
[ -d ../threadx ] || git clone https://github.com/azure-rtos/threadx.git ../threadx --depth 1
7+
[ -d ../filex ] || git clone https://github.com/azure-rtos/filex.git ../filex --depth 1
8+
[ -f .run.sh ] || ln -sf ../threadx/scripts/cmake_bootstrap.sh .run.sh
9+
CTEST_PARALLEL_LEVEL=1 ENABLE_IDLE=ON ./.run.sh $*

0 commit comments

Comments
 (0)