Skip to content

Commit b4d2da5

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

File tree

5 files changed

+66
-22
lines changed

5 files changed

+66
-22
lines changed

src/inet/tests/TestInetEndPoint.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ TEST_F(TestInetEndPoint, TestInetEndPointInternal)
257257

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

263265
// init all the EndPoints
@@ -266,10 +268,12 @@ TEST_F(TestInetEndPoint, TestInetEndPointInternal)
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

+18-1
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
94+
static const uint16_t kTCPPort = kUDPPort;
95+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
96+
9397
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
{

src/messaging/tests/echo/echo_requester.cpp

+27-14
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,27 @@ constexpr chip::FabricIndex gFabricIndex = 0;
6363
chip::Protocols::Echo::EchoClient gEchoClient;
6464

6565
chip::TransportMgr<chip::Transport::UDP> gUDPManager;
66+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
6667
chip::TransportMgr<chip::Transport::TCP<kMaxTcpActiveConnectionCount, kMaxTcpPendingPackets>> gTCPManager;
67-
chip::Inet::IPAddress gDestAddr;
68-
chip::SessionHolder gSession;
6968

7069
chip::Transport::AppTCPConnectionCallbackCtxt gAppTCPConnCbCtxt;
7170
chip::Transport::ActiveTCPConnectionState * gActiveTCPConnState = nullptr;
7271

73-
// The last time a CHIP Echo was attempted to be sent.
74-
chip::System::Clock::Timestamp gLastEchoTime = chip::System::Clock::kZero;
72+
static void HandleConnectionAttemptComplete(chip::Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr);
73+
static void HandleConnectionClosed(chip::Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr);
7574

7675
// True, if client is still connecting to the server, false otherwise.
7776
static bool gClientConInProgress = false;
7877

7978
// True, once client connection to server is established.
8079
static bool gClientConEstablished = false;
80+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
81+
82+
chip::Inet::IPAddress gDestAddr;
83+
chip::SessionHolder gSession;
84+
85+
// The last time a CHIP Echo was attempted to be sent.
86+
chip::System::Clock::Timestamp gLastEchoTime = chip::System::Clock::kZero;
8187

8288
// The handle to the TCP connection to the peer.
8389
// static chip::Transport::ActiveTCPConnectionState * gCon = nullptr;
@@ -95,9 +101,6 @@ uint64_t gTCPConnAttemptCount = 0;
95101
CHIP_ERROR SendEchoRequest();
96102
void EchoTimerHandler(chip::System::Layer * systemLayer, void * appState);
97103

98-
static void HandleConnectionAttemptComplete(chip::Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr);
99-
static void HandleConnectionClosed(chip::Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr);
100-
101104
void Shutdown()
102105
{
103106
chip::DeviceLayer::SystemLayer().CancelTimer(EchoTimerHandler, nullptr);
@@ -170,7 +173,7 @@ CHIP_ERROR SendEchoRequest()
170173
return err;
171174
}
172175

173-
CHIP_ERROR EstablishSecureSession(chip::Transport::ActiveTCPConnectionState * conn = nullptr)
176+
CHIP_ERROR EstablishSecureSession()
174177
{
175178
char peerAddrBuf[chip::Transport::PeerAddress::kMaxToStringSize];
176179
chip::Transport::PeerAddress peerAddr;
@@ -195,18 +198,21 @@ CHIP_ERROR EstablishSecureSession(chip::Transport::ActiveTCPConnectionState * co
195198
}
196199
else
197200
{
201+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
198202
if (gUseTCP)
199203
{
200-
printf("Associating secure session with connection %p\n", conn);
201-
gSession.Get().Value()->AsSecureSession()->SetTCPConnection(conn);
204+
printf("Associating secure session with connection %p\n", gActiveTCPConnState);
205+
gSession.Get().Value()->AsSecureSession()->SetTCPConnection(gActiveTCPConnState);
202206
}
207+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
203208

204209
printf("Successfully established secure session with peer at %s\n", peerAddrBuf);
205210
}
206211

207212
return err;
208213
}
209214

215+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
210216
void CloseConnection()
211217
{
212218
char peerAddrBuf[chip::Transport::PeerAddress::kMaxToStringSize];
@@ -225,7 +231,7 @@ void HandleConnectionAttemptComplete(chip::Transport::ActiveTCPConnectionState *
225231
{
226232
chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
227233

228-
if (err != CHIP_NO_ERROR)
234+
if (err != CHIP_NO_ERROR || conn != gActiveTCPConnState)
229235
{
230236
printf("Connection FAILED with err: %s\n", chip::ErrorStr(err));
231237

@@ -235,7 +241,7 @@ void HandleConnectionAttemptComplete(chip::Transport::ActiveTCPConnectionState *
235241
return;
236242
}
237243

238-
err = EstablishSecureSession(conn);
244+
err = EstablishSecureSession();
239245
if (err != CHIP_NO_ERROR)
240246
{
241247
printf("Secure session FAILED with err: %s\n", chip::ErrorStr(err));
@@ -281,6 +287,7 @@ void EstablishTCPConnection()
281287

282288
gClientConInProgress = true;
283289
}
290+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
284291

285292
void HandleEchoResponseReceived(chip::Messaging::ExchangeContext * ec, chip::System::PacketBufferHandle && payload)
286293
{
@@ -332,6 +339,7 @@ int main(int argc, char * argv[])
332339

333340
InitializeChip();
334341

342+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
335343
if (gUseTCP)
336344
{
337345
err = gTCPManager.Init(chip::Transport::TcpListenParameters(chip::DeviceLayer::TCPEndPointManager())
@@ -348,6 +356,7 @@ int main(int argc, char * argv[])
348356
gAppTCPConnCbCtxt.connClosedCb = HandleConnectionClosed;
349357
}
350358
else
359+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
351360
{
352361
err = gUDPManager.Init(chip::Transport::UdpListenParameters(chip::DeviceLayer::UDPEndPointManager())
353362
.SetAddressType(chip::Inet::IPAddressType::kIPv6)
@@ -365,13 +374,14 @@ int main(int argc, char * argv[])
365374
err = gMessageCounterManager.Init(&gExchangeManager);
366375
SuccessOrExit(err);
367376

377+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
368378
if (gUseTCP)
369379
{
370380

371381
while (!gClientConEstablished)
372382
{
373383
// For TCP transport, attempt to establish the connection to the CHIP echo responder.
374-
// On Connection completion, call EstablishSecureSession(conn);
384+
// On Connection completion, call EstablishSecureSession();
375385
EstablishTCPConnection();
376386

377387
chip::DeviceLayer::PlatformMgr().RunEventLoop();
@@ -383,9 +393,10 @@ int main(int argc, char * argv[])
383393
}
384394
}
385395
else
396+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
386397
{
387398
// Start the CHIP session to the CHIP echo responder.
388-
err = EstablishSecureSession(nullptr);
399+
err = EstablishSecureSession();
389400
SuccessOrExit(err);
390401
}
391402

@@ -402,11 +413,13 @@ int main(int argc, char * argv[])
402413

403414
gUDPManager.Close();
404415

416+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
405417
if (gUseTCP)
406418
{
407419
gTCPManager.TCPDisconnect(chip::Transport::PeerAddress::TCP(gDestAddr));
408420
}
409421
gTCPManager.Close();
422+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
410423

411424
Shutdown();
412425

src/messaging/tests/echo/echo_responder.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ namespace {
4545
// The EchoServer object.
4646
chip::Protocols::Echo::EchoServer gEchoServer;
4747
chip::TransportMgr<chip::Transport::UDP> gUDPManager;
48+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
4849
chip::TransportMgr<chip::Transport::TCP<kMaxTcpActiveConnectionCount, kMaxTcpPendingPackets>> gTCPManager;
50+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
4951
chip::SessionHolder gSession;
5052

5153
// Callback handler when a CHIP EchoRequest is received.
@@ -85,13 +87,15 @@ int main(int argc, char * argv[])
8587

8688
if (useTCP)
8789
{
90+
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
8891
err = gTCPManager.Init(chip::Transport::TcpListenParameters(chip::DeviceLayer::TCPEndPointManager())
8992
.SetAddressType(chip::Inet::IPAddressType::kIPv6));
9093
SuccessOrExit(err);
9194

9295
err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage,
9396
&gFabricTable, gSessionKeystore);
9497
SuccessOrExit(err);
98+
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
9599
}
96100
else
97101
{

0 commit comments

Comments
 (0)