Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::TwoNodeDatagramTest Class Reference

Test base class for OpenLCB unittests that simulate two physical or virtual nodes talking to each other with the canbus protocol. More...

#include <async_datagram_test_helper.hxx>

Inheritance diagram for openlcb::TwoNodeDatagramTest:
openlcb::AsyncDatagramTest openlcb::AsyncNodeTest openlcb::AsyncIfTest AsyncCanTest openlcb::StreamTestBase

Protected Types

enum  { OTHER_NODE_ID = TEST_NODE_ID + 0x100 , OTHER_NODE_ALIAS = 0x225 }
 

Protected Member Functions

NodeHandle other_handle ()
 
void setup_other_node (bool separate_if)
 
void expect_other_node_lookup ()
 Adds the necessary expectations for the address lookup reuqests on the CANbus by the first datagram being sent from node_ to otherNode_.
 
- Protected Member Functions inherited from openlcb::AsyncNodeTest
void wait_for_event_thread ()
 
- Protected Member Functions inherited from openlcb::AsyncIfTest
void create_allocated_alias ()
 Creates an alias allocator flow, and injects an already allocated alias.
 
void inject_allocated_alias (NodeAlias alias)
 
void expect_next_alias_allocation (NodeAlias a=0)
 
BarrierNotifiableget_notifiable ()
 
void wait_for_notification ()
 
- Protected Member Functions inherited from AsyncCanTest
void wait ()
 Delays the current thread until we are certain that all asynchrnous processing has completed.
 
void twait ()
 Delays the current thread until all asynchronous processing and all pending timers have completed.
 
void expect_any_packet ()
 Ignores all produced packets.
 
void print_all_packets ()
 Prints all packets sent to the canbus until the end of the current test function.
 
void send_packet (const string &gc_packet)
 Injects a packet to the interface.
 
void clear_expect (bool strict=false)
 Clears all existing expectations on the CAN-bus packets.
 
void send_packet_and_flush_expect (const string &pkt)
 Sends a packet to the canbus, waits for the executor to clear, and then verifies all previous expectations.
 

Protected Attributes

std::unique_ptr< DefaultNodeotherNode_
 
std::unique_ptr< IfCanotherIfCan_
 
IfCanotherNodeIf_
 
std::unique_ptr< CanDatagramServiceotherDatagramSupport_
 
CanDatagramServiceotherNodeDatagram_
 
- Protected Attributes inherited from openlcb::AsyncDatagramTest
CanDatagramService datagram_support_
 
- Protected Attributes inherited from openlcb::AsyncNodeTest
EventService eventService_
 
std::unique_ptr< DefaultNodeownedNode_
 
Nodenode_
 
- Protected Attributes inherited from openlcb::AsyncIfTest
SyncNotifiable n_
 
BarrierNotifiable bn_
 
std::unique_ptr< IfCanifCan_
 The interface under test.
 
AliasInfo testAlias_
 Temporary object used to send aliases around in the alias allocator flow.
 
NodeAlias aliasSeed_
 The next alias we will make the allocator create.
 
bool pendingAliasAllocation_
 true if we have a pending async alias allocation task.
 
- Protected Attributes inherited from AsyncCanTest
NiceMock< MockSendcanBus_
 Helper object for setting expectations on the packets sent on the bus.
 
std::unique_ptr< HubPortprinter_
 Object for debug-printing every packet (if requested).
 

Additional Inherited Members

- Static Public Member Functions inherited from AsyncCanTest
static void SetUpTestCase ()
 Initializes test case with CAN0.
 
static void TearDownTestCase ()
 De-Initializes test case with CAN0.
 
- Static Protected Attributes inherited from openlcb::AsyncIfTest
static int local_alias_cache_size = 10
 
static int local_node_count = 9
 
static int remote_alias_cache_size = 10
 

Detailed Description

Test base class for OpenLCB unittests that simulate two physical or virtual nodes talking to each other with the canbus protocol.

The two modes of operation are as follows:

1) The test base class creates one interface on the canbus, and adds two virtual nodes to this interface. These virtual nodes will be able to send datagrams to each other via local loopback without generating any CANbus traffic visible outside. This mode does not test the CAN frame fragmentation and parsing code.

2) the test base class creates two independent CAN interface objects that will be both wired to the same CAN hub (aka virtual CAN bus). The two interfaces will each have one virtual node (but separate alias allocation, local and remote alias cache and local nodes map structure). Talking between these nodes will cause the datagram to be fragmented and sent onto the CAN bus. Using this mode will require tests to make expectations on the canbus traffic, or ignore all canbus packets from the test correctness perspective.

Definition at line 76 of file async_datagram_test_helper.hxx.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected

Definition at line 79 of file async_datagram_test_helper.hxx.

Member Function Documentation

◆ expect_other_node_lookup()

void openlcb::TwoNodeDatagramTest::expect_other_node_lookup ( )
inlineprotected

Adds the necessary expectations for the address lookup reuqests on the CANbus by the first datagram being sent from node_ to otherNode_.

Not needed for mode 1 operation.

Definition at line 125 of file async_datagram_test_helper.hxx.

◆ other_handle()

NodeHandle openlcb::TwoNodeDatagramTest::other_handle ( )
inlineprotected
Returns
NodeHandle for the other node.

Definition at line 86 of file async_datagram_test_helper.hxx.

◆ setup_other_node()

void openlcb::TwoNodeDatagramTest::setup_other_node ( bool  separate_if)
inlineprotected
Parameters
separate_ifdefines which mode the test base should operate in. false = mode 1 (one interface, two virtual nodes); true = mode 2 (two interfaces).

Definition at line 97 of file async_datagram_test_helper.hxx.

Member Data Documentation

◆ otherDatagramSupport_

std::unique_ptr<CanDatagramService> openlcb::TwoNodeDatagramTest::otherDatagramSupport_
protected

Definition at line 137 of file async_datagram_test_helper.hxx.

◆ otherIfCan_

std::unique_ptr<IfCan> openlcb::TwoNodeDatagramTest::otherIfCan_
protected

Definition at line 135 of file async_datagram_test_helper.hxx.

◆ otherNode_

std::unique_ptr<DefaultNode> openlcb::TwoNodeDatagramTest::otherNode_
protected

Definition at line 133 of file async_datagram_test_helper.hxx.

◆ otherNodeDatagram_

CanDatagramService* openlcb::TwoNodeDatagramTest::otherNodeDatagram_
protected

Definition at line 138 of file async_datagram_test_helper.hxx.

◆ otherNodeIf_

IfCan* openlcb::TwoNodeDatagramTest::otherNodeIf_
protected

Definition at line 136 of file async_datagram_test_helper.hxx.


The documentation for this class was generated from the following file: