Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1506 from dan4thewin/sockets-test
Browse files Browse the repository at this point in the history
Change TooManySockets test to a concurrent count test
pvyawaha authored Nov 7, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents f65610f + 02c02f6 commit d5fedc0
Showing 9 changed files with 56 additions and 83 deletions.
86 changes: 51 additions & 35 deletions libraries/abstractions/secure_sockets/test/iot_test_tcp.c
Original file line number Diff line number Diff line change
@@ -782,7 +782,7 @@ TEST_GROUP_RUNNER( Full_TCP )
RUN_TEST_CASE( Full_TCP, AFQP_SOCKETS_Close );
RUN_TEST_CASE( Full_TCP, AFQP_SOCKETS_Recv_ByteByByte );
RUN_TEST_CASE( Full_TCP, AFQP_SOCKETS_SendRecv_VaryLength );
RUN_TEST_CASE( Full_TCP, AFQP_SOCKETS_Socket_InvalidTooManySockets );
RUN_TEST_CASE( Full_TCP, AFQP_SOCKETS_Socket_ConcurrentCount );
RUN_TEST_CASE( Full_TCP, AFQP_SOCKETS_Socket_InvalidInputParams );
RUN_TEST_CASE( Full_TCP, AFQP_SOCKETS_Send_Invalid );
RUN_TEST_CASE( Full_TCP, AFQP_SOCKETS_Recv_Invalid );
@@ -1744,64 +1744,80 @@ TEST( Full_TCP, AFQP_SOCKETS_Socket_InvalidInputParams )

/*-----------------------------------------------------------*/

