first commit

This commit is contained in:
fewikay committed 2026-10-16 13:08:06 +02:00
commit 92cbe97616
1978 files changed
+1688498

No files matched your search

@@ -0,0 +1,429 @@
# Set the required version.
cmake_minimum_required( VERSION 3.15.0 )
# Set the unit-test project.
project( "FreeRTOS-Plus-TCP test"
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( SANITIZE "" CACHE STRING "Comma-separated list of compiler sanitizers to enable; empty string disables." )
if( NOT ${SANITIZE} STREQUAL "" )
add_compile_options(-fsanitize=${SANITIZE} -fno-sanitize-recover)
add_link_options(-fsanitize=${SANITIZE} -fno-sanitize-recover)
endif()
# Align with: test/build-combination/CMakeLists.txt
add_compile_options(
$<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-fcolor-diagnostics>
### On the road to -Wall: Forbid warnings that need not be tolerated.
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=uninitialized> # definite use of uninitialized variable
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=array-bounds> # indexing outside sized array
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=switch> # enum switch with unhandled value
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=format> # format string wrong
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=format-security> # format string missing
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=comment> # comment within a comment
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=unused-value> # "statement has no effect"
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Werror=maybe-uninitialized> # possible use of uninitialized variable
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Werror=memset-elt-size> # memsetting array by length instead of size
# FIXME (part of -Wall):
# -Werror=return-type # "control reaches end of non-void function"
# -Werror=array-parameter # name clash
# -Werror=implicit-function-declaration # need header
# -Werror=unused-but-set-variable
# -Werror=unused-variable
# -Werror=unused-function
# -Werror=unused-parameter
# -Werror=missing-braces
# -Werror=pointer-sign
# -Werror=dangling-pointer
# -Werror=vla
### Currently needed to build cleanly with Clang 19:
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Werror>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-pragma-pack>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-parameter>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-return-type>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-pointer-sign>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-typedef-redefinition>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-strict-prototypes>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-sometimes-uninitialized>
)
# 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." )
# Set the unit-test directory.
set( UNIT_TEST_DIR ${MODULE_ROOT_DIR}/test/unit-test CACHE INTERNAL "Unit-test directory." )
set( KERNEL_DIRECTORY ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel )
# See if FreRTOS-Kernel is submoduled
if( NOT EXISTS ${KERNEL_DIRECTORY}/include )
# Inform the user of the actions
message( STATUS "FreeRTOS-Kernel is required for this build. Submoduling it..." )
execute_process( COMMAND git submodule update --init --checkout ${KERNEL_DIRECTORY}
WORKING_DIRECTORY ${MODULE_ROOT_DIR} )
endif()
# Set the include directories
string( APPEND GLOBAL_INCLUDES "-I ${MODULE_ROOT_DIR}/source/include ")
string( APPEND GLOBAL_INCLUDES "-I ${UNIT_TEST_DIR}/ConfigFiles " )
string( APPEND GLOBAL_INCLUDES "-I ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include " )
# 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 )
# 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 TCP includes.
set( TCP_INCLUDES "${MODULE_ROOT_DIR}/source/include/FreeRTOS_IP.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_BitConfig.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IPv4.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IPv6.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IP_Common.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IP_Common.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_ND.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_ARP.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_ARP.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_BitConfig.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_ICMP.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IP_Timers.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IP_Utils.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IPv4_Utils.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IPv6_Utils.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_Sockets.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IP_Private.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IPv4_Private.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IPv6_Private.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IPv4_Sockets.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_IPv6_Sockets.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_UDP_IP.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_DHCP.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_DHCPv6.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_DNS.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_DNS_Cache.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_DNS_Globals.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_DNS_Callback.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_DNS_Networking.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_DNS_Parser.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_Routing.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_ND.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_TCP_IP.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_TCP_Transmission.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_TCP_Reception.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_TCP_Utils.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_TCP_State_Handling.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_Stream_Buffer.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOS_TCP_WIN.h"
"${MODULE_ROOT_DIR}/source/include/FreeRTOSIPConfigDefaults.h"
"${MODULE_ROOT_DIR}/source/include/IPTraceMacroDefaults.h"
"${MODULE_ROOT_DIR}/source/include/NetworkBufferManagement.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/portable.h"
"${MODULE_ROOT_DIR}/source/include/NetworkInterface.h" )
# Create a directory for the modified files
file( MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Annexed_TCP )
# ===========================================================================
# ===========================================================================
# Preprocess the TCP include files as they will be mocked later.
foreach( file ${TCP_INCLUDES} )
get_filename_component( MODIFIED_FILE ${file} NAME_WLE )
string(TOUPPER ${MODIFIED_FILE} Guard)
if(${MODIFIED_FILE} STREQUAL "NetworkBufferManagement" )
set( Guard "NETWORK_BUFFER_MANAGEMENT_H" )
elseif( ${MODIFIED_FILE} STREQUAL "NetworkInterface" )
set( Guard "NETWORK_INTERFACE_H" )
else()
set( Guard ${Guard}_H )
endif()
# Remove IPConfigDefaults from the file
execute_process( COMMAND sed "s,#include \"FreeRTOSIPConfigDefaults.h\",,g" ${file}
OUTPUT_FILE ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp1.h )
# Add the FreeRTOSIPConfig file to each directory
execute_process( COMMAND sed "1 i\#include \"FreeRTOSIPConfig.h\"" ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp1.h
OUTPUT_FILE ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp.h )
if(${MODIFIED_FILE} STREQUAL "FreeRTOS_IP_Private" )
execute_process( COMMAND sed "s/extern const BaseType_t xBufferAllocFixedSize/extern BaseType_t xBufferAllocFixedSize/g" ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp.h
OUTPUT_FILE ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp2.h )
execute_process( COMMAND mv ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp2.h ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp.h )
endif()
# Find the unifdefall executable
find_program(UNIFDEFALL_EXECUTABLE unifdefall)
if (UNIFDEFALL_EXECUTABLE)
# Use this tool to process all conditional declarations.
if(${MODIFIED_FILE} STREQUAL "FreeRTOS_Routing" OR ${MODIFIED_FILE} STREQUAL "FreeRTOS_IP_Private" )
execute_process( COMMAND unifdefall -U${Guard} -USEND_REPEATED_COUNT
-UipTRUE_BOOL
-UipFALSE_BOOL
-UFreeRTOS_htonl
-D__COVERITY__
-DTEST
-DipconfigIS_ENABLED
-DipconfigUSE_IPv6
-DipconfigUSE_RA
-I ${MODULE_ROOT_DIR}/tools/CMock/vendor/unity/src
-I ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
-I ${UNIT_TEST_DIR}/ConfigFiles
-I ${MODULE_ROOT_DIR}/source/include
-I ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp.h
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_FILE ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}.h
OUTPUT_QUIET
ERROR_QUIET )
else()
execute_process( COMMAND unifdefall -U${Guard} -USEND_REPEATED_COUNT
-UipTRUE_BOOL
-UipFALSE_BOOL
-UFreeRTOS_htonl
-D__COVERITY__
-DTEST
-DipconfigIS_ENABLED
-I ${MODULE_ROOT_DIR}/tools/CMock/vendor/unity/src
-I ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
-I ${UNIT_TEST_DIR}/ConfigFiles
-I ${MODULE_ROOT_DIR}/source/include
-I ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp.h
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_FILE ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}.h
OUTPUT_QUIET
ERROR_QUIET )
endif()
else()
message(FATAL_ERROR "Error: unifdefall command not found.")
endif()
# Remove the temporary files
file( REMOVE ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp.h )
file( REMOVE ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp1.h )
# Add the guards back to the files
execute_process( COMMAND sed -i "1 i\#ifndef ${Guard}" ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}.h )
execute_process( COMMAND sed -i -e "$ a\#endif" ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}.h )
execute_process( COMMAND sed -i -E "s,[ ]*extern ipDECL_CAST_.*,,g" ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}.h )
endforeach()
# ===========================================================================
# ===================================== Include the cmake configurations =================================================
message( STATUS ${CMAKE_BINARY_DIR} )
# Include filepaths for source and include.
include( ${UNIT_TEST_DIR}/TCPFilePaths.cmake )
# ===========================================================================
# ===========================================================================
# Remove static qualifier from the source files so that internal functions
# can be called directly.
file( MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Annexed_TCP_Sources )
foreach( file ${TCP_SOURCES} )
get_filename_component( MODIFIED_FILE ${file} NAME_WLE )
if(${MODIFIED_FILE} STREQUAL "FreeRTOS_Sockets" )
execute_process( COMMAND sed "/#include \"task.h\"/ a \#include \"Sockets_list_macros.h\" " ${file}
OUTPUT_FILE ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp2.c )
set( file ${CMAKE_BINARY_DIR}/Annexed_TCP/${MODIFIED_FILE}_tmp2.c )
endif()
# Strip static constraints so unit tests may call internal functions
execute_process( COMMAND sed "s/^[ ]*static //"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
INPUT_FILE ${file}
OUTPUT_FILE ${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/${MODIFIED_FILE}.c )
# Generate a header file for internal functions
execute_process( COMMAND sed -n "/^[ ]*static.*(/,/^{\$/{s/^static //; s/)\$/&;/; /{/d; p;}"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
INPUT_FILE ${file}
OUTPUT_FILE ${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/${MODIFIED_FILE}_internal.h )
endforeach()
# ===========================================================================
# ========================= Test Configuration ==============================
# Define a CMock resource path.
set( CMOCK_DIR ${MODULE_ROOT_DIR}/tools/CMock CACHE INTERNAL "CMock library source directory." )
# Include CMock build configuration.
include( cmock_build.cmake )
# Check if the CMock source directory exists, and if not present, clone the submodule
# if BUILD_CLONE_SUBMODULES configuration is enabled.
if( NOT EXISTS ${CMOCK_DIR}/src )
# Attempt to clone CMock.
if( ${BUILD_CLONE_SUBMODULES} )
clone_cmock()
else()
message( FATAL_ERROR "The required submodule CMock does not exist. Either clone it manually, or set BUILD_CLONE_SUBMODULES to 'ON' to automatically clone it during build." )
endif()
endif()
# Use CTest utility for managing test runs. This has to be added BEFORE
# defining test targets with add_test()
enable_testing()
# Add build targets for CMock and Unit, required for unit testing.
add_cmock_targets()
# Add function to enable CMock based tests and coverage.
include( ${MODULE_ROOT_DIR}/test/unit-test/cmock/create_test.cmake )
# Include unit-test build configuration
include( ${UNIT_TEST_DIR}/FreeRTOS_ARP/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_ARP_DataLenLessThanMinPacket/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_BitConfig/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_DHCP/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_DHCPv6/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_WIN/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_Tiny_TCP/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_DNS/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_DNS_ConfigNoCallback/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_DNS_Cache/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_DNS_Networking/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_DNS_Callback/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_DNS_Parser/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IP/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IP_DiffConfig/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IP_DiffConfig1/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IP_DiffConfig2/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IP_DiffConfig3/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_ICMP/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_ICMP_wo_assert/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IP_Utils/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IP_Utils_DiffConfig/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IPv4_Utils/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IPv6_Utils/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IPv4/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IPv4_DiffConfig/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IPv4_DiffConfig1/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IPv4_Sockets/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IP_Timers/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_ND/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_Sockets/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_Sockets_DiffConfig/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_Sockets_DiffConfig1/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_Stream_Buffer/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_RA/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_UDP_IP/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_UDP_IPv4/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_UDP_IPv6/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_Reception/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_IP/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_IP_DiffConfig/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_State_Handling/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_State_Handling_IPv4/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_State_Handling_IPv6/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_Transmission/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_Transmission_IPv6/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_Utils/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_Utils_IPv6/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IPv6/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_IPv6_ConfigDriverCheckChecksum/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_Sockets_IPv6/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_Routing/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_Routing_ConfigV4Only/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_Routing_ConfigCompatibleWithSingle/ut.cmake )
# ==================================== Coverage Analysis configuration ========================================
# Add a target for running coverage on tests.
add_custom_target( coverage
COMMAND ${CMAKE_COMMAND} -P ${MODULE_ROOT_DIR}/test/unit-test/cmock/coverage.cmake
DEPENDS cmock unity
FreeRTOS_ARP_utest
FreeRTOS_ARP_DataLenLessThanMinPacket_utest
FreeRTOS_BitConfig_utest
FreeRTOS_DHCP_utest
FreeRTOS_DHCPv6_utest
FreeRTOS_DNS_utest
FreeRTOS_DNS_Cache_utest
FreeRTOS_DNS_Callback_utest
FreeRTOS_DNS_ConfigNoCallback_utest
FreeRTOS_DNS_Networking_utest
FreeRTOS_DNS_Parser_utest
FreeRTOS_ICMP_utest
FreeRTOS_ICMP_wo_assert_utest
FreeRTOS_IP_utest
FreeRTOS_IP_DiffConfig_utest
FreeRTOS_IP_DiffConfig1_utest
FreeRTOS_IP_DiffConfig2_utest
FreeRTOS_IP_DiffConfig3_utest
FreeRTOS_IP_Timers_utest
FreeRTOS_IP_Utils_utest
FreeRTOS_IP_Utils_DiffConfig_utest
FreeRTOS_IPv4_utest
FreeRTOS_IPv4_DiffConfig_utest
FreeRTOS_IPv4_DiffConfig1_utest
FreeRTOS_IPv4_Sockets_utest
FreeRTOS_IPv4_Utils_utest
FreeRTOS_IPv6_utest
FreeRTOS_IPv6_ConfigDriverCheckChecksum_utest
FreeRTOS_IPv6_Utils_utest
FreeRTOS_ND_utest
FreeRTOS_RA_utest
FreeRTOS_Routing_utest
FreeRTOS_Routing_ConfigCompatibleWithSingle_utest
FreeRTOS_Routing_ConfigV4Only_utest
FreeRTOS_Sockets_GenericAPI_utest
FreeRTOS_Sockets_privates_utest
FreeRTOS_Sockets_TCP_API_utest
FreeRTOS_Sockets_UDP_API_utest
FreeRTOS_Sockets_DiffConfig_privates_utest
FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest
FreeRTOS_Sockets_DiffConfig1_privates_utest
FreeRTOS_Sockets_DiffConfig1_TCP_API_utest
FreeRTOS_Sockets_DiffConfig1_UDP_API_utest
FreeRTOS_Sockets_IPv6_utest
FreeRTOS_Stream_Buffer_utest
FreeRTOS_TCP_IP_utest
FreeRTOS_TCP_IP_DiffConfig_utest
FreeRTOS_TCP_Reception_utest
FreeRTOS_TCP_State_Handling_utest
FreeRTOS_TCP_State_Handling_IPv4_utest
FreeRTOS_TCP_State_Handling_IPv6_utest
FreeRTOS_TCP_Transmission_utest
FreeRTOS_TCP_Transmission_IPv6_utest
FreeRTOS_TCP_Utils_utest
FreeRTOS_TCP_Utils_IPv6_utest
FreeRTOS_TCP_WIN_utest
FreeRTOS_Tiny_TCP_utest
FreeRTOS_UDP_IP_utest
FreeRTOS_UDP_IPv4_utest
FreeRTOS_UDP_IPv6_utest
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
@@ -0,0 +1,124 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <assert.h>
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_STATIC_ALLOCATION 1
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */
/* Software timer related configuration options. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configMAX_PRIORITIES ( 7 )
#define configENABLE_MPU 0
/* Run time stats gathering configuration options. */
#define configGENERATE_RUN_TIME_STATS 1
/* This demo makes use of one or more example stats formatting functions. These
* format the raw data provided by the uxTaskGetSystemState() function in to human
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
/* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. */
extern void vAssertCalled( unsigned long ulLine,
const char * const pcFileName );
#define configASSERT( x ) assert( x )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
/* #include "trcRecorder.h" */
#endif /* FREERTOS_CONFIG_H */
@@ -0,0 +1,336 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
#define ipconfigIPv4_BACKWARD_COMPATIBLE 0
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 0
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 1 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks using pdMS_TO_TICKS().*/
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 5000U )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 5
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD pdMS_TO_TICKS( 120000U )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 pdMS_TO_TICKS( 20 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigUSE_MDNS ( 1 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,34 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for an explanation of this file:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/10-Porting/02-Embedded_Compiler_Porting
*
*****************************************************************************/
__attribute__( ( packed ) );
@@ -0,0 +1,35 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for an explanation of this file:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/10-Porting/02-Embedded_Compiler_Porting
*
*****************************************************************************/
/* Nothing to do here. */
@@ -0,0 +1,144 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef PORTMACRO_H
#define PORTMACRO_H
#include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------
* Port specific definitions.
*
* The settings in this file configure FreeRTOS correctly for the
* given hardware and compiler.
*
* These settings should not be altered.
*-----------------------------------------------------------
*/
/* Type definitions. */
#define portCHAR char
#define portFLOAT float
#define portDOUBLE double
#define portLONG long
#define portSHORT short
#define portSTACK_TYPE unsigned long
#define portBASE_TYPE long
#define portPOINTER_SIZE_TYPE intptr_t
typedef portSTACK_TYPE StackType_t;
typedef long BaseType_t;
typedef unsigned long UBaseType_t;
typedef unsigned long TickType_t;
#define portMAX_DELAY ( TickType_t ) ULONG_MAX
#define portTICK_TYPE_IS_ATOMIC 1
/*-----------------------------------------------------------*/
/* Architecture specifics. */
#define portSTACK_GROWTH ( -1 )
#define portHAS_STACK_OVERFLOW_CHECKING ( 1 )
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
#define portTICK_RATE_MICROSECONDS ( ( portTickType ) 1000000 / configTICK_RATE_HZ )
#define portBYTE_ALIGNMENT 8
/*-----------------------------------------------------------*/
/* Scheduler utilities. */
extern void vPortYield( void );
#define portYIELD() vPortYield()
#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) vPortYield( )
#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
/*-----------------------------------------------------------*/
/* Critical section management. */
extern void vPortDisableInterrupts( void );
extern void vPortEnableInterrupts( void );
#define portSET_INTERRUPT_MASK() ( vPortDisableInterrupts() )
#define portCLEAR_INTERRUPT_MASK() ( vPortEnableInterrupts() )
extern portBASE_TYPE xPortSetInterruptMask( void );
extern void vPortClearInterruptMask( portBASE_TYPE xMask );
extern void vPortEnterCritical( void );
extern void vPortExitCritical( void );
#define portSET_INTERRUPT_MASK_FROM_ISR() xPortSetInterruptMask()
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vPortClearInterruptMask( x )
#define portDISABLE_INTERRUPTS() portSET_INTERRUPT_MASK()
#define portENABLE_INTERRUPTS() portCLEAR_INTERRUPT_MASK()
#define portENTER_CRITICAL() vPortEnterCritical()
#define portEXIT_CRITICAL() vPortExitCritical()
/*-----------------------------------------------------------*/
extern void vPortThreadDying( void * pxTaskToDelete,
volatile BaseType_t * pxPendYield );
extern void vPortCancelThread( void * pxTaskToDelete );
#define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortThreadDying( ( pvTaskToDelete ), ( pxPendYield ) )
#define portCLEAN_UP_TCB( pxTCB ) vPortCancelThread( pxTCB )
/*-----------------------------------------------------------*/
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
/*-----------------------------------------------------------*/
/** We need to define it here because CMock does not recognize the
* #if ( portUSING_MPU_WRAPPERS == 1 ) guard around xTaskGetMPUSettings
* and then complains about the missing xMPU_SETTINGS type in the
* generated mocks. */
typedef struct MPU_SETTINGS
{
uint32_t ulDummy;
} xMPU_SETTINGS;
/*
* Tasks run in their own pthreads and context switches between them
* are always a full memory barrier. ISRs are emulated as signals
* which also imply a full memory barrier.
*
* Thus, only a compiler barrier is needed to prevent the compiler
* reordering.
*/
#define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" )
extern unsigned long ulPortGetRunTime( void );
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() /* no-op */
#define portGET_RUN_TIME_COUNTER_VALUE() ulPortGetRunTime()
#ifdef __cplusplus
}
#endif
#endif /* PORTMACRO_H */
@@ -0,0 +1,150 @@
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
/** @brief A list of all network end-points. Each element has a next pointer. */
struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer = NULL;
volatile BaseType_t xInsideInterrupt = pdFALSE;
/** @brief For convenience, a MAC address of all 0xffs is defined const for quick
* reference. */
const MACAddress_t xBroadcastMACAddress = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
/** @brief Structure that stores the netmask, gateway address and DNS server addresses. */
NetworkAddressingParameters_t xNetworkAddressing =
{
0xC0C0C0C0, /* 192.192.192.192 - Default IP address. */
0xFFFFFF00, /* 255.255.255.0 - Netmask. */
0xC0C0C001, /* 192.192.192.1 - Gateway Address. */
0x01020304, /* 1.2.3.4 - DNS server address. */
0xC0C0C0FF
}; /* 192.192.192.255 - Broadcast address. */
/* ======================== Stub Callback Functions ========================= */
size_t xPortGetMinimumEverFreeHeapSize( void )
{
return 0;
}
BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint,
const char * pcName )
{
}
StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
StackType_t * pxEndOfStack,
TaskFunction_t pxCode,
void * pvParameters )
{
}
const char * pcApplicationHostnameHook( void )
{
}
uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
{
}
BaseType_t xNetworkInterfaceInitialise( void )
{
}
/* This function shall be defined by the application. */
void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent,
struct xNetworkEndPoint * pxEndPoint )
{
}
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
{
}
void vApplicationDaemonTaskStartupHook( void )
{
}
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
configSTACK_DEPTH_TYPE * puxTimerTaskStackSize )
{
}
void vPortDeleteThread( void * pvTaskToDelete )
{
}
void vApplicationIdleHook( void )
{
}
void vApplicationTickHook( void )
{
}
unsigned long ulGetRunTimeCounterValue( void )
{
}
void vPortEndScheduler( void )
{
}
BaseType_t xPortStartScheduler( void )
{
}
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xWantedSize )
{
return malloc( xWantedSize );
}
void vPortFree( void * pv )
{
free( pv );
}
void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber )
{
}
void vPortCloseRunningThread( void * pvTaskToDelete,
volatile BaseType_t * pxPendYield )
{
}
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
configSTACK_DEPTH_TYPE * puxIdleTaskStackSize )
{
}
void vConfigureTimerForRunTimeStats( void )
{
}
BaseType_t xNetworkInterfaceOutput( NetworkInterface_t * pxInterface,
NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t bReleaseAfterSend )
{
return pdPASS;
}
/**
* @brief Send an ND advertisement.
* @param[in] pxEndPoint: The end-point for which an ND advertisement should be sent.
*/
void FreeRTOS_OutputAdvertiseIPv6( NetworkEndPoint_t * pxEndPoint )
{
}
/*-----------------------------------------------------------*/
@@ -0,0 +1,98 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_ARP" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ND.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
)
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
)
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
# list the files you would like to test here
list(APPEND real_source_files
${MODULE_ROOT_DIR}/source/FreeRTOS_ARP.c
)
# list the directories the module under test includes
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,35 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#endif /* ifndef LIST_MACRO_H */
@@ -0,0 +1,332 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigUSE_IPv4 ( 1 )
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 0
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 1 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks by dividing the time in
* milliseconds by portTICK_PERIOD_MS. */
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 5
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD \
( 120000U / portTICK_PERIOD_MS )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 pdMS_TO_TICKS( 20 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
/* Value smaller than ARP packet size. */
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 40 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,137 @@
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer = NULL;
volatile BaseType_t xInsideInterrupt = pdFALSE;
/** @brief For convenience, a MAC address of all 0xffs is defined const for quick
* reference. */
const MACAddress_t xBroadcastMACAddress = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
/** @brief Structure that stores the netmask, gateway address and DNS server addresses. */
NetworkAddressingParameters_t xNetworkAddressing =
{
0xC0C0C0C0, /* 192.192.192.192 - Default IP address. */
0xFFFFFF00, /* 255.255.255.0 - Netmask. */
0xC0C0C001, /* 192.192.192.1 - Gateway Address. */
0x01020304, /* 1.2.3.4 - DNS server address. */
0xC0C0C0FF
}; /* 192.192.192.255 - Broadcast address. */
size_t xPortGetMinimumEverFreeHeapSize( void )
{
return 0;
}
/* Even though the function is defined in main.c, the rule is violated. */
/* misra_c_2012_rule_8_6_violation */
extern BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint,
const char * pcName )
{
}
StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
StackType_t * pxEndOfStack,
TaskFunction_t pxCode,
void * pvParameters )
{
}
const char * pcApplicationHostnameHook( void )
{
}
uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
{
}
/* This function shall be defined by the application. */
void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent,
struct xNetworkEndPoint * pxEndPoint )
{
}
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
{
}
void vApplicationDaemonTaskStartupHook( void )
{
}
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
configSTACK_DEPTH_TYPE * puxTimerTaskStackSize )
{
}
void vPortDeleteThread( void * pvTaskToDelete )
{
}
void vApplicationIdleHook( void )
{
}
void vApplicationTickHook( void )
{
}
unsigned long ulGetRunTimeCounterValue( void )
{
}
void vPortEndScheduler( void )
{
}
BaseType_t xPortStartScheduler( void )
{
}
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xWantedSize )
{
return malloc( xWantedSize );
}
void vPortFree( void * pv )
{
free( pv );
}
void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber )
{
}
void vPortCloseRunningThread( void * pvTaskToDelete,
volatile BaseType_t * pxPendYield )
{
}
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
configSTACK_DEPTH_TYPE * puxIdleTaskStackSize )
{
}
void vConfigureTimerForRunTimeStats( void )
{
}
/**
* @brief Send an ND advertisement.
* @param[in] pxEndPoint: The end-point for which an ND advertisement should be sent.
*/
void FreeRTOS_OutputAdvertiseIPv6( NetworkEndPoint_t * pxEndPoint )
{
}
@@ -0,0 +1,66 @@
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOSIPConfig.h"
#include "mock_FreeRTOS_IP.h"
#include "mock_FreeRTOS_Routing.h"
#include "mock_FreeRTOS_IP_Utils.h"
#include "mock_FreeRTOS_IP_Timers.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_task.h"
#include "mock_NetworkBufferManagement.h"
#include "mock_NetworkInterface.h"
#include "mock_ARP_DataLenLessThanMinPacket_list_macros.h"
#include "FreeRTOS_ARP_DataLenLessThanMinPacket_stubs.c"
#include "FreeRTOS_ARP.h"
#include "catch_assert.h"
static uint32_t uInterfaceOut_Called = 0;
BaseType_t xNetworkInterfaceOutput_ARP_Stub( NetworkInterface_t * pxInterface,
NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t bReleaseAfterSend )
{
uInterfaceOut_Called = 1;
return pdTRUE_UNSIGNED;
}
void test_FreeRTOS_OutputARPRequest_MinimumPacketSizeLessThanARPPacket( void )
{
NetworkEndPoint_t xEndPoint = { 0 };
NetworkInterface_t xInterface;
uint8_t ucBuffer[ sizeof( ARPPacket_t ) + ipBUFFER_PADDING + ipconfigETHERNET_MINIMUM_PACKET_BYTES ];
NetworkBufferDescriptor_t xNetworkBuffer = { 0 };
uint32_t ulIPAddress = 0xAAAAAAAA;
xNetworkBuffer.pucEthernetBuffer = ucBuffer;
xNetworkBuffer.xDataLength = sizeof( ARPPacket_t );
xInterface.pfOutput = xNetworkInterfaceOutput_ARP_Stub;
xEndPoint.pxNetworkInterface = &xInterface;
xEndPoint.bits.bIPv6 = pdFALSE_UNSIGNED;
xEndPoint.ipv4_settings.ulIPAddress = 0xC0C0C0C0;
/* =================================================== */
FreeRTOS_FindEndPointOnNetMask_ExpectAndReturn( ulIPAddress, &xEndPoint );
pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( ARPPacket_t ), 0, &xNetworkBuffer );
xIsCallingFromIPTask_IgnoreAndReturn( pdTRUE );
FreeRTOS_OutputARPRequest( ulIPAddress );
TEST_ASSERT_EQUAL( uInterfaceOut_Called, 1 );
/* =================================================== */
}
@@ -0,0 +1,104 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_ARP_DataLenLessThanMinPacket" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ND.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkInterface.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/ARP_DataLenLessThanMinPacket_list_macros.h"
)
# list the directories your mocks need
set(mock_include_list "")
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
)
#list the definitions of your mocks to control what to be included
set (mock_define_list "")
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
# list the files you would like to test here
set(real_source_files "")
list(APPEND real_source_files
${MODULE_ROOT_DIR}/source/FreeRTOS_ARP.c
)
# list the directories the module under test includes
set(real_include_directories "")
list(APPEND real_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
# list the directories your test needs to include
set(test_include_directories "")
list(APPEND test_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set (utest_link_list "")
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set(utest_dep_list "")
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,647 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_FreeRTOS_IP.h"
#include "mock_task.h"
#include "mock_queue.h"
#include "mock_portable.h"
#include "FreeRTOS_BitConfig.h"
#include "mock_list.h"
#include "FreeRTOSIPConfig.h"
/* =========================== EXTERN VARIABLES =========================== */
/* The length of the binary data stream used for validating test cases. */
#define SIZE_OF_BINARY_STREAM 10
/* ============================== Test Cases ============================== */
/**
* @brief This functions verifies failure in initialising
* a bit-config struct when Memory Allocation fails.
*/
void test_xBitConfig_init_Fail( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
uint8_t * pucData = NULL;
size_t uxSize = SIZE_OF_BINARY_STREAM;
BaseType_t xResult = pdFALSE;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
pvPortMalloc_ExpectAnyArgsAndReturn( NULL );
xResult = xBitConfig_init( pxConfig, pucData, uxSize );
TEST_ASSERT_EQUAL( pdFALSE, xResult );
TEST_ASSERT_EQUAL( pdTRUE, pxConfig->xHasError );
}
/**
* @brief This functions verifies bit-config struct
* Memory Allocation when pucData is NULL
* which means bit-stream not to be analysed.
*/
void test_xBitConfig_init_pucDataNull( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
uint8_t * pucData = NULL;
/* The length of the binary data stream. */
size_t uxSize = SIZE_OF_BINARY_STREAM;
uint8_t ucContent[ uxSize ], ucContentReturn[ uxSize ];
BaseType_t xResult = pdFALSE;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
memset( ucContent, 1, uxSize );
memset( ucContentReturn, 0, uxSize );
pxConfig->ucContents = ucContent;
pvPortMalloc_ExpectAnyArgsAndReturn( ucContent );
xResult = xBitConfig_init( pxConfig, pucData, uxSize );
TEST_ASSERT_EQUAL( pdTRUE, xResult );
TEST_ASSERT_EQUAL( uxSize, pxConfig->uxSize );
TEST_ASSERT_EQUAL_MEMORY( pxConfig->ucContents, ucContentReturn, uxSize );
}
/**
* @brief This functions verifies bit-config struct
* Memory Allocation when pucData is Not NULL
* which means bit-stream must be analysed.
*/
void test_xBitConfig_init_HappyPath( void )
{
BitConfig_t xConfig;
/* The length of the binary data stream. */
size_t uxSize = SIZE_OF_BINARY_STREAM;
uint8_t ucContent[ uxSize ];
uint8_t ucData[ uxSize ];
BaseType_t xResult = pdFALSE;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
memset( &ucData, 1, uxSize );
memset( &ucContent, 0, uxSize );
xConfig.ucContents = ucContent;
pvPortMalloc_ExpectAnyArgsAndReturn( ucContent );
xResult = xBitConfig_init( &xConfig, ucData, uxSize );
TEST_ASSERT_EQUAL( pdTRUE, xResult );
TEST_ASSERT_EQUAL( uxSize, xConfig.uxSize );
TEST_ASSERT_EQUAL_MEMORY( ucContent, ucData, uxSize );
}
/**
* @brief This functions verifies failure of
* reading from a bit-config struct as
* xHasError bit is set.
*/
void test_xBitConfig_read_uc_xHasError( void )
{
BitConfig_t xConfig;
uint8_t * pucData = NULL;
BaseType_t xResult = pdFALSE;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
xConfig.xHasError = pdTRUE;
xResult = xBitConfig_read_uc( &xConfig, pucData, SIZE_OF_BINARY_STREAM );
TEST_ASSERT_EQUAL( pdFALSE, xResult );
}
/**
* @brief This functions verifies failure of
* reading from a bit-config struct as
* an out of bound read.
*/
void test_xBitConfig_read_uc_OutOfBoundRead( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
BaseType_t xResult = pdFALSE;
memset( pxConfig, 0, sizeof( BitConfig_t ) );
pxConfig->xHasError = pdFALSE;
pxConfig->uxIndex = 1;
pxConfig->uxSize = SIZE_OF_BINARY_STREAM;
xResult = xBitConfig_read_uc( pxConfig, NULL, SIZE_OF_BINARY_STREAM );
TEST_ASSERT_EQUAL( pdFALSE, xResult );
TEST_ASSERT_EQUAL( pdTRUE, pxConfig->xHasError );
}
/**
* @brief This functions verifies failure of
* reading from a bit-config struct with
* pucData as NULL.
*/
void test_xBitConfig_read_uc_NullData( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
BaseType_t xResult = pdFALSE;
memset( pxConfig, 0, sizeof( BitConfig_t ) );
pxConfig->xHasError = pdFALSE;
pxConfig->uxIndex = 0;
pxConfig->uxSize = SIZE_OF_BINARY_STREAM;
xResult = xBitConfig_read_uc( pxConfig, NULL, SIZE_OF_BINARY_STREAM );
TEST_ASSERT_EQUAL( pdTRUE, xResult );
TEST_ASSERT_EQUAL( SIZE_OF_BINARY_STREAM, pxConfig->uxIndex );
}
/**
* @brief This functions verifies successful
* reading from a bit-config struct.
*/
void test_xBitConfig_read_uc_HappyPath( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM;
uint8_t ucContents[ uxSize ], ucData[ uxSize ];
BaseType_t xResult = pdFALSE;
memset( pxConfig, 0, sizeof( BitConfig_t ) );
memset( ucContents, 1, uxSize );
memset( ucData, 0, uxSize );
memset( ucContents, 1, uxSize );
pxConfig->xHasError = pdFALSE;
pxConfig->uxIndex = 0;
pxConfig->uxSize = uxSize;
pxConfig->ucContents = ucContents;
xResult = xBitConfig_read_uc( pxConfig, ucData, uxSize );
TEST_ASSERT_EQUAL( pdTRUE, xResult );
TEST_ASSERT_EQUAL( uxSize, pxConfig->uxIndex );
TEST_ASSERT_EQUAL_MEMORY( pxConfig->ucContents, ucData, uxSize );
}
/**
* @brief This functions verifies failure to
* Peek the last byte from a bit-config
* struct as xHasError bit is set.
*/
void test_pucBitConfig_peek_last_index_uc_xHasError( void )
{
BitConfig_t xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM;
BaseType_t xResult = pdFALSE;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
xConfig.xHasError = pdTRUE;
xResult = pucBitConfig_peek_last_index_uc( &xConfig, NULL, uxSize );
TEST_ASSERT_EQUAL( pdFALSE, xResult );
}
/**
* @brief This functions verifies failure to
* Peek the last byte from a bit-config
* struct as pucData is NULL.
*/
void test_pucBitConfig_peek_last_index_uc_NullpucData( void )
{
BitConfig_t xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM;
BaseType_t xResult = pdFALSE;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
xConfig.xHasError = pdFALSE;
xConfig.uxIndex = uxSize;
xResult = pucBitConfig_peek_last_index_uc( &xConfig, NULL, uxSize );
TEST_ASSERT_EQUAL( pdFALSE, xResult );
TEST_ASSERT_EQUAL( pdTRUE, xConfig.xHasError );
}
/**
* @brief This functions verifies failure to
* Peek the last byte from a bit-config
* struct as an out of bound peak.
*/
void test_pucBitConfig_peek_OutOfBound( void )
{
BitConfig_t xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM;
uint8_t ucData;
BaseType_t xResult = pdFALSE;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
xConfig.xHasError = pdFALSE;
xConfig.uxIndex = 0;
xResult = pucBitConfig_peek_last_index_uc( &xConfig, &ucData, uxSize );
TEST_ASSERT_EQUAL( pdFALSE, xResult );
TEST_ASSERT_EQUAL( pdTRUE, xConfig.xHasError );
}
/**
* @brief This functions verifies success while
* Peeking the last 5 byte from a bit-config
* struct.
*/
void test_pucBitConfig_peek_last_index_uc_HappyPath( void )
{
BitConfig_t xConfig;
size_t uxSize = 5; /* Read last 5 bytes */
uint8_t ucData[ uxSize ], ucContents[ SIZE_OF_BINARY_STREAM ];
BaseType_t xResult = pdFALSE;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
memset( ucData, 0, uxSize );
memset( ucContents, 1, SIZE_OF_BINARY_STREAM );
xConfig.xHasError = pdFALSE;
xConfig.uxIndex = SIZE_OF_BINARY_STREAM;
xConfig.ucContents = ucContents;
xResult = pucBitConfig_peek_last_index_uc( &xConfig, ucData, uxSize );
TEST_ASSERT_EQUAL( pdTRUE, xResult );
TEST_ASSERT_EQUAL_MEMORY( xConfig.ucContents, ucData, uxSize );
}
/**
* @brief This functions verifies failure to
* returning a byte from the bit stream
* as xHasError is set.
*/
void test_ucBitConfig_read_8_fail( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
uint8_t ucResult;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
pxConfig->xHasError = pdTRUE;
ucResult = ucBitConfig_read_8( pxConfig );
TEST_ASSERT_EQUAL( 0xffU, ucResult );
}
/**
* @brief This functions verifies successfully reading
* a byte from the bit stream.
*/
void test_xBitConfig_read_8_HappyPath( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM;
uint8_t ucContents[ uxSize ];
uint8_t ucResult;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
memset( &ucContents, 0, uxSize );
memset( ucContents, 1, uxSize );
pxConfig->xHasError = pdFALSE;
pxConfig->uxIndex = 0;
pxConfig->uxSize = uxSize;
pxConfig->ucContents = ucContents;
ucResult = ucBitConfig_read_8( pxConfig );
TEST_ASSERT_EQUAL( ucContents[ 0 ], ucResult );
TEST_ASSERT_EQUAL( 1, pxConfig->uxIndex );
}
/**
* @brief This functions verifies failure to
* returning 2 byte from the bit stream
* as xHasError is set.
*/
void test_usBitConfig_read_16_fail( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
uint16_t ucResult;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
pxConfig->xHasError = pdTRUE;
ucResult = usBitConfig_read_16( pxConfig );
TEST_ASSERT_EQUAL( 0xffffU, ucResult );
TEST_ASSERT_EQUAL( pdTRUE, xConfig.xHasError );
}
/**
* @brief This functions verifies reading and
* returning 2 byte from the bit stream.
*/
void test_usBitConfig_read_16_HappyPath( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM;
uint8_t ucContents[ uxSize ];
uint16_t ucResult, ucResultExpected;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
memset( ucContents, 1, uxSize );
pxConfig->xHasError = pdFALSE;
pxConfig->uxIndex = 0;
pxConfig->uxSize = uxSize;
pxConfig->ucContents = ucContents;
ucResultExpected = ( ( ( uint16_t ) ucContents[ 0 ] ) << 8 ) |
( ( ( uint16_t ) ucContents[ 1 ] ) );
ucResult = usBitConfig_read_16( pxConfig );
TEST_ASSERT_EQUAL( ucResultExpected, ucResult );
}
/**
* @brief This functions verifies failure to
* returning 4 byte from the bit stream
* as xHasError is set.
*/
void test_ulBitConfig_read_32_fail( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
uint32_t ulResult;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
pxConfig->xHasError = pdTRUE;
ulResult = ulBitConfig_read_32( pxConfig );
TEST_ASSERT_EQUAL( 0xffffffffU, ulResult );
TEST_ASSERT_EQUAL( pdTRUE, xConfig.xHasError );
}
/**
* @brief This functions verifies reading and
* returning 4 byte from the bit stream.
*/
void test_ulBitConfig_read_32_HappyPath( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM;
uint8_t ucContents[ uxSize ];
uint32_t ulResult, ulResultExpected;
memset( &xConfig, 0, sizeof( BitConfig_t ) );
memset( ucContents, 1, uxSize );
pxConfig->xHasError = pdFALSE;
pxConfig->uxIndex = 0;
pxConfig->uxSize = uxSize;
pxConfig->ucContents = ucContents;
ulResultExpected = ( ( ( uint32_t ) ucContents[ 0 ] ) << 24 ) |
( ( ( uint32_t ) ucContents[ 1 ] ) << 16 ) |
( ( ( uint32_t ) ucContents[ 2 ] ) << 8 ) |
( ( ( uint32_t ) ucContents[ 3 ] ) );
ulResult = ulBitConfig_read_32( pxConfig );
TEST_ASSERT_EQUAL( ulResultExpected, ulResult );
TEST_ASSERT_EQUAL( sizeof( uint32_t ), pxConfig->uxIndex );
}
/**
* @brief This functions verifies failure to
* writing any number of bytes from the bit stream.
*/
void test_vBitConfig_write_uc_xHasError( void )
{
BitConfig_t xConfig = { 0 };
xConfig.xHasError = pdTRUE;
vBitConfig_write_uc( &xConfig, NULL, SIZE_OF_BINARY_STREAM );
TEST_ASSERT_EQUAL( pdTRUE, xConfig.xHasError );
}
/**
* @brief This functions verifies failure to
* writing bytes to bit stream because
* of out of bound write.
*/
void test_vBitConfig_write_uc_OutOfBoundWrite( void )
{
BitConfig_t xConfig = { 0 };
xConfig.xHasError = pdFALSE;
xConfig.uxIndex = SIZE_OF_BINARY_STREAM;
xConfig.uxSize = SIZE_OF_BINARY_STREAM;
vBitConfig_write_uc( &xConfig, NULL, SIZE_OF_BINARY_STREAM );
TEST_ASSERT_EQUAL( pdTRUE, xConfig.xHasError );
}
/**
* @brief This functions verifies writing SIZE_OF_BINARY_STREAM
* bytes in the bit stream.
*/
void test_vBitConfig_write_uc_HappyPath( void )
{
BitConfig_t xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM;
uint8_t ucContents[ uxSize ];
uint8_t ucData[ uxSize ];
memset( &xConfig, 0, sizeof( BitConfig_t ) );
memset( ucContents, 0, uxSize );
memset( ucContents, 1, uxSize );
xConfig.xHasError = pdFALSE;
xConfig.uxIndex = 0;
xConfig.uxSize = uxSize;
xConfig.ucContents = ucContents;
vBitConfig_write_uc( &xConfig, ucData, uxSize );
TEST_ASSERT_EQUAL( SIZE_OF_BINARY_STREAM, xConfig.uxIndex );
TEST_ASSERT_EQUAL_MEMORY( xConfig.ucContents, ucData, uxSize );
}
/**
* @brief This functions verifies writing a
* byte to the bit stream.
*/
void test_vBitConfig_write_8( void )
{
BitConfig_t xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM, uxIndex = 0;
uint8_t ucValue = 1;
uint8_t ucContents[ uxSize ];
memset( &xConfig, 0, sizeof( BitConfig_t ) );
memset( ucContents, 0, uxSize );
xConfig.xHasError = pdFALSE;
xConfig.uxIndex = uxIndex;
xConfig.uxSize = uxSize;
xConfig.ucContents = ucContents;
vBitConfig_write_8( &xConfig, ucValue );
TEST_ASSERT_EQUAL( sizeof( uint8_t ), xConfig.uxIndex );
TEST_ASSERT_EQUAL( xConfig.ucContents[ uxIndex ], ucValue );
}
/**
* @brief This functions verifies writing a
* 2 byte to the bit stream.
*/
void test_vBitConfig_write_16( void )
{
BitConfig_t xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM;
uint16_t ucValue = 0;
uint8_t ucContents[ uxSize ];
uint8_t pucData[ sizeof ucValue ];
pucData[ 0 ] = ( uint8_t ) ( ( ucValue >> 8 ) & 0xFFU );
pucData[ 1 ] = ( uint8_t ) ( ucValue & 0xFFU );
memset( &xConfig, 0, sizeof( BitConfig_t ) );
memset( ucContents, 0, uxSize );
xConfig.xHasError = pdFALSE;
xConfig.uxIndex = 0;
xConfig.uxSize = uxSize;
xConfig.ucContents = ucContents;
vBitConfig_write_16( &xConfig, ucValue );
TEST_ASSERT_EQUAL( sizeof( uint16_t ), xConfig.uxIndex );
TEST_ASSERT_EQUAL_MEMORY( xConfig.ucContents, pucData, sizeof( ucValue ) );
}
/**
* @brief This functions verifies writing a
* 4 byte to the bit stream.
*/
void test_vBitConfig_write_32( void )
{
BitConfig_t xConfig;
size_t uxSize = SIZE_OF_BINARY_STREAM;
uint32_t ucValue = 0;
uint8_t ucContents[ uxSize ];
uint8_t pucData[ sizeof( ucValue ) ];
memset( &xConfig, 0, sizeof( BitConfig_t ) );
xConfig.xHasError = pdFALSE;
xConfig.uxIndex = 0;
xConfig.uxSize = uxSize;
xConfig.ucContents = ucContents;
pucData[ 0 ] = ( uint8_t ) ( ( ucValue >> 24 ) & 0xFFU );
pucData[ 1 ] = ( uint8_t ) ( ( ucValue >> 16 ) & 0xFFU );
pucData[ 2 ] = ( uint8_t ) ( ( ucValue >> 8 ) & 0xFFU );
pucData[ 3 ] = ( uint8_t ) ( ucValue & 0xFFU );
vBitConfig_write_32( &xConfig, ucValue );
TEST_ASSERT_EQUAL( sizeof( uint32_t ), xConfig.uxIndex );
TEST_ASSERT_EQUAL_MEMORY( xConfig.ucContents, pucData, sizeof( ucValue ) );
}
/**
* @brief This functions verifies failure in
* releasing the buffer as it is NULL.
*/
void test_vBitConfig_NoReleaseNULL( void )
{
BitConfig_t * pxConfig = NULL;
vBitConfig_release( pxConfig );
}
/**
* @brief This functions verifies failure in
* release the buffer as it is NULL.
*/
void test_vBitConfig_ReleaseNULL( void )
{
BitConfig_t xConfig, xConfigExpected;
memset( &xConfig, 1, sizeof( BitConfig_t ) );
memset( &xConfigExpected, 0, sizeof( BitConfig_t ) );
xConfig.ucContents = NULL;
vBitConfig_release( &xConfig );
TEST_ASSERT_EQUAL_MEMORY( &xConfigExpected, &xConfig, sizeof( BitConfig_t ) );
}
/**
* @brief This functions verifies releasing
* the buffer and clear the bit stream structure.
*/
void test_vBitConfig_Release( void )
{
BitConfig_t xConfig, xConfigExpected;
uint8_t ucContent[ SIZE_OF_BINARY_STREAM ];
memset( &xConfig, 1, sizeof( BitConfig_t ) );
memset( ucContent, 1, SIZE_OF_BINARY_STREAM );
memset( &xConfigExpected, 0, sizeof( BitConfig_t ) );
xConfig.ucContents = ucContent;
vPortFree_ExpectAnyArgs();
vBitConfig_release( &xConfig );
TEST_ASSERT_EQUAL_MEMORY( &xConfigExpected, &xConfig, sizeof( BitConfig_t ) );
}
@@ -0,0 +1,106 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_BitConfig" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/portable.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/${project_name}.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set( utest_dep_list "" )
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,5 @@
#include "FreeRTOS_DHCP.h"
eDHCPCallbackAnswer_t xApplicationDHCPHook_Multi( eDHCPCallbackPhase_t eDHCPPhase,
struct xNetworkEndPoint * pxEndPoint,
IP_Address_t * pxIPAddress );
@@ -0,0 +1,752 @@
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#define prvROUND_UP_TO( SIZE, ALIGNMENT ) ( ( ( SIZE ) + ( ALIGNMENT ) -1 ) / ( ALIGNMENT ) *( ALIGNMENT ) )
/* FIXME: Consider instead fixing ipBUFFER_PADDING if it's supposed to be pointer aligned. */
#define prvALIGNED_BUFFER_PADDING prvROUND_UP_TO( ipBUFFER_PADDING, sizeof( void * ) )
struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
NetworkInterface_t xInterfaces[ 1 ];
DHCPData_t xDHCPData;
volatile BaseType_t xInsideInterrupt = pdFALSE;
const MACAddress_t xDefault_MacAddress = { { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } };
#define xSizeofUDPBuffer 300
Socket_t xDHCPSocket;
extern Socket_t xDHCPv4Socket;
eDHCPCallbackPhase_t eStubExpectedDHCPPhase;
struct xNetworkEndPoint * pxStubExpectedEndPoint;
uint32_t ulStubExpectedIPAddress;
eDHCPCallbackAnswer_t eStubExpectedReturn;
static uint8_t * ucGenericPtr;
static int32_t ulGenericLength;
static NetworkBufferDescriptor_t * pxGlobalNetworkBuffer[ 10 ];
static uint8_t GlobalBufferCounter = 0;
static uint8_t pucUDPBuffer[ xSizeofUDPBuffer ];
static uint8_t DHCP_header[] =
{
dhcpREPLY_OPCODE, /**< Operation Code: Specifies the general type of message. */
0x01, /**< Hardware type used on the local network. */
0x06, /**< Hardware Address Length: Specifies how long hardware
* addresses are in this message. */
0x02, /**< Hops. */
0x01, 0xAB, 0xCD, 0xEF, /**< A 32-bit identification field generated by the client,
* to allow it to match up the request with replies received
* from DHCP servers. */
0x01, /**< Number of seconds elapsed since a client began an attempt to acquire or renew a lease. */
0x00, /**< Just one bit used to indicate broadcast. */
0xC0, 0xA8, 0x00, 0x0A, /**< Client's IP address if it has one or 0 is put in this field. */
0x00, 0xAA, 0xAA, 0xAA, /**< The IP address that the server is assigning to the client. */
0x00, 0xAA, 0xAA, 0xAA, /**< The DHCP server address that the client should use. */
0x00, 0xAA, 0xAA, 0xAA /**< Gateway IP address in case the server client are on different subnets. */
};
/*
* IP-clash detection is currently only used internally. When DHCP doesn't respond, the
* driver can try out a random LinkLayer IP address (169.254.x.x). It will send out a
* gratuitous ARP message and, after a period of time, check the variables here below:
*/
#if ( ipconfigARP_USE_CLASH_DETECTION != 0 )
/* Becomes non-zero if another device responded to a gratuitous ARP message. */
BaseType_t xARPHadIPClash;
/* MAC-address of the other device containing the same IP-address. */
MACAddress_t xARPClashMacAddress;
#endif /* ipconfigARP_USE_CLASH_DETECTION */
/** @brief For convenience, a MAC address of all 0xffs is defined const for quick
* reference. */
const MACAddress_t xBroadcastMACAddress = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
/** @brief Structure that stores the netmask, gateway address and DNS server addresses. */
NetworkAddressingParameters_t xNetworkAddressing =
{
0xC0C0C0C0, /* 192.192.192.192 - Default IP address. */
0xFFFFFF00, /* 255.255.255.0 - Netmask. */
0xC0C0C001, /* 192.192.192.1 - Gateway Address. */
0x01020304, /* 1.2.3.4 - DNS server address. */
0xC0C0C0FF
}; /* 192.192.192.255 - Broadcast address. */
/** @brief Structure that stores the netmask, gateway address and DNS server addresses. */
NetworkAddressingParameters_t xDefaultAddressing =
{
0xC0C0C0C0, /* 192.192.192.192 - Default IP address. */
0xFFFFFF00, /* 255.255.255.0 - Netmask. */
0xC0C0C001, /* 192.192.192.1 - Gateway Address. */
0x01020304, /* 1.2.3.4 - DNS server address. */
0xC0C0C0FF
};
size_t xPortGetMinimumEverFreeHeapSize( void )
{
return 0;
}
BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint,
const char * pcName )
{
}
StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
StackType_t * pxEndOfStack,
TaskFunction_t pxCode,
void * pvParameters )
{
}
uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
{
}
BaseType_t xNetworkInterfaceInitialise( void )
{
}
void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent,
struct xNetworkEndPoint * pxEndPoint )
{
}
void vApplicationDaemonTaskStartupHook( void )
{
}
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
configSTACK_DEPTH_TYPE * puxTimerTaskStackSize )
{
}
void vPortDeleteThread( void * pvTaskToDelete )
{
}
void vApplicationIdleHook( void )
{
}
void vApplicationTickHook( void )
{
}
unsigned long ulGetRunTimeCounterValue( void )
{
}
void vPortEndScheduler( void )
{
}
BaseType_t xPortStartScheduler( void )
{
}
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xWantedSize )
{
return malloc( xWantedSize );
}
void vPortFree( void * pv )
{
free( pv );
}
void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber )
{
}
void vPortCloseRunningThread( void * pvTaskToDelete,
volatile BaseType_t * pxPendYield )
{
}
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
configSTACK_DEPTH_TYPE * puxIdleTaskStackSize )
{
}
void vConfigureTimerForRunTimeStats( void )
{
}
/*--------------------------------STUB Functions---------------------------------------*/
eDHCPCallbackAnswer_t xStubApplicationDHCPHook_Multi( eDHCPCallbackPhase_t eDHCPPhase,
struct xNetworkEndPoint * pxEndPoint,
IP_Address_t * pxIPAddress,
int cmock_num_calls )
{
TEST_ASSERT_EQUAL( eStubExpectedDHCPPhase, eDHCPPhase );
TEST_ASSERT_EQUAL( pxStubExpectedEndPoint, pxEndPoint );
TEST_ASSERT_EQUAL( ulStubExpectedIPAddress, pxIPAddress->ulIP_IPv4 );
return eStubExpectedReturn;
}
BaseType_t NetworkInterfaceOutputFunction_Stub_Called = 0;
BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDescriptor,
NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xReleaseAfterSend )
{
NetworkInterfaceOutputFunction_Stub_Called++;
return 0;
}
static NetworkBufferDescriptor_t * GetNetworkBuffer( size_t SizeOfEthBuf,
long unsigned int xTimeToBlock,
int callbacks )
{
NetworkBufferDescriptor_t * pxNetworkBuffer = malloc( sizeof( NetworkBufferDescriptor_t ) + prvALIGNED_BUFFER_PADDING ) + prvALIGNED_BUFFER_PADDING;
pxNetworkBuffer->pucEthernetBuffer = malloc( SizeOfEthBuf + prvALIGNED_BUFFER_PADDING ) + prvALIGNED_BUFFER_PADDING;
/* Ignore the callback count. */
( void ) callbacks;
/* Ignore the timeout. */
( void ) xTimeToBlock;
/* Set the global network buffer so that memory can be freed later on. */
pxGlobalNetworkBuffer[ GlobalBufferCounter++ ] = pxNetworkBuffer;
return pxNetworkBuffer;
}
static void ReleaseNetworkBuffer( void )
{
/* Free the ethernet buffer. */
free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ --GlobalBufferCounter ]->pucEthernetBuffer ) - prvALIGNED_BUFFER_PADDING );
/* Free the network buffer. */
free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ GlobalBufferCounter ] ) - prvALIGNED_BUFFER_PADDING );
}
static void ReleaseUDPBuffer( const void * temp,
int callbacks )
{
/* Should just call network buffer. */
ReleaseNetworkBuffer();
}
static int32_t RecvFromStub( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
switch( callbacks )
{
case 0:
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
break;
case 1:
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
/* Put incorrect DHCP opcode. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE + 10;
break;
}
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_Generic( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = ucGenericPtr;
}
return ulGenericLength;
}
static int32_t FreeRTOS_recvfrom_Small_NullBuffer( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
/* Admittedly, returning a (NULL, 1) slice is contrived, but coverage speaks. */
*( ( uint8_t ** ) pvBuffer ) = NULL;
return 1;
}
static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromLessBytesNoTimeout( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
return sizeof( DHCPMessage_IPv4_t ) - 1;
}
static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;
while( pxIterator != NULL )
{
pxIterator->xDHCPData.xDHCPSocket = NULL;
pxIterator = pxIterator->pxNext;
}
if( ( xFlags & FREERTOS_ZERO_COPY ) != 0 )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_TwoFlagOptions_nullbytes( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
int32_t lBytes = 0;
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;
while( pxIterator != NULL )
{
pxIterator->xDHCPData.xDHCPSocket = NULL;
pxIterator = pxIterator->pxNext;
}
if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
lBytes = xSizeofUDPBuffer;
}
else
{
pvBuffer = NULL;
}
return lBytes;
}
static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_TwoFlagOptions_nullbuffer( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;
while( pxIterator != NULL )
{
pxIterator->xDHCPData.xDHCPSocket = NULL;
pxIterator = pxIterator->pxNext;
}
if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
}
else
{
*( ( uint8_t ** ) pvBuffer ) = NULL;
}
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_IncorrectDHCPCookie( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;
while( pxIterator != NULL )
{
pxIterator->xDHCPData.xDHCPSocket = NULL;
pxIterator = pxIterator->pxNext;
}
if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpBROADCAST;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_IncorrectOpCode( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;
while( pxIterator != NULL )
{
pxIterator->xDHCPData.xDHCPSocket = NULL;
pxIterator = pxIterator->pxNext;
}
if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREQUEST_OPCODE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSucceedsFalseCookieNoTimeout( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSucceedsFalseOpcodeNoTimeout( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSucceedsCorrectCookieAndOpcodeNoTimeout( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
/* Put in correct DHCP opcode. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccessCorrectTxID( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
/* Put in correct DHCP opcode. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
/* Put in correct DHCP Tx ID. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_CorrectAddrType( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
/* Put in correct DHCP opcode. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
/* Put in correct DHCP Tx ID. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
/* Put in address type as ethernet. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_CorrectAddrLen( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
/* Put in correct DHCP opcode. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
/* Put in correct DHCP Tx ID. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
/* Put in address type as ethernet. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
/* Put in correct address length. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressLength = ( uint8_t ) dhcpETHERNET_ADDRESS_LENGTH;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulYourIPAddress_yiaddr = 0xFFFFFFFF;
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_LocalHostAddr( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
/* Put in correct DHCP opcode. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
/* Put in correct DHCP Tx ID. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
/* Put in address type as ethernet. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
/* Put in correct address length. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressLength = ( uint8_t ) dhcpETHERNET_ADDRESS_LENGTH;
/* Non local host address. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulYourIPAddress_yiaddr = 0x01FFFF7F;
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_NonLocalHostAddr( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
/* Put in correct DHCP opcode. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
/* Put in correct DHCP Tx ID. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId + 1 );
/* Put in address type as ethernet. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
/* Put in correct address length. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressLength = ( uint8_t ) dhcpETHERNET_ADDRESS_LENGTH;
/* Non local host address. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulYourIPAddress_yiaddr = 0x01FFFF3F;
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_LocalMACAddrNotMatching( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
if( xFlags == FREERTOS_ZERO_COPY )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
/* Put in correct DHCP opcode. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
/* Put in correct DHCP Tx ID. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
/* Put in address type as ethernet. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
/* Put in correct address length. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressLength = ( uint8_t ) dhcpETHERNET_ADDRESS_LENGTH;
/* Non local host address. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulYourIPAddress_yiaddr = 0x01FFFF3F;
return xSizeofUDPBuffer;
}
static int32_t FreeRTOS_recvfrom_LoopedCall( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
NetworkEndPoint_t * pxIterator = pxNetworkEndPoints;
size_t xSizeRetBufferSize = xSizeofUDPBuffer;
if( callbacks == 2 )
{
pxNetworkEndPoints->xDHCPData.eDHCPState = eInitialWait;
}
else if( callbacks == 4 )
{
xSizeRetBufferSize = 200;
}
if( ( xFlags & FREERTOS_ZERO_COPY ) != 0 )
{
*( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
}
memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
/* Put in correct DHCP cookie. */
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
return xSizeRetBufferSize;
}
/*-----------------------------------------------------------*/
@@ -0,0 +1,98 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_DHCP" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Common.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/FreeRTOS_DHCP_mock.h"
)
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
)
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
# list the files you would like to test here
list(APPEND real_source_files
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/FreeRTOS_DHCP.c
)
# list the directories the module under test includes
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,126 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <assert.h>
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
#define configPRINTF( X ) printf X
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_STATIC_ALLOCATION 0
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */
/* Software timer related configuration options. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configMAX_PRIORITIES ( 7 )
#define configENABLE_MPU 0
/* Run time stats gathering configuration options. */
#define configGENERATE_RUN_TIME_STATS 1
/* This demo makes use of one or more example stats formatting functions. These
* format the raw data provided by the uxTaskGetSystemState() function in to human
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
/* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. */
extern void vAssertCalled( unsigned long ulLine,
const char * const pcFileName );
#define configASSERT( x ) assert( x )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
/* #include "trcRecorder.h" */
#endif /* FREERTOS_CONFIG_H */
@@ -0,0 +1,339 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
#define ipconfigUSE_DHCPv6 1
#define ipconfigIPv4_BACKWARD_COMPATIBLE 0
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 1 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks using pdMS_TO_TICKS().*/
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 5000U )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 2
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD pdMS_TO_TICKS( 30000U )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#define ipconfigCHECK_IP_QUEUE_SPACE ( 1 )
#define ipconfigSELECT_USES_NOTIFY ( 1 )
#define ipconfigUSE_LINKED_RX_MESSAGES ( 1 )
#define ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS ( 0 )
#define ipconfigZERO_COPY_TX_DRIVER ( 1 )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,501 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_Routing.h"
#include "FreeRTOS_BitConfig.h"
/* =========================== EXTERN VARIABLES =========================== */
#define TEST_DHCPV6_DEBUG ( 0 )
/* The maximum size in single read/write operation. */
#define TEST_DHCPv6_BIT_OPERATION_MAX_SIZE ( 64 )
/* The maximum number of bit operations in a test case. */
#define TEST_DHCPv6_BIT_OPERATION_MAX_NUM ( 128 )
/* The maximum size of debug message of bit operations. */
#define TEST_DHCPv6_BIT_OPERATION_DEBUG_MSG_MAX_SIZE ( 64 )
#define TEST_DHCPV6_TRANSACTION_ID ( 0x123456 )
#define TEST_DHCPV6_OPTION_CLIENT_ID ( 0x00010001C792BC80121122334422 )
#define TEST_DHCPV6_OPTION_SERVER_ID ( 0x28BADC54000ACD295EB6 )
typedef enum eTestStubsOperation
{
eTestStubsOperationNone = 0,
eTestStubsAllocateFail,
eTestStubsHookFail,
eTestStubsHookUseDefault
} eTestStubsOperation_t;
/** @brief A list of all network end-points. Each element has a next pointer. */
struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
extern Socket_t xDHCPv6Socket;
eTestStubsOperation_t eTestStubsOperation = eTestStubsOperationNone;
static uint8_t ucTestDHCPv6TransactionID[] = { 0x12, 0x34, 0x56 };
static uint8_t ucTestDHCPv6OptionClientID[] = { 0x00, 0x01, 0x00, 0x01, 0xC7, 0x92, 0xBC, 0x80, 0x12, 0x11, 0x22, 0x33, 0x44, 0x22 };
static uint8_t ucTestDHCPv6OptionServerID[] = { 0x28, 0xBA, 0xDC, 0x54, 0x00, 0x0A, 0xCD, 0x29, 0x5E, 0xB6 };
const uint8_t ucDefaultMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0xab, 0xcd, 0xef, 0x11, 0x22, 0x33 };
const IPv6_Address_t xDefaultNetPrefix = { 0x20, 0x01, 0x04, 0x70, 0xEC, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/* Default IPv6 address is set to 2001:0470:EC54::5 */
const IPv6_Address_t xDefaultIPAddress = { 0x20, 0x01, 0x04, 0x70, 0xEC, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05 };
const IPv6_Address_t xDNSAddress[ 3 ] =
{
/* 2001:0470:EC54::FF */
{ 0x20, 0x01, 0x04, 0x70, 0xEC, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF },
/* 2001:0470:EC54::FE */
{ 0x20, 0x01, 0x04, 0x70, 0xEC, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE },
/* 2001:0470:EC54::FD */
{ 0x20, 0x01, 0x04, 0x70, 0xEC, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }
};
typedef enum eTestDHCPv6BitOperationType
{
eTestDHCPv6BitOperationNone = 0,
eTestDHCPv6BitOperationWrite8,
eTestDHCPv6BitOperationWrite16,
eTestDHCPv6BitOperationWrite32,
eTestDHCPv6BitOperationWriteCustom,
eTestDHCPv6BitOperationRead8,
eTestDHCPv6BitOperationRead16,
eTestDHCPv6BitOperationRead32,
eTestDHCPv6BitOperationReadCustom,
eTestDHCPv6BitOperationReadPeek,
eTestDHCPv6BitOperationSetError,
eTestDHCPv6BitOperationReturnFalse
} eTestDHCPv6BitOperationType_t;
typedef struct xTestDHCPv6BitOperation
{
eTestDHCPv6BitOperationType_t eOperationType;
uint32_t ulCustomLength;
union operationValue
{
uint8_t ucVal;
uint16_t usVal;
uint32_t ulVal;
uint8_t ucValCustom[ TEST_DHCPv6_BIT_OPERATION_MAX_SIZE ];
} val;
uint8_t ucDebugMsg[ TEST_DHCPv6_BIT_OPERATION_DEBUG_MSG_MAX_SIZE ];
} xTestDHCPv6BitOperation_t;
xTestDHCPv6BitOperation_t xTestDHCPv6BitOperation[ TEST_DHCPv6_BIT_OPERATION_MAX_NUM ];
uint32_t ulTestDHCPv6BitOperationWriteIndex;
uint32_t ulTestDHCPv6BitOperationReadIndex;
Socket_t xStubFreeRTOS_setsockopt_xSocket;
size_t xStubFreeRTOS_setsockopt_uxOptionLength;
int32_t xStubFreeRTOS_setsockopt_lOptionName_BitMap;
FreeRTOS_Socket_t * xStubvSocketBind_pxSocket;
/* ======================== Stub Callback Functions ========================= */
void prvSetCheckerAndReturn_FreeRTOS_setsockopt( Socket_t xSocket,
size_t uxOptionLength )
{
xStubFreeRTOS_setsockopt_xSocket = xSocket;
xStubFreeRTOS_setsockopt_uxOptionLength = uxOptionLength;
xStubFreeRTOS_setsockopt_lOptionName_BitMap = 0;
}
BaseType_t xStubFreeRTOS_setsockopt( Socket_t xSocket,
int32_t lLevel,
int32_t lOptionName,
const void * pvOptionValue,
size_t uxOptionLength,
int NumCalls )
{
TEST_ASSERT_EQUAL( xStubFreeRTOS_setsockopt_xSocket, xSocket );
TEST_ASSERT_EQUAL( xStubFreeRTOS_setsockopt_uxOptionLength, uxOptionLength );
xStubFreeRTOS_setsockopt_lOptionName_BitMap |= ( 1 << lOptionName );
return pdTRUE;
}
void prvSetCheckerAndReturn_vSocketBind( FreeRTOS_Socket_t * pxSocket )
{
xStubvSocketBind_pxSocket = pxSocket;
}
BaseType_t xStubvSocketBind( FreeRTOS_Socket_t * pxSocket,
struct freertos_sockaddr * pxBindAddress,
size_t uxAddressLength,
BaseType_t xInternal,
int NumCalls )
{
TEST_ASSERT_EQUAL( xStubvSocketBind_pxSocket, pxSocket );
TEST_ASSERT_EQUAL( FREERTOS_AF_INET6, pxBindAddress->sin_family );
TEST_ASSERT_EQUAL( sizeof( struct freertos_sockaddr ), pxBindAddress->sin_len );
TEST_ASSERT_EQUAL( ipDHCPv6_CLIENT_PORT, FreeRTOS_ntohs( pxBindAddress->sin_port ) );
TEST_ASSERT_EQUAL( pdFALSE, xInternal );
return 0;
}
BaseType_t xStubxApplicationGetRandomNumber( uint32_t * pulNumber,
int NumCalls )
{
if( pulNumber != NULL )
{
*pulNumber = 0xFF000000 | TEST_DHCPV6_TRANSACTION_ID;
}
return pdPASS;
}
void xStubvBitConfig_write_8( BitConfig_t * pxConfig,
uint8_t ucValue,
int NumCalls )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Checking %s\n", xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ucDebugMsg ) );
#endif
TEST_ASSERT_EQUAL( eTestDHCPv6BitOperationWrite8, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType );
TEST_ASSERT_EQUAL( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].val.ucVal, ucValue );
ulTestDHCPv6BitOperationReadIndex++;
if( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType == eTestDHCPv6BitOperationSetError )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Setting Error\n" ) );
#endif
pxConfig->xHasError = pdTRUE;
ulTestDHCPv6BitOperationReadIndex++;
}
}
void xStubvBitConfig_write_16( BitConfig_t * pxConfig,
uint16_t usValue,
int NumCalls )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Checking %s\n", xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ucDebugMsg ) );
#endif
TEST_ASSERT_EQUAL( eTestDHCPv6BitOperationWrite16, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType );
TEST_ASSERT_EQUAL( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].val.usVal, usValue );
ulTestDHCPv6BitOperationReadIndex++;
if( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType == eTestDHCPv6BitOperationSetError )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Setting Error\n" ) );
#endif
pxConfig->xHasError = pdTRUE;
ulTestDHCPv6BitOperationReadIndex++;
}
}
void xStubvBitConfig_write_32( BitConfig_t * pxConfig,
uint32_t ulValue,
int NumCalls )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Checking %s\n", xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ucDebugMsg ) );
#endif
TEST_ASSERT_EQUAL( eTestDHCPv6BitOperationWrite32, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType );
TEST_ASSERT_EQUAL( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].val.ulVal, ulValue );
ulTestDHCPv6BitOperationReadIndex++;
if( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType == eTestDHCPv6BitOperationSetError )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Setting Error\n" ) );
#endif
pxConfig->xHasError = pdTRUE;
ulTestDHCPv6BitOperationReadIndex++;
}
}
void xStubvBitConfig_write_uc( BitConfig_t * pxConfig,
const uint8_t * pucData,
size_t uxSize,
int NumCalls )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Checking %s\n", xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ucDebugMsg ) );
#endif
TEST_ASSERT_EQUAL( eTestDHCPv6BitOperationWriteCustom, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType );
TEST_ASSERT_EQUAL_MEMORY( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].val.ucValCustom, pucData, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ulCustomLength );
ulTestDHCPv6BitOperationReadIndex++;
if( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType == eTestDHCPv6BitOperationSetError )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Setting Error\n" ) );
#endif
pxConfig->xHasError = pdTRUE;
ulTestDHCPv6BitOperationReadIndex++;
}
}
BaseType_t xStubxBitConfig_init( BitConfig_t * pxConfig,
const uint8_t * pucData,
size_t uxSize,
int NumCalls )
{
BaseType_t xReturn = pdPASS;
memset( pxConfig, 0, sizeof( BitConfig_t ) );
pxConfig->uxSize = uxSize;
pxConfig->uxIndex = 0;
pxConfig->xHasError = pdFALSE;
return xReturn;
}
uint8_t xStubucBitConfig_read_8( BitConfig_t * pxConfig,
int NumCalls )
{
uint8_t ucReturn = 0;
pxConfig->uxIndex++;
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Checking %s\n", xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ucDebugMsg ) );
#endif
TEST_ASSERT_EQUAL( eTestDHCPv6BitOperationRead8, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType );
ucReturn = xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].val.ucVal;
ulTestDHCPv6BitOperationReadIndex++;
if( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType == eTestDHCPv6BitOperationSetError )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Setting Error\n" ) );
#endif
pxConfig->xHasError = pdTRUE;
ulTestDHCPv6BitOperationReadIndex++;
}
return ucReturn;
}
BaseType_t xStubxBitConfig_read_uc( BitConfig_t * pxConfig,
uint8_t * pucData,
size_t uxSize,
int NumCalls )
{
BaseType_t xReturn = pdTRUE;
pxConfig->uxIndex += uxSize;
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Checking %s\n", xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ucDebugMsg ) );
#endif
TEST_ASSERT_EQUAL( eTestDHCPv6BitOperationReadCustom, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType );
if( pucData != NULL )
{
memcpy( pucData, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].val.ucValCustom, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ulCustomLength );
}
ulTestDHCPv6BitOperationReadIndex++;
if( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType == eTestDHCPv6BitOperationSetError )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Setting Error\n" ) );
#endif
pxConfig->xHasError = pdTRUE;
ulTestDHCPv6BitOperationReadIndex++;
}
return xReturn;
}
uint16_t xStubusBitConfig_read_16( BitConfig_t * pxConfig,
int NumCalls )
{
uint16_t usReturn = 0;
pxConfig->uxIndex += 2;
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Checking %s\n", xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ucDebugMsg ) );
#endif
TEST_ASSERT_EQUAL( eTestDHCPv6BitOperationRead16, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType );
usReturn = xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].val.usVal;
ulTestDHCPv6BitOperationReadIndex++;
if( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType == eTestDHCPv6BitOperationSetError )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Setting Error\n" ) );
#endif
pxConfig->xHasError = pdTRUE;
ulTestDHCPv6BitOperationReadIndex++;
}
return usReturn;
}
uint32_t xStubulBitConfig_read_32( BitConfig_t * pxConfig,
int NumCalls )
{
uint32_t ulReturn = 0;
pxConfig->uxIndex += 4;
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Checking %s\n", xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ucDebugMsg ) );
#endif
TEST_ASSERT_EQUAL( eTestDHCPv6BitOperationRead32, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType );
ulReturn = xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].val.ulVal;
ulTestDHCPv6BitOperationReadIndex++;
if( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType == eTestDHCPv6BitOperationSetError )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Setting Error\n" ) );
#endif
pxConfig->xHasError = pdTRUE;
ulTestDHCPv6BitOperationReadIndex++;
}
return ulReturn;
}
BaseType_t xStubpucBitConfig_peek_last_index_uc( BitConfig_t * pxConfig,
uint8_t * pucData,
size_t uxSize,
int NumCalls )
{
BaseType_t xReturn = pdTRUE;
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Checking %s\n", xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ucDebugMsg ) );
#endif
TEST_ASSERT_EQUAL( eTestDHCPv6BitOperationReadPeek, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType );
memcpy( pucData, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].val.ucValCustom, xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].ulCustomLength );
ulTestDHCPv6BitOperationReadIndex++;
if( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType == eTestDHCPv6BitOperationSetError )
{
#if TEST_DHCPV6_DEBUG
FreeRTOS_debug_printf( ( "Setting Error\n" ) );
#endif
pxConfig->xHasError = pdTRUE;
ulTestDHCPv6BitOperationReadIndex++;
}
if( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationReadIndex ].eOperationType == eTestDHCPv6BitOperationReturnFalse )
{
xReturn = pdFALSE;
ulTestDHCPv6BitOperationReadIndex++;
}
return xReturn;
}
void InitializeUnitTest()
{
pxNetworkEndPoints = NULL;
xDHCPv6Socket = NULL;
eTestStubsOperation = eTestStubsOperationNone;
}
uint32_t ulApplicationTimeHook( void )
{
/** @brief The function time() counts since 1-1-1970. The DHCPv6 time-stamp however
* uses a time stamp that had zero on 1-1-2000. */
return 946684800U;
}
void vAddStubsOperation( eTestStubsOperation_t eOperation )
{
eTestStubsOperation = eOperation;
}
eDHCPCallbackAnswer_t xApplicationDHCPHook_Multi( eDHCPCallbackPhase_t eDHCPPhase,
struct xNetworkEndPoint * pxEndPoint,
IP_Address_t * pxIPAddress )
{
eDHCPCallbackAnswer_t eReturn = eDHCPContinue;
if( eTestStubsOperation == eTestStubsHookFail )
{
eReturn = eDHCPStopNoChanges;
}
else if( eTestStubsOperation == eTestStubsHookUseDefault )
{
eReturn = eDHCPUseDefaults;
}
return eReturn;
}
void * pvPortMalloc( size_t xWantedSize )
{
void * pvReturn = NULL;
if( eTestStubsOperation != eTestStubsAllocateFail )
{
pvReturn = malloc( xWantedSize );
}
return pvReturn;
}
void vPortFree( void * pv )
{
free( pv );
}
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
@@ -0,0 +1,117 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_DHCPv6" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_BitConfig.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv6.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/${project_name}.c
${MODULE_ROOT_DIR}/test/unit-test/${project_name}/${project_name}_stubs.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set( utest_dep_list "" )
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,341 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
#define ipconfigIPv4_BACKWARD_COMPATIBLE 0
#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM 0
#define ipconfigUSE_MDNS 1
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 1 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks by dividing the time in
* milliseconds by portTICK_PERIOD_MS. */
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 2
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD pdMS_TO_TICKS( 30000U )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#define ipconfigCHECK_IP_QUEUE_SPACE ( 1 )
#define ipconfigSELECT_USES_NOTIFY ( 1 )
#define ipconfigUSE_LINKED_RX_MESSAGES ( 1 )
#define ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS ( 0 )
#define ipconfigZERO_COPY_TX_DRIVER ( 1 )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,72 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_DNS_Globals.h"
#include "FreeRTOS_IP_Private.h"
/* =========================== EXTERN VARIABLES =========================== */
int callback_called = 0;
bool isMallocFail = false;
/* ======================== Stub Callback Functions ========================= */
void dns_callback( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddress )
{
callback_called = 1;
}
void * pvPortMalloc( size_t xNeeded )
{
void * pvReturn = NULL;
if( isMallocFail != true )
{
pvReturn = malloc( xNeeded );
}
return pvReturn;
}
void vPortFree( void * ptr )
{
free( ptr );
}
@@ -0,0 +1,111 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_DNS" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
# list the files to mock here
set (mock_list "")
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Cache.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Callback.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Networking.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Parser.h"
)
# list the directories your mocks need
set(mock_include_list "")
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
)
#list the definitions of your mocks to control what to be included
set(mock_define_list "")
list(APPEND mock_define_list
-DipconfigDNS_USE_CALLBACKS=1
-DipconfigUSE_DNS=1
)
# ================= Create the library under test here (edit) ==================
add_compile_options(-Wno-pedantic -ggdb3)
# list the files you would like to test here
set(real_source_files "")
list(APPEND real_source_files
${MODULE_ROOT_DIR}/source/FreeRTOS_DNS.c
)
# list the directories the module under test includes
set(real_include_directories "")
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
# list the directories your test needs to include
set(test_include_directories "")
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/source/include
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "")
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set (utest_dep_list "")
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,64 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
const BaseType_t xBufferAllocFixedSize = pdTRUE;
/* =========================== EXTERN VARIABLES =========================== */
struct freertos_addrinfo pucAddrBuffer[ 2 ];
struct freertos_sockaddr pucSockAddrBuffer[ 1 ];
/* ======================== Stub Callback Functions ========================= */
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint,
const char * pcName )
{
return pdFALSE;
}
@@ -0,0 +1,774 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_FreeRTOS_IP.h"
#include "mock_FreeRTOS_Sockets.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_task.h"
#include "mock_list.h"
#include "mock_queue.h"
#include "mock_FreeRTOS_DNS_Callback.h"
#include "mock_FreeRTOS_DNS_Parser.h"
#include "mock_FreeRTOS_DNS_Networking.h"
#include "mock_NetworkBufferManagement.h"
#include "mock_FreeRTOS_DNS.h"
#include "FreeRTOS_DNS_Cache.h"
#include "catch_assert.h"
#include "FreeRTOSIPConfig.h"
#define LLMNR_ADDRESS "freertos"
#define GOOD_ADDRESS "www.freertos.org"
#define BAD_ADDRESS "this is a bad address"
#define DOTTED_ADDRESS "192.268.0.1"
typedef void (* FOnDNSEvent ) ( const char * /* pcName */,
void * /* pvSearchID */,
struct freertos_addrinfo * /* pxAddressInfo */ );
/* =========================== GLOBAL VARIABLES =========================== */
static int callback_called = 0;
/* =========================== STATIC FUNCTIONS =========================== */
static void dns_callback( const char * pcName,
void * pvSearchID,
uint32_t ulIPAddress )
{
callback_called = 1;
}
/* =========================== EXTERN VARIABLES =========================== */
struct freertos_addrinfo pucAddrBuffer[ 2 ];
struct freertos_sockaddr pucSockAddrBuffer[ 1 ];
/* ============================ UNITY FIXTURES ============================= */
/**
* @brief calls at the beginning of each test case
*/
void setUp( void )
{
FreeRTOS_dnsclear();
callback_called = 0;
}
/**
* @brief calls at the end of each test case
*/
void tearDown( void )
{
}
/*!
* @brief DNS cache structure instantiation
*/
static DNSCacheRow_t xDNSCache[ ipconfigDNS_CACHE_ENTRIES ];
/* ============================= TEST CASES =============================== */
/**
* @brief catch assertion on name being non-NULL.
*/
void test_processDNS_CACHE_CatchAssert( void )
{
BaseType_t x;
uint32_t pulIP = 1234;
xTaskGetTickCount_ExpectAndReturn( 5000 ); /* 5 seconds */
catch_assert( FreeRTOS_dnslookup( NULL ) );
}
/**
* @brief Ensures that the same entry is inserted into the cache and retrieved.
*/
void test_processDNS_CACHE_Success( void )
{
BaseType_t x;
uint32_t pulIP = 1234;
IPv46_Address_t pxIP;
pxIP.xIPAddress.ulIP_IPv4 = pulIP;
pxIP.xIs_IPv6 = pdFALSE;
xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&pxIP,
FreeRTOS_htonl( 3 ), pdFALSE, NULL ); /* lives 3 seconds */
xTaskGetTickCount_ExpectAndReturn( 5000 ); /* 5 seconds */
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
x = FreeRTOS_dnslookup( "hello" );
TEST_ASSERT_EQUAL( pulIP, x );
}
/**
* @brief Ensures that the same entry is inserted into the cache and retrieved for IPv6
*/
void test_processDNS_CACHE_Success2( void )
{
uint32_t ulReturn = 0U;
uint32_t pulIP = 1234;
IPv46_Address_t pxIP;
pxIP.xIPAddress.ulIP_IPv4 = pulIP;
pxIP.xIs_IPv6 = pdTRUE;
xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&pxIP,
FreeRTOS_htonl( 3 ), pdFALSE, NULL ); /* lives 3 seconds */
xTaskGetTickCount_ExpectAndReturn( 5000 ); /* 5 seconds */
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
ulReturn = FreeRTOS_dnslookup6( "hello", &( pxIP.xIPAddress.xIP_IPv6 ) );
TEST_ASSERT_EQUAL( ulReturn, 1 );
}
/**
* @brief Ensures that failure occurs when different entry is inserted into the cache and retrieved for IPv6
*/
void test_processDNS_CACHE_Fail_IPv6( void )
{
uint32_t ulReturn = 0U;
uint32_t pulIP = 1234;
IPv46_Address_t pxIP;
pxIP.xIPAddress.ulIP_IPv4 = pulIP;
pxIP.xIs_IPv6 = pdFALSE;
xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&pxIP,
FreeRTOS_htonl( 3 ), pdFALSE, NULL ); /* lives 3 seconds */
xTaskGetTickCount_ExpectAndReturn( 10000 ); /* 10 seconds */
ulReturn = FreeRTOS_dnslookup6( "helloworld", &( pxIP.xIPAddress.xIP_IPv6 ) );
TEST_ASSERT_EQUAL( ulReturn, 0 );
}
/**
* @brief Cannot Confirm that the record in the DNS Cache is still fresh.
*/
void test_processDNS_CACHE_Entry_NotFresh( void )
{
BaseType_t x;
uint32_t pulIP = 1234;
IPv46_Address_t pxIP;
pxIP.xIPAddress.ulIP_IPv4 = pulIP;
pxIP.xIs_IPv6 = 0;
xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&pxIP,
FreeRTOS_htonl( 3 ), pdFALSE, NULL ); /* lives 3 seconds */
xTaskGetTickCount_ExpectAndReturn( 8000 ); /* 8 seconds */
x = FreeRTOS_dnslookup( "hello" );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief Ensures empty cache returns zero
*/
void test_processDNS_CACHE_empty_cache( void )
{
BaseType_t x;
xTaskGetTickCount_ExpectAndReturn( 3000 );
x = FreeRTOS_dnslookup( "hello" );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief Ensures entry not found returns zero
*/
void test_processDNS_CACHE_entry_not_found( void )
{
BaseType_t x;
uint32_t pulIP = 1234;
IPv46_Address_t pxIP;
pxIP.xIPAddress.ulIP_IPv4 = pulIP;
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "world",
&pxIP,
400, pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 3000 );
x = FreeRTOS_dnslookup( "hello" );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief Ensures entry not found returns zero
*/
void test_processDNS_CACHE_update_entry( void )
{
BaseType_t x;
uint32_t pulIP = 1234;
IPv46_Address_t pxIP;
pxIP.xIPAddress.ulIP_IPv4 = pulIP;
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "world",
&pxIP,
400, pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "world",
&pxIP,
500, pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 3000 );
x = FreeRTOS_dnslookup( "hello" );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief Ensures that if an entry is expired it is zeroed
*/
void test_processDNS_CACHE_expired_entry( void )
{
BaseType_t x;
uint32_t pulIP = 1234;
IPv46_Address_t pxIP;
pxIP.xIPAddress.ulIP_IPv4 = pulIP;
xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "world",
&pxIP,
FreeRTOS_htonl( 20 ), pdFALSE, NULL ); /* lives 20 seconds */
xTaskGetTickCount_ExpectAndReturn( 50000 ); /* 50 Seconds */
x = FreeRTOS_dnslookup( "world" );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief Exceeding ip limit for an entry
*/
void test_processDNS_CACHE_exceed_IP_entry_limit( void )
{
BaseType_t x;
uint32_t pulIP = 789;
uint32_t pulIP_arr[ ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ] = { 123 };
IPv46_Address_t pxIP[ ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ], pxIP_2;
int i;
pxIP_2.xIs_IPv6 = 0;
pxIP_2.xIPAddress.ulIP_IPv4 = pulIP;
for( i = 0; i < ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; i++ )
{
pxIP[ i ].xIPAddress.ulIP_IPv4 = pulIP_arr[ i ];
pxIP[ i ].xIs_IPv6 = 0;
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "world",
&pxIP[ i ],
400, pdFALSE, NULL );
}
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "world",
&pxIP_2,
FreeRTOS_htonl( 400 ), pdFALSE, NULL ); /* lives 400 seconds */
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
x = FreeRTOS_dnslookup( "world" );
TEST_ASSERT_EQUAL( 789, x );
}
/**
* @brief Exceeding host limit for an entry, circles back to zero
*/
void test_processDNS_CACHE_exceed_host_entry_limit( void )
{
BaseType_t x;
uint32_t pulIP_arr[ ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1 ] = { 123 };
uint32_t pulIP = 456;
char hosts[ ipconfigDNS_CACHE_NAME_LENGTH ] = { "hello" };
char template[] = "helloXXXXXX";
IPv46_Address_t pxIP[ ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1 ], pxIP_2;
int i;
pxIP_2.xIs_IPv6 = 0;
pxIP_2.xIPAddress.ulIP_IPv4 = pulIP;
for( i = 0; i < ipconfigDNS_CACHE_ENTRIES; i++ )
{
pxIP[ i ].xIPAddress.ulIP_IPv4 = pulIP_arr[ i ];
pxIP[ i ].xIs_IPv6 = 0;
memcpy( template, "helloXXXXXX", strlen( template ) );
if( mkstemp( template ) != -1 )
{
memcpy( hosts, template, ipconfigDNS_CACHE_ENTRIES );
}
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( hosts,
&pxIP[ i ],
FreeRTOS_htonl( 400 ), pdFALSE, NULL ); /* lives 400 seconds */
}
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "world",
&pxIP_2,
400, pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
x = FreeRTOS_dnslookup( "world" );
TEST_ASSERT_EQUAL( 456, x );
}
/**
* @brief Exceeding dns name limit
*/
void test_processDNS_CACHE_exceed_dns_name_limit( void )
{
BaseType_t x;
uint32_t pulIP = 1234;
char long_dns_name[ ipconfigDNS_CACHE_NAME_LENGTH + 3 ];
IPv46_Address_t pxIP;
pxIP.xIPAddress.ulIP_IPv4 = pulIP;
memset( long_dns_name, 'a', ipconfigDNS_CACHE_NAME_LENGTH + 3 );
long_dns_name[ ipconfigDNS_CACHE_NAME_LENGTH + 2 ] = '\0';
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( long_dns_name,
&pxIP,
400, pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 50000 );
x = FreeRTOS_dnslookup( long_dns_name );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief DNS Lookup success
*/
void test_prepare_DNSLookup( void )
{
BaseType_t x = 0U;
BaseType_t xFamily;
struct freertos_addrinfo * pxAddressInfo = &pucAddrBuffer[ 0 ];
struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer;
IPv46_Address_t xAddress;
uint32_t ulIP = 1234U;
struct freertos_sockaddr * sockaddr = &pucSockAddrBuffer[ 0 ];
sockaddr->sin_address.ulIP_IPv4 = ulIP;
pxAddressInfo->ai_addr = sockaddr;
*ppxAddressInfo = pxAddressInfo;
xFamily = FREERTOS_AF_INET;
xAddress.xIs_IPv6 = pdFALSE;
xAddress.xIPAddress.ulIP_IPv4 = ulIP;
struct freertos_addrinfo * pxAddrInfo = &pucAddrBuffer[ 1 ];
( void ) memset( pxAddrInfo, 0, sizeof( *pxAddrInfo ) );
pxAddrInfo->ai_canonname = pxAddrInfo->xPrivateStorage.ucName;
( void ) strncpy( pxAddrInfo->xPrivateStorage.ucName, "hello", sizeof( pxAddrInfo->xPrivateStorage.ucName ) );
pxAddrInfo->ai_addr = ( ( struct freertos_sockaddr * ) &( pxAddrInfo->xPrivateStorage.sockaddr ) );
pxAddrInfo->ai_addr = sockaddr;
pxAddrInfo->ai_family = FREERTOS_AF_INET4;
pxAddrInfo->ai_addrlen = ipSIZE_OF_IPv4_ADDRESS;
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 5000 );
pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddrInfo );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
xDNSCache[ 0 ].xAddresses[ 0 ] = xAddress;
x = Prepare_CacheLookup( "hello", xFamily, ppxAddressInfo );
TEST_ASSERT_EQUAL( ulIP, x );
}
/**
* @brief DNS Lookup fail : pxAddressInfo = NULL
*/
void test_prepare_DNSLookup2( void )
{
BaseType_t x;
struct freertos_addrinfo * pxAddressInfo = NULL;
IPv46_Address_t xAddress;
xAddress.xIs_IPv6 = pdFALSE;
xAddress.xIPAddress.ulIP_IPv4 = ~0U;
xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "helloman",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL ); /* lives 3 seconds */
xTaskGetTickCount_ExpectAndReturn( 5000 ); /* 5 seconds */
pxNew_AddrInfo_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
x = Prepare_CacheLookup( "helloman", FREERTOS_AF_INET, &pxAddressInfo );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief DNS Lookup fail : (*ppxAddressInfo) == NULL, ( *pxAddressInfo = NULL )
*/
void test_prepare_DNSLookup3( void )
{
BaseType_t x;
IPv46_Address_t xAddress;
xAddress.xIs_IPv6 = pdFALSE;
xAddress.xIPAddress.ulIP_IPv4 = ~0U;
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "helloman",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 5000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
x = Prepare_CacheLookup( "helloman", FREERTOS_AF_INET, NULL );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief DNS Lookup fail : (*ppxAddressInfo) == NULL
*/
void test_prepare_DNSLookup4( void )
{
BaseType_t x;
IPv46_Address_t xAddress;
xAddress.xIs_IPv6 = pdFALSE;
xAddress.xIPAddress.ulIP_IPv4 = ~0U;
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 5000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
x = Prepare_CacheLookup( "hello", FREERTOS_AF_INET, NULL );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief DNS Lookup fail : Different entry lookup
*/
void test_prepare_DNSLookup5( void )
{
BaseType_t x = 0U;
BaseType_t xFamily;
struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer;
IPv46_Address_t xAddress;
xFamily = FREERTOS_AF_INET;
xAddress.xIs_IPv6 = pdFALSE;
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 5000 );
x = Prepare_CacheLookup( "aws", xFamily, ppxAddressInfo );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief DNS Lookup fail : xFamily invalid
*/
void test_prepare_DNSLookup6( void )
{
BaseType_t x = 0U;
BaseType_t xFamily;
struct freertos_addrinfo ** ppxAddressInfo = NULL;
IPv46_Address_t xAddress;
xFamily = FREERTOS_AF_INET ^ FREERTOS_AF_INET6;
xAddress.xIs_IPv6 = pdFALSE;
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL );
x = Prepare_CacheLookup( "hello", xFamily, ppxAddressInfo );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief DNS Lookup success : IPv6
*/
void test_prepare_DNSLookup_IPv6( void )
{
BaseType_t x;
BaseType_t xFamily = FREERTOS_AF_INET6;
struct freertos_addrinfo * pxAddressInfo = &pucAddrBuffer[ 0 ];
struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pxAddressInfo;
IPv46_Address_t xAddress;
xAddress.xIs_IPv6 = pdTRUE;
memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 );
*ppxAddressInfo = pxAddressInfo;
struct freertos_addrinfo * pxAddrInfo = &pucAddrBuffer[ 1 ];
( void ) memset( pxAddrInfo, 0, sizeof( *pxAddrInfo ) );
pxAddrInfo->ai_canonname = pxAddrInfo->xPrivateStorage.ucName;
( void ) strncpy( pxAddrInfo->xPrivateStorage.ucName, "hello", sizeof( pxAddrInfo->xPrivateStorage.ucName ) );
pxAddrInfo->ai_addr = ( ( struct freertos_sockaddr * ) &( pxAddrInfo->xPrivateStorage.sockaddr ) );
pxAddrInfo->ai_family = FREERTOS_AF_INET6;
pxAddrInfo->ai_addrlen = ipSIZE_OF_IPv6_ADDRESS;
xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL ); /* lives 3 seconds */
xTaskGetTickCount_ExpectAndReturn( 5000 ); /* 5 seconds */
pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddrInfo );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
x = Prepare_CacheLookup( "hello", xFamily, ppxAddressInfo );
TEST_ASSERT_EQUAL( 1, x );
}
/**
* @brief DNS IPv6 Lookup fail : pxAddressInfo = NULL
*/
void test_prepare_DNSLookup2_IPv6( void )
{
BaseType_t x = 0U;
BaseType_t xFamily;
struct freertos_addrinfo * pxAddressInfo = NULL;
struct freertos_addrinfo ** ppxAddressInfo;
IPv46_Address_t xAddress;
xFamily = FREERTOS_AF_INET6;
xAddress.xIs_IPv6 = pdTRUE;
memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 );
ppxAddressInfo = &pxAddressInfo;
xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "helloman",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL ); /* lives 3 seconds */
xTaskGetTickCount_ExpectAndReturn( 5000 ); /* 5 seconds */
pxNew_AddrInfo_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
x = Prepare_CacheLookup( "helloman", xFamily, ppxAddressInfo );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief DNS IPv6 Lookup fail : (*ppxAddressInfo) == NULL, ( *pxAddressInfo = NULL )
*/
void test_prepare_DNSLookup3_IPv6( void )
{
BaseType_t x = 0U;
BaseType_t xFamily;
struct freertos_addrinfo ** ppxAddressInfo = NULL;
IPv46_Address_t xAddress;
xFamily = FREERTOS_AF_INET6;
xAddress.xIs_IPv6 = pdTRUE;
memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 );
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "helloman",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 5000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
x = Prepare_CacheLookup( "helloman", xFamily, ppxAddressInfo );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief DNS IPv6 Lookup fail : (*ppxAddressInfo) == NULL
*/
void test_prepare_DNSLookup4_IPv6( void )
{
BaseType_t x = 0U;
BaseType_t xFamily;
struct freertos_addrinfo ** ppxAddressInfo = NULL;
IPv46_Address_t xAddress;
xFamily = FREERTOS_AF_INET6;
xAddress.xIs_IPv6 = pdTRUE;
memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 );
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 5000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
x = Prepare_CacheLookup( "hello", xFamily, ppxAddressInfo );
TEST_ASSERT_EQUAL( 0, x );
}
/**
* @brief DNS IPv6 Lookup fail : Different entry lookup
*/
void test_prepare_DNSLookup5_IPv6( void )
{
BaseType_t x = 0U;
BaseType_t xFamily;
struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer;
IPv46_Address_t xAddress;
xFamily = FREERTOS_AF_INET6;
xAddress.xIs_IPv6 = pdTRUE;
xTaskGetTickCount_ExpectAndReturn( 3000 );
FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL );
FreeRTOS_dns_update( "hello",
&xAddress,
FreeRTOS_htonl( 3 ), pdFALSE, NULL );
xTaskGetTickCount_ExpectAndReturn( 5000 );
x = Prepare_CacheLookup( "aws", xFamily, ppxAddressInfo );
TEST_ASSERT_EQUAL( 0, x );
}
@@ -0,0 +1,109 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_DNS_Cache" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
# list the files to mock here
set (mock_list "")
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Callback.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Networking.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Parser.h"
)
# list the directories your mocks need
set (mock_include_list "")
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
)
#list the definitions of your mocks to control what to be included
set (mock_define_list "")
list(APPEND mock_define_list
#-DportUSING_MPU_WRAPPERS=0
)
# ================= Create the library under test here (edit) ==================
add_compile_options(-Wno-pedantic -ggdb3)
# list the files you would like to test here
set(real_source_files ""
)
list(APPEND real_source_files
${project_name}/${project_name}_stubs.c
${MODULE_ROOT_DIR}/source/FreeRTOS_DNS_Cache.c
)
# list the directories the module under test includes
set (real_include_directories "")
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
# list the directories your test needs to include
set (test_include_directories "")
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/source/include
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "")
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set (utest_dep_list "")
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,56 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
const BaseType_t xBufferAllocFixedSize = pdTRUE;
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint,
const char * pcName )
{
}
@@ -0,0 +1,615 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_FreeRTOS_IP.h"
#include "mock_FreeRTOS_Sockets.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_FreeRTOS_IP_Timers.h"
#include "mock_task.h"
#include "mock_queue.h"
#include "mock_portable.h"
#include "FreeRTOS_DNS_Callback.h"
#include "mock_list.h"
#include "mock_Sockets_list_macros.h"
#include "mock_FreeRTOS_DNS_Parser.h"
#include "mock_NetworkBufferManagement.h"
#include "FreeRTOS_DNS.h"
#include "catch_assert.h"
#include "FreeRTOSIPConfig.h"
#define LLMNR_ADDRESS "freertos"
#define GOOD_ADDRESS "www.freertos.org"
#define BAD_ADDRESS "this is a bad address"
#define DOTTED_ADDRESS "192.268.0.1"
typedef void (* FOnDNSEvent ) ( const char * /* pcName */,
void * /* pvSearchID */,
struct freertos_addrinfo * /* pxAddressInfo */ );
/* =========================== GLOBAL VARIABLES =========================== */
static int callback_called = 0;
/* The second element is for the flexible array member
* when pvPortMalloc is mocked to return this object.
*/
static DNSCallback_t dnsCallback[ 2 ];
/* =========================== STATIC FUNCTIONS =========================== */
static void dns_callback( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddressInfo )
{
callback_called = 1;
}
/* ============================ TEST FIXTURES ============================= */
/**
* @brief calls at the beginning of each test case
*/
void setUp( void )
{
vListInitialise_ExpectAnyArgs();
vDNSCallbackInitialise();
callback_called = 0;
memset( dnsCallback, 0x00, sizeof( dnsCallback ) );
}
/**
* @brief calls at the end of each test case
*/
void tearDown( void )
{
}
/* ============================= TEST CASES =============================== */
/**
* @brief Happy Path identifier passed is not found!
*/
void test_xDNSDoCallback_success_not_equal_identifier( void )
{
BaseType_t ret;
ParseSet_t pxSet;
struct freertos_addrinfo pxAddress;
DNSMessage_t xDNSMessageHeader;
pxSet.pxDNSMessageHeader = &xDNSMessageHeader;
pxSet.pxDNSMessageHeader->usIdentifier = 123;
char pc_name[] = "test";
strcpy( pxSet.pcName, pc_name );
listGET_LIST_ITEM_OWNER_IgnoreAndReturn( ( DNSCallback_t * ) 1234 );
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 ); /* xEnd */
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 12345 );
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 );
xTaskResumeAll_ExpectAndReturn( pdFALSE );
ret = xDNSDoCallback( &pxSet, &pxAddress );
TEST_ASSERT_EQUAL( pdFALSE, ret );
}
/**
* @brief Happy Path!
*/
void test_xDNSDoCallback_success_equal_identifier( void )
{
BaseType_t ret;
ParseSet_t pxSet;
struct freertos_addrinfo pxAddress;
DNSMessage_t xDNSMessageHeader;
pxSet.pxDNSMessageHeader = &xDNSMessageHeader;
pxSet.pxDNSMessageHeader->usIdentifier = 123;
char pc_name[] = "test";
strcpy( pxSet.pcName, pc_name );
dnsCallback->pCallbackFunction = dns_callback;
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 );
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 123 );
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vPortFree_ExpectAnyArgs();
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
xTaskResumeAll_ExpectAndReturn( pdFALSE );
ret = xDNSDoCallback( &pxSet, &pxAddress );
TEST_ASSERT_EQUAL( pdTRUE, ret );
TEST_ASSERT_EQUAL( 1, callback_called );
}
/**
* @brief Happy Path!
*/
void test_xDNSDoCallback_success_equal_identifier_set_timer( void )
{
BaseType_t ret;
ParseSet_t pxSet;
struct freertos_addrinfo pxAddress;
DNSMessage_t xDNSMessageHeader;
pxSet.pxDNSMessageHeader = &xDNSMessageHeader;
pxSet.pxDNSMessageHeader->usIdentifier = 123;
char pc_name[] = "test";
strcpy( pxSet.pcName, pc_name );
dnsCallback->pCallbackFunction = dns_callback;
/* Expectations */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 );
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 123 );
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vPortFree_ExpectAnyArgs();
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
vIPSetDNSTimerEnableState_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdFALSE );
/* API Call */
ret = xDNSDoCallback( &pxSet, &pxAddress );
/* Validations */
TEST_ASSERT_EQUAL( pdTRUE, ret );
TEST_ASSERT_EQUAL( 1, callback_called );
}
/**
* @brief Happy Path!
*/
void test_xDNSDoCallback_success_equal_port_number_equal_name( void )
{
BaseType_t ret;
ParseSet_t pxSet;
struct freertos_addrinfo pxAddress;
DNSMessage_t xDNSMessageHeader;
char pc_name[] = "test";
uint8_t dnsCallbackMemory[ sizeof( DNSCallback_t ) + ipconfigDNS_CACHE_NAME_LENGTH ];
DNSCallback_t * pxDnsCallback = ( DNSCallback_t * ) &dnsCallbackMemory;
pxSet.pxDNSMessageHeader = &xDNSMessageHeader;
pxSet.usPortNumber = ipMDNS_PORT;
strcpy( pxSet.pcName, pc_name );
pxDnsCallback->pCallbackFunction = dns_callback;
strcpy( pxDnsCallback->pcName, pc_name );
/* Expectations */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 );
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( pxDnsCallback );
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vPortFree_ExpectAnyArgs();
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
vIPSetDNSTimerEnableState_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdFALSE );
/* API Call */
ret = xDNSDoCallback( &pxSet, &pxAddress );
/* Validations */
TEST_ASSERT_EQUAL( pdTRUE, ret );
TEST_ASSERT_EQUAL( 1, callback_called );
}
/**
* @brief A failure path occurs when the port number is for MDNS but
* the name does not match.
*/
void test_xDNSDoCallback_fail_equal_port_number_not_equal_name( void )
{
BaseType_t ret;
ParseSet_t pxSet;
struct freertos_addrinfo pxAddress;
DNSMessage_t xDNSMessageHeader;
pxSet.pxDNSMessageHeader = &xDNSMessageHeader;
pxSet.pxDNSMessageHeader->usIdentifier = 123;
pxSet.usPortNumber = ipMDNS_PORT;
char pc_name[] = "test";
strcpy( pxSet.pcName, pc_name );
dnsCallback->pCallbackFunction = dns_callback;
dnsCallback->pcName[ 0 ] = '\0';
/* Expectations */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 );
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 );
xTaskResumeAll_ExpectAndReturn( pdFALSE );
/* API Call */
ret = xDNSDoCallback( &pxSet, &pxAddress );
/* Validations */
TEST_ASSERT_EQUAL( pdFALSE, ret );
TEST_ASSERT_EQUAL( 0, callback_called );
}
/**
* @brief Happy Path!
*/
void test_xDNSSetCallBack_success( void )
{
void * pvSearchID = NULL;
BaseType_t xReturn;
/* Expectations */
pvPortMalloc_ExpectAnyArgsAndReturn( dnsCallback );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
vTaskSetTimeOutState_ExpectAnyArgs();
listSET_LIST_ITEM_OWNER_ExpectAnyArgs();
listSET_LIST_ITEM_VALUE_ExpectAnyArgs();
vTaskSuspendAll_Expect();
vListInsertEnd_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdFALSE );
/* API Call */
xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE );
/* Validations */
TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback->pcName, "hostname" ) );
TEST_ASSERT_EQUAL( dns_callback, dnsCallback->pCallbackFunction );
TEST_ASSERT_EQUAL( pvSearchID, dnsCallback->pvSearchID );
TEST_ASSERT_EQUAL( 56, dnsCallback->uxRemainingTime );
TEST_ASSERT_EQUAL( pdPASS, xReturn );
}
/**
* @brief Happy Path!
*/
void test_xDNSSetCallBack_success_empty_list( void )
{
void * pvSearchID = NULL;
BaseType_t xReturn;
/* Expectations */
pvPortMalloc_ExpectAnyArgsAndReturn( dnsCallback );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 0 );
vDNSTimerReload_ExpectAnyArgs();
vTaskSetTimeOutState_ExpectAnyArgs();
listSET_LIST_ITEM_OWNER_ExpectAnyArgs();
listSET_LIST_ITEM_VALUE_ExpectAnyArgs();
vTaskSuspendAll_Expect();
vListInsertEnd_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdFALSE );
/* API Call */
xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE );
/* Validations */
TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback->pcName, "hostname" ) );
TEST_ASSERT_EQUAL( dns_callback, dnsCallback->pCallbackFunction );
TEST_ASSERT_EQUAL( pvSearchID, dnsCallback->pvSearchID );
TEST_ASSERT_EQUAL( 56, dnsCallback->uxRemainingTime );
TEST_ASSERT_EQUAL( pdPASS, xReturn );
}
/**
* @brief Memory Allocation failed
*/
void test_xDNSSetCallBack_malloc_failed( void )
{
void * pvSearchID = NULL;
BaseType_t xReturn;
/* Expectations */
pvPortMalloc_ExpectAnyArgsAndReturn( NULL );
/* API Call */
xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE );
TEST_ASSERT_EQUAL( pdFAIL, xReturn );
}
/**
* @brief Happy path
*/
void test_vDNSCheckCallback_success_search_id_not_null( void )
{
void * pvSearchID = ( void * ) 456;
dnsCallback->pvSearchID = pvSearchID;
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
vListInitialise_ExpectAnyArgs();
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */
uxListRemove_ExpectAnyArgsAndReturn( pdFALSE );
vPortFree_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdFALSE );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
vIPSetDNSTimerEnableState_ExpectAnyArgs();
/* API Call */
vDNSCheckCallBack( pvSearchID );
/* Validations */
}
/**
* @brief Happy path with list non-empty at end.
*/
void test_vDNSCheckCallback_success_search_id_not_null_list_empty( void )
{
void * pvSearchID = ( void * ) 456;
dnsCallback->pvSearchID = pvSearchID;
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
vListInitialise_ExpectAnyArgs();
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */
uxListRemove_ExpectAnyArgsAndReturn( pdFALSE );
vPortFree_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdFALSE );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
/* API Call */
vDNSCheckCallBack( pvSearchID );
/* Validations */
}
/**
* @brief search id null
*/
void test_vDNSCheckCallback_success_search_id_null( void )
{
void * pvSearchID = ( void * ) 456;
dnsCallback->pvSearchID = pvSearchID;
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
vListInitialise_ExpectAnyArgs();
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */
xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdFALSE );
xTaskResumeAll_ExpectAndReturn( pdFALSE );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
vIPSetDNSTimerEnableState_ExpectAnyArgs();
/* API Call */
vDNSCheckCallBack( NULL );
/* Validations */
}
/**
* @brief search id null
*/
void test_vDNSCheckCallback_success_search_id_null_timeout( void )
{
List_t xTempList;
void * pvSearchID = ( void * ) 456;
dnsCallback->pvSearchID = pvSearchID;
dnsCallback->xIsIPv6 = 0;
dnsCallback->pCallbackFunction = dns_callback;
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
vListInitialise_ExpectAnyArgs();
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */
xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE );
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vListInsertEnd_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdFALSE );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL );
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vPortFree_ExpectAnyArgs();
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
vIPSetDNSTimerEnableState_ExpectAnyArgs();
/* API Call */
vDNSCheckCallBack( NULL );
/* Validations */
TEST_ASSERT_EQUAL( 1, callback_called );
}
/**
* @brief search id null same as the above function but calling IPv6
* sub-branch
*/
void test_vDNSCheckCallback_success_search_id_null_timeout_IPv6( void )
{
List_t xTempList;
void * pvSearchID = ( void * ) 456;
dnsCallback->pvSearchID = pvSearchID;
dnsCallback->xIsIPv6 = 1;
dnsCallback->pCallbackFunction = dns_callback;
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
vListInitialise_ExpectAnyArgs();
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */
xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE );
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vListInsertEnd_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdFALSE );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL );
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vPortFree_ExpectAnyArgs();
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
vIPSetDNSTimerEnableState_ExpectAnyArgs();
/* API Call */
vDNSCheckCallBack( NULL );
/* Validations */
TEST_ASSERT_EQUAL( 1, callback_called );
}
/**
* @brief search id null same as the above function but hitting a different
* sub-branch
*/
void test_vDNSCheckCallback_success_search_id_null_timeout2( void )
{
void * pvSearchID = ( void * ) 456;
void * pvSearchID2 = ( void * ) 457;
dnsCallback->pvSearchID = pvSearchID2;
dnsCallback->xIsIPv6 = 0;
dnsCallback->pCallbackFunction = dns_callback;
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
vListInitialise_ExpectAnyArgs();
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */
xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE );
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vListInsertEnd_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdFALSE );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL );
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vPortFree_ExpectAnyArgs();
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
vIPSetDNSTimerEnableState_ExpectAnyArgs();
/* API Call */
vDNSCheckCallBack( pvSearchID );
/* Validations */
TEST_ASSERT_EQUAL( 1, callback_called );
}
/**
* @brief search id null same as the above function but calling IPv6
* sub-branch
*/
void test_vDNSCheckCallback_success_search_id_null_timeout2_IPv6( void )
{
void * pvSearchID = ( void * ) 456;
void * pvSearchID2 = ( void * ) 457;
dnsCallback->pvSearchID = pvSearchID2;
dnsCallback->xIsIPv6 = 1;
dnsCallback->pCallbackFunction = dns_callback;
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 );
vListInitialise_ExpectAnyArgs();
vTaskSuspendAll_Expect();
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */
xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE );
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vListInsertEnd_ExpectAnyArgs();
xTaskResumeAll_ExpectAndReturn( pdFALSE );
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL );
listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 );
listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback );
listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */
uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
vPortFree_ExpectAnyArgs();
listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
vIPSetDNSTimerEnableState_ExpectAnyArgs();
/* API Call */
vDNSCheckCallBack( pvSearchID );
/* Validations */
TEST_ASSERT_EQUAL( 1, callback_called );
}
@@ -0,0 +1,121 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_DNS_Callback" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
# list the files to mock here
set (mock_list "")
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
#"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/portable.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/portable.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Cache.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Parser.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${MODULE_ROOT_DIR}/test/unit-test/FreeRTOS_Sockets/Sockets_list_macros.h"
)
# list the directories your mocks need
set(mock_include_list "")
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
)
#list the definitions of your mocks to control what to be included
set(mock_define_list "")
list(APPEND mock_define_list
)
# ================= Create the library under test here (edit) ==================
add_compile_options(-Wno-pedantic -ggdb3)
# list the files you would like to test here
set(real_source_files "")
list(APPEND real_source_files
${project_name}/${project_name}_stubs.c
${MODULE_ROOT_DIR}/source/FreeRTOS_DNS_Callback.c
)
# list the directories the module under test includes
set(real_include_directories "")
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
# list the directories your test needs to include
set(test_include_directories "")
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/source/include/
${MODULE_ROOT_DIR}/test/unit-test/FreeRTOS_Sockets
)
# To prevent the file under test from using the list macros and instead use our
# mocked version
add_definitions(
-I${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
-I${MODULE_ROOT_DIR}/test/unit-test/FreeRTOS_Sockets/
-I${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "")
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set (utest_dep_list "")
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
target_compile_options(${real_name} PUBLIC
-include Sockets_list_macros.h
)
@@ -0,0 +1,341 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
#define ipconfigIPv4_BACKWARD_COMPATIBLE 0
#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM 0
#define ipconfigUSE_MDNS 1
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 1 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks by dividing the time in
* milliseconds by portTICK_PERIOD_MS. */
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 2
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( 30000U / portTICK_PERIOD_MS )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigDNS_USE_CALLBACKS 0
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#define ipconfigCHECK_IP_QUEUE_SPACE ( 1 )
#define ipconfigSELECT_USES_NOTIFY ( 1 )
#define ipconfigUSE_LINKED_RX_MESSAGES ( 1 )
#define ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS ( 0 )
#define ipconfigZERO_COPY_TX_DRIVER ( 1 )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,64 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_DNS_Globals.h"
#include "FreeRTOS_IP_Private.h"
/* =========================== EXTERN VARIABLES =========================== */
bool isMallocFail = false;
/* ======================== Stub Callback Functions ========================= */
void * pvPortMalloc( size_t xNeeded )
{
void * pvReturn = NULL;
if( isMallocFail != true )
{
pvReturn = malloc( xNeeded );
}
return pvReturn;
}
void vPortFree( void * ptr )
{
free( ptr );
}
@@ -0,0 +1,280 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_FreeRTOS_IP.h"
#include "mock_FreeRTOS_Routing.h"
#include "mock_FreeRTOS_Sockets.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_FreeRTOS_DNS_Networking.h"
#include "mock_task.h"
#include "mock_list.h"
#include "mock_queue.h"
#include "mock_FreeRTOS_DNS_Cache.h"
#include "mock_FreeRTOS_DNS_Parser.h"
#include "mock_FreeRTOS_DNS_Networking.h"
#include "mock_NetworkBufferManagement.h"
#include "FreeRTOS_DNS.h"
#include "catch_assert.h"
#include "FreeRTOSIPConfig.h"
#include "FreeRTOS_DNS_ConfigNoCallback_stubs.c"
/* =========================== EXTERN VARIABLES =========================== */
#define LLMNR_ADDRESS "freertos"
#define LOCAL_ADDRESS "freertos.local"
#define GOOD_ADDRESS "www.freertos.org"
#define BAD_ADDRESS "this is a bad address"
#define DOTTED_IPV4_ADDRESS "192.168.0.1"
#define DOTTED_IPV4_ADDRESS_UINT32 ( 0x0100A8C0 )
#define DOTTED_IPv6_ADDRESS "2001::1"
IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } };
typedef void (* FOnDNSEvent ) ( const char * /* pcName */,
void * /* pvSearchID */,
struct freertos_addrinfo * /* pxAddressInfo */ );
extern IPPreference_t xDNS_IP_Preference;
/* ============================ Unity Fixtures ============================ */
/**
* @brief calls at the beginning of each test case
*/
void setUp( void )
{
xDNS_IP_Preference = xPreferenceIPv4;
isMallocFail = false;
}
/* ============================== Test Cases ============================== */
/**
* @brief IP address found with IPv4 address input
*/
void test_FreeRTOS_getaddrinfo_IPv4AddressFound( void )
{
BaseType_t xReturn;
struct freertos_addrinfo * pxAddress;
struct freertos_addrinfo xHint, * pxHint = &xHint;
memset( &xHint, 0, sizeof( struct freertos_addrinfo ) );
xHint.ai_family = FREERTOS_AF_INET4;
FreeRTOS_inet_addr_ExpectAndReturn( DOTTED_IPV4_ADDRESS, DOTTED_IPV4_ADDRESS_UINT32 );
ulChar2u32_IgnoreAndReturn( DOTTED_IPV4_ADDRESS_UINT32 );
xReturn = FreeRTOS_getaddrinfo( DOTTED_IPV4_ADDRESS, "Service", pxHint, &pxAddress );
TEST_ASSERT_EQUAL( 0, xReturn );
TEST_ASSERT_EQUAL( FREERTOS_AF_INET4, pxAddress->ai_family );
TEST_ASSERT_EQUAL( DOTTED_IPV4_ADDRESS_UINT32, FreeRTOS_htonl( pxAddress->ai_addr->sin_address.ulIP_IPv4 ) );
TEST_ASSERT_EQUAL( ipSIZE_OF_IPv4_ADDRESS, pxAddress->ai_addrlen );
vPortFree( pxAddress ); /* Make LeakSanitizer happy. */
}
/**
* @brief Ensures that when the supplied address is in the dotted format, it is
* translated to the numerical form and no lookup is performed
*/
void test_FreeRTOS_gethostbyname_SuccessDotAddress( void )
{
uint32_t ret;
FreeRTOS_inet_addr_ExpectAndReturn( DOTTED_IPV4_ADDRESS, 12345 );
xApplicationGetRandomNumber_IgnoreAndReturn( pdTRUE );
ulChar2u32_IgnoreAndReturn( 12345 );
ret = FreeRTOS_gethostbyname( DOTTED_IPV4_ADDRESS );
TEST_ASSERT_EQUAL( 12345, ret );
}
/**
* @brief Ensures that if the address is not in the dotted form and found in the cache,
* it is returned to the caller
*/
void test_FreeRTOS_gethostbyname_SuccessAddressInCache( void )
{
uint32_t ret;
FreeRTOS_inet_addr_ExpectAndReturn( GOOD_ADDRESS, 0 );
Prepare_CacheLookup_ExpectAnyArgsAndReturn( 12345 );
ret = FreeRTOS_gethostbyname( GOOD_ADDRESS );
TEST_ASSERT_EQUAL( 12345, ret );
}
/**
* @brief The identifier is different between DNS request and reply.
*/
void test_FreeRTOS_gethostbyname_DifferentIdentifier( void )
{
uint32_t ret;
uint32_t ulNumber = 34;
int pvSearchID = 32;
NetworkEndPoint_t xEndPoint = { 0 };
NetworkBufferDescriptor_t xNetworkBuffer;
struct xDNSBuffer xReceiveBuffer;
struct xSOCKET xDNSSocket;
size_t uxBytesNeeded = sizeof( UDPPacket_t ) + sizeof( NBNSRequest_t );
int i;
xNetworkBuffer.pucEthernetBuffer = malloc( uxBytesNeeded + ipBUFFER_PADDING );
xNetworkBuffer.pucEthernetBuffer += ipBUFFER_PADDING;
xNetworkBuffer.xDataLength = uxBytesNeeded;
xReceiveBuffer.pucPayloadBuffer = malloc( 300 );
xReceiveBuffer.uxPayloadLength = 300;
( void ) memset( xNetworkBuffer.pucEthernetBuffer, 0x00, uxBytesNeeded );
( void ) memset( xReceiveBuffer.pucPayloadBuffer, 0x00, 300 );
DNSMessage_t * header = ( DNSMessage_t * ) xReceiveBuffer.pucPayloadBuffer;
header->usIdentifier = 12;
xDNSSocket.usLocalPort = 0;
xEndPoint.bits.bIPv6 = pdFALSE;
xEndPoint.ipv4_settings.ucDNSIndex = 0;
xEndPoint.ipv4_settings.ulDNSServerAddresses[ 0 ] = 0xC0C0C0C0;
FreeRTOS_inet_addr_ExpectAndReturn( GOOD_ADDRESS, 0 );
Prepare_CacheLookup_ExpectAnyArgsAndReturn( 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnThruPtr_pulNumber( &ulNumber );
/* in prvGetHostByName */
DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket );
/* prvGetHostByNameOp */
/* prvFillSockAddress */
/* in prvSendBuffer */
/* in prvGetPayloadBuffer */
for( i = 0; i < ipconfigDNS_REQUEST_ATTEMPTS; i++ )
{
FreeRTOS_FirstEndPoint_ExpectAnyArgsAndReturn( &xEndPoint );
DNS_BindSocket_ExpectAnyArgsAndReturn( 0 );
pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( &xNetworkBuffer );
/* back in prvSendBuffer */
DNS_SendRequest_ExpectAnyArgsAndReturn( pdPASS );
/* back in prvGetHostByNameOp */
DNS_ReadReply_ExpectAnyArgsAndReturn( 4 );
DNS_ReadReply_ReturnThruPtr_pxReceiveBuffer( &xReceiveBuffer );
/* prvDNSReply */
FreeRTOS_ReleaseUDPPayloadBuffer_ExpectAnyArgs();
}
/* back in prvGetHostByName */
DNS_CloseSocket_ExpectAnyArgs();
ret = FreeRTOS_gethostbyname( GOOD_ADDRESS );
TEST_ASSERT_EQUAL( 0, ret );
free( xNetworkBuffer.pucEthernetBuffer - ipBUFFER_PADDING );
free( xReceiveBuffer.pucPayloadBuffer );
}
/**
* @brief The identifier is same between DNS request and reply.
*/
void test_FreeRTOS_gethostbyname_SameIdentifier( void )
{
uint32_t ret;
uint32_t ulNumber = 34;
int pvSearchID = 32;
NetworkEndPoint_t xEndPoint = { 0 };
NetworkBufferDescriptor_t xNetworkBuffer;
struct xDNSBuffer xReceiveBuffer;
struct xSOCKET xDNSSocket;
size_t uxBytesNeeded = sizeof( UDPPacket_t ) + sizeof( NBNSRequest_t );
int i;
xNetworkBuffer.pucEthernetBuffer = malloc( uxBytesNeeded + ipBUFFER_PADDING );
xNetworkBuffer.pucEthernetBuffer += ipBUFFER_PADDING;
xNetworkBuffer.xDataLength = uxBytesNeeded;
xReceiveBuffer.pucPayloadBuffer = malloc( 300 );
xReceiveBuffer.uxPayloadLength = 300;
( void ) memset( xNetworkBuffer.pucEthernetBuffer, 0x00, uxBytesNeeded );
( void ) memset( xReceiveBuffer.pucPayloadBuffer, 0x00, 300 );
DNSMessage_t * header = ( DNSMessage_t * ) xReceiveBuffer.pucPayloadBuffer;
header->usIdentifier = ulNumber;
xDNSSocket.usLocalPort = 0;
xEndPoint.bits.bIPv6 = pdFALSE;
xEndPoint.ipv4_settings.ucDNSIndex = 0;
xEndPoint.ipv4_settings.ulDNSServerAddresses[ 0 ] = 0xC0C0C0C0;
FreeRTOS_inet_addr_ExpectAndReturn( GOOD_ADDRESS, 0 );
Prepare_CacheLookup_ExpectAnyArgsAndReturn( 0 );
xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE );
xApplicationGetRandomNumber_ReturnThruPtr_pulNumber( &ulNumber );
/* in prvGetHostByName */
DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket );
/* prvGetHostByNameOp */
/* prvFillSockAddress */
/* in prvSendBuffer */
/* in prvGetPayloadBuffer */
FreeRTOS_FirstEndPoint_ExpectAnyArgsAndReturn( &xEndPoint );
DNS_BindSocket_ExpectAnyArgsAndReturn( 0 );
pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( &xNetworkBuffer );
/* back in prvSendBuffer */
DNS_SendRequest_ExpectAnyArgsAndReturn( pdPASS );
/* back in prvGetHostByNameOp */
DNS_ReadReply_ExpectAnyArgsAndReturn( 4 );
DNS_ReadReply_ReturnThruPtr_pxReceiveBuffer( &xReceiveBuffer );
/* prvDNSReply */
DNS_ParseDNSReply_ExpectAnyArgsAndReturn( 12345 );
FreeRTOS_ReleaseUDPPayloadBuffer_ExpectAnyArgs();
/* back in prvGetHostByName */
DNS_CloseSocket_ExpectAnyArgs();
ret = FreeRTOS_gethostbyname( GOOD_ADDRESS );
TEST_ASSERT_EQUAL( 12345, ret );
free( xNetworkBuffer.pucEthernetBuffer - ipBUFFER_PADDING );
free( xReceiveBuffer.pucPayloadBuffer );
}
@@ -0,0 +1,110 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_DNS_ConfigNoCallback" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
# list the files to mock here
set (mock_list "")
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Cache.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Callback.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Networking.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Parser.h"
)
# list the directories your mocks need
set(mock_include_list "")
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
)
#list the definitions of your mocks to control what to be included
set(mock_define_list "")
list(APPEND mock_define_list
-DipconfigUSE_DNS=1
)
# ================= Create the library under test here (edit) ==================
add_compile_options(-Wno-pedantic -ggdb3)
# list the files you would like to test here
set(real_source_files "")
list(APPEND real_source_files
${MODULE_ROOT_DIR}/source/FreeRTOS_DNS.c
)
# list the directories the module under test includes
set(real_include_directories "")
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
# list the directories your test needs to include
set(test_include_directories "")
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/source/include
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "")
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set (utest_dep_list "")
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,57 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
const BaseType_t xBufferAllocFixedSize = pdTRUE;
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint,
const char * pcName )
{
}
@@ -0,0 +1,215 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_FreeRTOS_IP.h"
#include "mock_FreeRTOS_Sockets.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_task.h"
#include "mock_list.h"
#include "mock_queue.h"
#include "mock_FreeRTOS_DNS_Callback.h"
/*#include "mock_FreeRTOS_DNS_Cache.h" */
#include "mock_FreeRTOS_DNS_Parser.h"
/* #include "mock_FreeRTOS_DNS_Networking.h"*/
#include "mock_NetworkBufferManagement.h"
#include "FreeRTOS_DNS.h"
#include "catch_assert.h"
#include "FreeRTOS_DNS_Networking.h"
#include "FreeRTOSIPConfig.h"
#define LLMNR_ADDRESS "freertos"
#define GOOD_ADDRESS "www.freertos.org"
#define BAD_ADDRESS "this is a bad address"
#define DOTTED_ADDRESS "192.268.0.1"
typedef void (* FOnDNSEvent ) ( const char * /* pcName */,
void * /* pvSearchID */,
struct freertos_addrinfo * /* pxAddressInfo */ );
/* =========================== GLOBAL VARIABLES =========================== */
static int callback_called = 0;
/* =========================== STATIC FUNCTIONS =========================== */
static void dns_callback( const char * pcName,
void * pvSearchID,
uint32_t ulIPAddress )
{
callback_called = 1;
}
/* ============================ TEST FIXTURES ============================= */
/**
* @brief calls at the beginning of each test case
*/
void setUp( void )
{
callback_called = 0;
}
/**
* @brief calls at the end of each test case
*/
void tearDown( void )
{
}
/* ============================= TEST CASES =============================== */
/**
* @brief Ensures that when the socket is invalid, null is returned
*/
void test_CreateSocket_fail_socket( void )
{
Socket_t s;
FreeRTOS_socket_ExpectAndReturn( FREERTOS_AF_INET,
FREERTOS_SOCK_DGRAM,
FREERTOS_IPPROTO_UDP,
NULL );
xSocketValid_ExpectAndReturn( NULL, pdFALSE );
s = DNS_CreateSocket( 235 );
TEST_ASSERT_EQUAL( NULL, s );
}
/**
* @brief Happy path!
*/
void test_CreateSocket_success( void )
{
Socket_t s;
FreeRTOS_socket_ExpectAndReturn( FREERTOS_AF_INET,
FREERTOS_SOCK_DGRAM,
FREERTOS_IPPROTO_UDP,
( Socket_t ) 235 );
xSocketValid_ExpectAndReturn( ( Socket_t ) 235, pdTRUE );
FreeRTOS_setsockopt_ExpectAnyArgsAndReturn( 0 );
FreeRTOS_setsockopt_ExpectAnyArgsAndReturn( 0 );
s = DNS_CreateSocket( 235 );
TEST_ASSERT_EQUAL( ( Socket_t ) 235, s );
}
/**
* @brief Happy path!
*/
void test_BindSocket_success( void )
{
struct freertos_sockaddr xAddress;
struct xSOCKET xSocket;
uint32_t ret;
FreeRTOS_bind_ExpectAnyArgsAndReturn( 1 );
ret = DNS_BindSocket( &xSocket, 80 );
TEST_ASSERT_EQUAL( 1, ret );
}
/**
* @brief Happy path!
*/
void test_SendRequest_success( void )
{
Socket_t s = ( Socket_t ) 123;
uint32_t ret;
struct freertos_sockaddr xAddress;
struct xDNSBuffer pxDNSBuf;
pxDNSBuf.uxPayloadLength = 1024;
FreeRTOS_sendto_ExpectAnyArgsAndReturn( pxDNSBuf.uxPayloadLength );
ret = DNS_SendRequest( s, &xAddress, &pxDNSBuf );
TEST_ASSERT_EQUAL( pdTRUE, ret );
}
/**
* @brief Ensures that when SendTo fails false is returned
*/
void test_SendRequest_fail( void )
{
Socket_t s = ( Socket_t ) 123;
uint32_t ret;
struct freertos_sockaddr xAddress;
struct xDNSBuffer pxDNSBuf;
pxDNSBuf.uxPayloadLength = 1024;
FreeRTOS_sendto_ExpectAnyArgsAndReturn( 1023 );
ret = DNS_SendRequest( s, &xAddress, &pxDNSBuf );
TEST_ASSERT_EQUAL( pdFALSE, ret );
}
/**
* @brief Happy path!
*/
void test_ReadReply_success( void )
{
Socket_t s = ( Socket_t ) 123;
struct freertos_sockaddr xAddress;
struct xDNSBuffer pxDNSBuf;
BaseType_t xReturn;
FreeRTOS_recvfrom_ExpectAnyArgsAndReturn( 600 );
xReturn = DNS_ReadReply( s, &xAddress, &pxDNSBuf );
TEST_ASSERT_EQUAL( 600, xReturn );
}
/**
* @brief Happy path!
*/
void test_CloseSocket_success( void )
{
Socket_t s = ( Socket_t ) 123;
FreeRTOS_closesocket_ExpectAndReturn( s, pdTRUE );
DNS_CloseSocket( s );
}
@@ -0,0 +1,104 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_DNS_Networking" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
# list the files to mock here
set (mock_list "")
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Cache.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Callback.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Parser.h"
)
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
)
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
)
# ================= Create the library under test here (edit) ==================
add_compile_options(-Wno-pedantic -ggdb3)
# list the files you would like to test here
set(real_source_files ""
)
list(APPEND real_source_files
${project_name}/${project_name}_stubs.c
${MODULE_ROOT_DIR}/source/FreeRTOS_DNS_Networking.c
)
# list the directories the module under test includes
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/include
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "")
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set (utest_dep_list "")
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,334 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
#define FreeRTOS_htons( usIn ) ( ( uint16_t ) ( ( ( usIn ) << 8U ) | ( ( usIn ) >> 8U ) ) )
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 2 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks using pdMS_TO_TICKS().*/
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 5000U )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 5
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD \
( 120000U / portTICK_PERIOD_MS )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 pdMS_TO_TICKS( 20 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,59 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
/* =========================== EXTERN VARIABLES =========================== */
BaseType_t xBufferAllocFixedSize = pdFALSE;
uint16_t usPacketIdentifier;
struct freertos_addrinfo pucAddrBuffer[ 2 ];
struct freertos_sockaddr pucSockAddrBuffer[ 1 ];
/* ======================== Stub Callback Functions ========================= */
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
@@ -0,0 +1,111 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_DNS_Parser" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
# list the files to mock here
set (mock_list "")
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Callback.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Cache.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Networking.h"
)
# list the directories your mocks need
list(APPEND mock_include_list
.
${CMAKE_BINARY_DIR}/Annexed_TCP/
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
)
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
)
# ================= Create the library under test here (edit) ==================
add_compile_options(-Wno-pedantic -ggdb3)
# list the files you would like to test here
set(real_source_files ""
)
list(APPEND real_source_files
${project_name}/FreeRTOS_DNS_Parser_stubs.c
${MODULE_ROOT_DIR}/source/FreeRTOS_DNS_Parser.c
)
# list the directories the module under test includes
set ( real_include_directories ""
)
list(APPEND real_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${CMAKE_BINARY_DIR}/Annexed_TCP/
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
# list the directories your test needs to include
set ( test_include_directories ""
)
list(APPEND test_include_directories
.
${CMAKE_BINARY_DIR}/Annexed_TCP/
${TCP_INCLUDE_DIRS}
${CMOCK_DIR}/vendor/unity/src
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/include
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "")
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set (utest_dep_list "")
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,66 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
/** @brief A list of all network end-points. Each element has a next pointer. */
struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
volatile BaseType_t xInsideInterrupt = pdFALSE;
const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } };
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xNeeded )
{
return malloc( xNeeded );
}
void vPortFree( void * ptr )
{
free( ptr );
}
@@ -0,0 +1,249 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_task.h"
#include "mock_list.h"
/* This must come after list.h is included (in this case, indirectly
* by mock_list.h). */
#include "mock_ICMP_list_macros.h"
#include "mock_queue.h"
#include "mock_event_groups.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_FreeRTOS_IP_Utils.h"
#include "mock_FreeRTOS_IP_Timers.h"
#include "mock_FreeRTOS_TCP_IP.h"
#include "mock_FreeRTOS_IP.h"
#include "mock_FreeRTOS_ARP.h"
#include "mock_NetworkBufferManagement.h"
#include "mock_NetworkInterface.h"
#include "mock_FreeRTOS_DHCP.h"
#include "mock_FreeRTOS_Sockets.h"
#include "mock_FreeRTOS_DNS.h"
#include "mock_FreeRTOS_Stream_Buffer.h"
#include "mock_FreeRTOS_TCP_WIN.h"
#include "mock_FreeRTOS_UDP_IP.h"
#include "FreeRTOS_ICMP.h"
#include "FreeRTOS_ICMP_stubs.c"
#include "catch_assert.h"
#include "FreeRTOSIPConfig.h"
void test_ProcessICMPPacket_CatchAssert( void )
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
pxNetworkBuffer = &xNetworkBuffer;
pxNetworkBuffer->xDataLength = sizeof( ICMPPacket_t ) - 1;
catch_assert( ProcessICMPPacket( pxNetworkBuffer ) );
}
void test_ProcessICMPPacket_AllZeroData( void )
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
pxNetworkBuffer = &xNetworkBuffer;
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
pxNetworkBuffer->xDataLength = ipconfigTCP_MSS;
memset( ucEthBuffer, 0, ipconfigTCP_MSS );
eResult = ProcessICMPPacket( pxNetworkBuffer );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}
void test_ProcessICMPPacket_EchoRequest( void )
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
IPHeader_t * pxIPHeader;
ICMPPacket_t * pxICMPPacket;
ICMPHeader_t * pxICMPHeader;
NetworkEndPoint_t xEndPoint = { 0 };
pxNetworkEndPoints = &xEndPoint;
pxNetworkBuffer = &xNetworkBuffer;
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
pxNetworkBuffer->xDataLength = ipconfigTCP_MSS;
memset( ucEthBuffer, 0, ipconfigTCP_MSS );
pxICMPPacket = ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer;
pxICMPHeader = ( ( ICMPHeader_t * ) &( pxICMPPacket->xICMPHeader ) );
pxIPHeader = &( pxICMPPacket->xIPHeader );
pxICMPPacket->xICMPHeader.ucTypeOfMessage = ipICMP_ECHO_REQUEST;
uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( 0 );
usGenerateChecksum_ExpectAnyArgsAndReturn( 0xAA );
usGenerateProtocolChecksum_ExpectAnyArgsAndReturn( 0 );
eResult = ProcessICMPPacket( pxNetworkBuffer );
TEST_ASSERT_EQUAL( eReturnEthernetFrame, eResult );
TEST_ASSERT_EQUAL( ( uint8_t ) ipICMP_ECHO_REPLY, pxICMPHeader->ucTypeOfMessage );
TEST_ASSERT_EQUAL( pxIPHeader->ulSourceIPAddress, pxIPHeader->ulDestinationIPAddress );
TEST_ASSERT_EQUAL( xEndPoint.ipv4_settings.ulIPAddress, pxIPHeader->ulSourceIPAddress );
TEST_ASSERT_EQUAL( ipconfigICMP_TIME_TO_LIVE, pxIPHeader->ucTimeToLive );
TEST_ASSERT_EQUAL( 0, pxIPHeader->usFragmentOffset );
TEST_ASSERT_EQUAL( ( uint16_t ) ~FreeRTOS_htons( 0xAA ), pxIPHeader->usHeaderChecksum );
}
void test_ProcessICMPPacket_UnknownICMPPacket( void )
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
ICMPPacket_t * pxICMPPacket;
pxNetworkBuffer = &xNetworkBuffer;
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
pxNetworkBuffer->xDataLength = ipconfigTCP_MSS;
memset( ucEthBuffer, 0, ipconfigTCP_MSS );
pxICMPPacket = ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer;
/* Unknown ICMP Packet. */
pxICMPPacket->xICMPHeader.ucTypeOfMessage = ipICMP_ECHO_REQUEST + 2;
eResult = ProcessICMPPacket( pxNetworkBuffer );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}
void test_ProcessICMPPacket_ICMPEchoReply_NULLData( void )
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
ICMPPacket_t * pxICMPPacket;
pxNetworkBuffer = &xNetworkBuffer;
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
pxNetworkBuffer->xDataLength = ipconfigTCP_MSS;
memset( ucEthBuffer, 0, ipconfigTCP_MSS );
pxICMPPacket = ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer;
pxICMPPacket->xIPHeader.usLength = FreeRTOS_htons( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_ICMPv4_HEADER );
/* ICMP Reply. */
pxICMPPacket->xICMPHeader.ucTypeOfMessage = ipICMP_ECHO_REPLY;
vApplicationPingReplyHook_Expect( eSuccess, 0 );
eResult = ProcessICMPPacket( pxNetworkBuffer );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}
void test_ProcessICMPPacket_ICMPEchoReply_ProperData( void )
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
ICMPPacket_t * pxICMPPacket;
uint8_t * pucByte;
pxNetworkBuffer = &xNetworkBuffer;
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
pxNetworkBuffer->xDataLength = ipconfigTCP_MSS;
memset( ucEthBuffer, 0, ipconfigTCP_MSS );
pxICMPPacket = ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer;
pxICMPPacket->xIPHeader.usLength = FreeRTOS_htons( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_ICMPv4_HEADER + 10 );
/* ICMP Reply. */
pxICMPPacket->xICMPHeader.ucTypeOfMessage = ipICMP_ECHO_REPLY;
pucByte = ( uint8_t * ) pxICMPPacket;
pucByte = &( pucByte[ sizeof( ICMPPacket_t ) ] );
memset( pucByte, ipECHO_DATA_FILL_BYTE, 10 );
vApplicationPingReplyHook_Expect( eSuccess, 0 );
eResult = ProcessICMPPacket( pxNetworkBuffer );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}
void test_ProcessICMPPacket_ICMPEchoReply_ImproperData( void )
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
ICMPPacket_t * pxICMPPacket;
uint8_t * pucByte;
pxNetworkBuffer = &xNetworkBuffer;
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
pxNetworkBuffer->xDataLength = ipconfigTCP_MSS;
memset( ucEthBuffer, 0, ipconfigTCP_MSS );
pxICMPPacket = ( ICMPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer;
pxICMPPacket->xIPHeader.usLength = FreeRTOS_htons( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_ICMPv4_HEADER + 10 );
/* ICMP Reply. */
pxICMPPacket->xICMPHeader.ucTypeOfMessage = ipICMP_ECHO_REPLY;
pucByte = ( uint8_t * ) pxICMPPacket;
pucByte = &( pucByte[ sizeof( ICMPPacket_t ) ] );
memset( pucByte, ipECHO_DATA_FILL_BYTE, 5 );
vApplicationPingReplyHook_Expect( eInvalidData, 0 );
eResult = ProcessICMPPacket( pxNetworkBuffer );
TEST_ASSERT_EQUAL( eSuccess, eResult );
}
@@ -0,0 +1,75 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#undef listSET_LIST_ITEM_OWNER
void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem,
void * owner );
#undef listGET_END_MARKER
ListItem_t * listGET_END_MARKER( List_t * pxList );
#undef listGET_NEXT
ListItem_t * listGET_NEXT( const ListItem_t * pxListItem );
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( const ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( const ListItem_t * listItem );
#endif /* ifndef LIST_MACRO_H */
@@ -0,0 +1,119 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_ICMP" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Stream_Buffer.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_WIN.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkInterface.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/ICMP_list_macros.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/${project_name}.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,124 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <assert.h>
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_STATIC_ALLOCATION 1
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */
/* Software timer related configuration options. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configMAX_PRIORITIES ( 7 )
#define configENABLE_MPU 0
/* Run time stats gathering configuration options. */
#define configGENERATE_RUN_TIME_STATS 1
/* This demo makes use of one or more example stats formatting functions. These
* format the raw data provided by the uxTaskGetSystemState() function in to human
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
/* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. */
extern void vAssertCalled( unsigned long ulLine,
const char * const pcFileName );
#define configASSERT( x )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
/* #include "trcRecorder.h" */
#endif /* FREERTOS_CONFIG_H */
@@ -0,0 +1,63 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
volatile BaseType_t xInsideInterrupt = pdFALSE;
const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } };
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xNeeded )
{
return malloc( xNeeded );
}
void vPortFree( void * ptr )
{
free( ptr );
}
@@ -0,0 +1,72 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_task.h"
#include "mock_list.h"
#include "mock_queue.h"
#include "mock_event_groups.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_FreeRTOS_IP_Utils.h"
#include "mock_FreeRTOS_IP_Timers.h"
#include "mock_FreeRTOS_TCP_IP.h"
#include "mock_FreeRTOS_IP.h"
#include "mock_FreeRTOS_ARP.h"
#include "mock_NetworkBufferManagement.h"
#include "mock_NetworkInterface.h"
#include "mock_FreeRTOS_DHCP.h"
#include "mock_FreeRTOS_Sockets.h"
#include "mock_FreeRTOS_DNS.h"
#include "mock_FreeRTOS_Stream_Buffer.h"
#include "mock_FreeRTOS_TCP_WIN.h"
#include "mock_FreeRTOS_UDP_IP.h"
#include "FreeRTOS_ICMP.h"
#include "FreeRTOSIPConfig.h"
void test_ProcessICMPPacket_PacketSizeSmall( void )
{
eFrameProcessingResult_t eResult;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
pxNetworkBuffer = &xNetworkBuffer;
pxNetworkBuffer->xDataLength = sizeof( ICMPPacket_t ) - 1;
eResult = ProcessICMPPacket( pxNetworkBuffer );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}
@@ -0,0 +1,119 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_ICMP_wo_assert" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Stream_Buffer.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_WIN.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkInterface.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/FreeRTOS_ICMP.c
${MODULE_ROOT_DIR}/test/unit-test/${project_name}/${project_name}_stubs.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,77 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
NetworkInterface_t xInterfaces[ 1 ];
volatile BaseType_t xInsideInterrupt = pdFALSE;
BaseType_t xNetworkUp;
struct xNetworkInterface * pxNetworkInterfaces = NULL;
/** @brief A list of all network end-points. Each element has a next pointer. */
struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } };
const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } };
const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } };
const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } };
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xNeeded )
{
return malloc( xNeeded );
}
void vPortFree( void * ptr )
{
free( ptr );
}
@@ -0,0 +1,92 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#include "FreeRTOS_IPv6_Private.h"
#undef listSET_LIST_ITEM_OWNER
void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem,
void * owner );
#undef listGET_END_MARKER
ListItem_t * listGET_END_MARKER( List_t * pxList );
#undef listGET_NEXT
ListItem_t * listGET_NEXT( const ListItem_t * pxListItem );
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( const ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( const ListItem_t * listItem );
extern NetworkInterface_t xInterfaces[ 1 ];
/* prvProcessICMPMessage_IPv6() is declared in FreeRTOS_routing.c
* It handles all ICMP messages except the PING requests. */
eFrameProcessingResult_t prvProcessICMPMessage_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer );
/**
* @brief Work on the RA/SLAAC processing.
* @param[in] xDoReset: WHen true, the state-machine will be reset and initialised.
* @param[in] pxEndPoint: The end-point for which the RA/SLAAC process should be done..
*/
void vRAProcess( BaseType_t xDoReset,
NetworkEndPoint_t * pxEndPoint );
NetworkInterface_t * pxFillInterfaceDescriptor( BaseType_t xEMACIndex,
NetworkInterface_t * pxInterface );
#endif /* ifndef LIST_MACRO_H */
@@ -0,0 +1,128 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_IP" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Cache.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv6.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ND.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv6_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ICMP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Stream_Buffer.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_WIN.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkInterface.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/IP_list_macros.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/${project_name}.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,124 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <assert.h>
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_STATIC_ALLOCATION 0
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */
/* Software timer related configuration options. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configMAX_PRIORITIES ( 7 )
#define configENABLE_MPU 0
/* Run time stats gathering configuration options. */
#define configGENERATE_RUN_TIME_STATS 1
/* This demo makes use of one or more example stats formatting functions. These
* format the raw data provided by the uxTaskGetSystemState() function in to human
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
/* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. */
extern void vAssertCalled( unsigned long ulLine,
const char * const pcFileName );
#define configASSERT( x )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
/* #include "trcRecorder.h" */
#endif /* FREERTOS_CONFIG_H */
@@ -0,0 +1,339 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
#define ipconfigIPv4_BACKWARD_COMPATIBLE 0
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 2 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks by dividing the time in
* milliseconds by portTICK_PERIOD_MS. */
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 5
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD pdMS_TO_TICKS( 120000U )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 pdMS_TO_TICKS( 20 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#define ipconfigCHECK_IP_QUEUE_SPACE ( 1 )
#define ipconfigSELECT_USES_NOTIFY ( 1 )
#define ipconfigUSE_LINKED_RX_MESSAGES ( 1 )
#define ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS ( 0 )
#define ipconfigZERO_COPY_TX_DRIVER ( 1 )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,78 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
BaseType_t xNetworkUp;
NetworkInterface_t xInterfaces[ 1 ];
volatile BaseType_t xInsideInterrupt = pdFALSE;
struct xNetworkInterface * pxNetworkInterfaces = NULL;
/** @brief A list of all network end-points. Each element has a next pointer. */
struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
const MACAddress_t xDefault_MacAddress = { { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } };
const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } };
const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } };
const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } };
const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } };
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xNeeded )
{
return malloc( xNeeded );
}
void vPortFree( void * ptr )
{
free( ptr );
}
@@ -0,0 +1,553 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_task.h"
#include "mock_list.h"
/* This must come after list.h is included (in this case, indirectly
* by mock_list.h). */
#include "mock_IP_DiffConfig_list_macros.h"
#include "mock_queue.h"
#include "mock_event_groups.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_FreeRTOS_IP_Timers.h"
#include "mock_NetworkBufferManagement.h"
#include "mock_FreeRTOS_Sockets.h"
#include "mock_FreeRTOS_Routing.h"
#include "mock_FreeRTOS_ARP.h"
#include "mock_FreeRTOS_Stream_Buffer.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_DiffConfig_stubs.c"
#include "catch_assert.h"
#include "FreeRTOSIPConfig.h"
/* =========================== EXTERN VARIABLES =========================== */
void prvIPTask( void * pvParameters );
void prvProcessIPEventsAndTimers( void );
eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket,
NetworkBufferDescriptor_t * const pxNetworkBuffer );
void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
extern BaseType_t xIPTaskInitialised;
extern BaseType_t xNetworkDownEventPending;
extern BaseType_t xNetworkUp;
extern UBaseType_t uxQueueMinimumSpace;
/* ============================ Unity Fixtures ============================ */
/*! called before each test case */
void setUp( void )
{
pxNetworkEndPoints = NULL;
pxNetworkInterfaces = NULL;
xNetworkDownEventPending = pdFALSE;
}
/*! called after each test case */
void tearDown( void )
{
}
/* ======================== Stub Callback Functions ========================= */
BaseType_t NetworkInterfaceOutputFunction_Stub_Called = 0;
BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDescriptor,
NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xReleaseAfterSend )
{
NetworkInterfaceOutputFunction_Stub_Called++;
return 0;
}
static uint8_t ReleaseTCPPayloadBuffer[ 1500 ];
static BaseType_t ReleaseTCPPayloadBufferxByteCount = 100;
static size_t StubuxStreamBufferGetPtr_ReturnBadAddress( StreamBuffer_t * pxBuffer,
uint8_t ** ppucData,
int lCounter )
{
*ppucData = &ReleaseTCPPayloadBuffer[ 150 ];
return 0xFFFFFF;
}
static size_t StubuxStreamBufferGetPtr_ReturnIncorrectSize( StreamBuffer_t * pxBuffer,
uint8_t ** ppucData,
int lCounter )
{
*ppucData = &ReleaseTCPPayloadBuffer[ 0 ];
return( ReleaseTCPPayloadBufferxByteCount >> 1 );
}
static size_t StubuxStreamBufferGetPtr_ReturnCorrectVals( StreamBuffer_t * pxBuffer,
uint8_t ** ppucData,
int lCounter )
{
*ppucData = &ReleaseTCPPayloadBuffer[ 0 ];
return ReleaseTCPPayloadBufferxByteCount;
}
/* ============================== Test Cases ============================== */
/**
* @brief test_prvProcessIPEventsAndTimers_NoEventReceived
* To validate the flow of prvProcessIPEventsAndTimers() to handle eNoEvent.
*/
void test_prvProcessIPEventsAndTimers_NoEventReceived( void )
{
vCheckNetworkTimers_Expect();
xCalculateSleepTime_ExpectAndReturn( 0 );
/* No event received. */
xQueueReceive_ExpectAnyArgsAndReturn( pdFALSE );
prvProcessIPEventsAndTimers();
}
/**
* @brief test_prvProcessIPEventsAndTimers_eNetworkRxEventNULL_LessSpace
* To validate the flow of prvProcessIPEventsAndTimers() doesn't update
* uxQueueMinimumSpace when uxQueueSpacesAvailable() returns more.
*/
void test_prvProcessIPEventsAndTimers_eNetworkRxEventNULL_LessSpace( void )
{
IPStackEvent_t xReceivedEvent;
BaseType_t xQueueReturn = 100;
xReceivedEvent.eEventType = eNetworkRxEvent;
xReceivedEvent.pvData = NULL;
uxQueueMinimumSpace = xQueueReturn - 10;
vCheckNetworkTimers_Expect();
xCalculateSleepTime_ExpectAndReturn( 0 );
xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE );
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) );
uxQueueSpacesAvailable_ExpectAnyArgsAndReturn( xQueueReturn );
prvProcessIPEventsAndTimers();
TEST_ASSERT_EQUAL( xQueueReturn - 10, uxQueueMinimumSpace );
}
/**
* @brief test_prvProcessIPEventsAndTimers_eNetworkRxEventNULL_LessSpace
* To validate the flow of prvProcessIPEventsAndTimers() updates uxQueueMinimumSpace
* when uxQueueSpacesAvailable() returns less.
*/
void test_prvProcessIPEventsAndTimers_eNetworkRxEvent_MoreSpace( void )
{
IPStackEvent_t xReceivedEvent;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
BaseType_t xQueueReturn = 100;
pxNetworkBuffer = &xNetworkBuffer;
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
pxNetworkBuffer->xDataLength = sizeof( EthernetHeader_t ) - 1;
pxNetworkBuffer->pxNextBuffer = NULL;
xReceivedEvent.eEventType = eNetworkRxEvent;
xReceivedEvent.pvData = pxNetworkBuffer;
uxQueueMinimumSpace = xQueueReturn + 10;
vCheckNetworkTimers_Expect();
xCalculateSleepTime_ExpectAndReturn( 0 );
xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE );
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) );
uxQueueSpacesAvailable_ExpectAnyArgsAndReturn( xQueueReturn );
vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer );
prvProcessIPEventsAndTimers();
TEST_ASSERT_EQUAL( xQueueReturn, uxQueueMinimumSpace );
}
/**
* @brief test_prvProcessIPEventsAndTimers_eSocketSelectEvent
* To validate if prvProcessIPEventsAndTimers() calls xTaskNotifyGive (xTaskGenericNotify)
* while handling eSocketSelectEvent.
*/
void test_prvProcessIPEventsAndTimers_eSocketSelectEvent( void )
{
IPStackEvent_t xReceivedEvent;
SocketSelectMessage_t xData;
BaseType_t xQueueReturn = 100;
memset( &xData, 0, sizeof( xData ) );
xData.pxSocketSet = ( void * ) 0xFFAABBCC;
xData.xTaskhandle = ( void * ) 0xABCDABCD;
xReceivedEvent.eEventType = eSocketSelectEvent;
xReceivedEvent.pvData = ( void * ) &xData;
vCheckNetworkTimers_Expect();
xCalculateSleepTime_ExpectAndReturn( 0 );
xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE );
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) );
uxQueueSpacesAvailable_ExpectAnyArgsAndReturn( xQueueReturn );
vSocketSelect_Expect( ( SocketSelect_t * ) 0xFFAABBCC );
xTaskGenericNotify_ExpectAndReturn( ( TaskHandle_t ) 0xABCDABCD, 0, ( 0 ), eIncrement, NULL, pdPASS );
prvProcessIPEventsAndTimers();
}
/**
* @brief test_FreeRTOS_ReleaseTCPPayloadBuffer_IncorrectBufferAssert
* The input buffer pointer must be obtained by calling FreeRTOS_recv() with the FREERTOS_ZERO_COPY flag.
* Because configASSERT is disabled in this configuration, there is no assertion in this test case.
*/
void test_FreeRTOS_ReleaseTCPPayloadBuffer_IncorrectBufferAssert( void )
{
FreeRTOS_Socket_t xSocket;
BaseType_t xByteCount = 100, xReturn;
memset( &xSocket, 0, sizeof( xSocket ) );
uxStreamBufferGetPtr_Stub( StubuxStreamBufferGetPtr_ReturnBadAddress );
xReturn = FreeRTOS_ReleaseTCPPayloadBuffer( &xSocket, ReleaseTCPPayloadBuffer, xByteCount );
TEST_ASSERT_EQUAL( pdFAIL, xReturn );
}
/**
* @brief test_FreeRTOS_ReleaseTCPPayloadBuffer_IncorrectSizeAssert
* Because configASSERT is disabled in this configuration, there is no assertion
* even though available buffer size is less than input length.
*/
void test_FreeRTOS_ReleaseTCPPayloadBuffer_IncorrectSizeAssert( void )
{
FreeRTOS_Socket_t xSocket;
BaseType_t xReturn;
memset( &xSocket, 0, sizeof( xSocket ) );
uxStreamBufferGetPtr_Stub( StubuxStreamBufferGetPtr_ReturnIncorrectSize );
xReturn = FreeRTOS_ReleaseTCPPayloadBuffer( &xSocket, ReleaseTCPPayloadBuffer, ReleaseTCPPayloadBufferxByteCount );
TEST_ASSERT_EQUAL( pdFAIL, xReturn );
}
/**
* @brief test_FreeRTOS_ReleaseTCPPayloadBuffer_IncorrectBytesReleasedAssert
* Because configASSERT is disabled in this configuration, there is no assertion
* even though bytes released from FreeRTOS_recv() is different from request.
*/
void test_FreeRTOS_ReleaseTCPPayloadBuffer_IncorrectBytesReleasedAssert( void )
{
FreeRTOS_Socket_t xSocket;
BaseType_t xReturn;
memset( &xSocket, 0, sizeof( xSocket ) );
uxStreamBufferGetPtr_Stub( StubuxStreamBufferGetPtr_ReturnCorrectVals );
FreeRTOS_recv_ExpectAndReturn( &xSocket, NULL, ReleaseTCPPayloadBufferxByteCount, FREERTOS_MSG_DONTWAIT, ( ReleaseTCPPayloadBufferxByteCount >> 1 ) );
xReturn = FreeRTOS_ReleaseTCPPayloadBuffer( &xSocket, ReleaseTCPPayloadBuffer, ReleaseTCPPayloadBufferxByteCount );
TEST_ASSERT_EQUAL( pdFAIL, xReturn );
}
/**
* @brief test_FreeRTOS_ReleaseTCPPayloadBuffer_HappyPath
* To validate happy path for FreeRTOS_ReleaseTCPPayloadBuffer.
*/
void test_FreeRTOS_ReleaseTCPPayloadBuffer_HappyPath( void )
{
FreeRTOS_Socket_t xSocket;
BaseType_t xReturn;
memset( &xSocket, 0, sizeof( xSocket ) );
uxStreamBufferGetPtr_Stub( StubuxStreamBufferGetPtr_ReturnCorrectVals );
FreeRTOS_recv_ExpectAndReturn( &xSocket, NULL, ReleaseTCPPayloadBufferxByteCount, FREERTOS_MSG_DONTWAIT, ReleaseTCPPayloadBufferxByteCount );
xReturn = FreeRTOS_ReleaseTCPPayloadBuffer( &xSocket, ReleaseTCPPayloadBuffer, ReleaseTCPPayloadBufferxByteCount );
TEST_ASSERT_EQUAL( pdPASS, xReturn );
}
/**
* @brief test_vReturnEthernetFrame_DuplicationFailed
* To validate if vReturnEthernetFrame is able to handle NULL network buffer descriptor.
*/
void test_vReturnEthernetFrame_DuplicationFailed( void )
{
NetworkBufferDescriptor_t xNetworkBuffer;
BaseType_t xReleaseAfterSend = pdFALSE;
NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint;
xNetworkBuffer.xDataLength = ipconfigETHERNET_MINIMUM_PACKET_BYTES;
pxDuplicateNetworkBufferWithDescriptor_ExpectAndReturn( &xNetworkBuffer, xNetworkBuffer.xDataLength, NULL );
FreeRTOS_FindEndPointOnNetMask_IgnoreAndReturn( pxEndPoint );
vReturnEthernetFrame( &xNetworkBuffer, xReleaseAfterSend );
}
/**
* @brief test_vReturnEthernetFrame_DuplicationSuccess
* To validate if vReturnEthernetFrame is able to handle duplicate network buffer descriptor.
*/
void test_vReturnEthernetFrame_DuplicationSuccess( void )
{
NetworkBufferDescriptor_t xDuplicateNetworkBuffer;
BaseType_t xReleaseAfterSend = pdFALSE;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
EthernetHeader_t * pxEthernetHeader;
struct xNetworkInterface xInterface;
NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint;
pxNetworkBuffer = &xNetworkBuffer;
memset( pxNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) );
memset( &xDuplicateNetworkBuffer, 0, sizeof( xDuplicateNetworkBuffer ) );
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
memset( ucEthBuffer, 0xAA, ipconfigTCP_MSS );
memset( pxEndPoint, 0, sizeof( NetworkEndPoint_t ) );
xDuplicateNetworkBuffer.pucEthernetBuffer = ucEthBuffer;
pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer;
memset( &pxEthernetHeader->xDestinationAddress, 0x11, sizeof( pxEthernetHeader->xDestinationAddress ) );
memset( &pxEthernetHeader->xSourceAddress, 0x22, sizeof( pxEthernetHeader->xSourceAddress ) );
memcpy( pxEndPoint->xMACAddress.ucBytes, xDefault_MacAddress.ucBytes, sizeof( MACAddress_t ) );
pxNetworkBuffer->pxEndPoint = &xEndPoint;
xEndPoint.pxNetworkInterface = &xInterfaces[ 0 ];
xInterfaces->pfOutput = &NetworkInterfaceOutputFunction_Stub;
NetworkInterfaceOutputFunction_Stub_Called = 0;
pxNetworkBuffer->xDataLength = ipconfigETHERNET_MINIMUM_PACKET_BYTES;
( ( ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ) )->usFrameType = ipIPv4_FRAME_TYPE;
pxDuplicateNetworkBufferWithDescriptor_ExpectAndReturn( &xNetworkBuffer, xNetworkBuffer.xDataLength, &xDuplicateNetworkBuffer );
FreeRTOS_FindEndPointOnNetMask_IgnoreAndReturn( pxEndPoint );
eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheMiss );
xIsCallingFromIPTask_ExpectAndReturn( pdTRUE );
vReturnEthernetFrame( pxNetworkBuffer, xReleaseAfterSend );
TEST_ASSERT_EQUAL( ipconfigETHERNET_MINIMUM_PACKET_BYTES, pxNetworkBuffer->xDataLength );
TEST_ASSERT_EQUAL( xNetworkBuffer.xDataLength, xDuplicateNetworkBuffer.xDataLength );
TEST_ASSERT_EACH_EQUAL_UINT8( 0x22, &pxEthernetHeader->xDestinationAddress, sizeof( pxEthernetHeader->xDestinationAddress ) );
TEST_ASSERT_EQUAL_MEMORY( xDefault_MacAddress.ucBytes, &pxEthernetHeader->xSourceAddress, sizeof( pxEthernetHeader->xSourceAddress ) );
TEST_ASSERT_EQUAL( 1, NetworkInterfaceOutputFunction_Stub_Called );
}
/**
* @brief test_vReturnEthernetFrame_DuplicationSuccess
* To validate if vReturnEthernetFrame is able to handle duplicate network buffer descriptor with cache hit.
*/
void test_vReturnEthernetFrame_DuplicationSuccessCacheHit( void )
{
NetworkBufferDescriptor_t xDuplicateNetworkBuffer;
BaseType_t xReleaseAfterSend = pdFALSE;
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
EthernetHeader_t * pxEthernetHeader;
struct xNetworkInterface xInterface;
NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint;
MACAddress_t xCacheMACAddress = { { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } };
pxNetworkBuffer = &xNetworkBuffer;
memset( pxNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) );
memset( &xDuplicateNetworkBuffer, 0, sizeof( xDuplicateNetworkBuffer ) );
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
memset( ucEthBuffer, 0xAA, ipconfigTCP_MSS );
memset( pxEndPoint, 0, sizeof( NetworkEndPoint_t ) );
xDuplicateNetworkBuffer.pucEthernetBuffer = ucEthBuffer;
pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer;
memset( &pxEthernetHeader->xDestinationAddress, 0x11, sizeof( pxEthernetHeader->xDestinationAddress ) );
memset( &pxEthernetHeader->xSourceAddress, 0x22, sizeof( pxEthernetHeader->xSourceAddress ) );
memcpy( pxEndPoint->xMACAddress.ucBytes, xDefault_MacAddress.ucBytes, sizeof( MACAddress_t ) );
pxNetworkBuffer->pxEndPoint = &xEndPoint;
xEndPoint.pxNetworkInterface = &xInterfaces[ 0 ];
xInterfaces->pfOutput = &NetworkInterfaceOutputFunction_Stub;
NetworkInterfaceOutputFunction_Stub_Called = 0;
pxNetworkBuffer->xDataLength = ipconfigETHERNET_MINIMUM_PACKET_BYTES;
( ( ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer ) )->usFrameType = ipIPv4_FRAME_TYPE;
pxDuplicateNetworkBufferWithDescriptor_ExpectAndReturn( &xNetworkBuffer, xNetworkBuffer.xDataLength, &xDuplicateNetworkBuffer );
FreeRTOS_FindEndPointOnNetMask_IgnoreAndReturn( pxEndPoint );
eARPGetCacheEntry_ExpectAnyArgsAndReturn( eResolutionCacheHit );
eARPGetCacheEntry_ReturnMemThruPtr_pxMACAddress( &xCacheMACAddress, sizeof( MACAddress_t ) );
xIsCallingFromIPTask_ExpectAndReturn( pdTRUE );
vReturnEthernetFrame( pxNetworkBuffer, xReleaseAfterSend );
TEST_ASSERT_EQUAL( ipconfigETHERNET_MINIMUM_PACKET_BYTES, pxNetworkBuffer->xDataLength );
TEST_ASSERT_EQUAL( xNetworkBuffer.xDataLength, xDuplicateNetworkBuffer.xDataLength );
TEST_ASSERT_EQUAL_MEMORY( xCacheMACAddress.ucBytes, &pxEthernetHeader->xDestinationAddress, sizeof( pxEthernetHeader->xDestinationAddress ) );
TEST_ASSERT_EQUAL_MEMORY( xDefault_MacAddress.ucBytes, &pxEthernetHeader->xSourceAddress, sizeof( pxEthernetHeader->xSourceAddress ) );
TEST_ASSERT_EQUAL( 1, NetworkInterfaceOutputFunction_Stub_Called );
}
/**
* @brief test_vReturnEthernetFrame_xReleaseAfterSend
* To validate if vReturnEthernetFrame is able to send with input network buffer descriptor.
*/
void test_vReturnEthernetFrame_xReleaseAfterSend( void )
{
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
BaseType_t xReleaseAfterSend = pdTRUE;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
EthernetHeader_t * pxEthernetHeader;
NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint;
pxNetworkBuffer = &xNetworkBuffer;
memset( pxNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) );
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
memset( ucEthBuffer, 0xAA, ipconfigTCP_MSS );
pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer;
memset( &pxEthernetHeader->xDestinationAddress, 0x11, sizeof( pxEthernetHeader->xDestinationAddress ) );
memset( &pxEthernetHeader->xSourceAddress, 0x22, sizeof( pxEthernetHeader->xSourceAddress ) );
memcpy( pxEndPoint->xMACAddress.ucBytes, xDefault_MacAddress.ucBytes, sizeof( MACAddress_t ) );
pxNetworkBuffer->xDataLength = ipconfigETHERNET_MINIMUM_PACKET_BYTES - 10;
pxNetworkBuffer->pxEndPoint = &xEndPoint;
xEndPoint.pxNetworkInterface = &xInterfaces[ 0 ];
xInterfaces->pfOutput = &NetworkInterfaceOutputFunction_Stub;
NetworkInterfaceOutputFunction_Stub_Called = 0;
FreeRTOS_FindEndPointOnNetMask_IgnoreAndReturn( pxEndPoint );
xIsCallingFromIPTask_ExpectAndReturn( pdTRUE );
vReturnEthernetFrame( pxNetworkBuffer, xReleaseAfterSend );
TEST_ASSERT_EQUAL( ipconfigETHERNET_MINIMUM_PACKET_BYTES, pxNetworkBuffer->xDataLength );
TEST_ASSERT_EACH_EQUAL_UINT8( 0, &ucEthBuffer[ ipconfigETHERNET_MINIMUM_PACKET_BYTES - 10 ], 10 );
TEST_ASSERT_EACH_EQUAL_UINT8( 0x22, &pxEthernetHeader->xDestinationAddress, sizeof( pxEthernetHeader->xDestinationAddress ) );
TEST_ASSERT_EQUAL_MEMORY( xDefault_MacAddress.ucBytes, &pxEthernetHeader->xSourceAddress, sizeof( pxEthernetHeader->xSourceAddress ) );
TEST_ASSERT_EQUAL( 1, NetworkInterfaceOutputFunction_Stub_Called );
}
/**
* @brief test_vReturnEthernetFrame_DataLenMoreThanRequired
* To validate if vReturnEthernetFrame changes the source/destination MAC addresses correctly
* and transmits though network interface. And the buffer length is equal to ipconfigETHERNET_MINIMUM_PACKET_BYTES.
*/
void test_vReturnEthernetFrame_DataLenMoreThanRequired( void )
{
NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer;
BaseType_t xReleaseAfterSend = pdTRUE;
uint8_t ucEthBuffer[ ipconfigTCP_MSS ];
EthernetHeader_t * pxEthernetHeader;
NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint;
pxNetworkBuffer = &xNetworkBuffer;
memset( pxNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) );
pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer;
memset( ucEthBuffer, 0xAA, ipconfigTCP_MSS );
pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer;
memset( &pxEthernetHeader->xDestinationAddress, 0x11, sizeof( pxEthernetHeader->xDestinationAddress ) );
memset( &pxEthernetHeader->xSourceAddress, 0x22, sizeof( pxEthernetHeader->xSourceAddress ) );
memcpy( pxEndPoint->xMACAddress.ucBytes, xDefault_MacAddress.ucBytes, sizeof( MACAddress_t ) );
pxNetworkBuffer->xDataLength = ipconfigETHERNET_MINIMUM_PACKET_BYTES;
pxNetworkBuffer->pxEndPoint = &xEndPoint;
xEndPoint.pxNetworkInterface = &xInterfaces[ 0 ];
xInterfaces->pfOutput = &NetworkInterfaceOutputFunction_Stub;
NetworkInterfaceOutputFunction_Stub_Called = 0;
FreeRTOS_FindEndPointOnNetMask_IgnoreAndReturn( pxEndPoint );
xIsCallingFromIPTask_ExpectAndReturn( pdTRUE );
vReturnEthernetFrame( pxNetworkBuffer, xReleaseAfterSend );
TEST_ASSERT_EQUAL( ipconfigETHERNET_MINIMUM_PACKET_BYTES, pxNetworkBuffer->xDataLength );
TEST_ASSERT_EACH_EQUAL_UINT8( 0xAA, &ucEthBuffer[ ipconfigETHERNET_MINIMUM_PACKET_BYTES - 10 ], 10 );
TEST_ASSERT_EACH_EQUAL_UINT8( 0x22, &pxEthernetHeader->xDestinationAddress, sizeof( pxEthernetHeader->xDestinationAddress ) );
TEST_ASSERT_EQUAL_MEMORY( xDefault_MacAddress.ucBytes, &pxEthernetHeader->xSourceAddress, sizeof( pxEthernetHeader->xSourceAddress ) );
TEST_ASSERT_EQUAL( 1, NetworkInterfaceOutputFunction_Stub_Called );
}
/**
* @brief test_uxGetMinimumIPQueueSpace
* To validate if uxGetMinimumIPQueueSpace returns correct minimum queue space.
*/
void test_uxGetMinimumIPQueueSpace( void )
{
UBaseType_t uxReturn;
uxQueueMinimumSpace = 10;
uxReturn = uxGetMinimumIPQueueSpace();
TEST_ASSERT_EQUAL( 10, uxReturn );
}
@@ -0,0 +1,141 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#include "FreeRTOS_IPv6_Private.h"
extern NetworkInterface_t xInterfaces[ 1 ];
#undef listSET_LIST_ITEM_OWNER
void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem,
void * owner );
#undef listGET_END_MARKER
ListItem_t * listGET_END_MARKER( List_t * pxList );
#undef listGET_NEXT
ListItem_t * listGET_NEXT( const ListItem_t * pxListItem );
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( const ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( const ListItem_t * listItem );
/**
* @brief Reduce the age counter in each entry within the ND cache. An entry is no
* longer considered valid and is deleted if its age reaches zero.
* Just before getting to zero, 3 times a neighbour solicitation will be sent.
*/
void vNDAgeCache( void );
/**
* >>>>>>> afcedead21c747cef64f07c7fedd50df75bcbd10
* @brief Work on the RA/SLAAC processing.
* @param[in] xDoReset: WHen true, the state-machine will be reset and initialised.
* @param[in] pxEndPoint: The end-point for which the RA/SLAAC process should be done..
*/
void vRAProcess( BaseType_t xDoReset,
NetworkEndPoint_t * pxEndPoint );
/* This function shall be defined by the application. */
void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent,
struct xNetworkEndPoint * pxEndPoint );
/* Do not call the following function directly. It is there for downward compatibility.
* The function FreeRTOS_IPInit() will call it to initialise the interface and end-point
* objects. See the description in FreeRTOS_Routing.h. */
struct xNetworkInterface * pxFillInterfaceDescriptor( BaseType_t xEMACIndex,
struct xNetworkInterface * pxInterface );
/* The function 'prvAllowIPPacket()' checks if a IPv6 packets should be processed. */
eFrameProcessingResult_t prvAllowIPPacketIPv6( const IPHeader_IPv6_t * const pxIPv6Header,
const NetworkBufferDescriptor_t * const pxNetworkBuffer,
UBaseType_t uxHeaderLength );
/* Return IPv6 header extension order number */
BaseType_t xGetExtensionOrder( uint8_t ucProtocol,
uint8_t ucNextHeader );
/** @brief Handle the IPv6 extension headers. */
eFrameProcessingResult_t eHandleIPv6ExtensionHeaders( NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xDoRemove );
/*
* If ulIPAddress is already in the ND cache table then reset the age of the
* entry back to its maximum value. If ulIPAddress is not already in the ND
* cache table then add it - replacing the oldest current entry if there is not
* a free space available.
*/
void vNDRefreshCacheEntry( const MACAddress_t * pxMACAddress,
const IPv6_Address_t * pxIPAddress,
NetworkEndPoint_t * pxEndPoint );
/* prvProcessICMPMessage_IPv6() is declared in FreeRTOS_routing.c
* It handles all ICMP messages except the PING requests. */
eFrameProcessingResult_t prvProcessICMPMessage_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer );
/* Return pdTRUE if all end-points are up.
* When pxInterface is null, all end-points will be checked. */
BaseType_t FreeRTOS_AllEndPointsUp( const struct xNetworkInterface * pxInterface );
#endif /* ifndef LIST_MACRO_H */
@@ -0,0 +1,123 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_IP_DiffConfig" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ICMP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Stream_Buffer.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_WIN.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkInterface.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/IP_DiffConfig_list_macros.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${project_name}/${project_name}_stubs.c
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/FreeRTOS_IP.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,333 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 0 )
#define ipconfigIPv4_BACKWARD_COMPATIBLE 1
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 0
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 2 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks using pdMS_TO_TICKS().*/
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 5000U )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 5
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD \
( 120000U / portTICK_PERIOD_MS )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 pdMS_TO_TICKS( 20 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,79 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
NetworkInterface_t xInterfaces[ 1 ];
volatile BaseType_t xInsideInterrupt = pdFALSE;
BaseType_t xNetworkUp;
struct xNetworkInterface * pxNetworkInterfaces = NULL;
/** @brief A list of all network end-points. Each element has a next pointer. */
struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
const MACAddress_t xDefault_MacAddress = { { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 } };
const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } };
const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } };
const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } };
const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } };
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xNeeded )
{
return malloc( xNeeded );
}
void vPortFree( void * ptr )
{
free( ptr );
}
@@ -0,0 +1,810 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_task.h"
#include "mock_list.h"
/* This must come after list.h is included (in this case, indirectly
* by mock_list.h). */
#include "FreeRTOSIPConfig.h"
#include "mock_IP_DiffConfig1_list_macros.h"
#include "mock_queue.h"
#include "mock_event_groups.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_FreeRTOS_IP_Utils.h"
#include "mock_FreeRTOS_IP_Timers.h"
#include "mock_NetworkBufferManagement.h"
#include "mock_FreeRTOS_Routing.h"
#include "mock_FreeRTOS_DNS.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_DiffConfig1_stubs.c"
#include "catch_assert.h"
/* =========================== EXTERN VARIABLES =========================== */
extern NetworkInterface_t xInterfaces[ 1 ];
void prvIPTask( void * pvParameters );
void prvProcessIPEventsAndTimers( void );
eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket,
NetworkBufferDescriptor_t * const pxNetworkBuffer );
void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
/* ============================ Unity Fixtures ============================ */
/*! called before each test case */
void setUp( void )
{
pxNetworkEndPoints = NULL;
pxNetworkInterfaces = NULL;
}
/*! called after each test case */
void tearDown( void )
{
}
/* ======================== Stub Callback Functions ========================= */
static BaseType_t NetworkInterfaceOutputFunction_Stub_Called = 0;
static BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDescriptor,
NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xReleaseAfterSend )
{
NetworkInterfaceOutputFunction_Stub_Called++;
return 0;
}
extern BaseType_t xIPTaskInitialised;
extern BaseType_t xNetworkDownEventPending;
static uint8_t ReleaseTCPPayloadBuffer[ 1500 ];
static BaseType_t ReleaseTCPPayloadBufferxByteCount = 100;
static size_t StubuxStreamBufferGetPtr_ReturnBadAddress( StreamBuffer_t * pxBuffer,
uint8_t ** ppucData,
int lCounter )
{
*ppucData = &ReleaseTCPPayloadBuffer[ 150 ];
return 0xFFFFFF;
}
static size_t StubuxStreamBufferGetPtr_ReturnIncorrectSize( StreamBuffer_t * pxBuffer,
uint8_t ** ppucData,
int lCounter )
{
*ppucData = &ReleaseTCPPayloadBuffer[ 0 ];
return( ReleaseTCPPayloadBufferxByteCount >> 1 );
}
static size_t StubuxStreamBufferGetPtr_ReturnCorrectVals( StreamBuffer_t * pxBuffer,
uint8_t ** ppucData,
int lCounter )
{
*ppucData = &ReleaseTCPPayloadBuffer[ 0 ];
return ReleaseTCPPayloadBufferxByteCount;
}
static void vSetIPTaskHandle( TaskHandle_t xTaskHandleToSet )
{
const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ];
const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ];
const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ];
const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ];
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ];
NetworkEndPoint_t xFirstEndPoint = { 0 }, * pxFirstEndPoint = &xFirstEndPoint;
NetworkInterface_t xNetworkInterface;
NetworkInterface_t * pxNetworkInterface = &xNetworkInterface;
pxFillInterfaceDescriptor_IgnoreAndReturn( pxNetworkInterface );
FreeRTOS_FillEndPoint_Ignore();
FreeRTOS_FirstNetworkInterface_IgnoreAndReturn( pxNetworkInterface );
vPreCheckConfigs_Expect();
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
xQueueGenericCreateStatic_ExpectAnyArgsAndReturn( ( QueueHandle_t ) 0x1234ABCD );
#else
xQueueGenericCreate_ExpectAnyArgsAndReturn( ( QueueHandle_t ) 0x1234ABCD );
#endif /* configSUPPORT_STATIC_ALLOCATION */
#if ( configQUEUE_REGISTRY_SIZE > 0 )
vQueueAddToRegistry_ExpectAnyArgs();
#endif
xNetworkBuffersInitialise_ExpectAndReturn( pdPASS );
vNetworkSocketsInit_Expect();
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
xTaskCreateStatic_ExpectAnyArgsAndReturn( xTaskHandleToSet );
#else
xTaskCreate_ReturnThruPtr_pxCreatedTask( xTaskHandleToSet );
#endif
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
}
/* ============================== Test Cases ============================== */
/**
* @brief test_FreeRTOS_GetIPTaskHandle
* To validate if FreeRTOS_GetIPTaskHandle() return correct handle pointer.
*/
void test_FreeRTOS_GetIPTaskHandle( void )
{
TaskHandle_t xIPTaskHandleToSet = ( TaskHandle_t ) 0x12ABCD34;
vSetIPTaskHandle( xIPTaskHandleToSet );
TEST_ASSERT_EQUAL( xIPTaskHandleToSet, FreeRTOS_GetIPTaskHandle() );
}
/**
* @brief test_FreeRTOS_IPInit_HappyPath
* To validate if FreeRTOS_IPInit() returns correctly in backward compatible mode.
*/
void test_FreeRTOS_IPInit_HappyPath( void )
{
const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC0, 0xB0, 0xAB, 0x12 };
const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC1, 0xB2, 0xAC, 0x13 };
const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC2, 0xB3, 0xAC, 0x14 };
const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC3, 0xB4, 0xAD, 0x15 };
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
BaseType_t xReturn;
QueueHandle_t ulPointerToQueue = ( QueueHandle_t ) 0x1234ABCD;
TaskHandle_t xTaskHandleToSet = ( TaskHandle_t ) 0xCDBA9087;
NetworkEndPoint_t xFirstEndPoint = { 0 };
NetworkInterface_t xNetworkInterface;
NetworkInterface_t * pxNetworkInterface = &xNetworkInterface;
/* Set the local IP to something other than 0. */
xFirstEndPoint.ipv4_settings.ulIPAddress = 0xABCD;
pxNetworkEndPoints = &xFirstEndPoint;
FreeRTOS_FillEndPoint_Ignore();
FreeRTOS_FirstNetworkInterface_IgnoreAndReturn( pxNetworkInterface );
pxFillInterfaceDescriptor_IgnoreAndReturn( pxNetworkInterface );
vPreCheckConfigs_Expect();
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
xQueueGenericCreateStatic_ExpectAndReturn( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ), NULL, NULL, 0, ulPointerToQueue );
xQueueGenericCreateStatic_IgnoreArg_pucQueueStorage();
xQueueGenericCreateStatic_IgnoreArg_pxStaticQueue();
#else
xQueueGenericCreate_ExpectAndReturn( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ), 0, ulPointerToQueue );
#endif /* configSUPPORT_STATIC_ALLOCATION */
#if ( configQUEUE_REGISTRY_SIZE > 0 )
vQueueAddToRegistry_Expect( ulPointerToQueue, "NetEvnt" );
#endif
xNetworkBuffersInitialise_ExpectAndReturn( pdPASS );
vNetworkSocketsInit_Expect();
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
xTaskCreateStatic_ExpectAnyArgsAndReturn( xTaskHandleToSet );
#else
xTaskCreate_ReturnThruPtr_pxCreatedTask( xTaskHandleToSet );
#endif
xReturn = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
TEST_ASSERT_EQUAL( pdPASS, xReturn );
TEST_ASSERT_EQUAL( xTaskHandleToSet, FreeRTOS_GetIPTaskHandle() );
}
/**
* @brief test_FreeRTOS_IPInit_QueueCreationFails
* To validate if FreeRTOS_IPInit() returns pdFAIL when xQueueGenericCreateStatic returns NULL.
*/
void test_FreeRTOS_IPInit_QueueCreationFails( void )
{
const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC0, 0xB0, 0xAB, 0x12 };
const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC1, 0xB2, 0xAC, 0x13 };
const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC2, 0xB3, 0xAC, 0x14 };
const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC3, 0xB4, 0xAD, 0x15 };
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
BaseType_t xReturn;
QueueHandle_t pxPointerToQueue = NULL;
NetworkEndPoint_t xFirstEndPoint = { 0 };
NetworkInterface_t xNetworkInterface;
NetworkInterface_t * pxNetworkInterface = &xNetworkInterface;
/* Set the local IP to something other than 0. */
xFirstEndPoint.ipv4_settings.ulIPAddress = 0xABCD;
pxNetworkEndPoints = &xFirstEndPoint;
FreeRTOS_FillEndPoint_Ignore();
FreeRTOS_FirstNetworkInterface_IgnoreAndReturn( pxNetworkInterface );
pxFillInterfaceDescriptor_IgnoreAndReturn( pxNetworkInterface );
vPreCheckConfigs_Expect();
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
xQueueGenericCreateStatic_ExpectAndReturn( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ), NULL, NULL, 0, pxPointerToQueue );
xQueueGenericCreateStatic_IgnoreArg_pucQueueStorage();
xQueueGenericCreateStatic_IgnoreArg_pxStaticQueue();
#else
xQueueGenericCreate_ExpectAndReturn( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ), 0, pxPointerToQueue );
#endif /* configSUPPORT_STATIC_ALLOCATION */
xReturn = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
TEST_ASSERT_EQUAL( pdFAIL, xReturn );
}
/**
* @brief test_FreeRTOS_IPInit_BufferCreationFails
* To validate if FreeRTOS_IPInit() returns pdFAIL when xNetworkBuffersInitialise returns pdFAIL.
*/
void test_FreeRTOS_IPInit_BufferCreationFails( void )
{
const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC0, 0xB0, 0xAB, 0x12 };
const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC1, 0xB2, 0xAC, 0x13 };
const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC2, 0xB3, 0xAC, 0x14 };
const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC3, 0xB4, 0xAD, 0x15 };
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
BaseType_t xReturn;
QueueHandle_t pxPointerToQueue = ( QueueHandle_t ) 0x1234ABCD;
NetworkEndPoint_t xFirstEndPoint = { 0 };
NetworkInterface_t xNetworkInterface;
NetworkInterface_t * pxNetworkInterface = &xNetworkInterface;
/* Set the local IP to something other than 0. */
xFirstEndPoint.ipv4_settings.ulIPAddress = 0xABCD;
pxNetworkEndPoints = &xFirstEndPoint;
FreeRTOS_FillEndPoint_Ignore();
FreeRTOS_FirstNetworkInterface_IgnoreAndReturn( pxNetworkInterface );
pxFillInterfaceDescriptor_IgnoreAndReturn( pxNetworkInterface );
vPreCheckConfigs_Expect();
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
xQueueGenericCreateStatic_ExpectAndReturn( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ), NULL, NULL, 0, pxPointerToQueue );
xQueueGenericCreateStatic_IgnoreArg_pucQueueStorage();
xQueueGenericCreateStatic_IgnoreArg_pxStaticQueue();
#else
xQueueGenericCreate_ExpectAndReturn( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ), 0, pxPointerToQueue );
#endif /* configSUPPORT_STATIC_ALLOCATION */
#if ( configQUEUE_REGISTRY_SIZE > 0 )
vQueueAddToRegistry_Expect( pxPointerToQueue, "NetEvnt" );
#endif
xNetworkBuffersInitialise_ExpectAndReturn( pdFAIL );
vQueueDelete_Expect( pxPointerToQueue );
xReturn = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
TEST_ASSERT_EQUAL( pdFAIL, xReturn );
}
/**
* @brief test_FreeRTOS_IPInit_TaskCreationFails
* To validate if FreeRTOS_IPInit() returns pdFAIL when xTaskCreate/xTaskCreateStatic returns pdFAIL/NULL.
*/
void test_FreeRTOS_IPInit_TaskCreationFails( void )
{
const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC0, 0xB0, 0xAB, 0x12 };
const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC1, 0xB2, 0xAC, 0x13 };
const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC2, 0xB3, 0xAC, 0x14 };
const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC3, 0xB4, 0xAD, 0x15 };
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
BaseType_t xReturn;
QueueHandle_t pxPointerToQueue = ( QueueHandle_t ) 0x1234ABCD;
NetworkEndPoint_t xFirstEndPoint = { 0 };
NetworkInterface_t xNetworkInterface;
NetworkInterface_t * pxNetworkInterface = &xNetworkInterface;
/* Set the local IP to something other than 0. */
xFirstEndPoint.ipv4_settings.ulIPAddress = 0xABCD;
pxNetworkEndPoints = &xFirstEndPoint;
FreeRTOS_FillEndPoint_Ignore();
FreeRTOS_FirstNetworkInterface_IgnoreAndReturn( pxNetworkInterface );
pxFillInterfaceDescriptor_IgnoreAndReturn( pxNetworkInterface );
vPreCheckConfigs_Expect();
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
xQueueGenericCreateStatic_ExpectAndReturn( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ), NULL, NULL, 0, pxPointerToQueue );
xQueueGenericCreateStatic_IgnoreArg_pucQueueStorage();
xQueueGenericCreateStatic_IgnoreArg_pxStaticQueue();
#else
xQueueGenericCreate_ExpectAndReturn( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ), 0, pxPointerToQueue );
#endif /* configSUPPORT_STATIC_ALLOCATION */
#if ( configQUEUE_REGISTRY_SIZE > 0 )
vQueueAddToRegistry_Expect( pxPointerToQueue, "NetEvnt" );
#endif
xNetworkBuffersInitialise_ExpectAndReturn( pdPASS );
vNetworkSocketsInit_Expect();
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
xTaskCreateStatic_ExpectAnyArgsAndReturn( NULL );
#else
xTaskCreate_ExpectAnyArgsAndReturn( pdFAIL );
xTaskCreate_ReturnThruPtr_pxCreatedTask( NULL );
#endif
xReturn = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
TEST_ASSERT_EQUAL( pdFAIL, xReturn );
TEST_ASSERT_EQUAL( NULL, FreeRTOS_GetIPTaskHandle() );
}
/**
* @brief test_prvProcessIPEventsAndTimers_eSocketBindEvent_IPv4_only_but_IPv6_bind
* To validate if prvProcessIPEventsAndTimers() handles IPv6 socket bind when IPv6 is disabled.
*/
void test_prvProcessIPEventsAndTimers_eSocketBindEvent_IPv4_only_but_IPv6_bind( void )
{
IPStackEvent_t xReceivedEvent;
FreeRTOS_Socket_t xSocket;
xReceivedEvent.eEventType = eSocketBindEvent;
xReceivedEvent.pvData = &xSocket;
xSocket.usLocalPort = ( uint16_t ) ~0U;
xSocket.xEventBits = 0;
xSocket.bits.bIsIPv6 = pdTRUE_UNSIGNED;
vCheckNetworkTimers_Expect();
xCalculateSleepTime_ExpectAndReturn( 0 );
xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE );
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) );
vSocketBind_ExpectAndReturn( &xSocket, NULL, sizeof( struct freertos_sockaddr ), pdFALSE, 0 );
vSocketBind_IgnoreArg_pxBindAddress();
vSocketWakeUpUser_Expect( &xSocket );
prvProcessIPEventsAndTimers();
}
/**
* @brief test_vIPNetworkUpCalls_BackwardCompatible
* To validate if vIPNetworkUpCalls() sets endpoint up in backward compatible mode.
*/
void test_vIPNetworkUpCalls_BackwardCompatible( void )
{
NetworkEndPoint_t xEndPoint = { 0 };
vApplicationIPNetworkEventHook_Expect( eNetworkUp );
vARPTimerReload_Expect( pdMS_TO_TICKS( 10000 ) );
vIPNetworkUpCalls( &xEndPoint );
TEST_ASSERT_EQUAL( pdTRUE_UNSIGNED, xEndPoint.bits.bEndPointUp );
}
/**
* @brief test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfigBackwardCompatible
* To validate if FreeRTOS_GetUDPPayloadBuffer() works in backward compatible mode.
*/
void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfigBackwardCompatible( void )
{
size_t uxRequestedSizeBytes = 300;
TickType_t uxBlockTimeTicks = ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS;
void * pvReturn;
NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer;
uint8_t pucEthernetBuffer[ 1500 ];
/* Put the ethernet buffer in place. */
pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET;
pxNetworkBuffer->xDataLength = 0;
pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, uxBlockTimeTicks, pxNetworkBuffer );
pvReturn = FreeRTOS_GetUDPPayloadBuffer( uxRequestedSizeBytes, uxBlockTimeTicks );
TEST_ASSERT_EQUAL( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, pxNetworkBuffer->xDataLength );
TEST_ASSERT_EQUAL_PTR( &( pxNetworkBuffer->pucEthernetBuffer[ sizeof( UDPPacket_t ) ] ), pvReturn );
}
/**
* @brief test_FreeRTOS_GetAddressConfiguration_HappyPath
* To validate if FreeRTOS_GetAddressConfiguration() works in backward compatible mode.
*/
void test_FreeRTOS_GetAddressConfiguration_HappyPath( void )
{
uint32_t ulIPAddress;
uint32_t ulNetMask;
uint32_t ulGatewayAddress;
uint32_t ulDNSServerAddress;
NetworkEndPoint_t xEndPoint;
memset( &xEndPoint, 0, sizeof( xEndPoint ) );
xEndPoint.ipv4_settings.ulIPAddress = 1;
xEndPoint.ipv4_settings.ulNetMask = 2;
xEndPoint.ipv4_settings.ulGatewayAddress = 3;
xEndPoint.ipv4_settings.ulDNSServerAddresses[ 0 ] = 4;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, &xEndPoint );
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
TEST_ASSERT_EQUAL( 1, ulIPAddress );
TEST_ASSERT_EQUAL( 2, ulNetMask );
TEST_ASSERT_EQUAL( 3, ulGatewayAddress );
TEST_ASSERT_EQUAL( 4, ulDNSServerAddress );
}
/**
* @brief test_FreeRTOS_GetAddressConfiguration_NoEndpoint
* To validate if FreeRTOS_GetAddressConfiguration() works with NULL inputs in backward compatible mode.
*/
void test_FreeRTOS_GetAddressConfiguration_NoEndpoint( void )
{
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, NULL );
FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, NULL );
}
/**
* @brief test_FreeRTOS_SetAddressConfiguration_HappyPath
* To validate if FreeRTOS_SetAddressConfiguration() works in backward compatible mode.
*/
void test_FreeRTOS_SetAddressConfiguration_HappyPath( void )
{
uint32_t ulIPAddress = 1;
uint32_t ulNetMask = 2;
uint32_t ulGatewayAddress = 3;
uint32_t ulDNSServerAddress = 4;
NetworkEndPoint_t xEndPoint;
memset( &xEndPoint, 0, sizeof( xEndPoint ) );
xEndPoint.ipv4_settings.ulIPAddress = 1;
xEndPoint.ipv4_settings.ulNetMask = 2;
xEndPoint.ipv4_settings.ulGatewayAddress = 3;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, &xEndPoint );
FreeRTOS_SetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
TEST_ASSERT_EQUAL( 1, xEndPoint.ipv4_settings.ulIPAddress );
TEST_ASSERT_EQUAL( 2, xEndPoint.ipv4_settings.ulNetMask );
TEST_ASSERT_EQUAL( 3, xEndPoint.ipv4_settings.ulGatewayAddress );
TEST_ASSERT_EQUAL( 4, xEndPoint.ipv4_settings.ulDNSServerAddresses[ 0 ] );
}
/**
* @brief test_FreeRTOS_SetAddressConfiguration_NoEndpoint
* To validate if FreeRTOS_SetAddressConfiguration() works with NULL inputs in backward compatible mode.
*/
void test_FreeRTOS_SetAddressConfiguration_NoEndpoint( void )
{
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, NULL );
FreeRTOS_SetAddressConfiguration( NULL, NULL, NULL, NULL );
}
/**
* @brief test_FreeRTOS_SetIPAddress_ValidEndpoint
* To validate if FreeRTOS_SetIPAddress() works in backward compatible mode.
*/
void test_FreeRTOS_SetIPAddress_ValidEndpoint( void )
{
NetworkEndPoint_t xEndpoint, * pxEndpoint = &xEndpoint;
uint32_t ulIPAddress = 0x00ABCDEFU;
memset( pxEndpoint, 0, sizeof( NetworkEndPoint_t ) );
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, pxEndpoint );
FreeRTOS_SetIPAddress( ulIPAddress );
TEST_ASSERT_EQUAL( ulIPAddress, pxEndpoint->ipv4_settings.ulIPAddress );
}
/**
* @brief test_FreeRTOS_SetIPAddress_NullEndpoint
* To validate if FreeRTOS_SetIPAddress() works with NULL inputs in backward compatible mode.
*/
void test_FreeRTOS_SetIPAddress_NullEndpoint( void )
{
uint32_t ulIPAddress = 0x00ABCDEFU;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, NULL );
FreeRTOS_SetIPAddress( ulIPAddress );
}
/**
* @brief test_FreeRTOS_SetGatewayAddress_ValidEndpoint
* To validate if FreeRTOS_SetGatewayAddress() works in backward compatible mode.
*/
void test_FreeRTOS_SetGatewayAddress_ValidEndpoint( void )
{
NetworkEndPoint_t xEndpoint, * pxEndpoint = &xEndpoint;
uint32_t ulIPAddress = 0x00ABCDEF;
memset( pxEndpoint, 0, sizeof( NetworkEndPoint_t ) );
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, pxEndpoint );
FreeRTOS_SetGatewayAddress( ulIPAddress );
TEST_ASSERT_EQUAL( ulIPAddress, pxEndpoint->ipv4_settings.ulGatewayAddress );
}
/**
* @brief test_FreeRTOS_SetGatewayAddress_NullEndpoint
* To validate if FreeRTOS_SetGatewayAddress() works with NULL inputs in backward compatible mode.
*/
void test_FreeRTOS_SetGatewayAddress_NullEndpoint( void )
{
uint32_t ulIPAddress = 0x00ABCDEF;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, NULL );
FreeRTOS_SetGatewayAddress( ulIPAddress );
}
/**
* @brief test_FreeRTOS_GetGatewayAddress_ValidEndpoint
* To validate if FreeRTOS_GetGatewayAddress() works in backward compatible mode.
*/
void test_FreeRTOS_GetGatewayAddress_ValidEndpoint( void )
{
NetworkEndPoint_t xEndpoint, * pxEndpoint = &xEndpoint;
uint32_t ulIPAddress = 0U;
memset( pxEndpoint, 0, sizeof( NetworkEndPoint_t ) );
pxEndpoint->ipv4_settings.ulGatewayAddress = 0x00ABCDEF;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, pxEndpoint );
ulIPAddress = FreeRTOS_GetGatewayAddress();
TEST_ASSERT_EQUAL( pxEndpoint->ipv4_settings.ulGatewayAddress, ulIPAddress );
}
/**
* @brief test_FreeRTOS_GetGatewayAddress_NullEndpoint
* To validate if FreeRTOS_GetGatewayAddress() works with no endpoints in backward compatible mode.
*/
void test_FreeRTOS_GetGatewayAddress_NullEndpoint( void )
{
uint32_t ulIPAddress = 0U;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, NULL );
ulIPAddress = FreeRTOS_GetGatewayAddress();
TEST_ASSERT_EQUAL( 0U, ulIPAddress );
}
/**
* @brief test_FreeRTOS_GetDNSServerAddress_ValidEndpoint
* To validate if FreeRTOS_GetDNSServerAddress() works in backward compatible mode.
*/
void test_FreeRTOS_GetDNSServerAddress_ValidEndpoint( void )
{
NetworkEndPoint_t xEndpoint, * pxEndpoint = &xEndpoint;
uint32_t ulIPAddress = 0U;
memset( pxEndpoint, 0, sizeof( NetworkEndPoint_t ) );
pxEndpoint->ipv4_settings.ulDNSServerAddresses[ 0 ] = 0x00ABCDEF;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, pxEndpoint );
ulIPAddress = FreeRTOS_GetDNSServerAddress();
TEST_ASSERT_EQUAL( pxEndpoint->ipv4_settings.ulDNSServerAddresses[ 0 ], ulIPAddress );
}
/**
* @brief test_FreeRTOS_GetDNSServerAddress_NullEndpoint
* To validate if FreeRTOS_GetDNSServerAddress() works with no endpoints in backward compatible mode.
*/
void test_FreeRTOS_GetDNSServerAddress_NullEndpoint( void )
{
uint32_t ulIPAddress = 0U;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, NULL );
ulIPAddress = FreeRTOS_GetDNSServerAddress();
TEST_ASSERT_EQUAL( 0U, ulIPAddress );
}
/**
* @brief test_FreeRTOS_SetNetmask_ValidEndpoint
* To validate if FreeRTOS_SetNetmask() works in backward compatible mode.
*/
void test_FreeRTOS_SetNetmask_ValidEndpoint( void )
{
NetworkEndPoint_t xEndpoint, * pxEndpoint = &xEndpoint;
uint32_t ulIPAddress = 0x00ABCDEF;
memset( pxEndpoint, 0, sizeof( NetworkEndPoint_t ) );
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, pxEndpoint );
FreeRTOS_SetNetmask( ulIPAddress );
TEST_ASSERT_EQUAL( ulIPAddress, pxEndpoint->ipv4_settings.ulNetMask );
}
/**
* @brief test_FreeRTOS_SetNetmask_NullEndpoint
* To validate if FreeRTOS_SetNetmask() works with no endpoints in backward compatible mode.
*/
void test_FreeRTOS_SetNetmask_NullEndpoint( void )
{
uint32_t ulIPAddress = 0x00ABCDEF;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, NULL );
FreeRTOS_SetNetmask( ulIPAddress );
}
/**
* @brief test_FreeRTOS_GetNetmask_ValidEndpoint
* To validate if FreeRTOS_GetNetmask() works in backward compatible mode.
*/
void test_FreeRTOS_GetNetmask_ValidEndpoint( void )
{
NetworkEndPoint_t xEndpoint, * pxEndpoint = &xEndpoint;
uint32_t ulIPAddress = 0U;
memset( pxEndpoint, 0, sizeof( NetworkEndPoint_t ) );
pxEndpoint->ipv4_settings.ulNetMask = 0x00ABCDEF;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, pxEndpoint );
ulIPAddress = FreeRTOS_GetNetmask();
TEST_ASSERT_EQUAL( pxEndpoint->ipv4_settings.ulNetMask, ulIPAddress );
}
/**
* @brief test_FreeRTOS_GetNetmask_NullEndpoint
* To validate if FreeRTOS_GetNetmask() works with no endpoints in backward compatible mode.
*/
void test_FreeRTOS_GetNetmask_NullEndpoint( void )
{
uint32_t ulIPAddress = 0U;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, NULL );
ulIPAddress = FreeRTOS_GetNetmask();
TEST_ASSERT_EQUAL( 0U, ulIPAddress );
}
/**
* @brief test_FreeRTOS_UpdateMACAddress_ValidEndpoint
* To validate if FreeRTOS_UpdateMACAddress() works in backward compatible mode.
*/
void test_FreeRTOS_UpdateMACAddress_ValidEndpoint( void )
{
NetworkEndPoint_t xEndpoint, * pxEndpoint = &xEndpoint;
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
memset( pxEndpoint, 0, sizeof( NetworkEndPoint_t ) );
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, pxEndpoint );
FreeRTOS_UpdateMACAddress( ucMACAddress );
TEST_ASSERT_EQUAL_MEMORY( ucMACAddress, pxEndpoint->xMACAddress.ucBytes, ipMAC_ADDRESS_LENGTH_BYTES );
}
/**
* @brief test_FreeRTOS_UpdateMACAddress_NullEndpoint
* To validate if FreeRTOS_UpdateMACAddress() works with no endpoints in backward compatible mode.
*/
void test_FreeRTOS_UpdateMACAddress_NullEndpoint( void )
{
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, NULL );
FreeRTOS_UpdateMACAddress( ucMACAddress );
}
/**
* @brief test_FreeRTOS_GetMACAddress_ValidEndpoint
* To validate if FreeRTOS_GetMACAddress() works in backward compatible mode.
*/
void test_FreeRTOS_GetMACAddress_ValidEndpoint( void )
{
NetworkEndPoint_t xEndpoint, * pxEndpoint = &xEndpoint;
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
const uint8_t * pucReturn = NULL;
memset( pxEndpoint, 0, sizeof( NetworkEndPoint_t ) );
memcpy( pxEndpoint->xMACAddress.ucBytes, ucMACAddress, ipMAC_ADDRESS_LENGTH_BYTES );
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, pxEndpoint );
pucReturn = FreeRTOS_GetMACAddress();
TEST_ASSERT_EQUAL_MEMORY( ucMACAddress, pucReturn, ipMAC_ADDRESS_LENGTH_BYTES );
}
/**
* @brief test_FreeRTOS_GetMACAddress_NullEndpoint
* To validate if FreeRTOS_GetMACAddress() works with no endpoints in backward compatible mode.
*/
void test_FreeRTOS_GetMACAddress_NullEndpoint( void )
{
const uint8_t * pucReturn = NULL;
FreeRTOS_FirstEndPoint_ExpectAndReturn( NULL, NULL );
pucReturn = FreeRTOS_GetMACAddress();
TEST_ASSERT_EQUAL( NULL, pucReturn );
}
/**
* @brief test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfig_IPv6NotSupported
* To validate if FreeRTOS_GetUDPPayloadBuffer_Multi() returns NULL with ipTYPE_IPv6 when IPv6 is disabled.
*/
void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfig_IPv6NotSupported( void )
{
size_t uxRequestedSizeBytes = 300;
TickType_t uxBlockTimeTicks = ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS;
void * pvReturn;
NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer;
uint8_t pucEthernetBuffer[ 1500 ];
/* Put the ethernet buffer in place. */
pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer;
pxNetworkBuffer->xDataLength = 0;
pvReturn = FreeRTOS_GetUDPPayloadBuffer_Multi( uxRequestedSizeBytes, uxBlockTimeTicks, ipTYPE_IPv6 );
TEST_ASSERT_EQUAL_PTR( NULL, pvReturn );
}
/**
* @brief test_eConsiderFrameForProcessing_IPv6_FrameType_But_Disabled
* eConsiderFrameForProcessing must return eReleaseBuffer when the frame type is IPv6 but
* ipconfigUSE_IPv6 is disabled.
*/
void test_eConsiderFrameForProcessing_IPv6_FrameType_But_Disabled( void )
{
eFrameProcessingResult_t eResult;
uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ];
EthernetHeader_t * pxEthernetHeader;
/* Map the buffer onto Ethernet Header struct for easy access to fields. */
pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer;
memset( ucEthernetBuffer, 0x00, ipconfigNETWORK_MTU );
pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE;
eResult = eConsiderFrameForProcessing( ucEthernetBuffer );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}
@@ -0,0 +1,107 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#include "FreeRTOS_IPv6_Private.h"
#undef listSET_LIST_ITEM_OWNER
void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem,
void * owner );
#undef listGET_END_MARKER
ListItem_t * listGET_END_MARKER( List_t * pxList );
#undef listGET_NEXT
ListItem_t * listGET_NEXT( const ListItem_t * pxListItem );
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( const ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( const ListItem_t * listItem );
extern NetworkInterface_t xInterfaces[ 1 ];
/* The function 'prvAllowIPPacket()' checks if a IPv6 packets should be processed. */
eFrameProcessingResult_t prvAllowIPPacketIPv6( const IPHeader_IPv6_t * const pxIPv6Header,
const NetworkBufferDescriptor_t * const pxNetworkBuffer,
UBaseType_t uxHeaderLength );
BaseType_t xGetExtensionOrder( uint8_t ucProtocol,
uint8_t ucNextHeader );
/** @brief Handle the IPv6 extension headers. */
eFrameProcessingResult_t eHandleIPv6ExtensionHeaders( NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xDoRemove );
/* prvProcessICMPMessage_IPv6() is declared in FreeRTOS_routing.c
* It handles all ICMP messages except the PING requests. */
eFrameProcessingResult_t prvProcessICMPMessage_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer );
/**
* @brief Work on the RA/SLAAC processing.
* @param[in] xDoReset: WHen true, the state-machine will be reset and initialised.
* @param[in] pxEndPoint: The end-point for which the RA/SLAAC process should be done..
*/
void vRAProcess( BaseType_t xDoReset,
NetworkEndPoint_t * pxEndPoint );
NetworkInterface_t * pxFillInterfaceDescriptor( BaseType_t xEMACIndex,
NetworkInterface_t * pxInterface );
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent );
#endif /* ifndef LIST_MACRO_H */
@@ -0,0 +1,124 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_IP_DiffConfig1" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ND.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ICMP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Stream_Buffer.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_WIN.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkInterface.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/IP_DiffConfig1_list_macros.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${project_name}/${project_name}_stubs.c
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/FreeRTOS_IP.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${CMAKE_BINARY_DIR}/../../../source/portable/Buffermanagement
${CMAKE_BINARY_DIR}/../../../source/portable/Compiler/MSVC
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${TCP_INCLUDE_DIRS}
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,124 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <assert.h>
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_STATIC_ALLOCATION 0
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */
/* Software timer related configuration options. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configMAX_PRIORITIES ( 7 )
#define configENABLE_MPU 0
/* Run time stats gathering configuration options. */
#define configGENERATE_RUN_TIME_STATS 1
/* This demo makes use of one or more example stats formatting functions. These
* format the raw data provided by the uxTaskGetSystemState() function in to human
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
/* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. */
extern void vAssertCalled( unsigned long ulLine,
const char * const pcFileName );
#define configASSERT( x )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
/* #include "trcRecorder.h" */
#endif /* FREERTOS_CONFIG_H */
@@ -0,0 +1,339 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
#define ipconfigIPv4_BACKWARD_COMPATIBLE 1
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 2 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks using pdMS_TO_TICKS().*/
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 5000U )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 5
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD pdMS_TO_TICKS( 120000U )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 0 )
#define ipconfigUSE_MDNS ( 0 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#define ipconfigCHECK_IP_QUEUE_SPACE ( 1 )
#define ipconfigSELECT_USES_NOTIFY ( 1 )
#define ipconfigUSE_LINKED_RX_MESSAGES ( 1 )
#define ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS ( 0 )
#define ipconfigZERO_COPY_TX_DRIVER ( 1 )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,75 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
BaseType_t xNetworkUp;
volatile BaseType_t xInsideInterrupt = pdFALSE;
struct xNetworkInterface * pxNetworkInterfaces = NULL;
/** @brief A list of all network end-points. Each element has a next pointer. */
struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } };
const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } };
const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } };
const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } };
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xNeeded )
{
return malloc( xNeeded );
}
void vPortFree( void * ptr )
{
free( ptr );
}
@@ -0,0 +1,256 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_task.h"
#include "mock_list.h"
/* This must come after list.h is included (in this case, indirectly
* by mock_list.h). */
#include "mock_IP_DiffConfig2_list_macros.h"
#include "mock_queue.h"
#include "mock_event_groups.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_FreeRTOS_IP_Utils.h"
#include "mock_NetworkBufferManagement.h"
#include "mock_FreeRTOS_Routing.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_DiffConfig2_stubs.c"
#include "catch_assert.h"
#include "FreeRTOSIPConfig.h"
/* =========================== EXTERN VARIABLES =========================== */
void prvIPTask( void * pvParameters );
void prvProcessIPEventsAndTimers( void );
eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket,
NetworkBufferDescriptor_t * const pxNetworkBuffer );
void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
extern BaseType_t xIPTaskInitialised;
extern BaseType_t xNetworkDownEventPending;
extern BaseType_t xNetworkUp;
extern UBaseType_t uxQueueMinimumSpace;
/* ============================ Unity Fixtures ============================ */
/*! called before each test case */
void setUp( void )
{
pxNetworkEndPoints = NULL;
pxNetworkInterfaces = NULL;
xNetworkDownEventPending = pdFALSE;
}
/*! called after each test case */
void tearDown( void )
{
}
/* ======================== Stub Callback Functions ========================= */
TaskHandle_t IPInItHappyPath_xTaskHandleToSet = ( TaskHandle_t ) 0xCDBA9087;
static BaseType_t StubxTaskCreate( TaskFunction_t pxTaskCode,
const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
const configSTACK_DEPTH_TYPE uxStackDepth,
void * const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t * const pxCreatedTask,
int cmock_num_calls )
{
*pxCreatedTask = IPInItHappyPath_xTaskHandleToSet;
return pdPASS;
}
/* ============================== Test Cases ============================== */
/**
* @brief test_FreeRTOS_IPInit_HappyPathDHCP
* To validate if FreeRTOS_IPInit() works with DHCP enabled.
*/
void test_FreeRTOS_IPInit_HappyPathDHCP( void )
{
const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC0, 0xB0, 0xAB, 0x12 };
const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC1, 0xB2, 0xAC, 0x13 };
const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC2, 0xB3, 0xAC, 0x14 };
const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 0xC3, 0xB4, 0xAD, 0x15 };
const uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
BaseType_t xReturn;
QueueHandle_t ulPointerToQueue = ( QueueHandle_t ) 0x1234ABCD;
NetworkEndPoint_t xEndPoint = { 0 };
/* Set the local IP to something other than 0. */
xEndPoint.ipv4_settings.ulIPAddress = 0xABCD;
pxNetworkEndPoints = &xEndPoint;
FreeRTOS_FillEndPoint_Ignore();
FreeRTOS_FirstNetworkInterface_IgnoreAndReturn( NULL );
pxFillInterfaceDescriptor_IgnoreAndReturn( NULL );
vPreCheckConfigs_Expect();
xQueueGenericCreate_ExpectAndReturn( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ), 0U, ulPointerToQueue );
#if ( configQUEUE_REGISTRY_SIZE > 0 )
vQueueAddToRegistry_Expect( ulPointerToQueue, "NetEvnt" );
#endif
xNetworkBuffersInitialise_ExpectAndReturn( pdPASS );
vNetworkSocketsInit_Expect();
xTaskCreate_Stub( StubxTaskCreate );
xReturn = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
TEST_ASSERT_EQUAL( pdPASS, xReturn );
TEST_ASSERT_EQUAL( IPInItHappyPath_xTaskHandleToSet, FreeRTOS_GetIPTaskHandle() );
}
/**
* @brief test_eConsiderFrameForProcessing_LLMNR_IPv4_MACMatch_But_Disabled
* eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet
* matches LLMNR MAC address and the frame type is valid but any of ipconfigUSE_DNS, ipconfigUSE_LLMNR
* or ipconfigUSE_IPv4 is disabled.
*/
void test_eConsiderFrameForProcessing_LLMNR_IPv4_MACMatch_But_Disabled( void )
{
eFrameProcessingResult_t eResult;
uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ];
EthernetHeader_t * pxEthernetHeader;
/* eConsiderFrameForProcessing */
FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL );
/* Map the buffer onto Ethernet Header struct for easy access to fields. */
pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer;
memset( ucEthernetBuffer, 0x00, ipconfigNETWORK_MTU );
memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xLLMNR_MacAddress.ucBytes, sizeof( MACAddress_t ) );
pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE;
eResult = eConsiderFrameForProcessing( ucEthernetBuffer );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}
/**
* @brief test_eConsiderFrameForProcessing_LLMNR_IPv6_MACMatch_But_Disabled
* eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet
* matches LLMNR MAC address and the frame type is valid but any of ipconfigUSE_DNS, ipconfigUSE_LLMNR
* or ipconfigUSE_IPv6 is disabled.
*/
void test_eConsiderFrameForProcessing_LLMNR_IPv6_MACMatch_But_Disabled( void )
{
eFrameProcessingResult_t eResult;
uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ];
EthernetHeader_t * pxEthernetHeader;
/* eConsiderFrameForProcessing */
FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL );
/* Map the buffer onto Ethernet Header struct for easy access to fields. */
pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer;
memset( ucEthernetBuffer, 0x00, ipconfigNETWORK_MTU );
memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xLLMNR_MacAddressIPv6.ucBytes, sizeof( MACAddress_t ) );
pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE;
eResult = eConsiderFrameForProcessing( ucEthernetBuffer );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}
/**
* @brief test_eConsiderFrameForProcessing_MDNS_IPv6_MACMatch_But_Disabled
* eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet
* matches MDNS MAC address and the frame type is valid but any of ipconfigUSE_DNS, ipconfigUSE_MDNS
* or ipconfigUSE_IPv6 is disabled.
*/
void test_eConsiderFrameForProcessing_MDNS_IPv6_MACMatch_But_Disabled( void )
{
eFrameProcessingResult_t eResult;
uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ];
EthernetHeader_t * pxEthernetHeader;
/* eConsiderFrameForProcessing */
FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL );
/* Map the buffer onto Ethernet Header struct for easy access to fields. */
pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer;
memset( ucEthernetBuffer, 0x00, ipconfigNETWORK_MTU );
memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xMDNS_MacAddressIPv6.ucBytes, sizeof( MACAddress_t ) );
pxEthernetHeader->usFrameType = ipIPv6_FRAME_TYPE;
eResult = eConsiderFrameForProcessing( ucEthernetBuffer );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}
/**
* @brief test_eConsiderFrameForProcessing_MDNS_IPv4_MACMatch_But_Disabled
* eConsiderFrameForProcessing must return eReleaseBuffer when the MAC address in packet
* matches MDNS MAC address and the frame type is valid but any of ipconfigUSE_DNS, ipconfigUSE_MDNS
* or ipconfigUSE_IPv4 is disabled.
*/
void test_eConsiderFrameForProcessing_MDNS_IPv4_MACMatch_But_Disabled( void )
{
eFrameProcessingResult_t eResult;
uint8_t ucEthernetBuffer[ ipconfigNETWORK_MTU ];
EthernetHeader_t * pxEthernetHeader;
/* eConsiderFrameForProcessing */
FreeRTOS_FindEndPointOnMAC_ExpectAnyArgsAndReturn( NULL );
/* Map the buffer onto Ethernet Header struct for easy access to fields. */
pxEthernetHeader = ( EthernetHeader_t * ) ucEthernetBuffer;
memset( ucEthernetBuffer, 0x00, ipconfigNETWORK_MTU );
memcpy( pxEthernetHeader->xDestinationAddress.ucBytes, xMDNS_MacAddress.ucBytes, sizeof( MACAddress_t ) );
pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE;
eResult = eConsiderFrameForProcessing( ucEthernetBuffer );
TEST_ASSERT_EQUAL( eReleaseBuffer, eResult );
}
@@ -0,0 +1,121 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#include "FreeRTOS_IPv6_Private.h"
extern NetworkInterface_t xInterfaces[ 1 ];
#undef listSET_LIST_ITEM_OWNER
void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem,
void * owner );
#undef listGET_END_MARKER
ListItem_t * listGET_END_MARKER( List_t * pxList );
#undef listGET_NEXT
ListItem_t * listGET_NEXT( const ListItem_t * pxListItem );
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( const ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( const ListItem_t * listItem );
/**
* >>>>>>> afcedead21c747cef64f07c7fedd50df75bcbd10
* @brief Work on the RA/SLAAC processing.
* @param[in] xDoReset: WHen true, the state-machine will be reset and initialised.
* @param[in] pxEndPoint: The end-point for which the RA/SLAAC process should be done..
*/
void vRAProcess( BaseType_t xDoReset,
NetworkEndPoint_t * pxEndPoint );
/* This function shall be defined by the application. */
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent );
/* Do not call the following function directly. It is there for downward compatibility.
* The function FreeRTOS_IPInit() will call it to initialise the interface and end-point
* objects. See the description in FreeRTOS_Routing.h. */
struct xNetworkInterface * pxFillInterfaceDescriptor( BaseType_t xEMACIndex,
struct xNetworkInterface * pxInterface );
/* The function 'prvAllowIPPacket()' checks if a IPv6 packets should be processed. */
eFrameProcessingResult_t prvAllowIPPacketIPv6( const IPHeader_IPv6_t * const pxIPv6Header,
const NetworkBufferDescriptor_t * const pxNetworkBuffer,
UBaseType_t uxHeaderLength );
/* Return IPv6 header extension order number */
BaseType_t xGetExtensionOrder( uint8_t ucProtocol,
uint8_t ucNextHeader );
/** @brief Handle the IPv6 extension headers. */
eFrameProcessingResult_t eHandleIPv6ExtensionHeaders( NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xDoRemove );
/* prvProcessICMPMessage_IPv6() is declared in FreeRTOS_routing.c
* It handles all ICMP messages except the PING requests. */
eFrameProcessingResult_t prvProcessICMPMessage_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer );
/* Return pdTRUE if all end-points are up.
* When pxInterface is null, all end-points will be checked. */
BaseType_t FreeRTOS_AllEndPointsUp( const struct xNetworkInterface * pxInterface );
#endif /* ifndef LIST_MACRO_H */
@@ -0,0 +1,127 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_IP_DiffConfig2" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ND.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv6_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ICMP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Stream_Buffer.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_WIN.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkInterface.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/IP_DiffConfig2_list_macros.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${project_name}/${project_name}_stubs.c
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/FreeRTOS_IP.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${CMAKE_BINARY_DIR}/../../../source/portable/Buffermanagement
${CMAKE_BINARY_DIR}/../../../source/portable/Compiler/MSVC
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${CMAKE_BINARY_DIR}/Annexed_TCP
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,124 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <assert.h>
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_STATIC_ALLOCATION 0
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */
/* Software timer related configuration options. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configMAX_PRIORITIES ( 7 )
#define configENABLE_MPU 0
/* Run time stats gathering configuration options. */
#define configGENERATE_RUN_TIME_STATS 1
/* This demo makes use of one or more example stats formatting functions. These
* format the raw data provided by the uxTaskGetSystemState() function in to human
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
/* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. */
extern void vAssertCalled( unsigned long ulLine,
const char * const pcFileName );
#define configASSERT( x )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
/* #include "trcRecorder.h" */
#endif /* FREERTOS_CONFIG_H */
@@ -0,0 +1,352 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
#define ipconfigUSE_DHCPv6 ( 1 )
#define ipconfigIPv4_BACKWARD_COMPATIBLE 0
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 2 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks using pdMS_TO_TICKS().*/
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 5000U )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 5
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD \
( 120000U / portTICK_PERIOD_MS )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 0
/* When ipconfigETHERNET_DRIVER_FILTERS_PACKETS is enabled, the network
* interface will inspect the incoming packets to see if they can be
* accepted.
* When enabled, the function 'xPortHasUDPSocket()' will become available.
* That function checks if there is a UDP socket listening to a
* given port number.
*/
#define ipconfigETHERNET_DRIVER_FILTERS_PACKETS 1
/* 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 pdMS_TO_TICKS( 20 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#define ipconfigCHECK_IP_QUEUE_SPACE ( 1 )
#define ipconfigSELECT_USES_NOTIFY ( 1 )
#define ipconfigUSE_LINKED_RX_MESSAGES ( 1 )
#define ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS ( 0 )
#define ipconfigZERO_COPY_TX_DRIVER ( 1 )
#define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES ( 1 )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,76 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
BaseType_t xNetworkUp;
NetworkInterface_t xInterfaces[ 1 ];
volatile BaseType_t xInsideInterrupt = pdFALSE;
struct xNetworkInterface * pxNetworkInterfaces = NULL;
/** @brief A list of all network end-points. Each element has a next pointer. */
struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } };
const MACAddress_t xLLMNR_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x01, 0x00, 0x03 } };
const MACAddress_t xMDNS_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb } };
const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } };
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xNeeded )
{
return malloc( xNeeded );
}
void vPortFree( void * ptr )
{
free( ptr );
}
@@ -0,0 +1,248 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_task.h"
#include "mock_list.h"
/* This must come after list.h is included (in this case, indirectly
* by mock_list.h). */
#include "mock_IP_DiffConfig_list_macros.h"
#include "mock_queue.h"
#include "mock_event_groups.h"
#include "mock_FreeRTOS_IP_Timers.h"
#include "mock_FreeRTOS_DHCP.h"
#include "mock_FreeRTOS_DHCPv6.h"
#include "mock_NetworkBufferManagement.h"
#include "mock_FreeRTOS_Routing.h"
#include "FreeRTOS_IP.h"
/*#include "FreeRTOS_IP_stubs.c" */
#include "catch_assert.h"
#include "FreeRTOSIPConfig.h"
/* =========================== EXTERN VARIABLES =========================== */
void prvIPTask( void * pvParameters );
void prvProcessIPEventsAndTimers( void );
eFrameProcessingResult_t prvProcessIPPacket( IPPacket_t * pxIPPacket,
NetworkBufferDescriptor_t * const pxNetworkBuffer );
void prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
extern BaseType_t xIPTaskInitialised;
extern BaseType_t xNetworkDownEventPending;
extern BaseType_t xNetworkUp;
extern UBaseType_t uxQueueMinimumSpace;
/* ============================ Unity Fixtures ============================ */
/*! called before each test case */
void setUp( void )
{
pxNetworkEndPoints = NULL;
pxNetworkInterfaces = NULL;
xNetworkDownEventPending = pdFALSE;
}
/*! called after each test case */
void tearDown( void )
{
}
/* ======================== Stub Callback Functions ========================= */
eFrameProcessingResult_t eApplicationProcessCustomFrameHook( NetworkBufferDescriptor_t * const pxNetworkBuffer )
{
( void ) ( pxNetworkBuffer );
/* Force hook function to return waiting resultion for unknown Ethernet frame type. */
return eWaitingResolution;
}
/* ============================== Test Cases ============================== */
/**
* @brief test_prvProcessIPEventsAndTimers_eDHCPEvent_DHCPv4
* To validate if prvProcessIPEventsAndTimers() calls vDHCPProcess() while receiving eDHCPEvent.
*/
void test_prvProcessIPEventsAndTimers_eDHCPEvent_DHCPv4( void )
{
IPStackEvent_t xReceivedEvent;
uint32_t ulDHCPEvent = 0x1234;
NetworkEndPoint_t xEndPoints, * pxEndPoints = &xEndPoints;
BaseType_t xQueueReturn = 100;
memset( pxEndPoints, 0, sizeof( NetworkEndPoint_t ) );
pxEndPoints->bits.bWantDHCP = pdTRUE_UNSIGNED;
xReceivedEvent.eEventType = eDHCPEvent;
xReceivedEvent.pvData = pxEndPoints;
vCheckNetworkTimers_Expect();
xCalculateSleepTime_ExpectAndReturn( 0 );
xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE );
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) );
uxQueueSpacesAvailable_ExpectAnyArgsAndReturn( xQueueReturn );
vDHCPProcess_Expect( pdFALSE, pxEndPoints );
prvProcessIPEventsAndTimers();
}
/**
* @brief test_prvProcessIPEventsAndTimers_eDHCPEvent_DHCPv6
* To validate if prvProcessIPEventsAndTimers() calls vDHCPv6Process() while receiving eDHCPEvent
* and the endpoint is IPv6.
*/
void test_prvProcessIPEventsAndTimers_eDHCPEvent_DHCPv6( void )
{
IPStackEvent_t xReceivedEvent;
uint32_t ulDHCPEvent = 0x1234;
NetworkEndPoint_t xEndPoints, * pxEndPoints = &xEndPoints;
BaseType_t xQueueReturn = 100;
memset( pxEndPoints, 0, sizeof( NetworkEndPoint_t ) );
pxEndPoints->bits.bWantDHCP = pdTRUE_UNSIGNED;
pxEndPoints->bits.bIPv6 = pdTRUE_UNSIGNED;
xReceivedEvent.eEventType = eDHCPEvent;
xReceivedEvent.pvData = pxEndPoints;
vCheckNetworkTimers_Expect();
xCalculateSleepTime_ExpectAndReturn( 0 );
xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE );
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) );
uxQueueSpacesAvailable_ExpectAnyArgsAndReturn( xQueueReturn );
vDHCPv6Process_Expect( pdFALSE, pxEndPoints );
prvProcessIPEventsAndTimers();
}
/**
* @brief test_prvProcessIPEventsAndTimers_eDHCPEvent_RA
* To validate if prvProcessIPEventsAndTimers() calls vRAProcess() while receiving eDHCPEvent
* and the endpoint is configured for RA.
*/
void test_prvProcessIPEventsAndTimers_eDHCPEvent_RA( void )
{
IPStackEvent_t xReceivedEvent;
uint32_t ulDHCPEvent = 0x1234;
NetworkEndPoint_t xEndPoints, * pxEndPoints = &xEndPoints;
BaseType_t xQueueReturn = 100;
memset( pxEndPoints, 0, sizeof( NetworkEndPoint_t ) );
pxEndPoints->bits.bWantRA = pdTRUE_UNSIGNED;
pxEndPoints->bits.bIPv6 = pdTRUE_UNSIGNED;
xReceivedEvent.eEventType = eDHCPEvent;
xReceivedEvent.pvData = pxEndPoints;
vCheckNetworkTimers_Expect();
xCalculateSleepTime_ExpectAndReturn( 0 );
xQueueReceive_ExpectAnyArgsAndReturn( pdTRUE );
xQueueReceive_ReturnMemThruPtr_pvBuffer( &xReceivedEvent, sizeof( xReceivedEvent ) );
uxQueueSpacesAvailable_ExpectAnyArgsAndReturn( xQueueReturn );
vRAProcess_Expect( pdFALSE, pxEndPoints );
prvProcessIPEventsAndTimers();
}
/**
* @brief test_prvProcessEthernetPacket_UnknownFrameType_NeedResolution
* But we release the network buffer because the frame type is unknown.
*/
void test_prvProcessEthernetPacket_UnknownFrameType_NeedResolution( void )
{
NetworkBufferDescriptor_t xNetworkBuffer;
NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer;
uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 };
EthernetHeader_t * pxEthernetHeader;
IPPacket_IPv6_t * pxIPv6Packet;
IPHeader_IPv6_t * pxIPv6Header;
struct xNetworkInterface xInterface;
NetworkEndPoint_t xNetworkEndPoint = { 0 };
pxNetworkBuffer->xDataLength = ipconfigTCP_MSS;
pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer;
pxNetworkBuffer->pxInterface = &xInterface;
pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint;
pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer;
pxEthernetHeader->usFrameType = 0xFFFF;
vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer );
prvProcessEthernetPacket( pxNetworkBuffer );
}
/**
* @brief test_prvProcessEthernetPacket_UnknownFrameType_NeedResolution
* But we release the network buffer because the frame type is unknown.
*/
void test_prvProcessEthernetPacket_IPv4FrameType_CheckFrameFail( void )
{
NetworkBufferDescriptor_t xNetworkBuffer;
NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer;
uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 };
EthernetHeader_t * pxEthernetHeader;
IPPacket_IPv6_t * pxIPv6Packet;
IPHeader_IPv6_t * pxIPv6Header;
struct xNetworkInterface xInterface;
NetworkEndPoint_t xNetworkEndPoint = { 0 };
pxNetworkBuffer->xDataLength = ipconfigTCP_MSS;
pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer;
pxNetworkBuffer->pxInterface = &xInterface;
pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint;
pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer;
pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE;
FreeRTOS_FindEndPointOnMAC_ExpectAndReturn( &pxEthernetHeader->xDestinationAddress, NULL, NULL );
vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer );
prvProcessEthernetPacket( pxNetworkBuffer );
}
@@ -0,0 +1,134 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#include "FreeRTOS_IPv6_Private.h"
extern NetworkInterface_t xInterfaces[ 1 ];
#undef listSET_LIST_ITEM_OWNER
void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem,
void * owner );
#undef listGET_END_MARKER
ListItem_t * listGET_END_MARKER( List_t * pxList );
#undef listGET_NEXT
ListItem_t * listGET_NEXT( const ListItem_t * pxListItem );
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( const ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( const ListItem_t * listItem );
/**
* >>>>>>> afcedead21c747cef64f07c7fedd50df75bcbd10
* @brief Work on the RA/SLAAC processing.
* @param[in] xDoReset: WHen true, the state-machine will be reset and initialised.
* @param[in] pxEndPoint: The end-point for which the RA/SLAAC process should be done..
*/
void vRAProcess( BaseType_t xDoReset,
NetworkEndPoint_t * pxEndPoint );
/* This function shall be defined by the application. */
void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent,
struct xNetworkEndPoint * pxEndPoint );
/* Do not call the following function directly. It is there for downward compatibility.
* The function FreeRTOS_IPInit() will call it to initialise the interface and end-point
* objects. See the description in FreeRTOS_Routing.h. */
struct xNetworkInterface * pxFillInterfaceDescriptor( BaseType_t xEMACIndex,
struct xNetworkInterface * pxInterface );
/* The function 'prvAllowIPPacket()' checks if a IPv6 packets should be processed. */
eFrameProcessingResult_t prvAllowIPPacketIPv6( const IPHeader_IPv6_t * const pxIPv6Header,
const NetworkBufferDescriptor_t * const pxNetworkBuffer,
UBaseType_t uxHeaderLength );
/* Return IPv6 header extension order number */
BaseType_t xGetExtensionOrder( uint8_t ucProtocol,
uint8_t ucNextHeader );
/** @brief Handle the IPv6 extension headers. */
eFrameProcessingResult_t eHandleIPv6ExtensionHeaders( NetworkBufferDescriptor_t * const pxNetworkBuffer,
BaseType_t xDoRemove );
/*
* If ulIPAddress is already in the ND cache table then reset the age of the
* entry back to its maximum value. If ulIPAddress is not already in the ND
* cache table then add it - replacing the oldest current entry if there is not
* a free space available.
*/
void vNDRefreshCacheEntry( const MACAddress_t * pxMACAddress,
const IPv6_Address_t * pxIPAddress,
NetworkEndPoint_t * pxEndPoint );
/* prvProcessICMPMessage_IPv6() is declared in FreeRTOS_routing.c
* It handles all ICMP messages except the PING requests. */
eFrameProcessingResult_t prvProcessICMPMessage_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer );
/* Return pdTRUE if all end-points are up.
* When pxInterface is null, all end-points will be checked. */
BaseType_t FreeRTOS_AllEndPointsUp( const struct xNetworkInterface * pxInterface );
#endif /* ifndef LIST_MACRO_H */
@@ -0,0 +1,124 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_IP_DiffConfig3" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ICMP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCPv6.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Stream_Buffer.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_WIN.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkInterface.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/IP_DiffConfig3_list_macros.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${project_name}/${project_name}_stubs.c
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/FreeRTOS_IP.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,70 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
volatile BaseType_t xInsideInterrupt = pdFALSE;
NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer;
NetworkBufferDescriptor_t * pxNDWaitingNetworkBuffer;
struct xNetworkEndPoint * pxNetworkEndPoints;
struct xNetworkInterface * pxNetworkInterfaces;
const MACAddress_t xLLMNR_MacAddress = { { 0x01, 0x00, 0x5e, 0x00, 0x00, 0xfc } };
QueueHandle_t xNetworkEventQueue;
void vPortEnterCritical( void )
{
}
void vPortExitCritical( void )
{
}
void * pvPortMalloc( size_t xNeeded )
{
return malloc( xNeeded );
}
void vPortFree( void * ptr )
{
free( ptr );
}
@@ -0,0 +1,85 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#undef listSET_LIST_ITEM_OWNER
void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem,
void * owner );
#undef listGET_END_MARKER
ListItem_t * listGET_END_MARKER( List_t * pxList );
#undef listGET_NEXT
ListItem_t * listGET_NEXT( const ListItem_t * pxListItem );
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( const ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( const ListItem_t * listItem );
size_t xPortGetMinimumEverFreeHeapSize( void );
/**
* @brief Work on the RA/SLAAC processing.
* @param[in] xDoReset: WHen true, the state-machine will be reset and initialised.
* @param[in] pxEndPoint: The end-point for which the RA/SLAAC process should be done..
*/
void vRAProcess( BaseType_t xDoReset,
NetworkEndPoint_t * pxEndPoint );
#endif /* ifndef LIST_MACRO_H */
@@ -0,0 +1,113 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_IP_Timers" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Callback.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ND.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/IP_Timers_list_macros.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/${project_name}.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set( utest_dep_list "" )
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,336 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigIPv4_BACKWARD_COMPATIBLE 0
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 1 )
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
#define FreeRTOS_htons( usIn ) ( ( uint16_t ) ( ( ( usIn ) << 8U ) | ( ( usIn ) >> 8U ) ) )
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 0
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 2 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks by dividing the time in
* milliseconds by portTICK_PERIOD_MS. */
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigUSE_DHCPv6 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 5
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD pdMS_TO_TICKS( 120000U )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN 1
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 pdMS_TO_TICKS( 20 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,190 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
/* =========================== EXTERN VARIABLES =========================== */
#define RELEASE_UDP_SOCKET_NETWORK_BUFFER_ADDRESS ( ( uint8_t * ) 0xABCD1234 )
#define RELEASE_UDP_SOCKET_NETWORK_BUFFER_SIZE 256
NetworkInterface_t xInterfaces[ 1 ];
BaseType_t xCallEventHook;
QueueHandle_t xNetworkEventQueue;
/* ============================ Stubs Functions =========================== */
BaseType_t xNetworkInterfaceInitialise_returnTrue( NetworkInterface_t * xInterface )
{
return pdTRUE;
}
BaseType_t xNetworkInterfaceInitialise_returnFalse( NetworkInterface_t * xInterface )
{
return pdFALSE;
}
BaseType_t prvChecksumICMPv6Checks_Valid( size_t uxBufferLength,
struct xPacketSummary * pxSet,
int NumCalls )
{
pxSet->uxProtocolHeaderLength = ipSIZE_OF_ICMPv6_HEADER;
return 0;
}
BaseType_t prvChecksumICMPv6Checks_BigHeaderLength( size_t uxBufferLength,
struct xPacketSummary * pxSet,
int NumCalls )
{
pxSet->uxProtocolHeaderLength = 0xFF;
return 0;
}
BaseType_t prvChecksumIPv6Checks_Valid( uint8_t * pucEthernetBuffer,
size_t uxBufferLength,
struct xPacketSummary * pxSet,
int NumCalls )
{
IPPacket_IPv6_t * pxIPPacket;
pxIPPacket = ( IPPacket_IPv6_t * ) pucEthernetBuffer;
pxSet->xIsIPv6 = pdTRUE;
pxSet->uxIPHeaderLength = ipSIZE_OF_IPv6_HEADER;
pxSet->usPayloadLength = FreeRTOS_ntohs( pxSet->pxIPPacket_IPv6->usPayloadLength );
pxSet->ucProtocol = pxIPPacket->xIPHeader.ucNextHeader;
pxSet->pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER ] ) );
pxSet->usProtocolBytes = pxSet->usPayloadLength;
return 0;
}
BaseType_t prvChecksumIPv4Checks_Valid( uint8_t * pucEthernetBuffer,
size_t uxBufferLength,
struct xPacketSummary * pxSet,
int NumCalls )
{
IPPacket_t * pxIPPacket;
pxIPPacket = ( IPPacket_t * ) pucEthernetBuffer;
pxSet->xIsIPv6 = pdFALSE;
pxSet->uxIPHeaderLength = ( pxIPPacket->xIPHeader.ucVersionHeaderLength & 0x0F ) * 4;
pxSet->usPayloadLength = FreeRTOS_ntohs( pxIPPacket->xIPHeader.usLength );
pxSet->ucProtocol = pxIPPacket->xIPHeader.ucProtocol;
pxSet->pxProtocolHeaders = ( ProtocolHeaders_t * ) &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + pxSet->uxIPHeaderLength ] );
pxSet->usProtocolBytes = pxSet->usPayloadLength - ipSIZE_OF_IPv4_HEADER;
return 0;
}
BaseType_t prvChecksumIPv4Checks_UnknownProtocol( uint8_t * pucEthernetBuffer,
size_t uxBufferLength,
struct xPacketSummary * pxSet,
int NumCalls )
{
prvChecksumIPv4Checks_Valid( pucEthernetBuffer, uxBufferLength, pxSet, NumCalls );
pxSet->ucProtocol = 0xFF;
return 0;
}
BaseType_t prvChecksumIPv4Checks_InvalidLength( uint8_t * pucEthernetBuffer,
size_t uxBufferLength,
struct xPacketSummary * pxSet,
int NumCalls )
{
BaseType_t xReturn = 0;
prvChecksumIPv4Checks_Valid( pucEthernetBuffer, uxBufferLength, pxSet, NumCalls );
if( uxBufferLength < sizeof( IPPacket_t ) )
{
pxSet->usChecksum = ipINVALID_LENGTH;
xReturn = 4;
}
return xReturn;
}
static int32_t FreeRTOS_recvfrom_StubHappyPath( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
configASSERT( uxBufferLength == 0 );
configASSERT( xFlags == FREERTOS_ZERO_COPY );
configASSERT( pxSourceAddress == NULL );
configASSERT( pxSourceAddressLength == NULL );
( void ) callbacks;
*( ( uint8_t ** ) pvBuffer ) = RELEASE_UDP_SOCKET_NETWORK_BUFFER_ADDRESS;
return RELEASE_UDP_SOCKET_NETWORK_BUFFER_SIZE;
}
static int32_t FreeRTOS_recvfrom_StubNonHappyPath( const ConstSocket_t xSocket,
void * pvBuffer,
size_t uxBufferLength,
BaseType_t xFlags,
struct freertos_sockaddr * pxSourceAddress,
socklen_t * pxSourceAddressLength,
int callbacks )
{
configASSERT( uxBufferLength == 0 );
configASSERT( xFlags == FREERTOS_ZERO_COPY );
configASSERT( pxSourceAddress == NULL );
configASSERT( pxSourceAddressLength == NULL );
( void ) callbacks;
*( ( uint8_t ** ) pvBuffer ) = NULL;
return -pdFREERTOS_ERRNO_EAGAIN;
}
@@ -0,0 +1,85 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#undef listSET_LIST_ITEM_OWNER
void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem,
void * owner );
#undef listGET_END_MARKER
ListItem_t * listGET_END_MARKER( List_t * pxList );
#undef listGET_NEXT
ListItem_t * listGET_NEXT( const ListItem_t * pxListItem );
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( const ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( const ListItem_t * listItem );
size_t xPortGetMinimumEverFreeHeapSize( void );
/**
* @brief Work on the RA/SLAAC processing.
* @param[in] xDoReset: WHen true, the state-machine will be reset and initialised.
* @param[in] pxEndPoint: The end-point for which the RA/SLAAC process should be done..
*/
void vRAProcess( BaseType_t xDoReset,
NetworkEndPoint_t * pxEndPoint );
#endif /* ifndef LIST_MACRO_H */
@@ -0,0 +1,118 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_IP_Utils" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ND.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCPv6.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv6_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/IP_Utils_list_macros.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
.
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/${project_name}.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
.
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
.
${CMOCK_DIR}/vendor/unity/src
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
${TCP_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set( utest_dep_list "" )
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,124 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <assert.h>
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_STATIC_ALLOCATION 1
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */
/* Software timer related configuration options. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
#define configMAX_PRIORITIES ( 7 )
#define configENABLE_MPU 0
/* Run time stats gathering configuration options. */
#define configGENERATE_RUN_TIME_STATS 1
/* This demo makes use of one or more example stats formatting functions. These
* format the raw data provided by the uxTaskGetSystemState() function in to human
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
/* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. */
extern void vAssertCalled( unsigned long ulLine,
const char * const pcFileName );
#define configASSERT( x )
#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */
/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
/* #include "trcRecorder.h" */
#endif /* FREERTOS_CONFIG_H */
@@ -0,0 +1,337 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/*****************************************************************************
*
* See the following URL for configuration information.
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
*
*****************************************************************************/
#ifndef FREERTOS_IP_CONFIG_H
#define FREERTOS_IP_CONFIG_H
#define _static
#define TEST 1
#define ipconfigIPv4_BACKWARD_COMPATIBLE 1
#define ipconfigUSE_IPv4 ( 1 )
#define ipconfigUSE_IPv6 ( 0 )
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 1
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif
/* Set to 1 to print out non debugging messages, for example the output of the
* FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
* then FreeRTOS_printf should be set to the function used to print out the
* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf( X ) configPRINTF( X )
#endif
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
* on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
/* If the network card/driver includes checksum offloading then set
* ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
* stack repeating the checksum calculations. */
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 0
/* Several API's will block until the result is known, or the action has been
* performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
* set per socket, using setsockopt(). If not set, the times below will be
* used as defaults. */
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
/* Include support for DNS caching. For TCP, having a small DNS cache is very
* useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
* and also DNS may use small timeouts. If a DNS reply comes in after the DNS
* socket has been destroyed, the result will be stored into the cache. The next
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
* a socket.
*/
#define ipconfigUSE_DNS_CACHE ( 1 )
#define ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY ( 2 )
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
#define ipconfigDNS_CACHE_NAME_LENGTH ( 254 )
/* The IP stack executes it its own task (although any application task can make
* use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
* sets the priority of the task that executes the IP stack. The priority is a
* standard FreeRTOS task priority so can take any value from 0 (the lowest
* priority) to (configMAX_PRIORITIES - 1) (the highest priority).
* configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
* FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
* the priority assigned to the task executing the IP stack relative to the
* priority assigned to tasks that use the IP stack. */
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
* task. This setting is less important when the FreeRTOS Win32 simulator is used
* as the Win32 simulator only stores a fixed amount of information on the task
* stack. FreeRTOS includes optional stack overflow detection, see:
* http://www.freertos.org/Stacks-and-stack-overflow-checking.html. */
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
* network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
* is not set to 1 then the network event hook will never be called. See:
* https://freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/57-vApplicationIPNetworkEventHook.
*/
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
* a network buffer cannot be obtained then the calling task is held in the Blocked
* state (so other tasks can continue to executed) until either a network buffer
* becomes available or the send block time expires. If the send block time expires
* then the send operation is aborted. The maximum allowable send block time is
* capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
* maximum allowable send block time prevents prevents a deadlock occurring when
* all the network buffers are in use and the tasks that process (and subsequently
* free) the network buffers are themselves blocked waiting for a network buffer.
* ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
* milliseconds can be converted to a time in ticks by dividing the time in
* milliseconds by portTICK_PERIOD_MS. */
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
* address, netmask, DNS server address and gateway address from a DHCP server. If
* ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
* stack will revert to using the static IP address even when ipconfigUSE_DHCP is
* set to 1 if a valid configuration cannot be obtained from a DHCP server for any
* reason. The static configuration used is that passed into the stack by the
* FreeRTOS_IPInit() function call. */
#define ipconfigUSE_DHCP 1
#define ipconfigDHCP_REGISTER_HOSTNAME 1
#define ipconfigDHCP_USES_UNICAST 1
#define ipconfigENDPOINT_DNS_ADDRESS_COUNT 5
/* If ipconfigDHCP_USES_USER_HOOK is set to 1 then the application writer must
* provide an implementation of the DHCP callback function,
* xApplicationDHCPUserHook(). */
#define ipconfigUSE_DHCP_HOOK 1
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
* increasing time intervals until either a reply is received from a DHCP server
* and accepted, or the interval between transmissions reaches
* ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
* static IP address passed as a parameter to FreeRTOS_IPInit() if the
* re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
* a DHCP reply being received. */
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD \
( 120000U / portTICK_PERIOD_MS )
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
* stack can only send a UDP message to a remove IP address if it knowns the MAC
* address associated with the IP address, or the MAC address of the router used to
* contact the remote IP address. When a UDP message is received from a remote IP
* address the MAC address and IP address are added to the ARP cache. When a UDP
* message is sent to a remote IP address that does not already appear in the ARP
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
* FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
* alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
* takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
* FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
* (for example, 192, 168, 0, 1) as its parameters. If
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
* be queued for processing at any one time. The event queue must be a minimum of
* 5 greater than the total number of network buffers. */
#define ipconfigEVENT_QUEUE_LENGTH \
( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
/* The address of a socket is the combination of its IP address and its port
* number. FreeRTOS_bind() is used to manually allocate a port number to a socket
* (to 'bind' the socket to a port), but manual binding is not normally necessary
* for client sockets (those sockets that initiate outgoing connections rather than
* wait for incoming connections on a known port number). If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
* FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
* stack automatically binding the socket to a port number from the range
* socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
* ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
* on a socket that has not yet been bound will result in the send operation being
* aborted. */
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
#define ipconfigUDP_TIME_TO_LIVE 128
/* Also defined in FreeRTOSIPConfigDefaults.h. */
#define ipconfigTCP_TIME_TO_LIVE 128
/* USE_TCP: Use TCP and all its features. */
#define ipconfigUSE_TCP ( 1 )
/* USE_WIN: Let TCP use windowing mechanism. */
#define ipconfigUSE_TCP_WIN ( 1 )
/* The MTU is the maximum number of bytes the payload of a network frame can
* contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
* lower value can save RAM, depending on the buffer management scheme used. If
* ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
* be divisible by 8. */
#define ipconfigNETWORK_MTU 1500U
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
* through the FreeRTOS_gethostbyname() API function. */
#define ipconfigUSE_DNS 1
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
* generate replies to incoming ICMP echo (ping) requests. */
#define ipconfigREPLY_TO_INCOMING_PINGS 1
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
* FreeRTOS_SendPingRequest() API function is available. */
#define ipconfigSUPPORT_OUTGOING_PINGS 1
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
* (and associated) API function is available. */
#define ipconfigSUPPORT_SELECT_FUNCTION 1
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
* that are not in Ethernet II format will be dropped. This option is included for
* potential future IP stack developments. */
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
* responsibility of the Ethernet interface to filter out packets that are of no
* interest. If the Ethernet interface does not implement this functionality, then
* set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
* perform the filtering instead (it is much less efficient for the stack to do it
* because the packet will already have been passed into the stack). If the
* Ethernet driver does all the necessary filtering in hardware then software
* filtering can be removed by using a value other than 1 or 0. */
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
/* 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 )
/* Advanced only: in order to access 32-bit fields in the IP packets with
* 32-bit memory instructions, all packets will be stored 32-bit-aligned,
* plus 16-bits. This has to do with the contents of the IP-packets: all
* 32-bit fields are 32-bit-aligned, plus 16-bit. */
#define ipconfigPACKET_FILLER_SIZE 2U
/* Define the size of the pool of TCP window descriptors. On the average, each
* TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
* outstanding packets (for Rx and Tx). When using up to 10 TP sockets
* simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
#define ipconfigTCP_WIN_SEG_COUNT 2
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
* maximum size. Define the size of Rx buffer for TCP sockets. */
#define ipconfigTCP_RX_BUFFER_LENGTH ( 10000 )
/* Define the size of Tx buffer for TCP sockets. */
#define ipconfigTCP_TX_BUFFER_LENGTH ( 10000 )
/* When using call-back handlers, the driver may check if the handler points to
* real program memory (RAM or flash) or just has a random non-zero value. */
#define ipconfigIS_VALID_PROG_ADDRESS( x ) ( ( x ) != NULL )
/* Include support for TCP keep-alive messages. */
#define ipconfigTCP_KEEP_ALIVE ( 1 )
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* Seconds. */
/* The socket semaphore is used to unblock the MQTT task. */
#define ipconfigSOCKET_HAS_USER_SEMAPHORE ( 1 )
#define ipconfigSOCKET_HAS_USER_WAKE_CALLBACK ( 1 )
#define ipconfigUSE_CALLBACKS ( 1 )
#define ipconfigUSE_NBNS ( 1 )
#define ipconfigUSE_LLMNR ( 1 )
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigUSE_ARP_REMOVE_ENTRY 1
#define ipconfigUSE_ARP_REVERSED_LOOKUP 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES ( 200 )
#define ipconfigARP_STORES_REMOTE_ADDRESSES ( 1 )
#define ipconfigARP_USE_CLASH_DETECTION ( 1 )
#define ipconfigDHCP_FALL_BACK_AUTO_IP ( 1 )
#define ipconfigUDP_MAX_RX_PACKETS ( 1 )
#define ipconfigSUPPORT_SIGNALS ( 1 )
#define ipconfigDNS_CACHE_ENTRIES ( 2 )
#define ipconfigBUFFER_PADDING ( 14 )
#define ipconfigTCP_SRTT_MINIMUM_VALUE_MS ( 34 )
#define ipconfigTCP_HANG_PROTECTION ( 1 )
#define portINLINE
#define ipconfigTCP_MAY_LOG_PORT( xPort ) ( ( xPort ) != 23U )
#define ipconfigCHECK_IP_QUEUE_SPACE ( 1 )
#define ipconfigZERO_COPY_TX_DRIVER ( 1 )
#endif /* FREERTOS_IP_CONFIG_H */
@@ -0,0 +1,58 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include <unity.h>
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "list.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_IP_Private.h"
/* =========================== EXTERN VARIABLES =========================== */
NetworkInterface_t xInterfaces[ 1 ];
#if ( ipconfigUSE_NETWORK_EVENT_HOOK == 1 )
BaseType_t xCallEventHook;
#endif
QueueHandle_t xNetworkEventQueue;
/* ============================ Stubs Functions =========================== */
static BaseType_t xNetworkInterfaceInitialise_test( struct xNetworkInterface * pxDescriptor )
{
return pdPASS;
}
@@ -0,0 +1,337 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
/* Include Unity header */
#include "unity.h"
/* Include standard libraries */
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "mock_task.h"
#include "mock_list.h"
/* This must come after list.h is included (in this case, indirectly
* by mock_list.h). */
#include "mock_IP_Utils_DiffConfig_list_macros.h"
#include "mock_queue.h"
#include "mock_event_groups.h"
#include "FreeRTOSIPConfig.h"
#include "mock_FreeRTOS_IP.h"
#include "mock_FreeRTOS_IP_Private.h"
#include "mock_FreeRTOS_IP_Timers.h"
#include "mock_FreeRTOS_ARP.h"
#include "mock_FreeRTOS_DHCP.h"
#include "mock_FreeRTOS_Sockets.h"
#include "mock_FreeRTOS_Routing.h"
#include "mock_NetworkBufferManagement.h"
#include "mock_FreeRTOS_IPv4_Utils.h"
#include "FreeRTOS_IP_Utils.h"
#include "FreeRTOS_IP_Utils_DiffConfig_stubs.c"
#include "catch_assert.h"
/* =========================== EXTERN VARIABLES =========================== */
#if ( ipconfigUSE_NETWORK_EVENT_HOOK == 1 )
extern BaseType_t xCallEventHook;
#endif
extern UBaseType_t uxLastMinBufferCount;
extern size_t uxMinLastSize;
extern UBaseType_t uxLastMinQueueSpace;
extern NetworkInterface_t xInterfaces[ 1 ];
/* ============================== Test Cases ============================== */
/**
* @brief test_pxPacketBuffer_to_NetworkBuffer
* To validate if pxPacketBuffer_to_NetworkBuffer returns NULL when input is NULL.
*/
void test_pxPacketBuffer_to_NetworkBuffer( void )
{
NetworkBufferDescriptor_t * pxReturn;
pxReturn = pxPacketBuffer_to_NetworkBuffer( NULL );
TEST_ASSERT_EQUAL( NULL, pxReturn );
}
/**
* @brief test_prvProcessNetworkDownEvent_Pass_DHCP_Enabled
* To validate if prvProcessNetworkDownEvent runs DHCP flow when it's enabled for that endpoint.
*/
void test_prvProcessNetworkDownEvent_Pass_DHCP_Enabled( void )
{
NetworkInterface_t xInterface;
NetworkEndPoint_t xEndPoint = { 0 };
xCallEventHook = pdFALSE;
xInterface.pfInitialise = xNetworkInterfaceInitialise_test;
vIPSetARPTimerEnableState_Expect( pdFALSE );
FreeRTOS_FirstEndPoint_ExpectAndReturn( &xInterface, &xEndPoint );
FreeRTOS_ClearARP_Expect( &xEndPoint );
vDHCPStop_Expect( &xEndPoint );
FreeRTOS_NextEndPoint_ExpectAndReturn( &xInterface, &xEndPoint, NULL );
xInterface.pfInitialise = xNetworkInterfaceInitialise_test;
FreeRTOS_FirstEndPoint_ExpectAndReturn( &xInterface, &xEndPoint );
xEndPoint.bits.bWantDHCP = pdTRUE;
vDHCPProcess_Expect( pdTRUE, &xEndPoint );
FreeRTOS_NextEndPoint_ExpectAndReturn( &xInterface, &xEndPoint, NULL );
prvProcessNetworkDownEvent( &xInterface );
}
/**
* @brief test_FreeRTOS_round_up
* To validate if FreeRTOS_round_up doesn't trigger assertion when configASSERT is not enabled.
*/
void test_FreeRTOS_round_up( void )
{
uint32_t ulReturn;
uint32_t a = 10;
ulReturn = FreeRTOS_round_up( a, 0 );
TEST_ASSERT_EQUAL( 10, ulReturn );
}
/**
* @brief test_FreeRTOS_round_down
* To validate if FreeRTOS_round_down doesn't trigger assertion when configASSERT is not enabled.
*/
void test_FreeRTOS_round_down( void )
{
uint32_t ulReturn;
uint32_t a = 10;
ulReturn = FreeRTOS_round_down( a, 0 );
TEST_ASSERT_EQUAL( 0, ulReturn );
}
/**
* @brief test_vPrintResourceStats_MinSizeIsBigger
* To validate if vPrintResourceStats updates uxLastMinQueueSpace when
* ipconfigCHECK_IP_QUEUE_SPACE is enabled.
*/
void test_vPrintResourceStats_MinSizeIsBigger( void )
{
uxLastMinBufferCount = ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS;
uxMinLastSize = 10u;
uxLastMinQueueSpace = 0;
uxGetMinimumFreeNetworkBuffers_ExpectAndReturn( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS - 2 );
xPortGetMinimumEverFreeHeapSize_ExpectAndReturn( 1024U * 1025U );
uxGetMinimumIPQueueSpace_ExpectAndReturn( 0 );
vPrintResourceStats();
TEST_ASSERT_EQUAL( 10, uxMinLastSize );
TEST_ASSERT_EQUAL( 0, uxLastMinQueueSpace );
}
/**
* @brief test_vPrintResourceStats_LastQueueNECurrentQueue
* To validate if vPrintResourceStats updates uxLastMinQueueSpace when
* ipconfigCHECK_IP_QUEUE_SPACE is enabled.
*/
void test_vPrintResourceStats_LastQueueNECurrentQueue( void )
{
uxLastMinBufferCount = ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS;
uxMinLastSize = 10u;
uxLastMinQueueSpace = 0;
uxGetMinimumFreeNetworkBuffers_ExpectAndReturn( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS - 2 );
xPortGetMinimumEverFreeHeapSize_ExpectAndReturn( 1024U * 1025U );
uxGetMinimumIPQueueSpace_ExpectAndReturn( 10 );
vPrintResourceStats();
TEST_ASSERT_EQUAL( 10, uxMinLastSize );
TEST_ASSERT_EQUAL( 10, uxLastMinQueueSpace );
}
/**
* @brief test_vPrintResourceStats_LastQueueNECurrentQueue
* To validate if prvProcessNetworkDownEvent skip DHCP flow when
* DHCP is disabled for that endpoint.
*/
void test_prvProcessNetworkDownEvent_Pass_DHCP_Disabled( void )
{
NetworkInterface_t xInterface;
NetworkEndPoint_t xEndPoint = { 0 };
xCallEventHook = pdFALSE;
xEndPoint.bits.bCallDownHook = 1;
xInterface.pfInitialise = xNetworkInterfaceInitialise_test;
vIPSetARPTimerEnableState_Expect( pdFALSE );
FreeRTOS_FirstEndPoint_ExpectAndReturn( &xInterface, &xEndPoint );
vApplicationIPNetworkEventHook_Expect( eNetworkDown );
FreeRTOS_ClearARP_Expect( &xEndPoint );
FreeRTOS_NextEndPoint_ExpectAndReturn( &xInterface, &xEndPoint, NULL );
xInterface.pfInitialise = xNetworkInterfaceInitialise_test;
FreeRTOS_FirstEndPoint_ExpectAndReturn( &xInterface, &xEndPoint );
xEndPoint.bits.bWantDHCP = pdFALSE;
xEndPoint.bits.bWantRA = pdFALSE;
vIPNetworkUpCalls_Expect( &xEndPoint );
FreeRTOS_NextEndPoint_ExpectAndReturn( &xInterface, &xEndPoint, NULL );
prvProcessNetworkDownEvent( &xInterface );
}
/**
* @brief test_prvProcessNetworkDownEvent_PassIPv6
* To validate if prvProcessNetworkDownEvent skip setting IPv6 address to
* endpoint when IPv6 is disabled.
*/
void test_prvProcessNetworkDownEvent_PassIPv6( void )
{
NetworkInterface_t xInterface;
NetworkEndPoint_t xEndPoint = { 0 };
xCallEventHook = pdFALSE;
xEndPoint.bits.bCallDownHook = 1;
xInterface.pfInitialise = xNetworkInterfaceInitialise_test;
vIPSetARPTimerEnableState_Expect( pdFALSE );
FreeRTOS_FirstEndPoint_ExpectAndReturn( &xInterface, &xEndPoint );
vApplicationIPNetworkEventHook_Expect( eNetworkDown );
FreeRTOS_ClearARP_Expect( &xEndPoint );
FreeRTOS_NextEndPoint_ExpectAndReturn( &xInterface, &xEndPoint, NULL );
xInterface.pfInitialise = xNetworkInterfaceInitialise_test;
FreeRTOS_FirstEndPoint_ExpectAndReturn( &xInterface, &xEndPoint );
xEndPoint.bits.bIPv6 = pdTRUE;
xEndPoint.bits.bWantDHCP = pdFALSE;
xEndPoint.bits.bWantRA = pdFALSE;
vIPNetworkUpCalls_Expect( &xEndPoint );
FreeRTOS_NextEndPoint_ExpectAndReturn( &xInterface, &xEndPoint, NULL );
prvProcessNetworkDownEvent( &xInterface );
}
/**
* @brief test_usGenerateProtocolChecksum_UDPv6IncomingPacket
* To validate usGenerateProtocolChecksum returns ipINVALID_LENGTH if
* checksum if IPv6 is not supported.
*/
void test_usGenerateProtocolChecksum_UDPv6IncomingPacket( void )
{
uint16_t usReturn;
uint8_t pucEthernetBuffer[ ipconfigTCP_MSS ];
BaseType_t xOutgoingPacket = pdFALSE;
IPPacket_IPv6_t * pxIPPacket;
UDPPacket_IPv6_t * pxUDPv6Packet;
uint16_t usLength = 100;
size_t uxBufferLength = usLength + ipSIZE_OF_ETH_HEADER;
memset( pucEthernetBuffer, 0, ipconfigTCP_MSS );
pxUDPv6Packet = ( UDPPacket_IPv6_t * ) pucEthernetBuffer;
pxIPPacket = ( IPPacket_IPv6_t * ) pucEthernetBuffer;
pxIPPacket->xEthernetHeader.usFrameType = ipIPv6_FRAME_TYPE;
pxIPPacket->xIPHeader.usPayloadLength = FreeRTOS_htons( usLength - ipSIZE_OF_IPv6_HEADER );
pxIPPacket->xIPHeader.ucNextHeader = ipPROTOCOL_UDP;
pxUDPv6Packet->xUDPHeader.usChecksum = 0xB2FF;
usReturn = usGenerateProtocolChecksum( pucEthernetBuffer, uxBufferLength, xOutgoingPacket );
TEST_ASSERT_EQUAL( ipINVALID_LENGTH, usReturn );
}
/**
* @brief test_pxUDPPayloadBuffer_to_NetworkBuffer_IPv6
* Though the packet is marked as IPv6, we count it as IPv4 packet when
* IPv6 is disabled.
*/
void test_pxUDPPayloadBuffer_to_NetworkBuffer_IPv6( void )
{
NetworkBufferDescriptor_t * pxNetBufferToReturn, xNetBufferToReturn;
size_t uxOffset = sizeof( UDPPacket_t );
uint8_t ucEthBuf[ ipBUFFER_PADDING + ipconfigTCP_MSS ];
uint8_t * pucIPType;
uint8_t * pucPayloadBuffer;
NetworkBufferDescriptor_t * pxNetworkBuffer;
memset( ucEthBuf, 0, sizeof( ucEthBuf ) );
memset( &xNetBufferToReturn, 0, sizeof( xNetBufferToReturn ) );
pxNetBufferToReturn = &xNetBufferToReturn;
pxNetBufferToReturn->pucEthernetBuffer = ucEthBuf;
*( ( NetworkBufferDescriptor_t ** ) pxNetBufferToReturn->pucEthernetBuffer ) = pxNetBufferToReturn;
pucPayloadBuffer = &ucEthBuf[ uxOffset + ipBUFFER_PADDING ];
pucIPType = pucPayloadBuffer - ipUDP_PAYLOAD_IP_TYPE_OFFSET;
*pucIPType = ipTYPE_IPv6;
pxNetworkBuffer = pxUDPPayloadBuffer_to_NetworkBuffer( pucPayloadBuffer );
TEST_ASSERT_EQUAL( pxNetBufferToReturn, pxNetworkBuffer );
}
@@ -0,0 +1,79 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#undef listSET_LIST_ITEM_OWNER
void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem,
void * owner );
#undef listGET_END_MARKER
ListItem_t * listGET_END_MARKER( List_t * pxList );
#undef listGET_NEXT
ListItem_t * listGET_NEXT( const ListItem_t * pxListItem );
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( const ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( const ListItem_t * listItem );
size_t xPortGetMinimumEverFreeHeapSize( void );
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent );
#endif /* ifndef LIST_MACRO_H */
@@ -0,0 +1,117 @@
# Include filepaths for source and include.
include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake )
# ==================== Define your project name (edit) ========================
set( project_name "FreeRTOS_IP_Utils_DiffConfig" )
message( STATUS "${project_name}" )
# ===================== Create your mock here (edit) ========================
set(mock_list "")
# list the files to mock here
list(APPEND mock_list
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h"
"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/event_groups.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IPv4_Utils.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_ARP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DHCP.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Routing.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h"
"${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkInterface.h"
"${MODULE_ROOT_DIR}/test/unit-test/${project_name}/IP_Utils_DiffConfig_list_macros.h"
)
set(mock_include_list "")
# list the directories your mocks need
list(APPEND mock_include_list
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
)
set(mock_define_list "")
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
""
)
# ================= Create the library under test here (edit) ==================
set(real_source_files "")
# list the files you would like to test here
list(APPEND real_source_files
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources/FreeRTOS_IP_Utils.c
${MODULE_ROOT_DIR}/test/unit-test/${project_name}/${project_name}_stubs.c
)
set(real_include_directories "")
# list the directories the module under test includes
list(APPEND real_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${TCP_INCLUDE_DIRS}
${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include
${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix
${CMOCK_DIR}/vendor/unity/src
)
# ===================== Create UnitTest Code here (edit) =====================
set(test_include_directories "")
# list the directories your test needs to include
list(APPEND test_include_directories
${MODULE_ROOT_DIR}/test/unit-test/${project_name}
.
${CMOCK_DIR}/vendor/unity/src
${TCP_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/Annexed_TCP_Sources
)
# ============================= (end edit) ===================================
set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")
create_mock_list(${mock_name}
"${mock_list}"
"${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml"
"${mock_include_list}"
"${mock_define_list}"
)
create_real_library(${real_name}
"${real_source_files}"
"${real_include_directories}"
"${mock_name}"
)
set( utest_link_list "" )
list(APPEND utest_link_list
-l${mock_name}
lib${real_name}.a
)
set( utest_dep_list "" )
list(APPEND utest_dep_list
${real_name}
)
set(utest_name "${project_name}_utest")
set(utest_source "${project_name}/${project_name}_utest.c")
create_test(${utest_name}
${utest_source}
"${utest_link_list}"
"${utest_dep_list}"
"${test_include_directories}"
)
@@ -0,0 +1,76 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/
#ifndef LIST_MACRO_H
#define LIST_MACRO_H
#include <FreeRTOS.h>
#include <portmacro.h>
#include <list.h>
#include "FreeRTOS_IPv6_Private.h"
#undef listSET_LIST_ITEM_OWNER
void listSET_LIST_ITEM_OWNER( ListItem_t * pxListItem,
void * owner );
#undef listGET_END_MARKER
ListItem_t * listGET_END_MARKER( List_t * pxList );
#undef listGET_NEXT
ListItem_t * listGET_NEXT( const ListItem_t * pxListItem );
#undef listLIST_IS_EMPTY
BaseType_t listLIST_IS_EMPTY( const List_t * pxList );
#undef listGET_OWNER_OF_HEAD_ENTRY
void * listGET_OWNER_OF_HEAD_ENTRY( const List_t * pxList );
#undef listIS_CONTAINED_WITHIN
BaseType_t listIS_CONTAINED_WITHIN( List_t * list,
const ListItem_t * listItem );
#undef listGET_LIST_ITEM_VALUE
TickType_t listGET_LIST_ITEM_VALUE( const ListItem_t * listItem );
#undef listSET_LIST_ITEM_VALUE
void listSET_LIST_ITEM_VALUE( ListItem_t * listItem,
TickType_t itemValue );
#undef listLIST_ITEM_CONTAINER
List_t * listLIST_ITEM_CONTAINER( const ListItem_t * listItem );
#undef listCURRENT_LIST_LENGTH
UBaseType_t listCURRENT_LIST_LENGTH( List_t * list );
#undef listGET_ITEM_VALUE_OF_HEAD_ENTRY
TickType_t listGET_ITEM_VALUE_OF_HEAD_ENTRY( List_t * list );
#undef listGET_LIST_ITEM_OWNER
void * listGET_LIST_ITEM_OWNER( const ListItem_t * listItem );
#endif /* ifndef LIST_MACRO_H */
Loaded 100 of 1978 files, more files were not shown because too many files have changed in this diff. Show more