Skip to content

Commit

Permalink
Merge pull request #16 from dspace-group/TestFixes
Browse files Browse the repository at this point in the history
Test fixes
  • Loading branch information
ACanisLupus authored Sep 19, 2024
2 parents 0652d0d + fa426ab commit 3740c69
Show file tree
Hide file tree
Showing 77 changed files with 635 additions and 571 deletions.
6 changes: 4 additions & 2 deletions benchmark/BenchmarkBusBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright dSPACE GmbH. All rights reserved.

#include <benchmark/benchmark.h>
#include <string>
#include <string_view>
#include <thread>

#include "BusBuffer.h"
Expand Down Expand Up @@ -40,8 +42,8 @@ void ReceiveMessages(size_t count, BusBuffer& receiverBusBuffer, Channel& channe
template <typename TypeParam>
void RunTest(benchmark::State& state,
ConnectionKind connectionKind,
const std::string& senderName,
const std::string& receiverName,
std::string_view senderName,
std::string_view receiverName,
Channel& senderChannel,
Channel& receiverChannel) {
using TController = std::tuple_element_t<0, TypeParam>;
Expand Down
6 changes: 4 additions & 2 deletions benchmark/BenchmarkIoBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright dSPACE GmbH. All rights reserved.

#include <benchmark/benchmark.h>
#include <string>
#include <string_view>
#include <thread>

#include "CoSimTypes.h"
Expand Down Expand Up @@ -35,8 +37,8 @@ void Receive(const IoSignal& signal, IoBuffer& readerIoBuffer, Channel& channel,

void RunTest(benchmark::State& state,
ConnectionKind connectionKind,
const std::string& writerName,
const std::string& readerName,
std::string_view writerName,
std::string_view readerName,
Channel& senderChannel,
Channel& receiverChannel) {
IoSignal signal = CreateSignal(DsVeosCoSim_DataType_Int8, DsVeosCoSim_SizeKind_Fixed);
Expand Down
4 changes: 3 additions & 1 deletion benchmark/OsAbstraction/BenchmarkNamedEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#ifdef _WIN32

#include <benchmark/benchmark.h>
#include <string>
#include <string_view>
#include <thread>

#include "Generator.h"
Expand Down Expand Up @@ -35,7 +37,7 @@ void EventSetAndWait(benchmark::State& state) {

bool stopThread;

void WaitAndSet(const std::string& eventName1, const std::string& eventName2) {
void WaitAndSet(std::string_view eventName1, std::string_view eventName2) {
NamedEvent event1 = NamedEvent::CreateOrOpen(eventName1);
NamedEvent event2 = NamedEvent::CreateOrOpen(eventName2);

Expand Down
2 changes: 1 addition & 1 deletion shared/ClientServerTestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "ClientServerTestHelper.h"

#include "BusBuffer.h"
#include "CoSimHelper.h"
#include "Generator.h"
#include "Logger.h"

using namespace DsVeosCoSim;

Expand Down
4 changes: 2 additions & 2 deletions shared/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ int64_t GenerateI64() {
return static_cast<int64_t>(GenerateU64());
}

std::string GenerateString(const std::string& prefix) {
return prefix + std::to_string(GenerateU32());
std::string GenerateString(std::string_view prefix) {
return fmt::format("{}{}", prefix, GenerateU32());
}

DsVeosCoSim_DataType GenerateDataType() {
Expand Down
3 changes: 2 additions & 1 deletion shared/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cstdint>
#include <string>
#include <string_view>

#include "BusBuffer.h"
#include "CoSimTypes.h"
Expand All @@ -22,7 +23,7 @@ template <typename T>
[[nodiscard]] uint32_t GenerateU32();
[[nodiscard]] uint64_t GenerateU64();
[[nodiscard]] int64_t GenerateI64();
[[nodiscard]] std::string GenerateString(const std::string& prefix);
[[nodiscard]] std::string GenerateString(std::string_view prefix);

[[nodiscard]] DsVeosCoSim_DataType GenerateDataType();
[[nodiscard]] DsVeosCoSim_SizeKind GenerateSizeKind();
Expand Down
14 changes: 7 additions & 7 deletions shared/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

#include <stdexcept>

#include "CoSimHelper.h"
#include "LogHelper.h"
#include "Logger.h"
#include "Result.h"
#include "Socket.h"
#include "SocketChannel.h"

#ifdef _WIN32
#include <Windows.h>
#include <conio.h>
#else
#include <cstdlib>
#include <termios.h>
#include <unistd.h>
#include <cstdlib>

#endif

using namespace DsVeosCoSim;
Expand Down Expand Up @@ -86,7 +86,7 @@ Socket ConnectSocket(std::string_view ipAddress, uint16_t remotePort) {
throw std::runtime_error("Could not connect within timeout.");
}

Socket ConnectSocket(const std::string& name) {
Socket ConnectSocket(std::string_view name) {
Socket socket(AddressFamily::Uds);
if (socket.TryConnect(name)) {
return socket;
Expand Down Expand Up @@ -122,7 +122,7 @@ SocketChannel Accept(const TcpChannelServer& server) {
throw std::runtime_error("Could not accept within timeout.");
}

SocketChannel ConnectToUdsChannel(const std::string& name) {
SocketChannel ConnectToUdsChannel(std::string_view name) {
std::optional<SocketChannel> channel = TryConnectToUdsChannel(name);
if (channel) {
return std::move(*channel);
Expand All @@ -142,7 +142,7 @@ SocketChannel Accept(const UdsChannelServer& server) {

#ifdef _WIN32

LocalChannel ConnectToLocalChannel(const std::string& name) {
LocalChannel ConnectToLocalChannel(std::string_view name) {
std::optional<LocalChannel> channel = TryConnectToLocalChannel(name);
if (channel) {
return std::move(*channel);
Expand All @@ -162,7 +162,7 @@ LocalChannel Accept(LocalChannelServer& server) {

#endif

std::string GetLoopBackAddress(AddressFamily addressFamily) {
[[nodiscard]] std::string_view GetLoopBackAddress(AddressFamily addressFamily) {
if (addressFamily == AddressFamily::Ipv4) {
return "127.0.0.1";
}
Expand Down
8 changes: 4 additions & 4 deletions shared/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ constexpr uint32_t DefaultTimeout = 1000; // NOLINT
[[nodiscard]] bool StartUp();

[[nodiscard]] DsVeosCoSim::Socket ConnectSocket(std::string_view ipAddress, uint16_t remotePort);
[[nodiscard]] DsVeosCoSim::Socket ConnectSocket(const std::string& name);
[[nodiscard]] DsVeosCoSim::Socket ConnectSocket(std::string_view name);
[[nodiscard]] DsVeosCoSim::Socket Accept(const DsVeosCoSim::Socket& serverSocket);

[[nodiscard]] DsVeosCoSim::SocketChannel ConnectToTcpChannel(std::string_view ipAddress, uint16_t remotePort);
[[nodiscard]] DsVeosCoSim::SocketChannel Accept(const DsVeosCoSim::TcpChannelServer& server);

[[nodiscard]] DsVeosCoSim::SocketChannel ConnectToUdsChannel(const std::string& name);
[[nodiscard]] DsVeosCoSim::SocketChannel ConnectToUdsChannel(std::string_view name);
[[nodiscard]] DsVeosCoSim::SocketChannel Accept(const DsVeosCoSim::UdsChannelServer& server);

#ifdef _WIN32

[[nodiscard]] DsVeosCoSim::LocalChannel ConnectToLocalChannel(const std::string& name);
[[nodiscard]] DsVeosCoSim::LocalChannel ConnectToLocalChannel(std::string_view name);
[[nodiscard]] DsVeosCoSim::LocalChannel Accept(DsVeosCoSim::LocalChannelServer& server);

#endif

[[nodiscard]] std::string GetLoopBackAddress(DsVeosCoSim::AddressFamily addressFamily);
[[nodiscard]] std::string_view GetLoopBackAddress(DsVeosCoSim::AddressFamily addressFamily);

[[nodiscard]] bool SendComplete(const DsVeosCoSim::Socket& socket, const void* buffer, size_t length);

Expand Down
9 changes: 5 additions & 4 deletions shared/LogHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include <fmt/color.h>
#include <iomanip>
#include <sstream>
#include "Logger.h"

#include "CoSimHelper.h"

#ifdef _WIN32
#include <Windows.h>
Expand All @@ -26,7 +27,7 @@ fmt::text_style gray = fg(fmt::color::light_gray);
fmt::text_style blue = fg(fmt::color::dodger_blue);
fmt::text_style violet = fg(fmt::color::fuchsia);

std::string DataToString(const uint8_t* data, uint32_t dataLength, char separator = 0) {
[[nodiscard]] std::string DataToString(const uint8_t* data, uint32_t dataLength, char separator = 0) {
std::ostringstream oss;
oss << std::hex << std::setfill('0');
for (uint32_t i = 0; i < dataLength; i++) {
Expand All @@ -39,7 +40,7 @@ std::string DataToString(const uint8_t* data, uint32_t dataLength, char separato
return oss.str();
}

std::string DataTypeValueToString(const void* value, uint32_t index, DsVeosCoSim_DataType dataType) {
[[nodiscard]] std::string DataTypeValueToString(const void* value, uint32_t index, DsVeosCoSim_DataType dataType) {
switch (dataType) {
case DsVeosCoSim_DataType_Bool:
return std::to_string(static_cast<const uint8_t*>(value)[index]);
Expand Down Expand Up @@ -70,7 +71,7 @@ std::string DataTypeValueToString(const void* value, uint32_t index, DsVeosCoSim
throw std::runtime_error("Invalid data type.");
}

std::string ValueToString(const void* value, uint32_t length, DsVeosCoSim_DataType dataType) {
[[nodiscard]] std::string ValueToString(const void* value, uint32_t length, DsVeosCoSim_DataType dataType) {
std::ostringstream oss;
for (uint32_t i = 0; i < length; i++) {
if (i > 0) {
Expand Down
30 changes: 15 additions & 15 deletions shared/PerformanceTestHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
#pragma once

#include <cstdint>
#include <string>
#include <string_view>

constexpr uint32_t BufferSize = 24U; // NOLINT
constexpr uint16_t UdpPort = 27100; // NOLINT
constexpr uint16_t TcpPort = 27101; // NOLINT
constexpr uint16_t CommunicationPort = 27102; // NOLINT
constexpr uint16_t CoSimPort = 27103; // NOLINT
constexpr uint16_t AsioAsyncPort = 27111; // NOLINT
constexpr uint16_t AsioBlockingPort = 27112; // NOLINT
const std::string UdsName = "Uds4711"; // NOLINT
const std::string PipeName = "Pipe4711"; // NOLINT
const std::string BeginEventName = "BeginEvent4711"; // NOLINT
const std::string EndEventName = "EndEvent4711"; // NOLINT
const std::string ShmName = "Shm4711"; // NOLINT
const std::string LocalName = "Local4711"; // NOLINT
const std::string CoSimServerName = "TestServer"; // NOLINT
constexpr uint32_t BufferSize = 24U; // NOLINT
constexpr uint16_t UdpPort = 27100; // NOLINT
constexpr uint16_t TcpPort = 27101; // NOLINT
constexpr uint16_t CommunicationPort = 27102; // NOLINT
constexpr uint16_t CoSimPort = 27103; // NOLINT
constexpr uint16_t AsioAsyncPort = 27111; // NOLINT
constexpr uint16_t AsioBlockingPort = 27112; // NOLINT
constexpr std::string_view UdsName = "Uds4711"; // NOLINT
constexpr std::string_view PipeName = "Pipe4711"; // NOLINT
constexpr std::string_view BeginEventName = "BeginEvent4711"; // NOLINT
constexpr std::string_view EndEventName = "EndEvent4711"; // NOLINT
constexpr std::string_view ShmName = "Shm4711"; // NOLINT
constexpr std::string_view LocalName = "Local4711"; // NOLINT
constexpr std::string_view CoSimServerName = "TestServer"; // NOLINT
18 changes: 6 additions & 12 deletions src/BusBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

#include "BusBuffer.h"

#include <fmt/format.h>
#include <cstring>
#include <memory>

#include "CoSimTypes.h"

namespace DsVeosCoSim {

namespace {
Expand Down Expand Up @@ -178,7 +172,7 @@ void LinMessage::CheckMaxLength() const {

BusBuffer::BusBuffer(CoSimType coSimType,
[[maybe_unused]] ConnectionKind connectionKind,
const std::string& name,
std::string_view name,
const std::vector<DsVeosCoSim_CanController>& canControllers,
const std::vector<DsVeosCoSim_EthController>& ethControllers,
const std::vector<DsVeosCoSim_LinController>& linControllers) {
Expand All @@ -204,8 +198,8 @@ BusBuffer::BusBuffer(CoSimType coSimType,
}
#endif

std::string suffixForTransmit = coSimType == CoSimType::Client ? "Transmit" : "Receive";
std::string suffixForReceive = coSimType == CoSimType::Client ? "Receive" : "Transmit";
std::string_view suffixForTransmit = coSimType == CoSimType::Client ? "Transmit" : "Receive";
std::string_view suffixForReceive = coSimType == CoSimType::Client ? "Receive" : "Transmit";

_canTransmitBuffer->Initialize(coSimType, fmt::format("{}.Can.{}", name, suffixForTransmit), canControllers);
_ethTransmitBuffer->Initialize(coSimType, fmt::format("{}.Eth.{}", name, suffixForTransmit), ethControllers);
Expand All @@ -217,21 +211,21 @@ BusBuffer::BusBuffer(CoSimType coSimType,

BusBuffer::BusBuffer(CoSimType coSimType,
ConnectionKind connectionKind,
const std::string& name,
std::string_view name,
const std::vector<DsVeosCoSim_CanController>& canControllers)
: BusBuffer(coSimType, connectionKind, name, canControllers, {}, {}) {
}

BusBuffer::BusBuffer(CoSimType coSimType,
ConnectionKind connectionKind,
const std::string& name,
std::string_view name,
const std::vector<DsVeosCoSim_EthController>& ethControllers)
: BusBuffer(coSimType, connectionKind, name, {}, ethControllers, {}) {
}

BusBuffer::BusBuffer(CoSimType coSimType,
ConnectionKind connectionKind,
const std::string& name,
std::string_view name,
const std::vector<DsVeosCoSim_LinController>& linControllers)
: BusBuffer(coSimType, connectionKind, name, {}, {}, linControllers) {
}
Expand Down
20 changes: 10 additions & 10 deletions src/BusBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
#include <concepts>
#include <memory>
#include <mutex>
#include <string_view>
#include <utility>
#include <vector>

#include "Channel.h"
#include "CoSimHelper.h"
#include "CoSimTypes.h"
#include "Logger.h"
#include "Result.h"
#include "RingBuffer.h"

#ifdef _WIN32
Expand Down Expand Up @@ -127,7 +127,7 @@ class BusProtocolBufferBase {
BusProtocolBufferBase(BusProtocolBufferBase&&) = delete;
BusProtocolBufferBase& operator=(BusProtocolBufferBase&&) = delete;

void Initialize(CoSimType coSimType, const std::string& name, const std::vector<TControllerExtern>& controllers) {
void Initialize(CoSimType coSimType, std::string_view name, const std::vector<TControllerExtern>& controllers) {
_coSimType = coSimType;

size_t totalQueueItemsCountPerBuffer = 0;
Expand Down Expand Up @@ -197,7 +197,7 @@ class BusProtocolBufferBase {
}

protected:
virtual void InitializeInternal(const std::string& name, size_t totalQueueItemsCountPerBuffer) = 0;
virtual void InitializeInternal(std::string_view name, size_t totalQueueItemsCountPerBuffer) = 0;

virtual void ClearDataInternal() = 0;

Expand Down Expand Up @@ -241,7 +241,7 @@ class RemoteBusProtocolBuffer final : public BusProtocolBufferBase<TMessageExter
RemoteBusProtocolBuffer& operator=(RemoteBusProtocolBuffer&&) = delete;

protected:
void InitializeInternal([[maybe_unused]] const std::string& name, size_t totalQueueItemsCountPerBuffer) override {
void InitializeInternal([[maybe_unused]] std::string_view name, size_t totalQueueItemsCountPerBuffer) override {
_messageCountPerController.resize(this->_controllers.size());
_messageBuffer = RingBuffer<TMessage>(totalQueueItemsCountPerBuffer);
}
Expand Down Expand Up @@ -364,7 +364,7 @@ class LocalBusProtocolBuffer final : public BusProtocolBufferBase<TMessageExtern
LocalBusProtocolBuffer& operator=(LocalBusProtocolBuffer&&) = delete;

protected:
void InitializeInternal(const std::string& name, size_t totalQueueItemsCountPerBuffer) override {
void InitializeInternal(std::string_view name, size_t totalQueueItemsCountPerBuffer) override {
// The memory layout looks like this:
// [ list of message count per controller ]
// [ message buffer ]
Expand Down Expand Up @@ -490,21 +490,21 @@ class BusBuffer {
public:
BusBuffer(CoSimType coSimType,
ConnectionKind connectionKind,
const std::string& name,
std::string_view name,
const std::vector<DsVeosCoSim_CanController>& canControllers,
const std::vector<DsVeosCoSim_EthController>& ethControllers,
const std::vector<DsVeosCoSim_LinController>& linControllers);
BusBuffer(CoSimType coSimType,
ConnectionKind connectionKind,
const std::string& name,
std::string_view name,
const std::vector<DsVeosCoSim_CanController>& canControllers);
BusBuffer(CoSimType coSimType,
ConnectionKind connectionKind,
const std::string& name,
std::string_view name,
const std::vector<DsVeosCoSim_EthController>& ethControllers);
BusBuffer(CoSimType coSimType,
ConnectionKind connectionKind,
const std::string& name,
std::string_view name,
const std::vector<DsVeosCoSim_LinController>& linControllers);
~BusBuffer() noexcept = default;

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_library(
${DSVEOSCOSIM_TYPE}
Communication/LocalChannel.cpp
Communication/SocketChannel.cpp
Helpers/Logger.cpp
Helpers/CoSimHelper.cpp
OsAbstraction/Handle.cpp
OsAbstraction/NamedEvent.cpp
OsAbstraction/NamedMutex.cpp
Expand Down
Loading

0 comments on commit 3740c69

Please sign in to comment.