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,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}"
)