diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f8ecdc68..58b87c798 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,7 @@ jobs: - name: Clone This Repo uses: actions/checkout@v2 with: - path: ./tcp + path: ./tcp - name: Install spell run: | sudo apt-get install spell @@ -115,19 +115,16 @@ jobs: run: git submodule update --init --checkout - name: Build checks (Enable all functionalities) run: | - cmake -S test/build-combination -B test/build-combination/build/ \ - -DTEST_CONFIGURATION=ENABLE_ALL - make -C test/build-combination/build/ + cmake -S . -B build/ -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL + make -C build/ - name: Build checks (Disable all functionalities) run: | - cmake -S test/build-combination -B test/build-combination/build/ \ - -DTEST_CONFIGURATION=DISABLE_ALL - make -C test/build-combination/build/ + cmake -S . -B build/ -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DISABLE_ALL + make -C build/ - name: Build checks (Default configuration) run: | - cmake -S test/build-combination -B test/build-combination/build/ \ - -DTEST_CONFIGURATION=DEFAULT_CONF - make -C test/build-combination/build/ + cmake -S . -B build/ -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DEFAULT_CONF + make -C build/ complexity: runs-on: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..7e4012e20 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,279 @@ + +cmake_minimum_required(VERSION 3.15) +cmake_policy(SET CMP0048 NEW) # project version +cmake_policy(SET CMP0076 NEW) # full paths + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules") + +######################################################################## +# Project Details +project(FreeRTOS-Plus-TCP + VERSION 3.1.0 + DESCRIPTION "FreeRTOS TCP/UDP Network Layer" + HOMEPAGE_URL https://freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html + LANGUAGES C) + +# Do not allow in-source build. +if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} ) +message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." ) +endif() + +# Options +option(FREERTOS_PLUS_TCP_BUILD_TEST "Build the test for FreeRTOS Plus TCP" OFF) + +# Configuration +# Override these at project level with: +# Optional: set(FREERTOS_PLUS_TCP_BUFFER_ALLOCATION "1" CACHE STRING "" FORCE) +# Optional: set(FREERTOS_PLUS_TCP_COMPILER "" CACHE STRING "" FORCE) +# Required: set(FREERTOS_PLUS_TCP_NETWORK_IF "POSIX" CACHE STRING "" FORCE) + +# Select the appropriate buffer allocaiton method. +# See: https://freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/Embedded_Ethernet_Buffer_Management.html +if (NOT FREERTOS_PLUS_TCP_BUFFER_ALLOCATION) + message(STATUS "Using default FREERTOS_PLUS_TCP_BUFFER_ALLOCATION = 2") + set(FREERTOS_PLUS_TCP_BUFFER_ALLOCATION "2" CACHE STRING "FreeRTOS buffer allocation model number. 1 .. 2.") +endif() + +# Select the Compiler - if left blank will detect using CMake +# Note relies on CMake to detect over any setting here. +# Valid options are: +# FREERTOS_PLUS_TCP_COMPILER | Detected | CMake +# ------------------------------------------------- +# CCS | No | ?TBD? +# GCC | Yes | GNU +# IAR | Yes | IAR +# Keil | Yes | ARMCC +# MSVC | Yes | MSVC # Note only for MinGW +# Renesas | No | ?TBD? +# Will always a attempt to detect and if detectable double checks that the compiler is set correctly. +set(FREERTOS_PLUS_TCP_COMPILER "" CACHE STRING "FreeRTOS Plus TCP Compiler Selection") + + +# Select the appropriate network interface +# This will fail the CMake preparation step if not set to one of those values. +set(FREERTOS_PLUS_TCP_NETWORK_IF "" CACHE STRING "FreeRTOS Plus TCP Network Interface selection") +set(FREERTOS_PLUS_TCP_NETWORK_IF_LIST + A_CUSTOM_NETWORK_IF + ATSAM43 ATSAME5x # AT + DRIVER_SAM + ESP32 + KSZ8851SNL + LPC17xx LPC18xx LPC54018 + M487 + MPS2_AN385 + MW300_RD + PIC32MZEF_ETH PIC32MZEF_WIFI + POSIX WIN_PCAP # Native Linux & Windows respectively + RX + SH2A + STM32FXX STM32HXX # ST Micro + MSP432 + TM4C + XILINX_ULTRASCALE ZYNQ # AMD/Xilinx +) +if(NOT FREERTOS_PLUS_TCP_NETWORK_IF) + # Attempt to detect the system. + if(UNIX) + message(STATUS "Detected UNIX/Posix system setting FREERTOS_PLUS_TCP_NETWORK_IF = POSIX") + set(FREERTOS_PLUS_TCP_NETWORK_IF POSIX) + elseif(MINGW) + message(STATUS "Detected Windows MinGW system setting FREERTOS_PLUS_TCP_NETWORK_IF = WIN_PCAP") + set(FREERTOS_PLUS_TCP_NETWORK_IF WIN_PCAP) + endif() +endif() + +if(NOT FREERTOS_PLUS_TCP_NETWORK_IF IN_LIST FREERTOS_PLUS_TCP_NETWORK_IF_LIST ) + message(FATAL_ERROR " FREERTOS_PLUS_TCP_NETWORK_IF is '${FREERTOS_PLUS_TCP_NETWORK_IF}'.\n" + " Please specify it from top-level CMake file (example):\n" + " set(FREERTOS_PLUS_TCP_NETWORK_IF POSIX CACHE STRING \"\")\n" + " or from CMake command line option:\n" + " -DFREERTOS_PLUS_TCP_NETWORK_IF=POSIX\n" + " \n" + " Available port options:\n" + " A_CUSTOM_NETWORK_IF Target: User Defined\n" + " ATSAM4E Target: ATSAM4E - TODO\n" + " ATSAME5x Target: ATSAME5x - TODO\n" + " DRIVER_SAM Target: Driver SAM - TODO\n" + " ESP32 Target: ESP-32 - TODO\n" + " KSZ8851SNL Target: ksz8851snl - TODO\n" + " POSIX Target: linux/Posix\n" + " LPC17xx Target: LPC17xx - TODO\n" + " LPC18xx Target: LPC18xx - TODO\n" + " LPC54018 Target: LPC54018 - TODO\n" + " M487 Target: M487- TODO\n" + " MPS2_AN385 Target: MPS2_AN385 - TODO\n" + " MW300_RD Target: mw300_rd - TODO\n" + " PIC32MZEF_ETH Target: pic32mzef ethernet- TODO\n" + " PIC32MZEF_WIFI Target: pic32mzef Wifi- TODO\n" + " RX Target: RX- TODO\n" + " SH2A Target: SH2A- TODO\n" + " STM32FXX Target: STM32Fxx - TODO\n" + " STM32HXX Target: STM32Hxx - TODO\n" + " MSP432 Target: MSP432 - TODO\n" + " TM4C Target: TM4C- TODO\n" + " WIN_PCAP Target: Windows - TODO\n" + " XILINX_ULTRASCALE Target: Xilinx Ultrascale - TODO\n" + " ZYNQ Target: Xilinx Zynq") +elseif((FREERTOS_PORT STREQUAL "A_CUSTOM_PORT") AND (NOT TARGET freertos_kernel_port) ) + message(FATAL_ERROR " FREERTOS_PLUS_TCP_NETWORK_IF is set to A_CUSTOM_NETWORK_IF.\n" + " Please specify the custom network interface target with all necessary files.\n" + " For example, assuming a directory of:\n" + " FreeRTOSCustomNetworkInterface/\n" + " CMakeLists.txt\n" + " NetworkInterface.c\n\n" + " Where FreeRTOSCustomNetworkInterface/CMakeLists.txt is a modified version of:\n" + " add_library(freertos_plus_tcp_network_if STATIC)\n\n" + " target_sources(freertos_plus_tcp_network_if\n" + " PRIVATE\n" + " NetworkInterface.c)\n\n" + " target_include_directories(freertos_plus_tcp_network_if\n" + " PUBLIC\n" + " .)\n\n" + " taget_link_libraries(freertos_plus_tcp_network_if\n" + " PRIVATE\n" + " freertos_kernel)") +endif() + +# There is also the need to add a target - typically an interface library that describes the +# Configuration for FreeRTOS-Kernel and FreeRTOS-Plus-TCP. +# This is called FreeRTOS::Config +# If not defined will be default compile with one of the test build combinations AllEnable. + +# Select the appropriate Build Test configuration +# This is only used when FreeRTOS::Config is not defined, otherwise the build test will be performed +# on the config defined in the FreeRTOS::Config +set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION "DEFAULT_CONF" CACHE STRING "FreeRTOS Plus TCP Build Test configuration") +set(FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST + CUSTOM # Custom (external) configuration -eg from a top-level project + ENABLE_ALL # Enable all configuration settings + DISABLE_ALL # Disable all configuration settings + DEFAULT_CONF # Default (typical) configuration) +) +if(NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION IN_LIST FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST) + message(FATAL_ERROR "Invalid FREERTOS_PLUS_TCP_TEST_CONFIGURATION value '${FREERTOS_PLUS_TCP_TEST_CONFIGURATION}' should be one of: ${FREERTOS_PLUS_TCP_TEST_CONFIGURATION_LIST}") +else() + message(WARNING "Using FreeRTOS-Plus-TCP Test Configuration : ${FREERTOS_PLUS_TCP_TEST_CONFIGURATION}" + " FreeRTOS-Kernel configuration settings are configured by FreeRTOS-Plus-TCP") + if (NOT FREERTOS_PLUS_TCP_TEST_CONFIGURATION STREQUAL "CUSTOM") + # Configuration for FreeRTOS-Kernel + set(FREERTOS_CONFIG_FILE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/test/build-combination/Common" CACHE STRING "" FORCE) + if(UNIX) + set(FREERTOS_PORT GCC_POSIX CACHE STRING "" FORCE) + elseif(MINGW) + set(FREERTOS_PORT MSVC_MINGW CACHE STRING "" FORCE) + endif() + endif() +endif() + +######################################################################## +# Requirements +set(CMAKE_C_STANDARD 99) # Note FreeRTOS-Kernel uses C99 constructs. +set(CMAKE_C_STANDARD_REQUIRED ON) + +######################################################################## +# Overall Compile Options +# Note the compile option strategy is to error on everything and then +# Per library opt-out of things that are warnings/errors. +# This ensures that no matter what strategy for compilation you take, the +# builds will still occur. +# +# Only tested with GNU and Clang. +# Other options are https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html#variable:CMAKE_%3CLANG%3E_COMPILER_ID +# Naming of compilers translation map: +# For the ?TBD? - Suggest trying GNU-based and adding the appropriate toolchain file. +# For Toolchain examples see _deps/cmake-src/toolchain/arm-none-eabil-gcc.toolchain.cmake +# +# FreeRTOS | CMake +# ------------------- +# CCS | ?TBD? +# GCC | GNU, Clang, *Clang Others? +# IAR | IAR +# Keil | ARMCC +# MSVC | MSVC # Note only for MinGW? +# Renesas | ?TBD? + +add_compile_options( + ### Gnu/Clang C Options + $<$:-fdiagnostics-color=always> + $<$:-fcolor-diagnostics> + + $<$:-Wall> + $<$:-Wextra> + $<$:-Wpedantic> + $<$:-Werror> + $<$:-Weverything> + + # Documentation types - add unrecognized but supported doxygen commands + # $<$:-fcomment-block-commands=retval> + # $<$:-fcomment-block-commands=copydetails> + + # TODO: Add in other Compilers here. +) + +######################################################################## +# External Dependencies +# Note: For backwards compatibility - still have .gitmodules defining submodules +# To support fetching content in a higher level project add: +# +# FetchContent_Declare( freertos_plus_tcp +# GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git +# GIT_TAG V3.0.0 +# GIT_SUBMODULES "" # Don't grab any submodules - rely on FetchContent +# ) +# +# This will allow you to upgrade submodules and have one common submodule for +# all your builds despite multiple submodules having different versions. +include(FetchContent) + +FetchContent_Declare( freertos_kernel + GIT_REPOSITORY https://github.com/FreeRTOS/FreeRTOS-Kernel.git + GIT_TAG V10.5.0 +) + +FetchContent_Declare( cmock + GIT_REPOSITORY https://github.com/ThrowTheSwitch/CMock + GIT_TAG v2.5.3 +) + +add_subdirectory(source) +add_subdirectory(tools) +add_subdirectory(test) + +FetchContent_MakeAvailable(freertos_kernel cmock) + +# Note following are can be removed once FreeRTOS-Kernel v10.5.0 + fixes their issues. +# To ignore header specific issues - change all of the headers to SYSTEM +set(_freertos_kernel_targets freertos_kernel freertos_kernel_port) +foreach (_target ${_freertos_kernel_targets} ) + get_target_property( interface_directories ${_target} INTERFACE_INCLUDE_DIRECTORIES ) + set_target_properties(${_target} PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${interface_directories}" ) +endforeach() +target_compile_options( freertos_kernel + PRIVATE + $<$:-Wno-cast-align> + $<$:-Wno-covered-switch-default> + $<$:-Wno-documentation> + $<$:-Wno-extra-semi-stmt> + $<$:-Wno-int-to-pointer-cast> + $<$:-Wno-missing-noreturn> + $<$:-Wno-missing-variable-declarations> + $<$:-Wno-padded> + $<$:-Wno-pointer-to-int-cast> + $<$:-Wno-shorten-64-to-32> + $<$:-Wno-sign-conversion> + $<$:-Wno-unused-macros> + $<$:-Wno-unused-variable> +) +target_compile_options( freertos_kernel_port + PRIVATE + $<$:-Wno-disabled-macro-expansion> + $<$:-Wno-documentation> + $<$:-Wno-missing-noreturn> + $<$:-Wno-missing-variable-declarations> + $<$:-Wno-padded> + $<$:-Wno-pointer-to-int-cast> + $<$:-Wno-reserved-macro-identifier> + $<$:-Wno-sign-conversion> + $<$:-Wno-type-limits> + $<$:-Wno-unused-macros> +) diff --git a/cmake_modules/FindPCAP.cmake b/cmake_modules/FindPCAP.cmake new file mode 100644 index 000000000..4f3c7b641 --- /dev/null +++ b/cmake_modules/FindPCAP.cmake @@ -0,0 +1,75 @@ +# - Try to find libpcap include dirs and libraries +# +# Usage of this module as follows: +# +# find_package(PCAP) +# +# Variables used by this module, they can change the default behaviour and need +# to be set before calling find_package: +# +# PCAP_ROOT_DIR Set this variable to the root installation of +# libpcap if the module has problems finding the +# proper installation path. +# +# Variables defined by this module: +# +# PCAP_FOUND System has libpcap, include and library dirs found +# PCAP_INCLUDE_DIR The libpcap include directories. +# PCAP_LIBRARY The libpcap library (possibly includes a thread +# library e.g. required by pf_ring's libpcap) +# HAVE_PF_RING If a found version of libpcap supports PF_RING + +find_path(PCAP_ROOT_DIR + NAMES include/pcap.h +) + +find_path(PCAP_INCLUDE_DIR + NAMES pcap.h + HINTS ${PCAP_ROOT_DIR}/include +) + +find_library(PCAP_LIBRARY + NAMES pcap + HINTS ${PCAP_ROOT_DIR}/lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PCAP DEFAULT_MSG + PCAP_LIBRARY + PCAP_INCLUDE_DIR +) + +include(CheckCSourceCompiles) +set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) +check_c_source_compiles("int main() { return 0; }" PCAP_LINKS_SOLO) +set(CMAKE_REQUIRED_LIBRARIES) + +# check if linking against libpcap also needs to link against a thread library +if (NOT PCAP_LINKS_SOLO) + find_package(Threads) + if (THREADS_FOUND) + set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) + check_c_source_compiles("int main() { return 0; }" PCAP_NEEDS_THREADS) + set(CMAKE_REQUIRED_LIBRARIES) + endif () + if (THREADS_FOUND AND PCAP_NEEDS_THREADS) + set(_tmp ${PCAP_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) + list(REMOVE_DUPLICATES _tmp) + set(PCAP_LIBRARY ${_tmp} + CACHE STRING "Libraries needed to link against libpcap" FORCE) + else () + message(FATAL_ERROR "Couldn't determine how to link against libpcap") + endif () +endif () + +include(CheckFunctionExists) +set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY}) +check_function_exists(pcap_get_pfring_id HAVE_PF_RING) +check_function_exists(pcap_dump_open_append HAVE_PCAP_DUMP_OPEN_APPEND) +set(CMAKE_REQUIRED_LIBRARIES) + +mark_as_advanced( + PCAP_ROOT_DIR + PCAP_INCLUDE_DIR + PCAP_LIBRARY +) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt new file mode 100644 index 000000000..96939e21c --- /dev/null +++ b/source/CMakeLists.txt @@ -0,0 +1,112 @@ +add_library( freertos_plus_tcp STATIC ) +add_library( FreeRTOS::PlusTCP ALIAS freertos_plus_tcp ) + +target_sources( freertos_plus_tcp + PRIVATE + include/FreeRTOS_ARP.h + include/FreeRTOS_DHCP.h + include/FreeRTOS_DNS_Cache.h + include/FreeRTOS_DNS_Callback.h + include/FreeRTOS_DNS_Globals.h + include/FreeRTOS_DNS_Networking.h + include/FreeRTOS_DNS_Parser.h + include/FreeRTOS_DNS.h + include/FreeRTOS_errno_TCP.h + include/FreeRTOS_ICMP.h + include/FreeRTOS_IP_Private.h + include/FreeRTOS_IP_Timers.h + include/FreeRTOS_IP_Utils.h + include/FreeRTOS_IP.h + include/FreeRTOS_Sockets.h + include/FreeRTOS_Stream_Buffer.h + include/FreeRTOS_TCP_IP.h + include/FreeRTOS_TCP_Reception.h + include/FreeRTOS_TCP_State_Handling.h + include/FreeRTOS_TCP_Transmission.h + include/FreeRTOS_TCP_Utils.h + include/FreeRTOS_TCP_WIN.h + include/FreeRTOS_UDP_IP.h + include/FreeRTOSIPConfigDefaults.h + include/IPTraceMacroDefaults.h + include/NetworkBufferManagement.h + include/NetworkInterface.h + + FreeRTOS_ARP.c + FreeRTOS_DHCP.c + FreeRTOS_DNS_Cache.c + FreeRTOS_DNS_Callback.c + FreeRTOS_DNS_Networking.c + FreeRTOS_DNS_Parser.c + FreeRTOS_DNS.c + FreeRTOS_ICMP.c + FreeRTOS_IP_Timers.c + FreeRTOS_IP_Utils.c + FreeRTOS_IP.c + FreeRTOS_Sockets.c + FreeRTOS_Stream_Buffer.c + FreeRTOS_TCP_IP.c + FreeRTOS_TCP_Reception.c + FreeRTOS_TCP_State_Handling.c + FreeRTOS_TCP_Transmission.c + FreeRTOS_TCP_Utils.c + FreeRTOS_TCP_WIN.c + FreeRTOS_Tiny_TCP.c + FreeRTOS_UDP_IP.c +) + +# Note: Have to make system due to compiler warnings in header files. +target_include_directories( freertos_plus_tcp SYSTEM + PUBLIC + include +) + +#TODO(phelter): Investigate and fix in freertos_plus_tcp if not already fixed. +target_compile_options( freertos_plus_tcp + PRIVATE + $<$:-Wno-address-of-packed-member> + $<$:-Wno-bad-function-cast> + $<$:-Wno-declaration-after-statement> + $<$:-Wno-documentation> + $<$:-Wno-cast-qual> + $<$:-Wno-conditional-uninitialized> + $<$:-Wno-covered-switch-default> + $<$:-Wno-extra-semi-stmt> + $<$:-Wno-format-nonliteral> + $<$:-Wno-format> + $<$:-Wno-gnu-statement-expression> + $<$:-Wno-implicit-int-conversion> + $<$:-Wno-int-to-pointer-cast> + $<$:-Wno-macro-redefined> + $<$:-Wno-missing-noreturn> + $<$:-Wno-missing-prototypes> + $<$:-Wno-missing-variable-declarations> + $<$:-Wno-packed> + $<$:-Wno-padded> + $<$:-Wno-pedantic> # ENABLE_ALL config only + $<$:-Wno-pointer-to-int-cast> + $<$:-Wno-reserved-identifier> + $<$:-Wno-reserved-macro-identifier> + $<$:-Wno-shorten-64-to-32> + $<$:-Wno-sign-conversion> + $<$:-Wno-tautological-constant-out-of-range-compare> + $<$:-Wno-type-limits> + $<$:-Wno-undef> + $<$:-Wno-uninitialized> + $<$:-Wno-unused-but-set-variable> + $<$:-Wno-unused-function> + $<$:-Wno-unused-macros> + $<$:-Wno-unused-parameter> + $<$:-Wno-unused-variable> +) + +target_link_libraries( freertos_plus_tcp + PUBLIC + FreeRTOS::Config + freertos_plus_tcp_port # for pack_struct_start.h used in headers. + PRIVATE + freertos_kernel + freertos_plus_tcp_network_if + freertos_plus_tcp_tools +) + +add_subdirectory(portable) diff --git a/source/portable/CMakeLists.txt b/source/portable/CMakeLists.txt new file mode 100644 index 000000000..0a04cd503 --- /dev/null +++ b/source/portable/CMakeLists.txt @@ -0,0 +1,177 @@ +add_library( freertos_plus_tcp_port STATIC ) +add_library( FreeRTOS::PlusTCP::Port ALIAS freertos_plus_tcp_port ) + +target_sources( freertos_plus_tcp_port + PRIVATE + BufferManagement/BufferAllocation_${FREERTOS_PLUS_TCP_BUFFER_ALLOCATION}.c + # TODO: There's NetworkInterface/pic32mzef that has it's own BufferAllocation_2.c +) + +target_include_directories( freertos_plus_tcp_port + PUBLIC + # Using Cmake to detect except for unknown compilers. + $<$:${CMAKE_CURRENT_SOURCE_DIR}/Compiler/CCS> + $<$:${CMAKE_CURRENT_SOURCE_DIR}/Compiler/CCS> + $<$:${CMAKE_CURRENT_SOURCE_DIR}/Compiler/GCC> + $<$:${CMAKE_CURRENT_SOURCE_DIR}/Compiler/IAR> + $<$:${CMAKE_CURRENT_SOURCE_DIR}/Compiler/Keil> + $<$:${CMAKE_CURRENT_SOURCE_DIR}/Compiler/MSVC> + $<$:${CMAKE_CURRENT_SOURCE_DIR}/Compiler/Renesas> +) + +target_compile_options( freertos_plus_tcp_port + PRIVATE + $<$:-Wno-cast-align> + $<$:-Wno-extra-semi> + $<$:-Wno-pedantic> # How STATIC_ASSERT is defined +) + +target_link_libraries( freertos_plus_tcp_port + PRIVATE + freertos_kernel + freertos_plus_tcp + freertos_plus_tcp_network_if +) + +#------------------------------------------------------------------------------ +if (FREERTOS_PLUS_TCP_NETWORK_IF STREQUAL "A_CUSTOM_NETWORK_IF") + message(STATUS "Using a custom FREERTOS_PLUS_TCP_NETWORK_IF.") + return() +endif() + +add_library( freertos_plus_tcp_network_if STATIC ) +add_library( FreeRTOS::PlusTCP::NetworkIF ALIAS freertos_plus_tcp_network_if ) + +target_sources( freertos_plus_tcp_network_if + PRIVATE + NetworkInterface/Common/phyHandling.c + NetworkInterface/include/phyHandling.h + + #$<$:> # TODO + $<$: + NetworkInterface/ATSAME5x/NetworkInterface.c> + $<$: + NetworkInterface/DriverSAM/gmac_SAM.c + NetworkInterface/DriverSAM/gmac_SAM.h + NetworkInterface/DriverSAM/NetworkInterface.c> + $<$: + NetworkInterface/esp32/NetworkInterface.c> + $<$: + NetworkInterface/ksz8851snl/ksz8851snl_reg.h + NetworkInterface/ksz8851snl/ksz8851snl.c + NetworkInterface/ksz8851snl/ksz8851snl.h + NetworkInterface/ksz8851snl/NetworkInterface.c> + $<$: + NetworkInterface/linux/NetworkInterface.c> + $<$: + NetworkInterface/LPC17xx/NetworkInterface.c> + $<$: + NetworkInterface/LPC18xx/NetworkInterface.c> + $<$: + NetworkInterface/LPC54018/NetworkInterface.c> + $<$: + NetworkInterface/M487/m480_eth.c + NetworkInterface/M487/m480_eth.h + NetworkInterface/M487/NetworkInterface.c> + # $<$:> # TODO + $<$: + NetworkInterface/mw300_rd/NetworkInterface.c> + # $<$:> # TODO + # $<$:> # TODO + $<$: + NetworkInterface/RX/ether_callback.c + NetworkInterface/RX/NetworkInterface.c> + $<$: + NetworkInterface/SH2A/NetworkInterface.c> + # $<$:> # TODO + # $<$:> # TODO + $<$: + NetworkInterface/ThirdParty/MSP432/NetworkInterface.c + NetworkInterface/ThirdParty/MSP432/NetworkInterface.h + NetworkInterface/ThirdParty/MSP432/NetworkMiddleware.c + NetworkInterface/ThirdParty/MSP432/NetworkMiddleware.h> + $<$: + NetworkInterface/TM4C/NetworkInterface.c> + $<$: + NetworkInterface/WinPCAP/FaultInjection.c + NetworkInterface/WinPCAP/NetworkInterface.c> + $<$: + NetworkInterface/xilinx_ultrascale/NetworkInterface.c + NetworkInterface/xilinx_ultrascale/readme.md + NetworkInterface/xilinx_ultrascale/uncached_memory.c + NetworkInterface/xilinx_ultrascale/uncached_memory.h + NetworkInterface/xilinx_ultrascale/x_emacpsif_dma.c + NetworkInterface/xilinx_ultrascale/x_emacpsif_hw.c + NetworkInterface/xilinx_ultrascale/x_emacpsif_hw.h + NetworkInterface/xilinx_ultrascale/x_emacpsif_physpeed.c + NetworkInterface/xilinx_ultrascale/x_emacpsif.h + NetworkInterface/xilinx_ultrascale/x_topology.h> + $<$: + NetworkInterface/Zynq/NetworkInterface.c + NetworkInterface/Zynq/README.txt + NetworkInterface/Zynq/uncached_memory.c + NetworkInterface/Zynq/uncached_memory.h + NetworkInterface/Zynq/x_emacpsif_dma.c + NetworkInterface/Zynq/x_emacpsif_hw.c + NetworkInterface/Zynq/x_emacpsif_hw.h + NetworkInterface/Zynq/x_emacpsif_physpeed.c + NetworkInterface/Zynq/x_emacpsif.h + NetworkInterface/Zynq/x_topology.h> +) + +if( FREERTOS_PLUS_TCP_NETWORK_IF STREQUAL "POSIX") + find_package(PCAP REQUIRED) + set(THREADS_PREFER_PTHREAD_FLAG TRUE) + find_package(Threads) +endif() + +target_include_directories( freertos_plus_tcp_network_if + PUBLIC + freertos_plus_tcp_port # For compiler pragmas. + NetworkInterface/include + PRIVATE + # $<$ #TODO + $<$:NetworkInterface/DriverSAM> + $<$:NetworkInterface/ksz8851snl> + $<$:NetworkInterface/M487> + # $<$:> #TODO + $<$:NetworkInterface/STM32Fxx> + $<$:NetworkInterface/STM32Hxx> + $<$:NetworkInterface/ThirdParty/MSP432> + $<$:NetworkInterface/xilinx_ultrascale> + $<$:NetworkInterface/Zynq> +) + +target_compile_options( freertos_plus_tcp_network_if + PRIVATE + $<$:-Wno-cast-align> + $<$:-Wno-conditional-uninitialized> + $<$:-Wno-documentation> + $<$:-Wno-empty-translation-unit> + $<$:-Wno-extra-semi-stmt> + $<$:-Wno-gnu-statement-expression> + $<$:-Wno-implicit-int-conversion> + $<$:-Wno-int-to-pointer-cast> + $<$:-Wno-missing-noreturn> + $<$:-Wno-missing-prototypes> + $<$:-Wno-pointer-to-int-cast> + $<$:-Wno-newline-eof> + $<$:-Wno-padded> + $<$:-Wno-shorten-64-to-32> + $<$:-Wno-type-limits> + $<$:-Wno-undef> + $<$:-Wno-uninitialized> + $<$:-Wno-unused-but-set-variable> + $<$:-Wno-unused-macros> + $<$:-Wno-unused-parameter> +) + +target_link_libraries( freertos_plus_tcp_network_if + PUBLIC + freertos_plus_tcp_port + PRIVATE + freertos_kernel + freertos_plus_tcp + $<$:${PCAP_LIBRARY}> + $<$:Threads::Threads> +) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 000000000..97d445910 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,8 @@ +add_subdirectory(build-combination) + +if(FREERTOS_PLUS_TCP_BUILD_TEST) + add_subdirectory(cbmc) + add_subdirectory(Coverity) + add_subdirectory(unit-test) +endif() + diff --git a/test/build-combination/CMakeLists.txt b/test/build-combination/CMakeLists.txt index c69507330..2a716510d 100644 --- a/test/build-combination/CMakeLists.txt +++ b/test/build-combination/CMakeLists.txt @@ -1,89 +1,58 @@ -cmake_minimum_required ( VERSION 3.13.0 ) -project ( "FreeRTOS-Plus-TCP Build Combination" - VERSION 1.0.0 - LANGUAGES C ) - -# Allow the project to be organized into folders. -set_property( GLOBAL PROPERTY USE_FOLDERS ON ) - -# Use C90. -set( CMAKE_C_STANDARD 90 ) -set( CMAKE_C_STANDARD_REQUIRED ON ) - -# Do not allow in-source build. -if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} ) - message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." ) -endif() - -# Set global path variables. -get_filename_component(__MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) -set(MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "FreeRTOS-Plus-TCP repository root.") - -# Configure options to always show in CMake GUI. -option( BUILD_CLONE_SUBMODULES - "Set this to ON to automatically clone any required Git submodules. When OFF, submodules must be manually cloned." - ON ) - - -option(TEST_CONFIGURATION "Configuration All Enable/Disable or default" ENABLE_ALL) - -message( STATUS "Argument: ${TEST_CONFIGURATION}") - -# Set output directories. -set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) -set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) -set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) - - -set( FREERTOS_KERNEL_DIR ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel ) -set( TEST_DIR ${MODULE_ROOT_DIR}/test/build-combination ) - -include_directories( ${MODULE_ROOT_DIR}/source/include ) -include_directories( ${MODULE_ROOT_DIR}/source/portable/Compiler/MSVC ) -include_directories( ${FREERTOS_KERNEL_DIR}/include ) -# Add the correct portable directory to include search paths. -if (WIN32) - include_directories( ${FREERTOS_KERNEL_DIR}/portable/MSVC-MingW ) -else() - include_directories( ${FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Posix ) -endif() -include_directories( ${TEST_DIR}/Common ) - -if( ${TEST_CONFIGURATION} STREQUAL "ENABLE_ALL" ) - include_directories( ${TEST_DIR}/AllEnable ) -elseif( ${TEST_CONFIGURATION} STREQUAL "DISABLE_ALL" ) - include_directories( ${TEST_DIR}/AllDisable ) -else() - include_directories( ${TEST_DIR}/DefaultConf ) -endif() - -# Pick the correct kernel port files for the platform. -if (WIN32) - file(GLOB KERNEL_SOURCES "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/*.c" - "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/MSVC-MingW/*.c") +add_library( freertos_plus_tcp_config_common INTERFACE ) +target_include_directories(freertos_plus_tcp_config_common INTERFACE Common ) + +# ------------------------------------------------------------------- +add_library( freertos_plus_tcp_config_all_disable INTERFACE) +target_include_directories(freertos_plus_tcp_config_all_disable INTERFACE AllDisable) +target_link_libraries(freertos_plus_tcp_config_all_disable INTERFACE freertos_plus_tcp_config_common) + +# ------------------------------------------------------------------- +add_library( freertos_plus_tcp_config_all_enable INTERFACE) +target_include_directories(freertos_plus_tcp_config_all_enable INTERFACE AllEnable) +target_link_libraries(freertos_plus_tcp_config_all_enable INTERFACE freertos_plus_tcp_config_common) + +# ------------------------------------------------------------------- +add_library( freertos_plus_tcp_config_default INTERFACE) +target_include_directories(freertos_plus_tcp_config_default INTERFACE DefaultConf) +target_link_libraries(freertos_plus_tcp_config_default INTERFACE freertos_plus_tcp_config_common) + +# ------------------------------------------------------------------- +# Configuration for FreeRTOS-Kernel +if(FREERTOS_PLUS_TCP_TEST_CONFIGURATION STREQUAL "CUSTOM" ) + # Check Config target is available. And then do nothing. + if(NOT TARGET FreeRTOS::Config ) + message(FATAL_ERROR "FREERTOS_PLUS_TCP_TEST_CONFIGURATIN = CUSTOM, but no FreeRTOS::Config target defined.") + endif() +elseif(FREERTOS_PLUS_TCP_TEST_CONFIGURATION STREQUAL "DISABLE_ALL" ) + add_library( FreeRTOS::Config ALIAS freertos_plus_tcp_config_all_disable) +elseif(FREERTOS_PLUS_TCP_TEST_CONFIGURATION STREQUAL "ENABLE_ALL" ) + add_library( FreeRTOS::Config ALIAS freertos_plus_tcp_config_all_enable) else() - file(GLOB KERNEL_SOURCES "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/*.c" - "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix/*.c" - "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix/utils/*.c") + add_library( FreeRTOS::Config ALIAS freertos_plus_tcp_config_default) endif() -file(GLOB TCP_SOURCES "${MODULE_ROOT_DIR}/source/*.c" ) - -message(STATUS "${KERNEL_SOURCES}") -message(STATUS "${TCP_SOURCES}") - -add_executable(project ${KERNEL_SOURCES} - ${TCP_SOURCES} - ${FREERTOS_KERNEL_DIR}/portable/MemMang/heap_4.c - ${MODULE_ROOT_DIR}/source/portable/BufferManagement/BufferAllocation_2.c - ${TEST_DIR}/Common/main.c ) - -if (WIN32) - # Add preprocessor definitions to suppress warnings. - target_compile_definitions( project PRIVATE - _CRT_SECURE_NO_WARNINGS ) -else() - # Link pthread which is needed for POSIX port. - find_package( Threads REQUIRED ) - target_link_libraries( project Threads::Threads ) -endif() +add_executable(freertos_plus_tcp_build_test) + +target_sources(freertos_plus_tcp_build_test + PRIVATE + Common/main.c +) + +target_compile_options(freertos_plus_tcp_build_test + PRIVATE + $<$:-Wno-cast-qual> + $<$:-Wno-missing-noreturn> + $<$:-Wno-missing-prototypes> + $<$:-Wno-missing-variable-declarations> + $<$:-Wno-shorten-64-to-32> + $<$:-Wno-sign-conversion> + $<$:-Wno-unused-parameter> + $<$:-Wno-unused-macros> + $<$:-Wno-unused-variable> +) + +target_link_libraries(freertos_plus_tcp_build_test + PRIVATE + freertos_plus_tcp + freertos_kernel +) diff --git a/test/build-combination/Common/FreeRTOSConfig.h b/test/build-combination/Common/FreeRTOSConfig.h index 7d5de97dc..082522559 100644 --- a/test/build-combination/Common/FreeRTOSConfig.h +++ b/test/build-combination/Common/FreeRTOSConfig.h @@ -219,7 +219,7 @@ extern void vLoggingPrint( const char * pcMessage ); #define configPROFILING ( 0 ) /* Pseudo random number generator used by some tasks. */ -extern uint32_t ulRand(); +extern uint32_t ulRand(void); #define configRAND32() ulRand() /* The platform that FreeRTOS is running on. */ diff --git a/test/build-combination/DefaultConf/FreeRTOSIPConfig.h b/test/build-combination/DefaultConf/FreeRTOSIPConfig.h index c908f0fcd..4bb2595be 100644 --- a/test/build-combination/DefaultConf/FreeRTOSIPConfig.h +++ b/test/build-combination/DefaultConf/FreeRTOSIPConfig.h @@ -40,4 +40,8 @@ * dependent. */ #define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN +/* The windows simulator cannot really simulate MAC interrupts, and needs to + * block occasionally to allow other tasks to run. */ +#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS ) + #endif diff --git a/test/build-combination/README.md b/test/build-combination/README.md index 0bbcba87d..8b83253ce 100644 --- a/test/build-combination/README.md +++ b/test/build-combination/README.md @@ -9,20 +9,20 @@ All the CMake commands are to be run from the root of the repository. * Build checks (Enable all functionalities) ``` -cmake -S test/build-combination -B test/build-combination/build/ -DTEST_CONFIGURATION=ENABLE_ALL -make -C test/build-combination/build/ +cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=ENABLE_ALL +make -C build ``` * Build checks (Disable all functionalities) ``` -cmake -S test/build-combination -B test/build-combination/build/ -DTEST_CONFIGURATION=DISABLE_ALL -make -C test/build-combination/build/ +cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DISABLE_ALL +make -C build ``` * Build checks (Default configuration) ``` -cmake -S test/build-combination -B test/build-combination/build/ -DTEST_CONFIGURATION=DEFAULT_CONF -make -C test/build-combination/build/ +cmake -S . -B build -DFREERTOS_PLUS_TCP_TEST_CONFIGURATION=DEFAULT_CONF +make -C . ``` ## Windows @@ -31,21 +31,21 @@ All the CMake commands are to be run from the root of the repository. * Build checks (Enable all functionalities) ``` -cmake -S test/build-combination -B test/build-combination/build/ -DTEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 +cmake -S . -B build -DTEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 ``` Open the generated Visual Studio Solution file `test\build-combination\build\FreeRTOS-Plus-TCP Build Combination.sln` in Visual Studio and click `Build --> Build Solution`. * Build checks (Disable all functionalities) ``` -cmake -S test/build-combination -B test/build-combination/build/ -DTEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 +cmake -S . -B build -DTEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 ``` Open the generated Visual Studio Solution file `test\build-combination\build\FreeRTOS-Plus-TCP Build Combination.sln` in Visual Studio and click `Build --> Build Solution`. * Build checks (Default configuration) ``` -cmake -S test/build-combination -B test/build-combination/build/ -DTEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 +cmake -S . -B build -DTEST_CONFIGURATION=ENABLE_ALL -DCMAKE_GENERATOR_PLATFORM=Win32 ``` Open the generated Visual Studio Solution file `test\build-combination\build\FreeRTOS-Plus-TCP Build Combination.sln` in Visual Studio and click `Build --> Build Solution`. diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 000000000..f5e346218 --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,38 @@ +add_library( freertos_plus_tcp_tools STATIC ) +add_library( FreeRTOS::PlusTCP::Tools ALIAS freertos_plus_tcp_tools ) + +target_sources( freertos_plus_tcp_tools + PRIVATE + tcp_utilities/include/tcp_dump_packets.h + tcp_utilities/include/tcp_mem_stats.h + tcp_utilities/include/tcp_netstat.h + + tcp_utilities/tcp_dump_packets.c + tcp_utilities/tcp_mem_stats.c + tcp_utilities/tcp_netstat.c +) + +# Note: Have to make system due to compiler warnings in header files. +target_include_directories( freertos_plus_tcp_tools SYSTEM + PUBLIC + tcp_utilities/include +) + +#TODO(phelter): Investigate and fix in freertos_plus_tcp if not already fixed. +target_compile_options( freertos_plus_tcp_tools + PRIVATE + $<$:-Wno-extra-semi-stmt> + $<$:-Wno-format> + $<$:-Wno-missing-variable-declarations> + $<$:-Wno-padded> + $<$:-Wno-unused-but-set-variable> + $<$:-Wno-unused-function> + $<$:-Wno-unused-macros> + $<$:-Wno-unused-variable> +) + +target_link_libraries( freertos_plus_tcp_tools + PRIVATE + freertos_kernel + freertos_plus_tcp +)