Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test code build issues when INET_CONFIG_TCP_ENDPOINT is set to false #35027

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/inet/tests/TestInetEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,24 @@ TEST_F(TestInetEndPoint, TestInetEndPointInternal)
InterfaceId intId;

// EndPoint
UDPEndPoint * testUDPEP = nullptr;
UDPEndPoint * testUDPEP = nullptr;
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
TCPEndPoint * testTCPEP1 = nullptr;
PacketBufferHandle buf = PacketBufferHandle::New(PacketBuffer::kMaxSize);
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
PacketBufferHandle buf = PacketBufferHandle::New(PacketBuffer::kMaxSize);

// init all the EndPoints
SYSTEM_STATS_RESET(System::Stats::kInetLayer_NumUDPEps);
err = gUDP.NewEndPoint(&testUDPEP);
ASSERT_EQ(err, CHIP_NO_ERROR);
EXPECT_TRUE(SYSTEM_STATS_TEST_IN_USE(System::Stats::kInetLayer_NumUDPEps, 1));

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
SYSTEM_STATS_RESET(System::Stats::kInetLayer_NumTCPEps);
err = gTCP.NewEndPoint(&testTCPEP1);
ASSERT_EQ(err, CHIP_NO_ERROR);
EXPECT_TRUE(SYSTEM_STATS_TEST_IN_USE(System::Stats::kInetLayer_NumUDPEps, 1));
EXPECT_TRUE(SYSTEM_STATS_TEST_IN_USE(System::Stats::kInetLayer_NumTCPEps, 1));
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

err = InterfaceId::Null().GetLinkLocalAddr(&addr);

Expand Down Expand Up @@ -323,6 +327,7 @@ TEST_F(TestInetEndPoint, TestInetEndPointInternal)
testUDPEP->Free();
EXPECT_TRUE(SYSTEM_STATS_TEST_IN_USE(System::Stats::kInetLayer_NumUDPEps, 0));

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
// TcpEndPoint special cases to cover the error branch
err = testTCPEP1->GetPeerInfo(nullptr, nullptr);
EXPECT_EQ(err, CHIP_ERROR_INCORRECT_STATE);
Expand Down Expand Up @@ -362,14 +367,17 @@ TEST_F(TestInetEndPoint, TestInetEndPointInternal)
testTCPEP1->Free();
EXPECT_TRUE(SYSTEM_STATS_TEST_IN_USE(System::Stats::kInetLayer_NumTCPEps, 0));
EXPECT_TRUE(SYSTEM_STATS_TEST_HIGH_WATER_MARK(System::Stats::kInetLayer_NumTCPEps, 1));
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
}

#if !CHIP_SYSTEM_CONFIG_POOL_USE_HEAP
// Test the Inet resource limitations.
TEST_F(TestInetEndPoint, TestInetEndPointLimit)
{
UDPEndPoint * testUDPEP[INET_CONFIG_NUM_UDP_ENDPOINTS + 1] = { nullptr };
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
TCPEndPoint * testTCPEP[INET_CONFIG_NUM_TCP_ENDPOINTS + 1] = { nullptr };
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

CHIP_ERROR err = CHIP_NO_ERROR;

Expand All @@ -388,6 +396,7 @@ TEST_F(TestInetEndPoint, TestInetEndPointLimit)
const int udpHighWaterMark = udpCount;
EXPECT_TRUE(SYSTEM_STATS_TEST_HIGH_WATER_MARK(System::Stats::kInetLayer_NumUDPEps, udpHighWaterMark));

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
int tcpCount = 0;
SYSTEM_STATS_RESET(System::Stats::kInetLayer_NumTCPEps);
for (int i = INET_CONFIG_NUM_TCP_ENDPOINTS; i >= 0; --i)
Expand All @@ -402,6 +411,7 @@ TEST_F(TestInetEndPoint, TestInetEndPointLimit)
}
const int tcpHighWaterMark = tcpCount;
EXPECT_TRUE(SYSTEM_STATS_TEST_HIGH_WATER_MARK(System::Stats::kInetLayer_NumTCPEps, tcpHighWaterMark));
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

#if CHIP_SYSTEM_CONFIG_NUM_TIMERS
// Verify same aComplete and aAppState args do not exhaust timer pool
Expand Down
21 changes: 19 additions & 2 deletions src/inet/tests/inet-layer-test-tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ static const uint32_t kExpectedTxSizeDefault = kExpectedRxSizeDefault;

