Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracing #19

Merged
merged 8 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 38 additions & 20 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
---
Checks: 'bugprone-*,
Checks: '*,
-altera-struct-pack-align,
-altera-unroll-loops,
-android-cloexec-accept,
-android-cloexec-socket,
-bugprone-easily-swappable-parameters,
clang-diagnostic-*,
clang-analyzer-*,
google-readability-*,
-google-readability-casting,
google-runtime-operator,
misc-*,
-misc-const-correctness,
-cert-err34-c,
-cert-err58-cpp,
-cert-msc30-c,
-cert-msc32-c,
-cert-msc50-cpp,
-cert-msc51-cpp,
-concurrency-mt-unsafe,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-pro-type-reinterpret-cast,
-fuchsia-default-arguments-calls,
-fuchsia-default-arguments-declarations,
-fuchsia-statically-constructed-objects,
-google-build-using-namespace,
-google-runtime-int,
-hicpp-avoid-c-arrays,
-hicpp-no-array-decay,
-hicpp-vararg,
-hicpp-signed-bitwise,
-llvmlibc-callee-namespace,
-llvmlibc-implementation-in-namespace,
-llvmlibc-restrict-system-libc-headers,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion,
-misc-use-anonymous-namespace,
modernize-*,
-modernize-avoid-c-arrays,
-modernize-pass-by-value,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
performance-*,
portability-*,
readability-*,
-readability-function-cognitive-complexity,
-readability-redundant-access-specifiers,
-readability-magic-numbers,
-readability-identifier-length'
-readability-identifier-length,
-readability-magic-numbers'

CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@
[submodule "third_party/fmt"]
path = third_party/fmt
url = https://github.com/fmtlib/fmt.git
[submodule "third_party/asio"]
path = third_party/asio
url = https://github.com/chriskohlhoff/asio.git
5 changes: 2 additions & 3 deletions benchmark/BenchmarkBusBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

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

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

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

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

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

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

bool stopThread;

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

Expand Down
1 change: 1 addition & 0 deletions benchmark/OsAbstraction/BenchmarkSocket.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright dSPACE GmbH. All rights reserved.

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

Expand Down
3 changes: 1 addition & 2 deletions compile_flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-DDSVEOSCOSIM_EXPORT
-DWIN32_LEAN_AND_MEAN
-D_CRT_SECURE_NO_WARNINGS
-DDSVEOSCOSIM_ENABLE_TRACING
-DEXCEPTION_TESTS
-Wall
-Wextra
Expand All @@ -17,8 +18,6 @@
-Itest
-Itest/Helpers
-isystem
third_party/asio/asio/include
-isystem
third_party/benchmark/include
-isystem
third_party/fmt/include
Expand Down
8 changes: 7 additions & 1 deletion shared/BackgroundService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "BackgroundService.h"

#include <thread>

using namespace DsVeosCoSim;