static void prvSOCKETS_Socket_InvalidTooManySockets( Server_t xConn )
/*
* Verify the number of sockets that can be concurrently
* created up to a configured maximum. Return pdFAIL if
* fewer than that number are created. If more than the
* maximum can be created, a warning is printed, but this
* is not a failure condition. Some ports are limited only
* by free memory. For these ports, check that a reasonable
* number of sockets can be created concurrently.
*/
#ifdef integrationtestportableMAX_NUM_UNSECURE_SOCKETS
#define MAX_NUM_SOCKETS integrationtestportableMAX_NUM_UNSECURE_SOCKETS
#else
#define MAX_NUM_SOCKETS 5u
#endif
static void prvSOCKETS_Socket_ConcurrentCount( Server_t xConn )
{
#if !defined( WIN32 ) && !defined( PIC32MZ ) && !defined( ESP32 ) && !defined( ZYNQ7000 ) && !defined( __RX ) && !defined( MW320 ) /* Socket can be created as much as there is memory */
BaseType_t xResult;
Socket_t xCreatedSockets[ integrationtestportableMAX_NUM_UNSECURE_SOCKETS ];
BaseType_t xSocketsCreated;
Socket_t xSocket;
BaseType_t xResult = pdFAIL;
Socket_t xCreatedSockets[ MAX_NUM_SOCKETS ];
BaseType_t xSocketsCreated;
Socket_t xSocket;

tcptestPRINTF( ( "Starting %s.\r\n", __FUNCTION__ ) );
tcptestPRINTF( ( "Starting %s.\r\n", __FUNCTION__ ) );

xResult = pdPASS;
xResult = pdPASS;

for( xSocketsCreated = 0; xSocketsCreated < integrationtestportableMAX_NUM_UNSECURE_SOCKETS; xSocketsCreated++ )
{
xSocket = SOCKETS_Socket( SOCKETS_AF_INET, SOCKETS_SOCK_STREAM, SOCKETS_IPPROTO_TCP );
for( xSocketsCreated = 0; xSocketsCreated < MAX_NUM_SOCKETS; xSocketsCreated++ )
{
xSocket = SOCKETS_Socket( SOCKETS_AF_INET, SOCKETS_SOCK_STREAM, SOCKETS_IPPROTO_TCP );

if( xSocket == SOCKETS_INVALID_SOCKET )
{
xResult = pdFAIL;
tcptestPRINTF( ( "%s failed creating a socket number %d \r\n", __FUNCTION__, xSocketsCreated ) );
break;
}
else
{
xCreatedSockets[ xSocketsCreated ] = xSocket;
}
if( xSocket == SOCKETS_INVALID_SOCKET )
{
xResult = pdFAIL;
tcptestPRINTF( ( "%s failed creating a socket number %d \r\n", __FUNCTION__, xSocketsCreated ) );
break;
}
else
{
xCreatedSockets[ xSocketsCreated ] = xSocket;
}
}

#ifdef integrationtestportableMAX_NUM_UNSECURE_SOCKETS
if( xResult == pdPASS )
{
xSocket = SOCKETS_Socket( SOCKETS_AF_INET, SOCKETS_SOCK_STREAM, SOCKETS_IPPROTO_TCP );

if( xSocket != SOCKETS_INVALID_SOCKET )
{
xResult = pdFAIL;
SOCKETS_Close( xSocket );
tcptestPRINTF( ( "%s exceeded maximum number of sockets (%d > %d); is the value of " \
"integrationtestportableMAX_NUM_UNSECURE_SOCKETS correct?\r\n", __FUNCTION__,
( MAX_NUM_SOCKETS + 1 ), MAX_NUM_SOCKETS ) );
}
}
#endif /* ifdef integrationtestportableMAX_NUM_UNSECURE_SOCKETS */

/* Cleanup. */
while( xSocketsCreated > 0 )
{
--xSocketsCreated;
SOCKETS_Close( xCreatedSockets[ xSocketsCreated ] );
}
/* Cleanup. */
while( xSocketsCreated > 0 )
{
--xSocketsCreated;
SOCKETS_Close( xCreatedSockets[ xSocketsCreated ] );
}

TEST_ASSERT_EQUAL_UINT32_MESSAGE( pdPASS, xResult, "Max num sockets test failed" );
TEST_ASSERT_EQUAL_UINT32_MESSAGE( pdPASS, xResult, "Concurrent num sockets test failed" );

/* Report Test Results. */
tcptestPRINTF( ( "%s passed\r\n", __FUNCTION__ ) );
#endif /*ifndef WIN32 */
/* Report Test Results. */
tcptestPRINTF( ( "%s passed\r\n", __FUNCTION__ ) );
}

TEST( Full_TCP, AFQP_SOCKETS_Socket_InvalidTooManySockets )
TEST( Full_TCP, AFQP_SOCKETS_Socket_ConcurrentCount )
{
tcptestPRINTF( ( "Starting %s.\r\n", __FUNCTION__ ) );

prvSOCKETS_Socket_InvalidTooManySockets( eNonsecure );
prvSOCKETS_Socket_ConcurrentCount( eNonsecure );
}

TEST( Full_TCP, AFQP_SECURE_SOCKETS_Socket_InvalidTooManySockets )
Original file line number Diff line number Diff line change
@@ -30,12 +30,6 @@
* @file aws_integration_test_tcp_portable.h
* @brief Port-specific variables for TCP tests. */

/**
* @brief The number of sockets that can be open at one time on a port.
*
*/
#define integrationtestportableMAX_NUM_UNSECURE_SOCKETS 1

/**
* @brief Indicates how much longer than the specified timeout is acceptable for
* RCVTIMEO tests.
Original file line number Diff line number Diff line change
@@ -29,12 +29,6 @@
/**
* @file aws_integration_test_tcp_portable.h
* @brief Port-specific variables for TCP tests. */
#define MW320
/**
* @brief The number of sockets that can be open at one time on a port.
*
*/
#define integrationtestportableMAX_NUM_UNSECURE_SOCKETS 20

/**
* @brief Indicates how much longer than the specified timeout is acceptable for
Original file line number Diff line number Diff line change
@@ -31,13 +31,6 @@
* @brief Port-specific variables for TCP tests. */


/**
* @brief The number of sockets that can be open at one time on a port.
*
* This test is not run in WinSim as there are too many sockets that can be opened at one time.
*/
#define integrationtestportableMAX_NUM_UNSECURE_SOCKETS 0

/**
* @brief Indicates how much longer than the specified timeout is acceptable for
* RCVTIMEO tests.
Original file line number Diff line number Diff line change
@@ -30,13 +30,6 @@
* @brief Port-specific variables for TCP tests. */


/**
* @brief The number of sockets that can be open at one time on a port.
*
* This test is not run in WinSim as there are too many sockets that can be opened at one time.
*/
#define integrationtestportableMAX_NUM_UNSECURE_SOCKETS 0

/**
* @brief Indicates how much longer than the specified timeout is acceptable for
* RCVTIMEO tests.
Original file line number Diff line number Diff line change
@@ -30,13 +30,6 @@
* @brief Port-specific variables for TCP tests. */


/**
* @brief The number of sockets that can be open at one time on a port.
*
* This test is not run in WinSim as there are too many sockets that can be opened at one time.
*/
#define integrationtestportableMAX_NUM_UNSECURE_SOCKETS 0

/**
* @brief Indicates how much longer than the specified timeout is acceptable for
* RCVTIMEO tests.
Original file line number Diff line number Diff line change
@@ -30,12 +30,6 @@
* @file aws_integration_test_tcp_portable.h
* @brief Port-specific variables for TCP tests. */

/**
* @brief The number of sockets that can be open at one time on a port.
*
*/
#define integrationtestportableMAX_NUM_UNSECURE_SOCKETS 1

/**
* @brief Indicates how much longer than the specified timeout is acceptable for
* RCVTIMEO tests.
Original file line number Diff line number Diff line change
@@ -31,10 +31,12 @@
* @brief Port-specific variables for TCP tests. */

/**
* @brief The number of sockets that can be open at one time on a port.
*
* @brief Port-specific maximum number of concurrent sockets
* Do not define this if the number is limited only by free memory.
*/
#if 0
#define integrationtestportableMAX_NUM_UNSECURE_SOCKETS 1 /* FIX ME. */
#endif

/**
* @brief Indicates how much longer than the specified timeout is acceptable for
@@ -69,4 +71,4 @@



#endif /*AWS_INTEGRATION_TEST_TCP_CONFIG_H */
#endif /*AWS_INTEGRATION_TEST_TCP_CONFIG_H */
Original file line number Diff line number Diff line change
@@ -30,12 +30,6 @@
* @file aws_integration_test_tcp_portable.h
* @brief Port-specific variables for TCP tests. */

/**
* @brief The number of sockets that can be open at one time on a port.
*
*/
#define integrationtestportableMAX_NUM_UNSECURE_SOCKETS 0

/**
* @brief Indicates how much longer than the specified timeout is acceptable for
* RCVTIMEO tests.

0 comments on commit d5fedc0

Please sign in to comment.