PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
test_ethernetPacketBackendLinux.cpp
Go to the documentation of this file.
1
9
10#include <chrono>
11#include <cstdint>
12
14#include "profinet/protocol.h"
15
16using namespace profinet;
17using namespace std::chrono_literals;
18
19namespace
20{
21constexpr std::uint16_t kLinuxTestEtherType = 0x88B6;
22
23const Bytes kFrame{
24 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
25 0x02, 0x00, 0x00, 0x00, 0x10, 0x01,
26 0x88, 0xB6,
27 0x10, 0x20, 0x30, 0x40};
28} // namespace
29
31TEST_F(EthernetPacketBackendTestFixture, LinuxPacketReadinessReceivesFrame)
32{
33 const auto interfaceValue = GetTestInterface();
34 if (!interfaceValue.has_value())
35 {
36 GTEST_SKIP() << "Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
37 }
38 const std::string& interface = *interfaceValue;
39
40 auto sender = CreateBackend(interface, 0U);
41 auto receiver = CreateBackend(interface, kLinuxTestEtherType);
42
43 receiver->SetTimeout(1000ms);
44 sender->Send(kFrame);
45
46 const Bytes received = receiver->Recv();
47
48 ASSERT_FALSE(received.empty());
49 EXPECT_EQ(received, kFrame);
50}
51
53TEST_F(EthernetPacketBackendTestFixture, LinuxPacketReadinessTimesOut)
54{
55 const auto interfaceValue = GetTestInterface();
56 if (!interfaceValue.has_value())
57 {
58 GTEST_SKIP() << "Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
59 }
60 const std::string& interface = *interfaceValue;
61
62 auto backend = CreateBackend(interface, kLinuxTestEtherType);
63 backend->SetTimeout(25ms);
64
65 const auto start = std::chrono::steady_clock::now();
66 const Bytes received = backend->Recv();
67 const auto elapsed = std::chrono::steady_clock::now() - start;
68
69 EXPECT_TRUE(received.empty());
70 EXPECT_GE(elapsed, 15ms);
71}
Shared fixture for EthernetPacketBackend tests.
Shared test fixture helpers for EthernetPacketBackend tests.
TEST_F(AlarmListenerTests, InitializesWithEndpoint)
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
Definition protocol.h:55
PROFINET protocol wire-format structures and serialization helpers.