PROFINET IO Controller Stack
1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
ethernetPacketBackendTestFixture.h
Go to the documentation of this file.
1
3
4
#pragma once
5
6
#include <gtest/gtest.h>
7
8
#include <asio/io_context.hpp>
9
#include <chrono>
10
#include <cstdlib>
11
#include <memory>
12
#include <optional>
13
#include <string>
14
#include <vector>
15
16
#include "
profinet/AsioIoContextRunner.h
"
17
#include "
profinet/ethernetPacketBackend.h
"
18
19
namespace
profinet
20
{
29
class
EthernetPacketBackendTestFixture
:
public
::testing::Test
30
{
31
protected
:
33
using
Backend
=
AsioEthernetSocket::EthernetPacketBackend
;
34
40
[[nodiscard]] std::unique_ptr<Backend>
CreateBackend
(
const
std::string& interface, std::uint16_t ethertype = 0U)
41
{
42
return
std::make_unique<Backend>(
ioContext
, interface, ethertype);
43
}
44
50
[[nodiscard]]
bool
MatchesEtherType
(
const
Backend
& backend,
const
std::vector<std::uint8_t>&
frame
)
const
51
{
52
return
backend.
MatchesEtherType
(
frame
);
53
}
54
58
[[nodiscard]]
static
std::optional<std::string>
GetTestInterface
()
59
{
60
const
char
* value = std::getenv(
"PROFINET_TEST_INTERFACE"
);
61
62
if
(value ==
nullptr
|| *value ==
'\0'
)
63
{
64
return
std::nullopt;
65
}
66
67
return
std::string(value);
68
}
69
71
asio::io_context
ioContext
;
72
74
std::unique_ptr<AsioIoContextRunner>
runner
;
75
77
void
SetUp
()
override
78
{
79
runner
= std::make_unique<AsioIoContextRunner>(
ioContext
);
80
}
81
83
void
TearDown
()
override
84
{
85
runner
.reset();
86
}
87
};
88
89
}
// namespace profinet
AsioIoContextRunner.h
Runs an Asio I/O context on a dedicated worker thread.
profinet::AsioEthernetSocket::EthernetPacketBackend
Private packet-capture backend for complete Ethernet frames.
Definition
ethernetPacketBackend.h:56
profinet::AsioEthernetSocket::EthernetPacketBackend::MatchesEtherType
bool MatchesEtherType(const std::vector< std::uint8_t > &frame) const
Check whether an Ethernet frame matches the configured EtherType.
Definition
ethernetPacketBackend.cpp:475
profinet::EthernetPacketBackendTestFixture
Shared fixture for EthernetPacketBackend tests.
Definition
ethernetPacketBackendTestFixture.h:30
profinet::EthernetPacketBackendTestFixture::MatchesEtherType
bool MatchesEtherType(const Backend &backend, const std::vector< std::uint8_t > &frame) const
Query the backend EtherType matcher through the test seam.
Definition
ethernetPacketBackendTestFixture.h:50
profinet::EthernetPacketBackendTestFixture::GetTestInterface
static std::optional< std::string > GetTestInterface()
Return the explicitly configured live-test interface.
Definition
ethernetPacketBackendTestFixture.h:58
profinet::EthernetPacketBackendTestFixture::TearDown
void TearDown() override
Stop the external Asio execution context.
Definition
ethernetPacketBackendTestFixture.h:83
profinet::EthernetPacketBackendTestFixture::CreateBackend
std::unique_ptr< Backend > CreateBackend(const std::string &interface, std::uint16_t ethertype=0U)
Construct one backend instance for the supplied interface.
Definition
ethernetPacketBackendTestFixture.h:40
profinet::EthernetPacketBackendTestFixture::ioContext
asio::io_context ioContext
Asio execution context used by the backend.
Definition
ethernetPacketBackendTestFixture.h:71
profinet::EthernetPacketBackendTestFixture::runner
std::unique_ptr< AsioIoContextRunner > runner
External Asio worker used by synchronous Recv() operations.
Definition
ethernetPacketBackendTestFixture.h:74
profinet::EthernetPacketBackendTestFixture::SetUp
void SetUp() override
Start the external Asio execution context.
Definition
ethernetPacketBackendTestFixture.h:77
ethernetPacketBackend.h
Private Ethernet packet backend used by AsioEthernetSocket.
profinet
Definition
alarmListener.h:33
frame
Bytes frame
Definition
test_cyclicCapture.cpp:85
tests
ethernetPacketBackendTestFixture.h
Generated on Fri Oct 2 2026 23:15:10 for PROFINET IO Controller Stack by
1.9.8