PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
test_rpcTransport.cpp File Reference

Unit tests for the PROFINET DCE/RPC UDP transport. More...

#include <gtest/gtest.h>
#include <array>
#include <asio.hpp>
#include <chrono>
#include <cstdint>
#include <memory>
#include <string>
#include <system_error>
#include <thread>
#include <vector>
#include "profinet/AsioIoContextRunner.h"
#include "profinet/exceptions.h"
#include "profinet/rpcTransport.h"
+ Include dependency graph for test_rpcTransport.cpp:

Go to the source code of this file.

Classes

class  RpcTransportTests
 

Functions

 TEST_F (RpcTransportTests, ConstructorCreatesClosedTransport)
 
 TEST_F (RpcTransportTests, OpenCreatesUdpSocket)
 
 TEST_F (RpcTransportTests, OpenListenerBindsRequestedPort)
 
 TEST_F (RpcTransportTests, OpenRejectsInvalidIpv4Address)
 
 TEST_F (RpcTransportTests, OpenListenerRejectsOccupiedPort)
 
 TEST_F (RpcTransportTests, OpenUpdatesEndpointWhenTransportIsAlreadyOpen)
 
 TEST_F (RpcTransportTests, ReceiveReturnsDatagramAndSenderEndpoint)
 
 TEST_F (RpcTransportTests, ReceiveFailsWhenTransportIsClosed)
 
 TEST_F (RpcTransportTests, ReceiveRejectsZeroTimeout)
 
 TEST_F (RpcTransportTests, ReceiveRejectsNegativeTimeout)
 
 TEST_F (RpcTransportTests, ReceiveThrowsOnTimeout)
 
 TEST_F (RpcTransportTests, ReceiveThrowsSystemErrorWhenSocketIsCancelled)
 
 TEST_F (RpcTransportTests, SendToTransmitsDatagramToSuppliedEndpoint)
 
 TEST_F (RpcTransportTests, SendToFailsWhenTransportIsClosed)
 
 TEST_F (RpcTransportTests, SendToReportsUnderlyingSocketError)
 
 TEST_F (RpcTransportTests, SendReceiveReturnsEchoResponse)
 
 TEST_F (RpcTransportTests, SendReceiveUsesExternallyDrivenIoContext)
 
 TEST_F (RpcTransportTests, SendReceiveThrowsOnTimeout)
 
 TEST_F (RpcTransportTests, SendReceiveFailsWhenTransportIsClosed)
 
 TEST_F (RpcTransportTests, SendReceiveRejectsZeroTimeout)
 
 TEST_F (RpcTransportTests, SendReceiveRejectsNegativeTimeout)
 
 TEST_F (RpcTransportTests, SendReceiveThrowsSystemErrorWhenSocketIsCancelled)
 
 TEST_F (RpcTransportTests, SendTransmitsDatagramWithoutWaiting)
 
 TEST_F (RpcTransportTests, SendFailsWhenTransportIsClosed)
 
 TEST_F (RpcTransportTests, CloseClosesSocket)
 
 TEST_F (RpcTransportTests, CloseIsIdempotent)
 
 TEST_F (RpcTransportTests, CloseOnClosedTransportDoesNothing)
 
 TEST_F (RpcTransportTests, IsOpenReturnsTrueForOpenTransport)
 
 TEST_F (RpcTransportTests, IsOpenReturnsFalseForClosedTransport)
 
 TEST_F (RpcTransportTests, ReceiveUsesExternallyDrivenIoContext)
 

Detailed Description

Unit tests for the PROFINET DCE/RPC UDP transport.

Tests the synchronous RpcTransport wrapper around standalone Asio. The tests use localhost UDP communication so socket creation, transmission, reception, timeout handling, cancellation, listener mode, and shutdown are exercised without requiring a physical PROFINET IO-Device.

Definition in file test_rpcTransport.cpp.

Function Documentation

◆ TEST_F() [1/30]

