fix: address clang-tidy warnings in stress tests

This commit is contained in:
Stanislav Angelovič
2025-05-05 21:52:05 +02:00
parent 5fdb2f7f13
commit 55e6232b50
3 changed files with 54 additions and 19 deletions

View File

@@ -25,7 +25,10 @@ Checks: "*,\
-llvmlibc-*,\
-altera-*,\
-fuchsia-*,
-cert-err58-cpp,\
-modernize-use-trailing-return-type,\
-cppcoreguidelines-avoid-magic-numbers,\
-readability-magic-numbers,\
-readability-braces-around-statements,\
-google-readability-braces-around-statements,\
-hicpp-braces-around-statements,\

View File

@@ -268,15 +268,17 @@ endif()
if(SDBUSCPP_CLANG_TIDY)
message(STATUS "Building with static analysis")
#set(CLANG_TIDY "/home/one/CLion2/clion-2024.3.5/bin/clang/linux/x64/bin/clang-tidy")
find_program(CLANG_TIDY NAMES clang-tidy)
if(NOT CLANG_TIDY)
message(STATUS "clang-tidy not found")
message(WARNING "clang-tidy not found")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY}")
set_target_properties(sdbus-c++-objlib PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
set_target_properties(sdbus-c++ PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
set_target_properties(sdbus-c++-unit-tests PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
set_target_properties(sdbus-c++-integration-tests PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
#set_target_properties(sdbus-c++-unit-tests PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
#set_target_properties(sdbus-c++-integration-tests PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
set_target_properties(sdbus-c++-stress-tests PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
endif()
endif()

View File

@@ -62,13 +62,18 @@ public:
registerAdaptor();
}
CelsiusThermometerAdaptor(const CelsiusThermometerAdaptor&) = delete;
CelsiusThermometerAdaptor& operator=(const CelsiusThermometerAdaptor&) = delete;
CelsiusThermometerAdaptor(CelsiusThermometerAdaptor&&) = delete;
CelsiusThermometerAdaptor& operator=(CelsiusThermometerAdaptor&&) = delete;
~CelsiusThermometerAdaptor()
{
unregisterAdaptor();
}
protected:
virtual uint32_t getCurrentTemperature() override
uint32_t getCurrentTemperature() override
{
return m_currentTemperature++;
}
@@ -86,6 +91,11 @@ public:
registerProxy();
}
CelsiusThermometerProxy(const CelsiusThermometerProxy&) = delete;
CelsiusThermometerProxy& operator=(const CelsiusThermometerProxy&) = delete;
CelsiusThermometerProxy(CelsiusThermometerProxy&&) = delete;
CelsiusThermometerProxy& operator=(CelsiusThermometerProxy&&) = delete;
~CelsiusThermometerProxy()
{
unregisterProxy();
@@ -152,6 +162,11 @@ public:
registerAdaptor();
}
FahrenheitThermometerAdaptor(const FahrenheitThermometerAdaptor&) = delete;
FahrenheitThermometerAdaptor& operator=(const FahrenheitThermometerAdaptor&) = delete;
FahrenheitThermometerAdaptor(FahrenheitThermometerAdaptor&&) = delete;
FahrenheitThermometerAdaptor& operator=(FahrenheitThermometerAdaptor&&) = delete;
~FahrenheitThermometerAdaptor()
{
exit_ = true;
@@ -163,13 +178,13 @@ public:
}
protected:
virtual uint32_t getCurrentTemperature() override
uint32_t getCurrentTemperature() override
{
// In this D-Bus call, make yet another D-Bus call to another service over the same connection
return static_cast<uint32_t>(celsiusProxy_.getCurrentTemperature() * 1.8 + 32.);
}
virtual void createDelegateObject(sdbus::Result<sdbus::ObjectPath>&& result) override
void createDelegateObject(sdbus::Result<sdbus::ObjectPath>&& result) override
{
static size_t objectCounter{};
objectCounter++;
@@ -180,7 +195,7 @@ protected:
cond_.notify_one();
}
virtual void destroyDelegateObject(sdbus::Result<>&& /*result*/, sdbus::ObjectPath delegate) override
void destroyDelegateObject(sdbus::Result<>&& /*result*/, sdbus::ObjectPath delegate) override
{
std::unique_lock<std::mutex> lock(mutex_);
requests_.push(WorkItem{0, std::move(delegate), {}});
@@ -216,6 +231,11 @@ public:
registerProxy();
}
FahrenheitThermometerProxy(const FahrenheitThermometerProxy&) = delete;
FahrenheitThermometerProxy& operator=(const FahrenheitThermometerProxy&) = delete;
FahrenheitThermometerProxy(FahrenheitThermometerProxy&&) = delete;
FahrenheitThermometerProxy& operator=(FahrenheitThermometerProxy&&) = delete;
~FahrenheitThermometerProxy()
{
unregisterProxy();
@@ -262,6 +282,11 @@ public:
registerAdaptor();
}
ConcatenatorAdaptor(const ConcatenatorAdaptor&) = delete;
ConcatenatorAdaptor& operator=(const ConcatenatorAdaptor&) = delete;
ConcatenatorAdaptor(ConcatenatorAdaptor&&) = delete;
ConcatenatorAdaptor& operator=(ConcatenatorAdaptor&&) = delete;
~ConcatenatorAdaptor()
{
exit_ = true;
@@ -273,7 +298,7 @@ public:
}
protected:
virtual void concatenate(sdbus::Result<std::string>&& result, std::map<std::string, sdbus::Variant> params) override
void concatenate(sdbus::Result<std::string>&& result, std::map<std::string, sdbus::Variant> params) override
{
std::unique_lock<std::mutex> lock(mutex_);
requests_.push(WorkItem{std::move(params), std::move(result)});
@@ -303,13 +328,18 @@ public:
registerProxy();
}
ConcatenatorProxy(const ConcatenatorProxy&) = delete;
ConcatenatorProxy& operator=(const ConcatenatorProxy&) = delete;
ConcatenatorProxy(ConcatenatorProxy&&) = delete;
ConcatenatorProxy& operator=(ConcatenatorProxy&&) = delete;
~ConcatenatorProxy()
{
unregisterProxy();
}
private:
virtual void onConcatenateReply(const std::string& result, [[maybe_unused]] std::optional<sdbus::Error> error) override
void onConcatenateReply(const std::string& result, [[maybe_unused]] std::optional<sdbus::Error> error) override
{
assert(error == std::nullopt);
@@ -318,21 +348,21 @@ private:
str >> aString;
assert(aString == "sdbus-c++-stress-tests");
uint32_t aNumber;
uint32_t aNumber{};
str >> aNumber;
assert(aNumber > 0);
++repliesReceived_;
}
virtual void onConcatenatedSignal(const std::string& concatenatedString) override
void onConcatenatedSignal(const std::string& concatenatedString) override
{
std::stringstream str(concatenatedString);
std::string aString;
str >> aString;
assert(aString == "sdbus-c++-stress-tests");
uint32_t aNumber;
uint32_t aNumber{};
str >> aNumber;
assert(aNumber > 0);
@@ -345,10 +375,10 @@ public:
};
//-----------------------------------------
int main(int argc, char *argv[])
int main(int argc, char *argv[]) // NOLINT(bugprone-exception-escape, readability-function-cognitive-complexity)
{
long loops;
long loopDuration;
long loops{};
long loopDuration{};
if (argc == 1)
{
@@ -357,8 +387,8 @@ int main(int argc, char *argv[])
}
else if (argc == 3)
{
loops = std::atol(argv[1]);
loopDuration = std::atol(argv[2]);
loops = std::atol(argv[1]); // NOLINT(cert-err34-c, cppcoreguidelines-pro-bounds-pointer-arithmetic)
loopDuration = std::atol(argv[2]); // NOLINT(cert-err34-c, cppcoreguidelines-pro-bounds-pointer-arithmetic)
}
else
throw std::runtime_error("Wrong program options");
@@ -442,8 +472,8 @@ int main(int argc, char *argv[])
// Update statistics
concatenationCallsMade = localCounter;
concatenationRepliesReceived = (uint32_t)concatenator.repliesReceived_;
concatenationSignalsReceived = (uint32_t)concatenator.signalsReceived_;
concatenationRepliesReceived = static_cast<uint32_t>(concatenator.repliesReceived_);
concatenationSignalsReceived = static_cast<uint32_t>(concatenator.signalsReceived_);
}
}
});