transport_stats_provider.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #include <gtest/gtest.h>
7 #include "helpers.hpp"
8 
9 
10 TEST(TransportStatsProvider, Basic)
11 {
13 
15 
18 
19  ASSERT_LE(0, tsp.start());
20 
22 
23  /*
24  * First request
25  */
26  ASSERT_LE(0, tsp_cln.call(1, uavcan::protocol::GetTransportStats::Request()));
27  ASSERT_LE(0, nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(10)));
28 
29  ASSERT_TRUE(tsp_cln.collector.result.get());
30  ASSERT_TRUE(tsp_cln.collector.result->isSuccessful());
31  ASSERT_EQ(0, tsp_cln.collector.result->getResponse().transfer_errors);
32  ASSERT_EQ(1, tsp_cln.collector.result->getResponse().transfers_rx);
33  ASSERT_EQ(0, tsp_cln.collector.result->getResponse().transfers_tx);
34  ASSERT_EQ(1, tsp_cln.collector.result->getResponse().can_iface_stats.size());
35  ASSERT_EQ(0, tsp_cln.collector.result->getResponse().can_iface_stats[0].errors);
36  ASSERT_EQ(1, tsp_cln.collector.result->getResponse().can_iface_stats[0].frames_rx);
37  ASSERT_EQ(0, tsp_cln.collector.result->getResponse().can_iface_stats[0].frames_tx);
38 
39  /*
40  * Second request
41  */
42  ASSERT_LE(0, tsp_cln.call(1, uavcan::protocol::GetTransportStats::Request()));
43  ASSERT_LE(0, nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(10)));
44 
45  ASSERT_TRUE(tsp_cln.collector.result.get());
46  ASSERT_EQ(0, tsp_cln.collector.result->getResponse().transfer_errors);
47  ASSERT_EQ(2, tsp_cln.collector.result->getResponse().transfers_rx);
48  ASSERT_EQ(1, tsp_cln.collector.result->getResponse().transfers_tx);
49  ASSERT_EQ(1, tsp_cln.collector.result->getResponse().can_iface_stats.size());
50  ASSERT_EQ(0, tsp_cln.collector.result->getResponse().can_iface_stats[0].errors);
51  ASSERT_EQ(2, tsp_cln.collector.result->getResponse().can_iface_stats[0].frames_rx);
52  ASSERT_EQ(6, tsp_cln.collector.result->getResponse().can_iface_stats[0].frames_tx);
53 
54  /*
55  * Sending a malformed frame, it must be registered as tranfer error
56  */
57  uavcan::Frame frame(uavcan::protocol::GetTransportStats::DefaultDataTypeID, uavcan::TransferTypeServiceRequest,
58  2, 1, 1);
59  frame.setStartOfTransfer(true);
60  frame.setEndOfTransfer(true);
61  uavcan::CanFrame can_frame;
62  ASSERT_TRUE(frame.compile(can_frame));
63  nodes.can_a.read_queue.push(can_frame);
64 
65  ASSERT_LE(0, nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(10)));
66 
67  /*
68  * Introducing a CAN driver error
69  */
70  nodes.can_a.error_count = 72;
71 
72  /*
73  * Third request
74  */
75  ASSERT_LE(0, tsp_cln.call(1, uavcan::protocol::GetTransportStats::Request()));
76  ASSERT_LE(0, nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(10)));
77 
78  ASSERT_TRUE(tsp_cln.collector.result.get());
79  EXPECT_EQ(1, tsp_cln.collector.result->getResponse().transfer_errors); // That broken frame
80  EXPECT_EQ(3, tsp_cln.collector.result->getResponse().transfers_rx);
81  EXPECT_EQ(2, tsp_cln.collector.result->getResponse().transfers_tx);
82  EXPECT_EQ(1, tsp_cln.collector.result->getResponse().can_iface_stats.size());
83  EXPECT_EQ(72, tsp_cln.collector.result->getResponse().can_iface_stats[0].errors);
84  EXPECT_EQ(4, tsp_cln.collector.result->getResponse().can_iface_stats[0].frames_rx); // Same here
85  EXPECT_EQ(12, tsp_cln.collector.result->getResponse().can_iface_stats[0].frames_tx);
86 }
uavcan::TransportStatsProvider::start
int start()
Definition: transport_stats_provider.hpp:57
transport_stats_provider.hpp
uavcan::DefaultDataTypeRegistrator
Definition: global_data_type_registry.hpp:186
uavcan::DurationBase< MonotonicDuration >::fromMSec
static MonotonicDuration fromMSec(int64_t ms)
Definition: time.hpp:41
uavcan::CanFrame
Definition: libuavcan/libuavcan/include/uavcan/driver/can.hpp:24
ServiceClientWithCollector::call
int call(uavcan::NodeID node_id, const typename DataType::Request &request)
Definition: libuavcan/libuavcan/test/protocol/helpers.hpp:111
uavcan::TransferTypeServiceRequest
@ TransferTypeServiceRequest
Definition: transfer.hpp:21
ServiceClientWithCollector
Definition: libuavcan/libuavcan/test/protocol/helpers.hpp:99
ServiceCallResultCollector::result
std::unique_ptr< Result > result
Definition: libuavcan/libuavcan/test/protocol/helpers.hpp:88
helpers.hpp
uavcan::TransportStatsProvider
Definition: transport_stats_provider.hpp:19
InterlinkedTestNodes
Definition: test_node.hpp:149
PairableCanDriver::error_count
uint64_t error_count
Definition: test_node.hpp:58
TEST
TEST(TransportStatsProvider, Basic)
Definition: transport_stats_provider.cpp:10
frame
uavcan::CanFrame frame
Definition: can.cpp:78
InterlinkedTestNodes::a
TestNode a
Definition: test_node.hpp:155
uavcan::Frame
Definition: frame.hpp:17
InterlinkedTestNodes::spinBoth
int spinBoth(uavcan::MonotonicDuration duration)
Definition: test_node.hpp:176
PairableCanDriver::read_queue
std::queue< uavcan::CanFrame > read_queue
Definition: test_node.hpp:56
uavcan::GlobalDataTypeRegistry::instance
static GlobalDataTypeRegistry & instance()
Definition: uc_global_data_type_registry.cpp:128
InterlinkedTestNodes::b
TestNode b
Definition: test_node.hpp:156
InterlinkedTestNodes::can_a
PairableCanDriver can_a
Definition: test_node.hpp:153
ServiceClientWithCollector::collector
Collector collector
Definition: libuavcan/libuavcan/test/protocol/helpers.hpp:104


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03