TEST_F ( RpcTransportTests  ,
CloseClosesSocket   
)
Test:
Close closes an open UDP socket.

Definition at line 621 of file test_rpcTransport.cpp.

References profinet::rpc::RpcTransport::Close(), ioContext, profinet::rpc::RpcTransport::IsOpen(), and profinet::rpc::RpcTransport::Open().

+ Here is the call graph for this function:

◆ TEST_F() [2/30]

TEST_F ( RpcTransportTests  ,
CloseIsIdempotent   
)
Test:
Close is safe to call repeatedly.

Definition at line 635 of file test_rpcTransport.cpp.

References profinet::rpc::RpcTransport::Close(), ioContext, profinet::rpc::RpcTransport::IsOpen(), and profinet::rpc::RpcTransport::Open().

+ Here is the call graph for this function:

◆ TEST_F() [3/30]

TEST_F ( RpcTransportTests  ,
CloseOnClosedTransportDoesNothing   
)
Test:
Close is safe to call on an already closed transport.

Definition at line 648 of file test_rpcTransport.cpp.

References profinet::rpc::RpcTransport::Close(), ioContext, and profinet::rpc::RpcTransport::IsOpen().

+ Here is the call graph for this function:

◆ TEST_F() [4/30]

TEST_F ( RpcTransportTests  ,
ConstructorCreatesClosedTransport   
)
Test:
A transport can be constructed with an Asio execution context.

Definition at line 237 of file test_rpcTransport.cpp.

References ioContext, and profinet::rpc::RpcTransport::IsOpen().

+ Here is the call graph for this function:

◆ TEST_F() [5/30]

TEST_F ( RpcTransportTests  ,
IsOpenReturnsFalseForClosedTransport   
)
Test:
IsOpen reports false after the UDP socket has been closed.

Definition at line 672 of file test_rpcTransport.cpp.

References profinet::rpc::RpcTransport::Close(), ioContext, profinet::rpc::RpcTransport::IsOpen(), and profinet::rpc::RpcTransport::Open().

+ Here is the call graph for this function:

◆ TEST_F() [6/30]

TEST_F ( RpcTransportTests  ,
IsOpenReturnsTrueForOpenTransport   
)
Test:
IsOpen reports true after the UDP socket has been successfully opened.

Definition at line 660 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::IsOpen(), and profinet::rpc::RpcTransport::Open().

+ Here is the call graph for this function:

◆ TEST_F() [7/30]

TEST_F ( RpcTransportTests  ,
OpenCreatesUdpSocket   
)
Test:
Open creates a UDP socket for a valid IPv4 client endpoint.

Definition at line 245 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::IsOpen(), and profinet::rpc::RpcTransport::Open().

+ Here is the call graph for this function:

◆ TEST_F() [8/30]

TEST_F ( RpcTransportTests  ,
OpenListenerBindsRequestedPort   
)
Test:
Open binds a UDP socket to the requested local endpoint when listener mode is enabled.

Definition at line 257 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::IsOpen(), and profinet::rpc::RpcTransport::Open().

+ Here is the call graph for this function:

◆ TEST_F() [9/30]

TEST_F ( RpcTransportTests  ,
OpenListenerRejectsOccupiedPort   
)
Test:
Open reports a bind failure when listener mode targets an occupied UDP port.

Definition at line 279 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::IsOpen(), and profinet::rpc::RpcTransport::Open().

+ Here is the call graph for this function:

◆ TEST_F() [10/30]

TEST_F ( RpcTransportTests  ,
OpenRejectsInvalidIpv4Address   
)
Test:
Open rejects an invalid IPv4 address before attempting to open the UDP socket.

Definition at line 269 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::IsOpen(), and profinet::rpc::RpcTransport::Open().

+ Here is the call graph for this function:

◆ TEST_F() [11/30]