static const uint32_t kOptFlagsDefault = (kOptFlagUseIPv6 | kOptFlagUseUDPIP);

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
static TCPEndPoint * sTCPIPEndPoint = nullptr; // Used for connect/send/receive
static TCPEndPoint * sTCPIPListenEndPoint = nullptr; // Used for accept/listen
static UDPEndPoint * sUDPIPEndPoint = nullptr;
static const uint16_t kTCPPort = kUDPPort;
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

static UDPEndPoint * sUDPIPEndPoint = nullptr;

static const uint16_t kTCPPort = kUDPPort;
// clang-format off
static TestState sTestState =
{
Expand Down Expand Up @@ -184,6 +187,7 @@ static OptionSet * sToolOptionSets[] =
namespace chip {
namespace Inet {

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
class TCPTest
{
public:
Expand All @@ -193,6 +197,7 @@ class TCPTest
return endPoint->mState == TCPEndPoint::State::kConnected || endPoint->mState == TCPEndPoint::State::kReceiveShutdown;
}
};
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

} // namespace Inet
} // namespace chip
Expand Down Expand Up @@ -502,6 +507,7 @@ static bool HandleDataReceived(const PacketBufferHandle & aBuffer, bool aCheckBu

// TCP Endpoint Callbacks

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
void HandleTCPConnectionComplete(TCPEndPoint * aEndPoint, CHIP_ERROR aError)
{
CHIP_ERROR lStatus;
Expand Down Expand Up @@ -636,6 +642,7 @@ static void HandleTCPConnectionReceived(TCPEndPoint * aListenEndPoint, TCPEndPoi

sTCPIPEndPoint = aConnectEndPoint;
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

// UDP Endpoint Callbacks

Expand Down Expand Up @@ -673,11 +680,13 @@ static bool IsTransportReadyForSend()
return (sUDPIPEndPoint != nullptr);
}

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
if ((gOptFlags & kOptFlagUseTCPIP) == kOptFlagUseTCPIP)
{
return (sTCPIPEndPoint != nullptr) && (sTCPIPEndPoint->PendingSendLength() == 0) &&
TCPTest::StateIsConnectedOrReceiveShutdown(sTCPIPEndPoint);
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

return false;
}
Expand All @@ -686,6 +695,7 @@ static CHIP_ERROR PrepareTransportForSend()
{
CHIP_ERROR lStatus = CHIP_NO_ERROR;

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
if (gOptFlags & kOptFlagUseTCPIP)
{
if (sTCPIPEndPoint == nullptr)
Expand All @@ -702,6 +712,7 @@ static CHIP_ERROR PrepareTransportForSend()
INET_FAIL_ERROR(lStatus, "TCPEndPoint::Connect failed");
}
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

return (lStatus);
}
Expand All @@ -722,6 +733,7 @@ static CHIP_ERROR DriveSendForDestination(const IPAddress & aAddress, uint16_t a

ReturnErrorOnFailure(sUDPIPEndPoint->SendTo(aAddress, kUDPPort, std::move(lBuffer)));
}
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
else if ((gOptFlags & kOptFlagUseTCPIP) == kOptFlagUseTCPIP)
{
const uint32_t lFirstValue = sTestState.mStats.mTransmit.mActual;
Expand All @@ -737,6 +749,7 @@ static CHIP_ERROR DriveSendForDestination(const IPAddress & aAddress, uint16_t a

ReturnErrorOnFailure(sTCPIPEndPoint->Send(std::move(lBuffer)));
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -838,6 +851,7 @@ static void StartTest()
lStatus = sUDPIPEndPoint->Listen(HandleUDPMessageReceived, HandleUDPReceiveError);
INET_FAIL_ERROR(lStatus, "UDPEndPoint::Listen failed");
}
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
else if (gOptFlags & kOptFlagUseTCPIP)
{
const uint16_t lConnectionBacklogMax = 1;
Expand All @@ -855,6 +869,7 @@ static void StartTest()
lStatus = sTCPIPListenEndPoint->Listen(lConnectionBacklogMax);
INET_FAIL_ERROR(lStatus, "TCPEndPoint::Listen failed");
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
}

if (Common::IsReceiver())
Expand All @@ -870,6 +885,7 @@ static void CleanupTest()

// Release the resources associated with the allocated end points.

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
if (sTCPIPEndPoint != nullptr)
{
sTCPIPEndPoint->Close();
Expand All @@ -881,6 +897,7 @@ static void CleanupTest()
sTCPIPListenEndPoint->Shutdown();
sTCPIPListenEndPoint->Free();
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

if (sUDPIPEndPoint != nullptr)
{
Expand Down
Loading
Loading