BackgroundService::BackgroundService(CoSimServer& coSimServer) : _coSimServer(coSimServer) {
Expand All @@ -18,5 +20,9 @@ BackgroundService::BackgroundService(CoSimServer& coSimServer) : _coSimServer(co

BackgroundService::~BackgroundService() noexcept {
_stopEvent.Set();
_thread.join();
if (std::this_thread::get_id() == _thread.get_id()) {
_thread.detach();
} else {
_thread.join();
}
}
11 changes: 6 additions & 5 deletions shared/ClientServerTestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ClientServerTestHelper.h"

#include <fmt/format.h>
#include <string_view>

#include "BusBuffer.h"
#include "CoSimHelper.h"
Expand Down Expand Up @@ -43,23 +44,23 @@ void SwitchSendingLinMessages() {
PrintStatus(g_sendLinMessages, "LIN messages");
}

bool IsSendingIoSignalsEnabled() {
[[nodiscard]] bool IsSendingIoSignalsEnabled() {
return g_sendIoData;
}

bool IsSendingCanMessagesEnabled() {
[[nodiscard]] bool IsSendingCanMessagesEnabled() {
return g_sendCanMessages;
}

bool IsSendingEthMessagesEnabled() {
[[nodiscard]] bool IsSendingEthMessagesEnabled() {
return g_sendEthMessages;
}

bool IsSendingLinMessagesEnabled() {
[[nodiscard]] bool IsSendingLinMessagesEnabled() {
return g_sendLinMessages;
}

bool SendSomeData(DsVeosCoSim_SimulationTime simulationTime, const RunTimeInfo& runTimeInfo) {
[[nodiscard]] bool SendSomeData(DsVeosCoSim_SimulationTime simulationTime, const RunTimeInfo& runTimeInfo) {
static int64_t lastHalfSecond = -1;
static int64_t counter = 0;
const int64_t currentHalfSecond = simulationTime / 500000000;
Expand Down
8 changes: 4 additions & 4 deletions shared/ClientServerTestHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void SwitchSendingCanMessages();
void SwitchSendingEthMessages();
void SwitchSendingLinMessages();

bool IsSendingIoSignalsEnabled();
bool IsSendingCanMessagesEnabled();
bool IsSendingEthMessagesEnabled();
bool IsSendingLinMessagesEnabled();
[[nodiscard]] bool IsSendingIoSignalsEnabled();
[[nodiscard]] bool IsSendingCanMessagesEnabled();
[[nodiscard]] bool IsSendingEthMessagesEnabled();
[[nodiscard]] bool IsSendingLinMessagesEnabled();

[[nodiscard]] bool SendSomeData(DsVeosCoSim_SimulationTime simulationTime, const RunTimeInfo& runTimeInfo);
42 changes: 22 additions & 20 deletions shared/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
#include "Generator.h"

#include <fmt/format.h>
#include <string>
#include <string_view>

using namespace DsVeosCoSim;

int32_t Random(int32_t min, int32_t max) {
[[nodiscard]] int32_t Random(int32_t min, int32_t max) {
static bool first = true;
if (first) {
srand(42); // NOLINT(cert-msc51-cpp)
srand(42);
first = false;
}

const int32_t diff = max + 1 - min;

return min + rand() % diff; // NOLINT(concurrency-mt-unsafe)
return min + rand() % diff;
}

void FillWithRandom(uint8_t* data, size_t length) {
Expand All @@ -24,47 +26,47 @@ void FillWithRandom(uint8_t* data, size_t length) {
}
}

uint8_t GenerateU8() {
[[nodiscard]] uint8_t GenerateU8() {
return GenerateRandom(static_cast<uint8_t>(0U), static_cast<uint8_t>(UINT8_MAX));
}

uint16_t GenerateU16() {
[[nodiscard]] uint16_t GenerateU16() {
return GenerateRandom(static_cast<uint16_t>(0U), static_cast<uint16_t>(UINT16_MAX));
}

uint32_t GenerateU32() {
[[nodiscard]] uint32_t GenerateU32() {
return GenerateRandom(0U, 123456789U);
}

uint64_t GenerateU64() {
[[nodiscard]] uint64_t GenerateU64() {
return (static_cast<uint64_t>(GenerateU32()) << sizeof(uint32_t)) + static_cast<uint64_t>(GenerateU32());
}

int64_t GenerateI64() {
[[nodiscard]] int64_t GenerateI64() {
return static_cast<int64_t>(GenerateU64());
}

std::string GenerateString(std::string_view prefix) {
[[nodiscard]] std::string GenerateString(std::string_view prefix) {
return fmt::format("{}{}", prefix, GenerateU32());
}

DsVeosCoSim_DataType GenerateDataType() {
[[nodiscard]] DsVeosCoSim_DataType GenerateDataType() {
return GenerateRandom(DsVeosCoSim_DataType_Bool, DsVeosCoSim_DataType_Float64);
}

DsVeosCoSim_SizeKind GenerateSizeKind() {
[[nodiscard]] DsVeosCoSim_SizeKind GenerateSizeKind() {
return GenerateRandom(DsVeosCoSim_SizeKind_Fixed, DsVeosCoSim_SizeKind_Variable);
}

IoSignal CreateSignal() {
[[nodiscard]] IoSignal CreateSignal() {
return CreateSignal(GenerateDataType(), GenerateSizeKind());
}

IoSignal CreateSignal(DsVeosCoSim_DataType dataType) {
[[nodiscard]] IoSignal CreateSignal(DsVeosCoSim_DataType dataType) {
return CreateSignal(dataType, GenerateSizeKind());
}

IoSignal CreateSignal(DsVeosCoSim_DataType dataType, DsVeosCoSim_SizeKind sizeKind) {
[[nodiscard]] IoSignal CreateSignal(DsVeosCoSim_DataType dataType, DsVeosCoSim_SizeKind sizeKind) {
IoSignal signal{};
signal.id = GenerateU32();
signal.length = GenerateRandom(1U, 10U);
Expand All @@ -74,13 +76,13 @@ IoSignal CreateSignal(DsVeosCoSim_DataType dataType, DsVeosCoSim_SizeKind sizeKi
return signal;
}

std::vector<uint8_t> GenerateIoData(const DsVeosCoSim_IoSignal& signal) {
[[nodiscard]] std::vector<uint8_t> GenerateIoData(const DsVeosCoSim_IoSignal& signal) {
std::vector<uint8_t> data = CreateZeroedIoData(signal);
FillWithRandom(data.data(), data.size());
return data;
}

std::vector<uint8_t> CreateZeroedIoData(const DsVeosCoSim_IoSignal& signal) {
[[nodiscard]] std::vector<uint8_t> CreateZeroedIoData(const DsVeosCoSim_IoSignal& signal) {
std::vector<uint8_t> data;
data.resize(GetDataTypeSize(signal.dataType) * signal.length);
return data;
Expand Down Expand Up @@ -142,7 +144,7 @@ void FillWithRandom(LinMessage& message, DsVeosCoSim_BusControllerId controllerI
FillWithRandom(message.data.data(), length);
}

std::vector<IoSignal> CreateSignals(size_t count) {
[[nodiscard]] std::vector<IoSignal> CreateSignals(size_t count) {
std::vector<IoSignal> signals;

for (size_t i = 0; i < count; i++) {
Expand All @@ -152,7 +154,7 @@ std::vector<IoSignal> CreateSignals(size_t count) {
return signals;
}

std::vector<CanController> CreateCanControllers(size_t count) {
[[nodiscard]] std::vector<CanController> CreateCanControllers(size_t count) {
std::vector<CanController> controllers;

for (size_t i = 0; i < count; i++) {
Expand All @@ -164,7 +166,7 @@ std::vector<CanController> CreateCanControllers(size_t count) {
return controllers;
}

std::vector<EthController> CreateEthControllers(size_t count) {
[[nodiscard]] std::vector<EthController> CreateEthControllers(size_t count) {
std::vector<EthController> controllers;

for (size_t i = 0; i < count; i++) {
Expand All @@ -176,7 +178,7 @@ std::vector<EthController> CreateEthControllers(size_t count) {
return controllers;
}

std::vector<LinController> CreateLinControllers(size_t count) {
[[nodiscard]] std::vector<LinController> CreateLinControllers(size_t count) {
std::vector<LinController> controllers;

for (size_t i = 0; i < count; i++) {
Expand Down
Loading