Skip to content

Commit d689614

Browse files
committed
Fix test code build issues when INET_CONFIG_TCP_ENDPOINT is set to false
1 parent 6cdd274 commit d689614

File tree

5 files changed

+88
-33
lines changed

5 files changed

+88
-33
lines changed

src/inet/tests/TestInetEndPoint.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -256,20 +256,24 @@ TEST_F(TestInetEndPoint, TestInetEndPointInternal)
256256
InterfaceId intId;
257257

258258
// EndPoint
259-
UDPEndPoint * testUDPEP = nullptr;
259+
UDPEndPoint * testUDPEP = nullptr;
260+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
260261
TCPEndPoint * testTCPEP1 = nullptr;
261-
PacketBufferHandle buf = PacketBufferHandle::New(PacketBuffer::kMaxSize);
262+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
263+
PacketBufferHandle buf = PacketBufferHandle::New(PacketBuffer::kMaxSize);
262264

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

271+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
269272
SYSTEM_STATS_RESET(System::Stats::kInetLayer_NumTCPEps);
270273
err = gTCP.NewEndPoint(&testTCPEP1);
271274
ASSERT_EQ(err, CHIP_NO_ERROR);
272-
EXPECT_TRUE(SYSTEM_STATS_TEST_IN_USE(System::Stats::kInetLayer_NumUDPEps, 1));
275+
EXPECT_TRUE(SYSTEM_STATS_TEST_IN_USE(System::Stats::kInetLayer_NumTCPEps, 1));
276+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
273277

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

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

330+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
326331
// TcpEndPoint special cases to cover the error branch
327332
err = testTCPEP1->GetPeerInfo(nullptr, nullptr);
328333
EXPECT_EQ(err, CHIP_ERROR_INCORRECT_STATE);
@@ -362,14 +367,17 @@ TEST_F(TestInetEndPoint, TestInetEndPointInternal)
362367
testTCPEP1->Free();
363368
EXPECT_TRUE(SYSTEM_STATS_TEST_IN_USE(System::Stats::kInetLayer_NumTCPEps, 0));
364369
EXPECT_TRUE(SYSTEM_STATS_TEST_HIGH_WATER_MARK(System::Stats::kInetLayer_NumTCPEps, 1));
370+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
365371
}
366372

367373
#if !CHIP_SYSTEM_CONFIG_POOL_USE_HEAP
368374
// Test the Inet resource limitations.
369375
TEST_F(TestInetEndPoint, TestInetEndPointLimit)
370376
{
371377
UDPEndPoint * testUDPEP[INET_CONFIG_NUM_UDP_ENDPOINTS + 1] = { nullptr };
378+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
372379
TCPEndPoint * testTCPEP[INET_CONFIG_NUM_TCP_ENDPOINTS + 1] = { nullptr };
380+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
373381

374382
CHIP_ERROR err = CHIP_NO_ERROR;
375383

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

399+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
391400
int tcpCount = 0;
392401
SYSTEM_STATS_RESET(System::Stats::kInetLayer_NumTCPEps);
393402
for (int i = INET_CONFIG_NUM_TCP_ENDPOINTS; i >= 0; --i)
@@ -402,6 +411,7 @@ TEST_F(TestInetEndPoint, TestInetEndPointLimit)
402411
}
403412
const int tcpHighWaterMark = tcpCount;
404413
EXPECT_TRUE(SYSTEM_STATS_TEST_HIGH_WATER_MARK(System::Stats::kInetLayer_NumTCPEps, tcpHighWaterMark));
414+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
405415

406416
#if CHIP_SYSTEM_CONFIG_NUM_TIMERS
407417
// Verify same aComplete and aAppState args do not exhaust timer pool

src/inet/tests/inet-layer-test-tool.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@ static const uint32_t kExpectedTxSizeDefault = kExpectedRxSizeDefault;
8888

8989
static const uint32_t kOptFlagsDefault = (kOptFlagUseIPv6 | kOptFlagUseUDPIP);
9090

