20using namespace std::chrono_literals;
24constexpr std::uint16_t kTestEtherType = 0x88B5;
26const Bytes kUntaggedFrame{
27 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
28 0x02, 0x00, 0x00, 0x00, 0x00, 0x01,
30 0x01, 0x02, 0x03, 0x04};
32const Bytes kSingleVlanFrame{
33 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
34 0x02, 0x00, 0x00, 0x00, 0x00, 0x02,
38 0x05, 0x06, 0x07, 0x08};
40const Bytes kQinQFrame{
41 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
42 0x02, 0x00, 0x00, 0x00, 0x00, 0x03,
48 0x09, 0x0A, 0x0B, 0x0C};
60 EXPECT_THROW(CreateBackend(
"this-interface-does-not-exist"),
SocketError);
66 const auto interfaceValue = GetTestInterface();
67 if (!interfaceValue.has_value())
69 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
71 const std::string&
interface = *interfaceValue;
73 EXPECT_NO_THROW(CreateBackend(interface, kTestEtherType));
79 const auto interfaceValue = GetTestInterface();
80 if (!interfaceValue.has_value())
82 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
84 const std::string&
interface = *interfaceValue;
85 const Bytes frame(kUntaggedFrame.begin(), kUntaggedFrame.begin() + 14);
87 auto backend = CreateBackend(interface, kTestEtherType);
89 EXPECT_NO_THROW(backend->Send(
frame));
95 const auto interfaceValue = GetTestInterface();
96 if (!interfaceValue.has_value())
98 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
100 const std::string&
interface = *interfaceValue;
101 auto backend = CreateBackend(interface, kTestEtherType);
103 EXPECT_THROW(backend->Send(
Bytes(13U, 0x00)), std::invalid_argument);
109 const auto interfaceValue = GetTestInterface();
110 if (!interfaceValue.has_value())
112 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
114 const std::string&
interface = *interfaceValue;
115 auto backend = CreateBackend(interface, kTestEtherType);
117 EXPECT_TRUE(MatchesEtherType(*backend, kUntaggedFrame));
123 const auto interfaceValue = GetTestInterface();
124 if (!interfaceValue.has_value())
126 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
128 const std::string&
interface = *interfaceValue;
129 auto backend = CreateBackend(interface, kTestEtherType);
135 EXPECT_FALSE(MatchesEtherType(*backend,
frame));
141 const auto interfaceValue = GetTestInterface();
142 if (!interfaceValue.has_value())
144 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
146 const std::string&
interface = *interfaceValue;
147 auto backend = CreateBackend(interface, kTestEtherType);
149 EXPECT_TRUE(MatchesEtherType(*backend, kSingleVlanFrame));
155 const auto interfaceValue = GetTestInterface();
156 if (!interfaceValue.has_value())
158 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
160 const std::string&
interface = *interfaceValue;
161 auto backend = CreateBackend(interface, kTestEtherType);
163 EXPECT_TRUE(MatchesEtherType(*backend, kQinQFrame));
169 const auto interfaceValue = GetTestInterface();
170 if (!interfaceValue.has_value())
173 <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
175 const std::string&
interface = *interfaceValue;
176 auto backend = CreateBackend(interface, kTestEtherType);
179 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
180 0x02, 0x00, 0x00, 0x00, 0x00, 0x04,
186 EXPECT_TRUE(MatchesEtherType(*backend,
frame));
192 const auto interfaceValue = GetTestInterface();
193 if (!interfaceValue.has_value())
195 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
197 const std::string&
interface = *interfaceValue;
198 auto backend = CreateBackend(interface, kTestEtherType);
200 EXPECT_FALSE(MatchesEtherType(*backend,
Bytes(13U, 0x00)));
206 const auto interfaceValue = GetTestInterface();
207 if (!interfaceValue.has_value())
209 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
211 const std::string&
interface = *interfaceValue;
212 auto backend = CreateBackend(interface, kTestEtherType);
215 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
216 0x02, 0x00, 0x00, 0x00, 0x00, 0x05,
219 EXPECT_FALSE(MatchesEtherType(*backend,
frame));
225 const auto interfaceValue = GetTestInterface();
226 if (!interfaceValue.has_value())
228 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
230 const std::string&
interface = *interfaceValue;
231 auto backend = CreateBackend(interface, 0U);
233 EXPECT_TRUE(MatchesEtherType(*backend, kUntaggedFrame));
239 const auto interfaceValue = GetTestInterface();
240 if (!interfaceValue.has_value())
242 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
244 const std::string&
interface = *interfaceValue;
245 auto backend = CreateBackend(interface, kTestEtherType);
247 backend->SetTimeout(25ms);
249 const Bytes received = backend->Recv();
251 EXPECT_TRUE(received.empty());
257 const auto interfaceValue = GetTestInterface();
258 if (!interfaceValue.has_value())
260 GTEST_SKIP() <<
"Set PROFINET_TEST_INTERFACE to run live Ethernet backend tests";
262 const std::string&
interface = *interfaceValue;
263 auto sender = CreateBackend(interface, 0U);
264 auto receiver = CreateBackend(interface, kTestEtherType);
266 Bytes nonMatching = kUntaggedFrame;
267 nonMatching[12] = 0x88;
268 nonMatching[13] = 0x92;
270 receiver->SetTimeout(1000ms);
272 sender->Send(nonMatching);
273 sender->Send(kUntaggedFrame);
275 const Bytes received = receiver->Recv();
277 ASSERT_FALSE(received.empty());
278 EXPECT_EQ(received, kUntaggedFrame);
Shared fixture for EthernetPacketBackend tests.
Shared test fixture helpers for EthernetPacketBackend tests.
Declares exceptions and error types used by the PROFINET IO controller stack.
TEST_F(AlarmListenerTests, InitializesWithEndpoint)
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
PROFINET protocol wire-format structures and serialization helpers.
Declares Linux Ethernet, addressing, timing, and utility helpers used by the PROFINET stack.