PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
test_ethernetPacketBackendWindows.cpp
Go to the documentation of this file.
1
8
9#include <chrono>
10#include <cstdint>
11
13#include "profinet/protocol.h"
14
15using namespace profinet;
16using namespace std::chrono_literals;
17
18namespace
19{
20constexpr std::uint16_t kWindowsTestEtherType = 0x88B7;
21
22const Bytes kFrame{
23 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
24 0x02, 0x00, 0x00, 0x00, 0x10, 0x02,
25 0x88, 0xB7,
26 0x50, 0x60, 0x70, 0x80};
27} // namespace
28
30TEST_F(EthernetPacketBackendTestFixture, WindowsPacketReadinessReceivesFrame)
31{
32 const auto interfaceValue = GetTestInterface();
33 if (!interfaceValue.has_value())
34 {
35 GTEST_SKIP() << "Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
36 }
37 const std::string& interface = *interfaceValue;
38
39 auto sender = CreateBackend(interface, 0U);
40 auto receiver = CreateBackend(interface, kWindowsTestEtherType);
41
42 receiver->SetTimeout(1000ms);
43 sender->Send(kFrame);
44
45 const Bytes received = receiver->Recv();
46
47 ASSERT_FALSE(received.empty());
48 EXPECT_EQ(received, kFrame);
49}
50
52TEST_F(EthernetPacketBackendTestFixture, WindowsPacketReadinessTimesOut)
53{
54 const auto interfaceValue = GetTestInterface();
55 if (!interfaceValue.has_value())
56 {
57 GTEST_SKIP() << "Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
58 }
59 const std::string& interface = *interfaceValue;
60
61 auto backend = CreateBackend(interface, kWindowsTestEtherType);
62 backend->SetTimeout(25ms);
63
64 const auto start = std::chrono::steady_clock::now();
65 const Bytes received = backend->Recv();
66 const auto elapsed = std::chrono::steady_clock::now() - start;
67
68 EXPECT_TRUE(received.empty());
69 EXPECT_GE(elapsed, 15ms);
70}
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.