91+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
9192
static TCPEndPoint * sTCPIPEndPoint = nullptr; // Used for connect/send/receive
9293
static TCPEndPoint * sTCPIPListenEndPoint = nullptr; // Used for accept/listen
93-
static UDPEndPoint * sUDPIPEndPoint = nullptr;
94+
static const uint16_t kTCPPort = kUDPPort;
95+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
96+
97+
static UDPEndPoint * sUDPIPEndPoint = nullptr;
9498

95-
static const uint16_t kTCPPort = kUDPPort;
9699
// clang-format off
97100
static TestState sTestState =
98101
{
@@ -184,6 +187,7 @@ static OptionSet * sToolOptionSets[] =
184187
namespace chip {
185188
namespace Inet {
186189

190+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
187191
class TCPTest
188192
{
189193
public:
@@ -193,6 +197,7 @@ class TCPTest
193197
return endPoint->mState == TCPEndPoint::State::kConnected || endPoint->mState == TCPEndPoint::State::kReceiveShutdown;
194198
}
195199
};
200+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
196201

197202
} // namespace Inet
198203
} // namespace chip
@@ -502,6 +507,7 @@ static bool HandleDataReceived(const PacketBufferHandle & aBuffer, bool aCheckBu
502507

503508
// TCP Endpoint Callbacks
504509

510+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
505511
void HandleTCPConnectionComplete(TCPEndPoint * aEndPoint, CHIP_ERROR aError)
506512
{
507513
CHIP_ERROR lStatus;
@@ -636,6 +642,7 @@ static void HandleTCPConnectionReceived(TCPEndPoint * aListenEndPoint, TCPEndPoi
636642

637643
sTCPIPEndPoint = aConnectEndPoint;
638644
}
645+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
639646

640647
// UDP Endpoint Callbacks
641648

@@ -673,11 +680,13 @@ static bool IsTransportReadyForSend()
673680
return (sUDPIPEndPoint != nullptr);
674681
}
675682

683+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
676684
if ((gOptFlags & kOptFlagUseTCPIP) == kOptFlagUseTCPIP)
677685
{
678686
return (sTCPIPEndPoint != nullptr) && (sTCPIPEndPoint->PendingSendLength() == 0) &&
679687
TCPTest::StateIsConnectedOrReceiveShutdown(sTCPIPEndPoint);
680688
}
689+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
681690

682691
return false;
683692
}
@@ -686,6 +695,7 @@ static CHIP_ERROR PrepareTransportForSend()
686695
{
687696
CHIP_ERROR lStatus = CHIP_NO_ERROR;
688697

698+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
689699
if (gOptFlags & kOptFlagUseTCPIP)
690700
{
691701
if (sTCPIPEndPoint == nullptr)
@@ -702,6 +712,7 @@ static CHIP_ERROR PrepareTransportForSend()
702712
INET_FAIL_ERROR(lStatus, "TCPEndPoint::Connect failed");
703713
}
704714
}
715+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
705716

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

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

738750
ReturnErrorOnFailure(sTCPIPEndPoint->Send(std::move(lBuffer)));
739751
}
752+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
740753

741754
return CHIP_NO_ERROR;
742755
}
@@ -838,6 +851,7 @@ static void StartTest()
838851
lStatus = sUDPIPEndPoint->Listen(HandleUDPMessageReceived, HandleUDPReceiveError);
839852
INET_FAIL_ERROR(lStatus, "UDPEndPoint::Listen failed");
840853
}
854+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
841855
else if (gOptFlags & kOptFlagUseTCPIP)
842856
{
843857
const uint16_t lConnectionBacklogMax = 1;
@@ -855,6 +869,7 @@ static void StartTest()
855869
lStatus = sTCPIPListenEndPoint->Listen(lConnectionBacklogMax);
856870
INET_FAIL_ERROR(lStatus, "TCPEndPoint::Listen failed");
857871
}
872+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
858873
}
859874

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

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

888+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
873889
if (sTCPIPEndPoint != nullptr)
874890
{
875891
sTCPIPEndPoint->Close();
@@ -881,6 +897,7 @@ static void CleanupTest()
881897
sTCPIPListenEndPoint->Shutdown();
882898
sTCPIPListenEndPoint->Free();
883899
}
900+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
884901

885902
if (sUDPIPEndPoint != nullptr)
886903
{

0 commit comments

Comments
 (0)