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
18
19namespace profinet
20{
29class EthernetPacketBackendTestFixture : public ::testing::Test
30{
31 protected:
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
Runs an Asio I/O context on a dedicated worker thread.
Private packet-capture backend for complete Ethernet frames.
bool MatchesEtherType(const std::vector< std::uint8_t > &frame) const
Check whether an Ethernet frame matches the configured EtherType.
Shared fixture for EthernetPacketBackend tests.
bool MatchesEtherType(const Backend &backend, const std::vector< std::uint8_t > &frame) const
Query the backend EtherType matcher through the test seam.
static std::optional< std::string > GetTestInterface()
Return the explicitly configured live-test interface.
void TearDown() override
Stop the external Asio execution context.
std::unique_ptr< Backend > CreateBackend(const std::string &interface, std::uint16_t ethertype=0U)
Construct one backend instance for the supplied interface.
asio::io_context ioContext
Asio execution context used by the backend.
std::unique_ptr< AsioIoContextRunner > runner
External Asio worker used by synchronous Recv() operations.
void SetUp() override
Start the external Asio execution context.
Private Ethernet packet backend used by AsioEthernetSocket.
Bytes frame