TEST_F ( RpcTransportTests  ,
OpenUpdatesEndpointWhenTransportIsAlreadyOpen   
)
Test:
Open updates the client destination when called again after the socket is already open.

Definition at line 297 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::IsOpen(), profinet::rpc::RpcTransport::Open(), and profinet::rpc::RpcTransport::Send().

+ Here is the call graph for this function:

◆ TEST_F() [12/30]

TEST_F ( RpcTransportTests  ,
ReceiveFailsWhenTransportIsClosed   
)
Test:
Receive rejects calls when the transport socket is closed.

Definition at line 343 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Receive(), and remoteEndpoint.

+ Here is the call graph for this function:

◆ TEST_F() [13/30]

TEST_F ( RpcTransportTests  ,
ReceiveRejectsNegativeTimeout   
)
Test:
Receive rejects a negative timeout before starting asynchronous operations.

Definition at line 366 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), profinet::rpc::RpcTransport::Receive(), and remoteEndpoint.

+ Here is the call graph for this function:

◆ TEST_F() [14/30]

TEST_F ( RpcTransportTests  ,
ReceiveRejectsZeroTimeout   
)
Test:
Receive rejects a zero timeout before starting asynchronous operations.

Definition at line 353 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), profinet::rpc::RpcTransport::Receive(), and remoteEndpoint.

+ Here is the call graph for this function:

◆ TEST_F() [15/30]

TEST_F ( RpcTransportTests  ,
ReceiveReturnsDatagramAndSenderEndpoint   
)
Test:
Receive returns the datagram and captures the sender endpoint in listener mode.

Definition at line 323 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), profinet::rpc::RpcTransport::Receive(), and remoteEndpoint.

+ Here is the call graph for this function:

◆ TEST_F() [16/30]

TEST_F ( RpcTransportTests  ,
ReceiveThrowsOnTimeout   
)
Test:
Receive throws RPCTimeoutError when no datagram arrives before the timeout.

Definition at line 379 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), profinet::rpc::RpcTransport::Receive(), and remoteEndpoint.

+ Here is the call graph for this function:

◆ TEST_F() [17/30]

TEST_F ( RpcTransportTests  ,
ReceiveThrowsSystemErrorWhenSocketIsCancelled   
)
Test:
Receive converts socket cancellation into std::system_error when the cancellation was not caused by the timeout timer.

Definition at line 392 of file test_rpcTransport.cpp.

References profinet::rpc::RpcTransport::Close(), ioContext, profinet::rpc::RpcTransport::Open(), profinet::rpc::RpcTransport::Receive(), and remoteEndpoint.

+ Here is the call graph for this function:

◆ TEST_F() [18/30]

TEST_F ( RpcTransportTests  ,
ReceiveUsesExternallyDrivenIoContext   
)
Test:
Verifies that RpcTransport::Receive() relies on an externally driven Asio execution context and does not run the context itself.

A dedicated AsioIoContextRunner drives the io_context from another thread. The transport then starts its asynchronous receive operation and blocks synchronously until that operation completes.

This test is specifically intended to protect the execution model where RpcTransport schedules asynchronous work but does not call asio::io_context::run() or asio::io_context::restart() itself.

Definition at line 696 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), profinet::rpc::RpcTransport::Receive(), and remoteEndpoint.

+ Here is the call graph for this function:

◆ TEST_F() [19/30]

TEST_F ( RpcTransportTests  ,
SendFailsWhenTransportIsClosed   
)
Test:
Send rejects calls when the transport has not been opened.

Definition at line 611 of file test_rpcTransport.cpp.

References ioContext, and profinet::rpc::RpcTransport::Send().

+ Here is the call graph for this function:

◆ TEST_F() [20/30]

TEST_F ( RpcTransportTests  ,
SendReceiveFailsWhenTransportIsClosed   
)
Test:
SendReceive throws std::system_error when the transport socket is closed.

Definition at line 525 of file test_rpcTransport.cpp.

References ioContext, and profinet::rpc::RpcTransport::SendReceive().

