From 28087b7cb80fb3c64c292395076ca080b9240c23 Mon Sep 17 00:00:00 2001 From: Wenhui Xie <54433186+wenhui-xie@users.noreply.github.com> Date: Mon, 4 Dec 2023 15:17:05 +0800 Subject: [PATCH] Add Web regression test. (#213) --- .github/workflows/regression_test.yml | 19 ++++- scripts/build_web.sh | 3 + scripts/test_web.sh | 3 + test/cmake/web/CMakeLists.txt | 94 ++++++++++++++++++++++++ test/cmake/web/coverage.sh | 8 ++ test/cmake/web/libs | 1 + test/cmake/web/regression/CMakeLists.txt | 80 ++++++++++++++++++++ test/cmake/web/run.sh | 9 +++ 8 files changed, 215 insertions(+), 2 deletions(-) create mode 100755 scripts/build_web.sh create mode 100755 scripts/test_web.sh create mode 100644 test/cmake/web/CMakeLists.txt create mode 100755 test/cmake/web/coverage.sh create mode 120000 test/cmake/web/libs create mode 100644 test/cmake/web/regression/CMakeLists.txt create mode 100755 test/cmake/web/run.sh diff --git a/.github/workflows/regression_test.yml b/.github/workflows/regression_test.yml index d9256157..654f17ef 100644 --- a/.github/workflows/regression_test.yml +++ b/.github/workflows/regression_test.yml @@ -28,6 +28,21 @@ jobs: cmake_path: ./test/cmake/netxduo result_affix: NetXDuo skip_deploy: true + Web: + 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_web.sh + test_script: ./scripts/test_web.sh + cmake_path: ./test/cmake/web + result_affix: Web + skip_deploy: true Deploy: permissions: contents: read @@ -36,8 +51,8 @@ jobs: pull-requests: write pages: write id-token: write - needs: [NetXDuo] + needs: [NetXDuo, Web] uses: azure-rtos/threadx/.github/workflows/regression_template.yml@master with: skip_test: true - deploy_list: "NetXDuo" \ No newline at end of file + deploy_list: "NetXDuo Web" \ No newline at end of file diff --git a/scripts/build_web.sh b/scripts/build_web.sh new file mode 100755 index 00000000..a8bee025 --- /dev/null +++ b/scripts/build_web.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +$(dirname `realpath $0`)/../test/cmake/web/run.sh build all diff --git a/scripts/test_web.sh b/scripts/test_web.sh new file mode 100755 index 00000000..a77050dd --- /dev/null +++ b/scripts/test_web.sh @@ -0,0 +1,3 @@ +#! /bin/bash + +CTEST_PARALLEL_LEVEL=4 $(dirname `realpath $0`)/../test/cmake/web/run.sh test all diff --git a/test/cmake/web/CMakeLists.txt b/test/cmake/web/CMakeLists.txt new file mode 100644 index 00000000..d3695f00 --- /dev/null +++ b/test/cmake/web/CMakeLists.txt @@ -0,0 +1,94 @@ +cmake_minimum_required(VERSION 3.13 FATAL_ERROR) +cmake_policy(SET CMP0054 NEW) +cmake_policy(SET CMP0057 NEW) +cmake_policy(SET CMP0077 NEW) + +project(web_test LANGUAGES C) + +# Set build configurations +set(BUILD_CONFIGURATIONS default_build_coverage no_tls_build_coverage + digest_authenticate_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_WEB_HTTPS_ENABLE -DNX_TCPSERVER_ENABLE_TLS -DNX_SECURE_ENABLE_CLIENT_CERTIFICATE_VERIFY) +set(MULTIPART -DNX_WEB_HTTP_MULTIPART_ENABLE) +set(DIGEST -DNX_WEB_HTTP_DIGEST_ENABLE) + +set(default_build_coverage ${SECURE} ${MULTIPART} -DNX_ENABLE_EXTENDED_NOTIFY_SUPPORT) +set(no_tls_build_coverage ${MULTIPART}) +set(digest_authenticate_build ${SECURE} ${MULTIPART} ${DIGEST}) + +add_compile_options( + -m32 + -std=c99 + -ggdb + -g3 + -gdwarf-2 + -fdiagnostics-color + -Werror + -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 + -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) diff --git a/test/cmake/web/coverage.sh b/test/cmake/web/coverage.sh new file mode 100755 index 00000000..3ebcb55f --- /dev/null +++ b/test/cmake/web/coverage.sh @@ -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/web -r ../../../addons/web --xml-pretty --output coverage_report/$1.xml +gcovr --object-directory=build/$1/netxduo/CMakeFiles/netxduo.dir/addons/web -r ../../../addons/web --html --html-details --output coverage_report/$1/index.html diff --git a/test/cmake/web/libs b/test/cmake/web/libs new file mode 120000 index 00000000..d4bda9b4 --- /dev/null +++ b/test/cmake/web/libs @@ -0,0 +1 @@ +../libs \ No newline at end of file diff --git a/test/cmake/web/regression/CMakeLists.txt b/test/cmake/web/regression/CMakeLists.txt new file mode 100644 index 00000000..9111f250 --- /dev/null +++ b/test/cmake/web/regression/CMakeLists.txt @@ -0,0 +1,80 @@ +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(web_test_cases + ${SOURCE_DIR}/web_test/netx_https_api_test.c + ${SOURCE_DIR}/web_test/netx_web_basic_test.c + ${SOURCE_DIR}/web_test/netx_web_basic_ecc_test.c + ${SOURCE_DIR}/web_test/netx_web_head_basic_test.c + ${SOURCE_DIR}/web_test/netx_web_post_basic_test.c + ${SOURCE_DIR}/web_test/netx_web_put_basic_test.c + ${SOURCE_DIR}/web_test/netx_web_delete_basic_test.c + ${SOURCE_DIR}/web_test/netx_web_basic_authenticate_test.c + ${SOURCE_DIR}/web_test/netx_web_if_modified_since_test.c + ${SOURCE_DIR}/web_test/netx_web_get_content_length_test.c + ${SOURCE_DIR}/web_test/netx_web_request_in_multiple_packets_test.c + ${SOURCE_DIR}/web_test/netx_web_multipart_fragment_test.c + ${SOURCE_DIR}/web_test/netx_web_multipart_underflow_test.c + ${SOURCE_DIR}/web_test/netx_web_get_put_referred_URI_test.c + ${SOURCE_DIR}/web_test/netx_web_status_404_test.c + ${SOURCE_DIR}/web_test/netx_web_multiple_sessions_test.c + ${SOURCE_DIR}/web_test/netx_web_multiple_sessions_timeout_test.c + ${SOURCE_DIR}/web_test/netx_web_response_in_multiple_packets_test.c + ${SOURCE_DIR}/web_test/netx_web_connect_three_times_test.c + ${SOURCE_DIR}/web_test/netx_web_keep_alive_test.c + ${SOURCE_DIR}/web_test/netx_web_digest_authenticate_test.c + ${SOURCE_DIR}/web_test/netx_web_digest_authenticate_test2.c + ${SOURCE_DIR}/web_test/netx_web_server_content_process_test.c + ${SOURCE_DIR}/web_test/netx_web_concurrent_sessions_test.c + ${SOURCE_DIR}/web_test/netx_web_post_long_message_test.c + ${SOURCE_DIR}/web_test/netx_web_host_field_test.c + ${SOURCE_DIR}/web_test/netx_web_chunked_request_test.c + ${SOURCE_DIR}/web_test/netx_web_chunked_request_additional_test.c + ${SOURCE_DIR}/web_test/netx_web_chunked_response_test.c + ${SOURCE_DIR}/web_test/netx_web_chunked_response_process_test.c + ${SOURCE_DIR}/web_test/netx_web_chunked_response_packet_chain_test.c + ${SOURCE_DIR}/web_test/netx_web_client_cleanup_test.c + ${SOURCE_DIR}/web_test/netx_web_server_chunked_content_process_test.c + ${SOURCE_DIR}/web_test/netx_web_packet_allocate_test.c + ${SOURCE_DIR}/web_test/netx_web_status_code_test.c + ${SOURCE_DIR}/web_test/netx_web_secure_connect_fail_test.c + ${SOURCE_DIR}/web_test/netx_web_tcpserver_rst_test.c + ${SOURCE_DIR}/web_test/netx_web_tcpserver_two_listen_test.c + ${SOURCE_DIR}/web_test/netx_web_abnormal_test.c + ${SOURCE_DIR}/web_test/netx_web_client_send_fail_test.c + ${SOURCE_DIR}/web_test/netx_web_client_receive_no_packet_test.c + ${SOURCE_DIR}/web_test/netx_web_keep_alive_abnormal_test.c + ${SOURCE_DIR}/web_test/netx_web_one_session_test.c + ${SOURCE_DIR}/web_test/netx_web_server_type_get_extended_test.c + ${SOURCE_DIR}/web_test/netx_web_secure_reconnect_test.c + ${SOURCE_DIR}/web_test/netx_web_non_block_basic_test.c + ${SOURCE_DIR}/web_test/netx_web_non_block_reconnect_test.c + ${SOURCE_DIR}/web_test/netx_web_tcpserver_tls_fail_rst_test.c + ${SOURCE_DIR}/web_test/netx_web_invalid_release_test.c + ${SOURCE_DIR}/web_test/netx_web_certifiacte_verify_test.c + ${SOURCE_DIR}/web_test/netx_web_client_rst_test.c + ${SOURCE_DIR}/web_test/netx_web_basic_authenticate_empty_test.c + ${SOURCE_DIR}/web_test/netx_web_digest_authenticate_timeout_test.c) + +set(test_utility_files + ${SOURCE_DIR}/test/nx_ram_network_driver_test_1500.c + ${SOURCE_DIR}/web_test/netx_https_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 + ${web_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() diff --git a/test/cmake/web/run.sh b/test/cmake/web/run.sh new file mode 100755 index 00000000..ff51762d --- /dev/null +++ b/test/cmake/web/run.sh @@ -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 $* \ No newline at end of file