+ Here is the call graph for this function:

◆ TEST_F() [21/30]

TEST_F ( RpcTransportTests  ,
SendReceiveRejectsNegativeTimeout   
)
Test:
SendReceive rejects a negative timeout before sending the request.

Definition at line 551 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), and profinet::rpc::RpcTransport::SendReceive().

+ Here is the call graph for this function:

◆ TEST_F() [22/30]

TEST_F ( RpcTransportTests  ,
SendReceiveRejectsZeroTimeout   
)
Test:
SendReceive rejects a zero timeout before sending the request.

Definition at line 535 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), and profinet::rpc::RpcTransport::SendReceive().

+ Here is the call graph for this function:

◆ TEST_F() [23/30]

TEST_F ( RpcTransportTests  ,
SendReceiveReturnsEchoResponse   
)
Test:
SendReceive sends a datagram and returns the echoed response.

Definition at line 460 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), and profinet::rpc::RpcTransport::SendReceive().

+ Here is the call graph for this function:

◆ TEST_F() [24/30]

TEST_F ( RpcTransportTests  ,
SendReceiveThrowsOnTimeout   
)
Test:
SendReceive throws RPCTimeoutError when the destination receives the request but sends no response.

Definition at line 511 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), and profinet::rpc::RpcTransport::SendReceive().

+ Here is the call graph for this function:

◆ TEST_F() [25/30]

TEST_F ( RpcTransportTests  ,
SendReceiveThrowsSystemErrorWhenSocketIsCancelled   
)
Test:
SendReceive converts socket cancellation into std::system_error when the cancellation was not caused by the timeout timer.

Definition at line 567 of file test_rpcTransport.cpp.

References profinet::rpc::RpcTransport::Close(), ioContext, profinet::rpc::RpcTransport::Open(), and profinet::rpc::RpcTransport::SendReceive().

+ Here is the call graph for this function:

◆ TEST_F() [26/30]

TEST_F ( RpcTransportTests  ,
SendReceiveUsesExternallyDrivenIoContext   
)
Test:
Verifies that RpcTransport::SendReceive() completes when its Asio execution context is driven externally.

The transport and the test echo server use independent execution contexts. The transport's context is driven only by AsioIoContextRunner, proving that SendReceive() does not call io_context::run() internally.

Definition at line 484 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), and profinet::rpc::RpcTransport::SendReceive().

+ Here is the call graph for this function:

◆ TEST_F() [27/30]

TEST_F ( RpcTransportTests  ,
SendToFailsWhenTransportIsClosed   
)
Test:
SendTo rejects calls when the transport socket is closed.

Definition at line 437 of file test_rpcTransport.cpp.

References ioContext, and profinet::rpc::RpcTransport::SendTo().

+ Here is the call graph for this function:

◆ TEST_F() [28/30]

TEST_F ( RpcTransportTests  ,
SendToReportsUnderlyingSocketError   
)
Test:
SendTo reports the underlying UDP send error when the destination uses the wrong IP address family.

Definition at line 448 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), and profinet::rpc::RpcTransport::SendTo().

+ Here is the call graph for this function:

◆ TEST_F() [29/30]

TEST_F ( RpcTransportTests  ,
SendToTransmitsDatagramToSuppliedEndpoint   
)
Test:
SendTo sends exactly the supplied datagram to the supplied destination endpoint.

Definition at line 415 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), and profinet::rpc::RpcTransport::SendTo().

+ Here is the call graph for this function:

◆ TEST_F() [30/30]

TEST_F ( RpcTransportTests  ,
SendTransmitsDatagramWithoutWaiting   
)
Test:
Send transmits a UDP datagram without waiting for a response.

Definition at line 592 of file test_rpcTransport.cpp.

References ioContext, profinet::rpc::RpcTransport::Open(), and profinet::rpc::RpcTransport::Send().

+ Here is the call graph for this function: