From 279bb6295d1d1c0d7fa9849e6a7ca04805ab84b0 Mon Sep 17 00:00:00 2001 From: Richard Peters Date: Tue, 17 Sep 2024 08:54:09 +0200 Subject: [PATCH 01/11] fix: trace outgoing echo calls (#710) * fix: trace outgoing echo calls * protobuf/echo/TracingEcho: Trace message members * protobuf/echo/TracingEcho: Use the proper '0' padding * Resolve warning --- protobuf/echo/TracingEcho.cpp | 4 ++-- protobuf/echo/TracingEcho.hpp | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/protobuf/echo/TracingEcho.cpp b/protobuf/echo/TracingEcho.cpp index 2f64d9ef4..1f56fbf98 100644 --- a/protobuf/echo/TracingEcho.cpp +++ b/protobuf/echo/TracingEcho.cpp @@ -47,7 +47,7 @@ namespace services { tracer.Continue() << "["; for (auto v : value) - tracer.Continue() << infra::hex << infra::Width(2, 0) << v; + tracer.Continue() << infra::hex << infra::Width(2, '0') << v; tracer.Continue() << "]"; } @@ -168,7 +168,7 @@ namespace services auto save = stream.Reader().ConstructSaveMarker(); auto [contents, methodId] = parser.GetPartialField(); - if (stream.Failed() || (contents.Is() && contents.Get().length <= writerBuffer.max_size() - writerBuffer.size())) + if (stream.Failed() || !contents.Is() || contents.Get().length > writerBuffer.max_size() - writerBuffer.size()) break; if (contents.Is() && contents.Get().length > stream.Available()) diff --git a/protobuf/echo/TracingEcho.hpp b/protobuf/echo/TracingEcho.hpp index 61a60cfba..ddf6622c7 100644 --- a/protobuf/echo/TracingEcho.hpp +++ b/protobuf/echo/TracingEcho.hpp @@ -37,22 +37,17 @@ namespace services PrintField(static_cast(value), tracer); } - template - void PrintSubFields(const T& value, services::Tracer& tracer, typename T::template Type* = 0) + template + void PrintSubFields(const T& value, services::Tracer& tracer, std::index_sequence) { - PrintField(value.Get(std::integral_constant()), tracer); - PrintSubFields(value, tracer); + (void)((PrintField(value.Get(std::integral_constant()), tracer), true) && ...); } - template - void PrintSubFields(const T& value, services::Tracer& tracer, ...) - {} - template void PrintField(const T& value, services::Tracer& tracer, typename T::template Type<0>* = 0) { tracer.Continue() << "{"; - PrintSubFields<0>(value, tracer); + PrintSubFields(value, tracer, std::make_index_sequence{}); tracer.Continue() << "}"; } From 4a69845e0b2ffa44a96b80a792db5a9b44e98742 Mon Sep 17 00:00:00 2001 From: Richard Peters Date: Fri, 20 Sep 2024 07:44:20 +0200 Subject: [PATCH 02/11] fix: services.echo_console: parsing tokens of nested messages and arrays, formatting of messages, and properly close upon losing connection (#712) * fix(services.echo_console): parsing tokens of nested messages and arrays, formatting of messages, and properly close upon losing connection * Add hexadecimal integers, fix nested vectors and messages * services/echo_console/Console: Remove duplication --- services/echo_console/Console.cpp | 189 +++++++++++++++--------------- services/echo_console/Console.hpp | 10 +- services/echo_console/Main.cpp | 31 ++--- 3 files changed, 115 insertions(+), 115 deletions(-) diff --git a/services/echo_console/Console.cpp b/services/echo_console/Console.cpp index b9f943d07..92fcba122 100644 --- a/services/echo_console/Console.cpp +++ b/services/echo_console/Console.cpp @@ -1,5 +1,5 @@ #include "services/echo_console/Console.hpp" -#include "infra/stream/ByteOutputStream.hpp" +#include "infra/stream/StdVectorOutputStream.hpp" #include "infra/stream/StringInputStream.hpp" #include "services/tracer/GlobalTracer.hpp" #include @@ -299,14 +299,34 @@ namespace application ++parseIndex; } - while (parseIndex != line.size() && std::isdigit(line[parseIndex])) - ++parseIndex; + int32_t value = 0; + if (parseIndex != line.size() && line.substr(parseIndex, 2) == "0x") + { + tokenStart += 2; + parseIndex += 2; + while (parseIndex != line.size() && std::isxdigit(line[parseIndex])) + ++parseIndex; - std::string integer = line.substr(tokenStart, parseIndex - tokenStart); + std::string integer = line.substr(tokenStart, parseIndex - tokenStart); - int32_t value = 0; - for (std::size_t index = sign ? 1 : 0; index < integer.size(); ++index) - value = value * 10 + integer[index] - '0'; + for (std::size_t index = sign ? 1 : 0; index < integer.size(); ++index) + { + if (std::isdigit(integer[index])) + value = value * 16 + integer[index] - '0'; + else + value = value * 16 + std::tolower(integer[index]) - 'a' + 10; + } + } + else + { + while (parseIndex != line.size() && std::isdigit(line[parseIndex])) + ++parseIndex; + + std::string integer = line.substr(tokenStart, parseIndex - tokenStart); + + for (std::size_t index = sign ? 1 : 0; index < integer.size(); ++index) + value = value * 10 + integer[index] - '0'; + } if (sign) value *= -1; @@ -330,17 +350,22 @@ namespace application return ConsoleToken::String(tokenStart, identifier); } - Console::Console(EchoRoot& root) + Console::Console(EchoRoot& root, bool stopOnNetworkClose) : root(root) - , eventDispatcherThread([this]() + , eventDispatcherThread([this, stopOnNetworkClose]() { - RunEventDispatcher(); + RunEventDispatcher(stopOnNetworkClose); }) {} void Console::Run() { - while (!quit) + { + std::unique_lock lock(mutex); + started = true; + } + + while (!quit && !stoppedEventDispatcher) { std::string line; std::getline(std::cin, line); @@ -364,7 +389,7 @@ namespace application condition.notify_all(); }); - while (!processDone) + while (!processDone && !stoppedEventDispatcher) condition.wait(lock); } } @@ -592,14 +617,21 @@ namespace application std::cout << "Received method call " << methodId << " for unknown service " << serviceId << std::endl; } - void Console::RunEventDispatcher() + void Console::RunEventDispatcher(bool stopOnNetworkClose) { try { - network.Run(); + network.ExecuteUntil([this, stopOnNetworkClose]() + { + std::unique_lock lock(mutex); + return !network.NetworkActivity() && stopOnNetworkClose && started; + }); } catch (Quit&) {} + + std::unique_lock lock(mutex); + stoppedEventDispatcher = true; } void Console::ListInterfaces() @@ -745,7 +777,7 @@ namespace application MethodInvocation methodInvocation(line); auto [service, method] = SearchMethod(methodInvocation); - infra::ByteOutputStream::WithStorage<4096> stream; + infra::StdVectorOutputStream::WithStorage stream; infra::ProtoFormatter formatter(stream); formatter.PutVarInt(service->serviceId); @@ -754,8 +786,7 @@ namespace application methodInvocation.EncodeParameters(method.parameter, line.size(), formatter); } - auto range = infra::ReinterpretCastMemoryRange(stream.Writer().Processed()); - GetObserver().Send(std::string(range.begin(), range.end())); + GetObserver().Send(infra::ByteRangeAsStdString(infra::MakeRange(stream.Storage()))); } catch (ConsoleExceptions::SyntaxError& error) { @@ -767,11 +798,11 @@ namespace application } catch (ConsoleExceptions::MissingParameter& error) { - services::GlobalTracer().Trace() << "Missing parameter at index " << error.index << " (contents after that position is " << line.substr(error.index) << ")\n"; + services::GlobalTracer().Trace() << "Missing parameter at index " << error.index << " of type " << error.missingType << " (contents after that position is " << line.substr(error.index) << ")\n"; } catch (ConsoleExceptions::IncorrectType& error) { - services::GlobalTracer().Trace() << "Incorrect type at index " << error.index << " (contents after that position is " << line.substr(error.index) << ")\n"; + services::GlobalTracer().Trace() << "Incorrect type at index " << error.index << " expected type " << error.correctType << " (contents after that position is " << line.substr(error.index) << ")\n"; } catch (ConsoleExceptions::MethodNotFound& error) { @@ -942,25 +973,22 @@ namespace application if (!currentToken.Is()) throw ConsoleExceptions::SyntaxError{ IndexOf(currentToken) }; - currentToken = tokenizer.Token(); return result; } - std::vector Console::MethodInvocation::ProcessArray() + Console::MessageTokens Console::MethodInvocation::ProcessArray() { - std::vector result; + Console::MessageTokens result; while (true) { - Console::MessageTokens message; while (!currentToken.Is() && !currentToken.Is() && !currentToken.Is()) { - message.tokens.push_back(CreateMessageTokenValue()); + result.tokens.push_back(CreateMessageTokenValue()); currentToken = tokenizer.Token(); } - result.push_back(message); if (!currentToken.Is()) break; @@ -969,7 +997,6 @@ namespace application if (!currentToken.Is()) throw ConsoleExceptions::SyntaxError{ IndexOf(currentToken) }; - currentToken = tokenizer.Token(); return result; } @@ -981,7 +1008,7 @@ namespace application for (auto field : message.fields) { if (tokens.empty()) - throw ConsoleExceptions::MissingParameter{ valueIndex }; + throw ConsoleExceptions::MissingParameter{ valueIndex, field->protoType }; EncodeField(*field, tokens.front().first, tokens.front().second, formatter); tokens.erase(tokens.begin()); } @@ -1002,7 +1029,7 @@ namespace application void VisitInt64(const EchoFieldInt64& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "integer" }; formatter.PutVarIntField(value.Get(), field.number); } @@ -1010,7 +1037,7 @@ namespace application void VisitUint64(const EchoFieldUint64& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "integer" }; formatter.PutVarIntField(value.Get(), field.number); } @@ -1018,7 +1045,7 @@ namespace application void VisitInt32(const EchoFieldInt32& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "integer" }; formatter.PutVarIntField(value.Get(), field.number); } @@ -1026,7 +1053,7 @@ namespace application void VisitFixed32(const EchoFieldFixed32& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "integer" }; formatter.PutFixed32Field(static_cast(value.Get()), field.number); } @@ -1034,7 +1061,7 @@ namespace application void VisitFixed64(const EchoFieldFixed64& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "integer" }; formatter.PutFixed64Field(static_cast(value.Get()), field.number); } @@ -1042,7 +1069,7 @@ namespace application void VisitBool(const EchoFieldBool& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "bool" }; formatter.PutVarIntField(value.Get(), field.number); } @@ -1050,7 +1077,7 @@ namespace application void VisitString(const EchoFieldString& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "string" }; formatter.PutStringField(infra::BoundedConstString(value.Get().data(), value.Get().size()), field.number); } @@ -1058,7 +1085,7 @@ namespace application void VisitUnboundedString(const EchoFieldUnboundedString& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "string" }; formatter.PutStringField(infra::BoundedConstString(value.Get().data(), value.Get().size()), field.number); } @@ -1066,7 +1093,7 @@ namespace application void VisitEnum(const EchoFieldEnum& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "integer" }; formatter.PutVarIntField(value.Get(), field.number); } @@ -1074,7 +1101,7 @@ namespace application void VisitSFixed32(const EchoFieldSFixed32& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "integer" }; formatter.PutFixed32Field(static_cast(value.Get()), field.number); } @@ -1082,7 +1109,7 @@ namespace application void VisitSFixed64(const EchoFieldSFixed64& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "integer" }; formatter.PutFixed64Field(static_cast(value.Get()), field.number); } @@ -1090,55 +1117,28 @@ namespace application void VisitMessage(const EchoFieldMessage& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, field.protoType }; - methodInvocation.EncodeMessage(*field.message, value.Get(), valueIndex, formatter); + infra::StdVectorOutputStream::WithStorage stream; + infra::ProtoFormatter messageFormatter(stream); + methodInvocation.EncodeMessage(*field.message, value.Get(), valueIndex, messageFormatter); + formatter.PutLengthDelimitedField(infra::MakeRange(stream.Storage()), field.number); } void VisitBytes(const EchoFieldBytes& field) override { - if (!value.Is>()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; - std::vector bytes; - for (auto& messageTokens : value.Get>()) - { - if (messageTokens.tokens.size() < 1) - throw ConsoleExceptions::MissingParameter{ valueIndex }; - if (messageTokens.tokens.size() > 1) - throw ConsoleExceptions::TooManyParameters{ messageTokens.tokens[1].second }; - if (!messageTokens.tokens.front().first.Is()) - throw ConsoleExceptions::IncorrectType{ messageTokens.tokens[0].second }; - - bytes.push_back(static_cast(messageTokens.tokens.front().first.Get())); - } - - formatter.PutBytesField(infra::MakeRange(bytes), field.number); + PutVector(field.number); } void VisitUnboundedBytes(const EchoFieldUnboundedBytes& field) override { - if (!value.Is>()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; - std::vector bytes; - for (auto& messageTokens : value.Get>()) - { - if (messageTokens.tokens.size() < 1) - throw ConsoleExceptions::MissingParameter{ valueIndex }; - if (messageTokens.tokens.size() > 1) - throw ConsoleExceptions::TooManyParameters{ messageTokens.tokens[1].second }; - if (!messageTokens.tokens.front().first.Is()) - throw ConsoleExceptions::IncorrectType{ messageTokens.tokens[0].second }; - - bytes.push_back(static_cast(messageTokens.tokens.front().first.Get())); - } - - formatter.PutBytesField(infra::MakeRange(bytes), field.number); + PutVector(field.number); } void VisitUint32(const EchoFieldUint32& field) override { if (!value.Is()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, "integer" }; formatter.PutVarIntField(value.Get(), field.number); } @@ -1154,39 +1154,40 @@ namespace application void VisitRepeated(const EchoFieldRepeated& field) override { - if (!value.Is>()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + PutRepeated(field.protoType, field.type); + } - for (auto& messageTokens : value.Get>()) + void VisitUnboundedRepeated(const EchoFieldUnboundedRepeated& field) override + { + PutRepeated(field.protoType, field.type); + } + + private: + void PutVector(int fieldNumber) + { + if (!value.Is()) + throw ConsoleExceptions::IncorrectType{ valueIndex, "vector of integers" }; + std::vector bytes; + for (auto& messageToken : value.Get().tokens) { - if (messageTokens.tokens.size() < 1) - throw ConsoleExceptions::MissingParameter{ valueIndex }; - if (messageTokens.tokens.size() > 1) - throw ConsoleExceptions::TooManyParameters{ messageTokens.tokens[1].second }; - if (!messageTokens.tokens.front().first.Is()) - throw ConsoleExceptions::IncorrectType{ messageTokens.tokens.front().second }; + if (!messageToken.first.Is()) + throw ConsoleExceptions::IncorrectType{ messageToken.second, "integer" }; - EncodeFieldVisitor visitor(messageTokens, valueIndex, formatter, methodInvocation); - field.type->Accept(visitor); + bytes.push_back(static_cast(messageToken.first.Get())); } + + formatter.PutBytesField(infra::MakeRange(bytes), fieldNumber); } - void VisitUnboundedRepeated(const EchoFieldUnboundedRepeated& field) override + void PutRepeated(const std::string& fieldProtoType, std::shared_ptr fieldType) { if (!value.Is>()) - throw ConsoleExceptions::IncorrectType{ valueIndex }; + throw ConsoleExceptions::IncorrectType{ valueIndex, fieldProtoType }; for (auto& messageTokens : value.Get>()) { - if (messageTokens.tokens.size() < 1) - throw ConsoleExceptions::MissingParameter{ valueIndex }; - if (messageTokens.tokens.size() > 1) - throw ConsoleExceptions::TooManyParameters{ messageTokens.tokens[1].second }; - if (!messageTokens.tokens.front().first.Is()) - throw ConsoleExceptions::IncorrectType{ messageTokens.tokens.front().second }; - EncodeFieldVisitor visitor(messageTokens, valueIndex, formatter, methodInvocation); - field.type->Accept(visitor); + fieldType->Accept(visitor); } } diff --git a/services/echo_console/Console.hpp b/services/echo_console/Console.hpp index c91e276b8..9a6425deb 100644 --- a/services/echo_console/Console.hpp +++ b/services/echo_console/Console.hpp @@ -186,7 +186,7 @@ namespace application : public infra::Subject { public: - explicit Console(EchoRoot& root); + explicit Console(EchoRoot& root, bool stopOnNetworkClose); void Run(); services::ConnectionFactory& ConnectionFactory(); @@ -219,7 +219,7 @@ namespace application void ProcessParameterTokens(); std::pair CreateMessageTokenValue(); MessageTokens::MessageTokenValue ProcessMessage(); - std::vector ProcessArray(); + Console::MessageTokens ProcessArray(); void EncodeMessage(const EchoMessage& message, const MessageTokens& messageTokens, std::size_t valueIndex, infra::ProtoFormatter& formatter); void EncodeField(const EchoField& field, const MessageTokens::MessageTokenValue& value, std::size_t valueIndex, infra::ProtoFormatter& formatter); @@ -235,7 +235,7 @@ namespace application void PrintField(infra::Variant& fieldData, const EchoField& field, infra::ProtoParser& parser); void MethodNotFound(const EchoService& service, uint32_t methodId) const; void ServiceNotFound(uint32_t serviceId, uint32_t methodId) const; - void RunEventDispatcher(); + void RunEventDispatcher(bool stopOnNetworkClose); void ListInterfaces(); void ListFields(const EchoMessage& message); void Process(const std::string& line) const; @@ -246,7 +246,9 @@ namespace application main_::NetworkAdapter network; hal::TimerServiceGeneric timerService{ infra::systemTimerServiceId }; std::thread eventDispatcherThread; + bool started = false; bool quit = false; + bool stoppedEventDispatcher = false; std::mutex mutex; std::condition_variable condition; bool processDone = false; @@ -273,11 +275,13 @@ namespace application struct MissingParameter { std::size_t index; + std::string missingType; }; struct IncorrectType { std::size_t index; + std::string correctType; }; } } diff --git a/services/echo_console/Main.cpp b/services/echo_console/Main.cpp index 883346f4e..1a61b8178 100644 --- a/services/echo_console/Main.cpp +++ b/services/echo_console/Main.cpp @@ -185,7 +185,8 @@ ConsoleClientTcp::ConsoleClientTcp(services::ConnectionFactoryWithNameResolver& ConsoleClientTcp::~ConsoleClientTcp() { - consoleClientConnection->services::ConnectionObserver::Subject().AbortAndDestroy(); + if (!!consoleClientConnection) + consoleClientConnection->services::ConnectionObserver::Subject().AbortAndDestroy(); } infra::BoundedConstString ConsoleClientTcp::Hostname() const @@ -317,7 +318,8 @@ int main(int argc, char* argv[], const char* env[]) std::cout << "Loaded " << path << std::endl; } - application::Console console(root); + bool serialConnectionRequested = get(target).substr(0, 3) == "COM" || get(target).substr(0, 4) == "/dev"; + application::Console console(root, !serialConnectionRequested); services::ConnectionFactoryWithNameResolverImpl::WithStorage<4> connectionFactory(console.ConnectionFactory(), console.NameResolver()); infra::Optional consoleClientTcp; infra::Optional consoleClientWebSocket; @@ -325,24 +327,17 @@ int main(int argc, char* argv[], const char* env[]) infra::Optional> bufferedUart; infra::Optional consoleClientUart; - auto construct = [&]() + if (serialConnectionRequested) { - if (get(target).substr(0, 3) == "COM" || get(target).substr(0, 4) == "/dev") - { - uart.Emplace(get(target)); - bufferedUart.Emplace(*uart); - consoleClientUart.Emplace(console, *bufferedUart); - } - else if (services::SchemeFromUrl(infra::BoundedConstString(get(target))) == "ws") - consoleClientWebSocket.Emplace(connectionFactory, console, get(target), randomDataGenerator, tracer); - else - consoleClientTcp.Emplace(connectionFactory, console, get(target), tracer); - }; + uart.Emplace(get(target)); + bufferedUart.Emplace(*uart); + consoleClientUart.Emplace(console, *bufferedUart); + } + else if (services::SchemeFromUrl(infra::BoundedConstString(get(target))) == "ws") + consoleClientWebSocket.Emplace(connectionFactory, console, get(target), randomDataGenerator, tracer); + else + consoleClientTcp.Emplace(connectionFactory, console, get(target), tracer); - infra::EventDispatcher::Instance().Schedule([&construct]() - { - construct(); - }); console.Run(); } catch (const args::Help&) From bee0cd8433ad3325f2dcbf4d70651e4d04ce4960 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 09:20:47 +0200 Subject: [PATCH 03/11] build(deps): bump the minor-and-patch-action-updates group across 1 directory with 5 updates (#717) Bumps the minor-and-patch-action-updates group with 5 updates in the / directory: | Package | From | To | | --- | --- | --- | | [actions/checkout](https://github.com/actions/checkout) | `4.1.7` | `4.2.0` | | [lukka/run-cmake](https://github.com/lukka/run-cmake) | `10.7` | `10.8` | | [github/codeql-action](https://github.com/github/codeql-action) | `3.26.6` | `3.26.9` | | [reviewdog/action-suggester](https://github.com/reviewdog/action-suggester) | `1.17.0` | `1.18.0` | | [actions/create-github-app-token](https://github.com/actions/create-github-app-token) | `1.10.3` | `1.11.0` | Updates `actions/checkout` from 4.1.7 to 4.2.0 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/692973e3d937129bcbf40652eb9f2f61becf3332...d632683dd7b4114ad314bca15554477dd762a938) Updates `lukka/run-cmake` from 10.7 to 10.8 - [Release notes](https://github.com/lukka/run-cmake/releases) - [Commits](https://github.com/lukka/run-cmake/compare/2ce8982be71b8e9a3c4d5e432135035afd1e76a7...af1be47fd7c933593f687731bc6fdbee024d3ff4) Updates `github/codeql-action` from 3.26.6 to 3.26.9 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/4dd16135b69a43b6c8efb853346f8437d92d3c93...461ef6c76dfe95d5c364de2f431ddbd31a417628) Updates `reviewdog/action-suggester` from 1.17.0 to 1.18.0 - [Release notes](https://github.com/reviewdog/action-suggester/releases) - [Commits](https://github.com/reviewdog/action-suggester/compare/63b8f8cc21dfa052ac44436e65ed31edcffcb6c1...db4abb16fbaabe386831e5addb7be1485d0d63d3) Updates `actions/create-github-app-token` from 1.10.3 to 1.11.0 - [Release notes](https://github.com/actions/create-github-app-token/releases) - [Commits](https://github.com/actions/create-github-app-token/compare/31c86eb3b33c9b601a1f60f98dcbfd1d70f379b4...5d869da34e18e7287c1daad50e0b8ea0f506ce69) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch-action-updates - dependency-name: lukka/run-cmake dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch-action-updates - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch dependency-group: minor-and-patch-action-updates - dependency-name: reviewdog/action-suggester dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch-action-updates - dependency-name: actions/create-github-app-token dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor-and-patch-action-updates ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 32 ++++++++++++------------ .github/workflows/dependency-scanner.yml | 4 +-- .github/workflows/documentation.yml | 6 ++--- .github/workflows/linting-formatting.yml | 6 ++--- .github/workflows/release-please.yml | 6 ++--- .github/workflows/security.yml | 4 +-- .github/workflows/static-analysis.yml | 12 ++++----- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6dbda8230..b9f2db25d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: name: Host Build & Test (ubuntu-latest) runs-on: ubuntu-latest steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - uses: hendrikmuhs/ccache-action@ed74d11c0b343532753ecead8a951bb09bb34bc9 # v1.2.14 @@ -30,7 +30,7 @@ jobs: key: ${{ github.job }}-ubuntu-latest variant: sccache - uses: seanmiddleditch/gha-setup-ninja@96bed6edff20d1dd61ecff9b75cc519d516e6401 # v5 - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "host" buildPreset: "host-Debug-WithPackage" @@ -52,14 +52,14 @@ jobs: runs-on: ubuntu-latest container: ghcr.io/philips-software/amp-devcontainer-cpp:5.1.4@sha256:46239906460dedb3baf3c33d9275f3de4f17d7a237fc136c2013b021589a6dbd # 5.1.4 steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - uses: hendrikmuhs/ccache-action@ed74d11c0b343532753ecead8a951bb09bb34bc9 # v1.2.14 with: key: ${{ github.job }}-ubuntu-latest - uses: seanmiddleditch/gha-setup-ninja@96bed6edff20d1dd61ecff9b75cc519d516e6401 # v5 - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "host" buildPreset: "host-RelWithDebInfo" @@ -76,7 +76,7 @@ jobs: runs-on: ubuntu-latest container: ghcr.io/philips-software/amp-devcontainer-cpp:5.1.4@sha256:46239906460dedb3baf3c33d9275f3de4f17d7a237fc136c2013b021589a6dbd # 5.1.4 steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 @@ -90,7 +90,7 @@ jobs: with: key: ${{ github.job }}-clang-msvc - uses: seanmiddleditch/gha-setup-ninja@96bed6edff20d1dd61ecff9b75cc519d516e6401 # v5 - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "host-ClangMsvc" buildPreset: "host-ClangMsvc-Debug" @@ -102,14 +102,14 @@ jobs: matrix: os: [macos-latest, windows-latest, windows-2019] steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - uses: hendrikmuhs/ccache-action@ed74d11c0b343532753ecead8a951bb09bb34bc9 # v1.2.14 with: key: ${{ github.job }}-${{ matrix.os }} variant: sccache - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "host-single-Debug" buildPreset: "host-single-Debug" @@ -125,7 +125,7 @@ jobs: name: Host Build without MbedTLS runs-on: ubuntu-latest steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - uses: hendrikmuhs/ccache-action@ed74d11c0b343532753ecead8a951bb09bb34bc9 # v1.2.14 @@ -133,7 +133,7 @@ jobs: key: ${{ github.job }}-ubuntu-latest variant: sccache - uses: seanmiddleditch/gha-setup-ninja@96bed6edff20d1dd61ecff9b75cc519d516e6401 # v5 - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "host-no-mbedtls" buildPreset: "host-no-mbedtls-Debug" @@ -147,7 +147,7 @@ jobs: gcc: ["7-2018-q2", "8-2019-q3", "9-2020-q2", "10.3-2021.10"] configuration: ["RelWithDebInfo"] steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - name: Install GNU Arm Embedded Toolchain ${{ matrix.gcc }} @@ -163,7 +163,7 @@ jobs: name: emil - run: tar -zxvf emil-*.tar.gz - run: mkdir install && mv emil-*/* install/ - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "embedded" buildPreset: "embedded-${{ matrix.configuration }}" @@ -172,7 +172,7 @@ jobs: name: Embedded Build Without Host Install runs-on: ubuntu-latest steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - name: Install GNU Arm Embedded Toolchain 10.3-2021.10 @@ -183,7 +183,7 @@ jobs: - uses: hendrikmuhs/ccache-action@ed74d11c0b343532753ecead8a951bb09bb34bc9 # v1.2.14 with: key: ${{ github.job }} - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "embedded" buildPreset: "embedded-RelWithDebInfo" @@ -196,7 +196,7 @@ jobs: matrix: rtos: ["FreeRTOS", "ThreadX"] steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - name: Install GNU Arm Embedded Toolchain 10.3-2021.10 @@ -212,7 +212,7 @@ jobs: name: emil - run: tar -zxvf emil-*.tar.gz - run: mkdir install && mv emil-*/* install/ - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "embedded-${{ matrix.rtos }}" buildPreset: "embedded-${{ matrix.rtos }}-RelWithDebInfo" diff --git a/.github/workflows/dependency-scanner.yml b/.github/workflows/dependency-scanner.yml index 0c0543234..712c05fa8 100644 --- a/.github/workflows/dependency-scanner.yml +++ b/.github/workflows/dependency-scanner.yml @@ -16,7 +16,7 @@ jobs: contents: write pull-requests: write steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - uses: philips-forks/cmake-dependency-submission@72880580a7cafc16145d82268f1892c0ece3da2a # main dependency-review: runs-on: ubuntu-latest @@ -25,7 +25,7 @@ jobs: permissions: pull-requests: write steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - uses: actions/dependency-review-action@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c # v4.3.4 with: comment-summary-in-pr: true diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 362e5c89f..d9674851c 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -16,7 +16,7 @@ jobs: if: ${{ github.ref == 'refs/heads/main' }} steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: fetch-depth: 0 persist-credentials: false @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: fetch-depth: 0 persist-credentials: false @@ -69,7 +69,7 @@ jobs: name: Publish to GitHub Pages steps: - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Retrieve Antora Site uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 with: diff --git a/.github/workflows/linting-formatting.yml b/.github/workflows/linting-formatting.yml index c74f94bcb..600e65b86 100644 --- a/.github/workflows/linting-formatting.yml +++ b/.github/workflows/linting-formatting.yml @@ -22,7 +22,7 @@ jobs: pull-requests: write security-events: write steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: fetch-depth: 0 persist-credentials: false @@ -32,7 +32,7 @@ jobs: VALIDATE_ALL_CODEBASE: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: git diff - - uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6 + - uses: github/codeql-action/upload-sarif@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 if: ${{ success() || failure() }} with: sarif_file: megalinter-reports/megalinter-report.sarif @@ -42,6 +42,6 @@ jobs: name: linter path: | megalinter-reports - - uses: reviewdog/action-suggester@63b8f8cc21dfa052ac44436e65ed31edcffcb6c1 # v1.17.0 + - uses: reviewdog/action-suggester@db4abb16fbaabe386831e5addb7be1485d0d63d3 # v1.18.0 with: tool_name: MegaLinter diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index eb2e612c8..f12968c0b 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -20,7 +20,7 @@ jobs: releases_created: ${{ steps.release.outputs.releases_created }} tag_name: ${{ steps.release.outputs.tag_name }} steps: - - uses: actions/create-github-app-token@31c86eb3b33c9b601a1f60f98dcbfd1d70f379b4 # v1.10.3 + - uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0 id: token with: app-id: ${{ vars.FOREST_RELEASER_APP_ID }} @@ -40,14 +40,14 @@ jobs: matrix: os: [macos-latest, ubuntu-latest, windows-latest] steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - uses: hendrikmuhs/ccache-action@ed74d11c0b343532753ecead8a951bb09bb34bc9 # v1.2.14 with: key: ${{ github.job }}-${{ matrix.os }} variant: sccache - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "host-single-MinSizeRel" buildPreset: "release-package" diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 063459d66..0016b6fa5 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -21,7 +21,7 @@ jobs: actions: read contents: read steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - name: Analysis @@ -31,6 +31,6 @@ jobs: results_format: sarif repo_token: ${{ secrets.SCORECARD_READ_TOKEN }} publish_results: true - - uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6 + - uses: github/codeql-action/upload-sarif@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 with: sarif_file: scorecards.sarif diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 28859f2de..ac280e0ca 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -23,7 +23,7 @@ jobs: SONAR_SCANNER_VERSION: 5.0.1.3006 SONAR_SERVER_URL: "https://sonarcloud.io" steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: fetch-depth: 0 # Disable shallow clone to enable blame information persist-credentials: false @@ -42,7 +42,7 @@ jobs: cmake --build --preset coverage GTEST_OUTPUT="xml:${PWD}/testresults/" ctest --preset coverage gcovr --sonarqube=coverage.xml --exclude-lines-by-pattern '.*assert\(.*\);|.*really_assert\(.*\);|.*std::abort();' --exclude-unreachable-branches --exclude-throw-branches -j "$(nproc)" --exclude=.*/generated/.* --exclude=.*/examples/.* --exclude=.*/external/.* --exclude=.*/lwip/.* --exclude=.*/tracing/.* --exclude=.*/test/.* - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "mutation-testing" buildPreset: "mutation-testing" @@ -69,18 +69,18 @@ jobs: permissions: security-events: write steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: persist-credentials: false - uses: hendrikmuhs/ccache-action@ed74d11c0b343532753ecead8a951bb09bb34bc9 # v1.2.14 with: key: ${{ github.job }} - - uses: github/codeql-action/init@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6 + - uses: github/codeql-action/init@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 with: languages: cpp - - uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7 + - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 with: configurePreset: "host" buildPreset: "host-Debug" configurePresetAdditionalArgs: "['-DCMAKE_C_COMPILER_LAUNCHER=ccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache']" - - uses: github/codeql-action/analyze@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6 + - uses: github/codeql-action/analyze@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 From 594b9c17006367a06ce930c34d2b5b0468996129 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 09:21:19 +0200 Subject: [PATCH 04/11] build(deps): bump philips-software/amp-devcontainer-cpp from v5.1.4 to v5.2.0 in /.devcontainer (#713) build(deps): bump philips-software/amp-devcontainer-cpp Bumps [philips-software/amp-devcontainer-cpp](https://github.com/philips-software/amp-devcontainer) from v5.1.4 to v5.2.0. - [Release notes](https://github.com/philips-software/amp-devcontainer/releases) - [Changelog](https://github.com/philips-software/amp-devcontainer/blob/main/CHANGELOG.md) - [Commits](https://github.com/philips-software/amp-devcontainer/compare/v5.1.4...v5.2.0) --- updated-dependencies: - dependency-name: philips-software/amp-devcontainer-cpp dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7b4c7a681..24e2c9c7d 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,3 +1,3 @@ -FROM ghcr.io/philips-software/amp-devcontainer-cpp:v5.1.4@sha256:46239906460dedb3baf3c33d9275f3de4f17d7a237fc136c2013b021589a6dbd +FROM ghcr.io/philips-software/amp-devcontainer-cpp:v5.2.0@sha256:c47fcc83b59fb08f3a3a6e591b18bad49b3862acc35770fca6cec9ad0adb9cb2 HEALTHCHECK NONE From 7821a57dc3c0434eb85ae9a92c81e46130f67f23 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 3 Oct 2024 09:08:13 +0200 Subject: [PATCH 05/11] build(deps): bump github/codeql-action from 3.26.9 to 3.26.10 in the minor-and-patch-action-updates group (#720) build(deps): bump github/codeql-action Bumps the minor-and-patch-action-updates group with 1 update: [github/codeql-action](https://github.com/github/codeql-action). Updates `github/codeql-action` from 3.26.9 to 3.26.10 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/461ef6c76dfe95d5c364de2f431ddbd31a417628...e2b3eafc8d227b0241d48be5f425d47c2d750a13) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch dependency-group: minor-and-patch-action-updates ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/linting-formatting.yml | 2 +- .github/workflows/security.yml | 2 +- .github/workflows/static-analysis.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linting-formatting.yml b/.github/workflows/linting-formatting.yml index 600e65b86..0a265e6d2 100644 --- a/.github/workflows/linting-formatting.yml +++ b/.github/workflows/linting-formatting.yml @@ -32,7 +32,7 @@ jobs: VALIDATE_ALL_CODEBASE: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: git diff - - uses: github/codeql-action/upload-sarif@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 + - uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10 if: ${{ success() || failure() }} with: sarif_file: megalinter-reports/megalinter-report.sarif diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 0016b6fa5..b189de75a 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -31,6 +31,6 @@ jobs: results_format: sarif repo_token: ${{ secrets.SCORECARD_READ_TOKEN }} publish_results: true - - uses: github/codeql-action/upload-sarif@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 + - uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10 with: sarif_file: scorecards.sarif diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index ac280e0ca..4ee9d4817 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -75,7 +75,7 @@ jobs: - uses: hendrikmuhs/ccache-action@ed74d11c0b343532753ecead8a951bb09bb34bc9 # v1.2.14 with: key: ${{ github.job }} - - uses: github/codeql-action/init@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 + - uses: github/codeql-action/init@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10 with: languages: cpp - uses: lukka/run-cmake@af1be47fd7c933593f687731bc6fdbee024d3ff4 # v10.8 @@ -83,4 +83,4 @@ jobs: configurePreset: "host" buildPreset: "host-Debug" configurePresetAdditionalArgs: "['-DCMAKE_C_COMPILER_LAUNCHER=ccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache']" - - uses: github/codeql-action/analyze@461ef6c76dfe95d5c364de2f431ddbd31a417628 # v3.26.9 + - uses: github/codeql-action/analyze@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10 From 95ddf856192b8eb7e7282f3cb6f4e028aef200ad Mon Sep 17 00:00:00 2001 From: Daan Timmer <8293597+daantimmer@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:52:33 +0200 Subject: [PATCH 06/11] feat: extend gpio interrupt interface to enable immediate interrupt handlers (#721) --- hal/interfaces/Gpio.cpp | 7 ++++--- hal/interfaces/Gpio.hpp | 13 ++++++++++--- hal/interfaces/test_doubles/GpioMock.hpp | 21 +++++++++++---------- hal/interfaces/test_doubles/GpioStub.cpp | 8 +++++++- hal/interfaces/test_doubles/GpioStub.hpp | 10 ++++------ services/util/GpioPinInverted.cpp | 9 +++++++-- services/util/GpioPinInverted.hpp | 4 ++-- 7 files changed, 45 insertions(+), 27 deletions(-) diff --git a/hal/interfaces/Gpio.cpp b/hal/interfaces/Gpio.cpp index 027d9fd49..308d2f81f 100644 --- a/hal/interfaces/Gpio.cpp +++ b/hal/interfaces/Gpio.cpp @@ -1,4 +1,5 @@ #include "hal/interfaces/Gpio.hpp" +#include "infra/util/Function.hpp" namespace hal { @@ -20,9 +21,9 @@ namespace hal return pin.Get(); } - void InputPin::EnableInterrupt(const infra::Function& action, InterruptTrigger trigger) + void InputPin::EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type) { - pin.EnableInterrupt(action, trigger); + pin.EnableInterrupt(action, trigger, type); } void InputPin::DisableInterrupt() @@ -133,7 +134,7 @@ namespace hal void DummyPin::ResetConfig() {} - void DummyPin::EnableInterrupt(const infra::Function& actionOnInterrupt, InterruptTrigger trigger) + void DummyPin::EnableInterrupt(const infra::Function& actionOnInterrupt, InterruptTrigger trigger, InterruptType type) {} void DummyPin::DisableInterrupt() diff --git a/hal/interfaces/Gpio.hpp b/hal/interfaces/Gpio.hpp index 408afea17..bf0aec326 100644 --- a/hal/interfaces/Gpio.hpp +++ b/hal/interfaces/Gpio.hpp @@ -2,6 +2,7 @@ #define HAL_GPIO_HPP #include "infra/util/Function.hpp" +#include namespace hal { @@ -12,6 +13,12 @@ namespace hal bothEdges }; + enum class InterruptType : uint8_t + { + dispatched, + immediate + }; + enum class PinConfigType : uint8_t { input, @@ -40,7 +47,7 @@ namespace hal virtual void Config(PinConfigType config, bool startOutputState) = 0; virtual void ResetConfig() = 0; - virtual void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger) = 0; + virtual void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type = InterruptType::dispatched) = 0; virtual void DisableInterrupt() = 0; }; @@ -54,7 +61,7 @@ namespace hal bool Get() const; - void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger); + void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type = InterruptType::dispatched); void DisableInterrupt(); private: @@ -110,7 +117,7 @@ namespace hal void Config(PinConfigType config) override; void Config(PinConfigType config, bool startOutputState) override; void ResetConfig() override; - void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger) override; + void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type = InterruptType::dispatched) override; void DisableInterrupt() override; }; diff --git a/hal/interfaces/test_doubles/GpioMock.hpp b/hal/interfaces/test_doubles/GpioMock.hpp index 63b134e89..b663b4bfa 100644 --- a/hal/interfaces/test_doubles/GpioMock.hpp +++ b/hal/interfaces/test_doubles/GpioMock.hpp @@ -2,6 +2,7 @@ #define HAL_GPIO_MOCK_HPP #include "hal/interfaces/Gpio.hpp" +#include "infra/util/Function.hpp" #include "gmock/gmock.h" namespace hal @@ -10,16 +11,16 @@ namespace hal : public GpioPin { public: - MOCK_CONST_METHOD0(Get, bool()); - MOCK_METHOD1(Set, void(bool value)); - MOCK_CONST_METHOD0(GetOutputLatch, bool()); - MOCK_METHOD0(SetAsInput, void()); - MOCK_CONST_METHOD0(IsInput, bool()); - MOCK_METHOD1(Config, void(PinConfigType config)); - MOCK_METHOD2(Config, void(PinConfigType config, bool startOutputState)); - MOCK_METHOD0(ResetConfig, void()); - MOCK_METHOD2(EnableInterrupt, void(const infra::Function& action, InterruptTrigger trigger)); - MOCK_METHOD0(DisableInterrupt, void()); + MOCK_METHOD(bool, Get, (), (const override)); + MOCK_METHOD(void, Set, (bool value), (override)); + MOCK_METHOD(bool, GetOutputLatch, (), (const override)); + MOCK_METHOD(void, SetAsInput, (), (override)); + MOCK_METHOD(bool, IsInput, (), (const override)); + MOCK_METHOD(void, Config, (PinConfigType config), (override)); + MOCK_METHOD(void, Config, (PinConfigType config, bool startOutputState), (override)); + MOCK_METHOD(void, ResetConfig, (), (override)); + MOCK_METHOD(void, EnableInterrupt, (const infra::Function& action, InterruptTrigger trigger, InterruptType type), (override)); + MOCK_METHOD(void, DisableInterrupt, (), (override)); }; } diff --git a/hal/interfaces/test_doubles/GpioStub.cpp b/hal/interfaces/test_doubles/GpioStub.cpp index 2bee4f03a..6a11c7679 100644 --- a/hal/interfaces/test_doubles/GpioStub.cpp +++ b/hal/interfaces/test_doubles/GpioStub.cpp @@ -1,5 +1,11 @@ #include "hal/interfaces/test_doubles/GpioStub.hpp" +#include "hal/interfaces/Gpio.hpp" +#include "infra/timer/Timer.hpp" #include "infra/util/CompareMembers.hpp" +#include "infra/util/Function.hpp" +#include "infra/util/Optional.hpp" +#include +#include namespace hal { @@ -50,7 +56,7 @@ namespace hal void GpioPinStub::ResetConfig() {} - void GpioPinStub::EnableInterrupt(const infra::Function& actionOnInterrupt, InterruptTrigger trigger) + void GpioPinStub::EnableInterrupt(const infra::Function& actionOnInterrupt, InterruptTrigger trigger, InterruptType type) { triggerOnChange = std::make_pair(actionOnInterrupt, trigger); } diff --git a/hal/interfaces/test_doubles/GpioStub.hpp b/hal/interfaces/test_doubles/GpioStub.hpp index ec4ff0ee8..33066760d 100644 --- a/hal/interfaces/test_doubles/GpioStub.hpp +++ b/hal/interfaces/test_doubles/GpioStub.hpp @@ -2,12 +2,10 @@ #define HAL_GPIO_STUB_HPP #include "hal/interfaces/Gpio.hpp" -#include "infra/timer/TimerService.hpp" +#include "infra/timer/Timer.hpp" +#include "infra/util/Function.hpp" #include "infra/util/Optional.hpp" -#include "infra/util/VariantDetail.hpp" -#include -#include -#include +#include #include namespace hal @@ -26,7 +24,7 @@ namespace hal void Config(PinConfigType config) override; void Config(PinConfigType config, bool startOutputState) override; void ResetConfig() override; - void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger) override; + void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type) override; void DisableInterrupt() override; void SetStubState(bool value); diff --git a/services/util/GpioPinInverted.cpp b/services/util/GpioPinInverted.cpp index 5b3f63702..3f5d74307 100644 --- a/services/util/GpioPinInverted.cpp +++ b/services/util/GpioPinInverted.cpp @@ -1,4 +1,9 @@ #include "services/util/GpioPinInverted.hpp" +#include "hal/interfaces/Gpio.hpp" +#include "infra/util/Function.hpp" +#include +#include +#include namespace services { @@ -46,12 +51,12 @@ namespace services pin.ResetConfig(); } - void GpioPinInverted::EnableInterrupt(const infra::Function& action, hal::InterruptTrigger trigger) + void GpioPinInverted::EnableInterrupt(const infra::Function& action, hal::InterruptTrigger trigger, hal::InterruptType type) { static const std::array inverse = { hal::InterruptTrigger::fallingEdge, hal::InterruptTrigger::risingEdge, hal::InterruptTrigger::bothEdges }; assert(static_cast(trigger) < inverse.size()); - pin.EnableInterrupt(action, inverse[static_cast(trigger)]); + pin.EnableInterrupt(action, inverse[static_cast(trigger)], type); } void GpioPinInverted::DisableInterrupt() diff --git a/services/util/GpioPinInverted.hpp b/services/util/GpioPinInverted.hpp index b1e83bfa0..2ba06d08c 100644 --- a/services/util/GpioPinInverted.hpp +++ b/services/util/GpioPinInverted.hpp @@ -2,7 +2,7 @@ #define SERVICES_GPIO_PIN_INVERTED_HPP #include "hal/interfaces/Gpio.hpp" -#include "infra/timer/Timer.hpp" +#include "infra/util/Function.hpp" namespace services { @@ -20,7 +20,7 @@ namespace services void Config(hal::PinConfigType config) override; void Config(hal::PinConfigType config, bool startOutputState) override; void ResetConfig() override; - void EnableInterrupt(const infra::Function& action, hal::InterruptTrigger trigger) override; + void EnableInterrupt(const infra::Function& action, hal::InterruptTrigger trigger, hal::InterruptType type) override; void DisableInterrupt() override; private: From 609b36528066e64db9521f7c5cc54a0df1d349d0 Mon Sep 17 00:00:00 2001 From: Richard Peters Date: Fri, 4 Oct 2024 13:04:15 +0200 Subject: [PATCH 07/11] refactor: ble interfaces (#715) * services/ble/GattClient: Require less information for characteristic and descriptor discovery * Update TestGattClient * Gatt.proto: Remove Stop*Discovery * services/ble/Gatt: Add GattDescriptor fields and accessors * services/ble/GattClient: Remove const from interface methods * services/ble/GattClient: Fix order of methods * Improve tracing of not found service methods * services/ble/Gatt: Add comparison operator to GattDescriptor * Require CXX standard 20 for use of spaceship operator * Fix infra/util/Endian for C++20 * TestCucumberWireProtocolServer: Resolve warning * infra/timer/Timer.hpp: Remove PrintTo from namespace std * Revert "infra/timer/Timer.hpp: Remove PrintTo from namespace std" This reverts commit 6048fe6a1c580340a113c761d3b793182eb8dc74. * infra/util/CMakeLists: set permissive for VS2019 * infra/util/CMakeLists: set permissive for VS2019 * Undo usage of C++20 * infra/util/Variant: Add default move constructor/assignment operator with noexcept specification --- infra/event/EventDispatcher.cpp | 4 ++ infra/event/EventDispatcherWithWeakPtr.cpp | 4 ++ infra/util/Endian.hpp | 8 ++-- infra/util/Variant.hpp | 2 + protobuf/echo/Serialization.cpp | 2 - protobuf/echo/TracingEcho.cpp | 2 +- .../protoc_echo_plugin/ProtoCEchoPlugin.cpp | 2 +- services/ble/Gatt.cpp | 30 ++++++++++++++ services/ble/Gatt.hpp | 21 +++++++--- services/ble/Gatt.proto | 5 --- services/ble/GattClient.cpp | 8 ++-- services/ble/GattClient.hpp | 39 ++++++++++++------- services/ble/GattServerCharacteristicImpl.hpp | 2 +- services/ble/test/TestGattClient.cpp | 10 ++--- services/ble/test_doubles/GattClientMock.hpp | 28 ++++++++----- .../test/TestCucumberWireProtocolServer.cpp | 2 +- 16 files changed, 113 insertions(+), 56 deletions(-) diff --git a/infra/event/EventDispatcher.cpp b/infra/event/EventDispatcher.cpp index bf26d1db5..9e4e43c78 100644 --- a/infra/event/EventDispatcher.cpp +++ b/infra/event/EventDispatcher.cpp @@ -65,6 +65,10 @@ namespace infra { struct ExceptionSafePop { + ExceptionSafePop(EventDispatcherWorkerImpl& worker) + : worker(worker) + {} + ExceptionSafePop(const ExceptionSafePop&) = delete; ExceptionSafePop& operator=(const ExceptionSafePop&) = delete; diff --git a/infra/event/EventDispatcherWithWeakPtr.cpp b/infra/event/EventDispatcherWithWeakPtr.cpp index d256a633d..1cb0e7694 100644 --- a/infra/event/EventDispatcherWithWeakPtr.cpp +++ b/infra/event/EventDispatcherWithWeakPtr.cpp @@ -81,6 +81,10 @@ namespace infra { struct ExceptionSafePop { + ExceptionSafePop(EventDispatcherWithWeakPtrWorker& worker) + : worker(worker) + {} + ExceptionSafePop(const ExceptionSafePop&) = delete; ExceptionSafePop& operator=(const ExceptionSafePop&) = delete; diff --git a/infra/util/Endian.hpp b/infra/util/Endian.hpp index af9214146..deb75d690 100644 --- a/infra/util/Endian.hpp +++ b/infra/util/Endian.hpp @@ -163,24 +163,24 @@ namespace infra friend bool operator==(T x, BigEndian y) { - return y == x; + return y.operator==(x); } friend bool operator!=(T x, BigEndian y) { - return y != x; + return y.operator!=(x); } template friend bool operator==(U x, BigEndian y) { - return y == x; + return y.operator==(x); } template friend bool operator!=(U x, BigEndian y) { - return y != x; + return y.operator!=(x); } private: diff --git a/infra/util/Variant.hpp b/infra/util/Variant.hpp index 0c00b9727..2562a6a02 100644 --- a/infra/util/Variant.hpp +++ b/infra/util/Variant.hpp @@ -20,6 +20,7 @@ namespace infra Variant(); Variant(const Variant& other); + Variant(Variant&& other) noexcept((std::is_nothrow_move_constructible_v && ...)) = default; template Variant(const Variant& other); template @@ -30,6 +31,7 @@ namespace infra Variant(AtIndex, std::size_t index, Args&&... args); Variant& operator=(const Variant& other); + Variant& operator=(Variant&& other) noexcept((std::is_nothrow_move_assignable_v && ...) && (std::is_nothrow_move_constructible_v && ...)) = default; template Variant& operator=(const Variant& other); template diff --git a/protobuf/echo/Serialization.cpp b/protobuf/echo/Serialization.cpp index aea1646c9..3b16b155f 100644 --- a/protobuf/echo/Serialization.cpp +++ b/protobuf/echo/Serialization.cpp @@ -11,8 +11,6 @@ namespace services { while (!reader->Empty()) reader->ExtractContiguousRange(std::numeric_limits::max()); - - reader = nullptr; } void MethodDeserializerDummy::ExecuteMethod() diff --git a/protobuf/echo/TracingEcho.cpp b/protobuf/echo/TracingEcho.cpp index 1f56fbf98..ace696933 100644 --- a/protobuf/echo/TracingEcho.cpp +++ b/protobuf/echo/TracingEcho.cpp @@ -173,7 +173,7 @@ namespace services if (contents.Is() && contents.Get().length > stream.Available()) { - tracer.Trace() << "< message too big"; + tracer.Trace() << "< message too big for service " << serviceId << " method " << methodId << " length " << contents.Get().length << " available " << stream.Available(); skipping = contents.Get().length; writerBuffer.erase(writerBuffer.begin(), writerBuffer.begin() + stream.Reader().Processed()); auto skippingNow = std::min(skipping, writerBuffer.size()); diff --git a/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp b/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp index 1da7ccf4e..aa5870bf1 100644 --- a/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp +++ b/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp @@ -1584,7 +1584,7 @@ switch (methodId) printer.Print("}\n"); } else - printer.Print(R"(tracer.Continue() << "$servicename$ method " << methodId << " not found";\n)", "servicename", service->name); + printer.Print(R"(tracer.Continue() << "$servicename$ method " << methodId << " not found";\ncontents.SkipEverything();\n)", "servicename", service->name); } return result.str(); diff --git a/services/ble/Gatt.cpp b/services/ble/Gatt.cpp index 283798149..55ba3ad06 100644 --- a/services/ble/Gatt.cpp +++ b/services/ble/Gatt.cpp @@ -2,6 +2,36 @@ namespace services { + GattDescriptor::GattDescriptor(const AttAttribute::Uuid& type, AttAttribute::Handle handle) + : type(type) + , handle(handle) + {} + + const AttAttribute::Uuid& GattDescriptor::Type() const + { + return type; + } + + AttAttribute::Handle GattDescriptor::Handle() const + { + return handle; + } + + AttAttribute::Handle& GattDescriptor::Handle() + { + return handle; + } + + bool GattDescriptor::operator==(const GattDescriptor& other) const + { + return type == other.type && handle == other.handle; + } + + bool GattDescriptor::operator!=(const GattDescriptor& other) const + { + return !(*this == other); + } + GattCharacteristic::GattCharacteristic(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle valueHandle, GattCharacteristic::PropertyFlags properties) : type(type) , handle(handle) diff --git a/services/ble/Gatt.hpp b/services/ble/Gatt.hpp index 82e9972c5..4d04aa21d 100644 --- a/services/ble/Gatt.hpp +++ b/services/ble/Gatt.hpp @@ -35,6 +35,21 @@ namespace services enableIndication = 0x0002, }; }; + + GattDescriptor(const AttAttribute::Uuid& type, AttAttribute::Handle handle); + GattDescriptor() = default; + + const AttAttribute::Uuid& Type() const; + + AttAttribute::Handle Handle() const; + AttAttribute::Handle& Handle(); + + bool operator==(const GattDescriptor& other) const; + bool operator!=(const GattDescriptor& other) const; + + private: + AttAttribute::Uuid type; + AttAttribute::Handle handle; }; namespace uuid @@ -72,9 +87,6 @@ namespace services public: GattCharacteristic(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle valueHandle, PropertyFlags properties); GattCharacteristic() = default; - GattCharacteristic(GattCharacteristic& other) = delete; - GattCharacteristic& operator=(const GattCharacteristic& other) = delete; - virtual ~GattCharacteristic() = default; const PropertyFlags& Properties() const; const AttAttribute::Uuid& Type() const; @@ -96,9 +108,6 @@ namespace services public: GattService(const AttAttribute::Uuid& type); GattService(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle endHandle); - GattService(GattService& other) = delete; - GattService& operator=(const GattService& other) = delete; - virtual ~GattService() = default; AttAttribute::Uuid Type() const; AttAttribute::Handle Handle() const; diff --git a/services/ble/Gatt.proto b/services/ble/Gatt.proto index a857aa531..d1c1146e8 100644 --- a/services/ble/Gatt.proto +++ b/services/ble/Gatt.proto @@ -94,13 +94,8 @@ service GattClient rpc MtuSizeExchangeRequest(Nothing) returns (Nothing) { option (method_id) = 1; } rpc StartServiceDiscovery(Nothing) returns (Nothing) { option (method_id) = 2; } - rpc StopServiceDiscovery(Nothing) returns (Nothing) { option (method_id) = 3; } - rpc StartCharacteristicDiscovery(HandleRange) returns (Nothing) { option (method_id) = 4; } - rpc StopCharacteristicDiscovery(Nothing) returns (Nothing) { option (method_id) = 5; } - rpc StartDescriptorDiscovery(HandleRange) returns (Nothing) { option (method_id) = 6; } - rpc StopDescriptorDiscovery(Nothing) returns (Nothing) { option (method_id) = 7; } rpc Read(Handle) returns (Nothing) { option (method_id) = 8; } rpc Write(CharacteristicData) returns (Nothing) { option (method_id) = 9; } diff --git a/services/ble/GattClient.cpp b/services/ble/GattClient.cpp index ddf67e65d..cf4b385a1 100644 --- a/services/ble/GattClient.cpp +++ b/services/ble/GattClient.cpp @@ -148,13 +148,13 @@ namespace services GattClientDiscoveryObserver::Subject().StartServiceDiscovery(); } - void GattClientDiscoveryDecorator::StartCharacteristicDiscovery(const GattService& service) + void GattClientDiscoveryDecorator::StartCharacteristicDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) { - GattClientDiscoveryObserver::Subject().StartCharacteristicDiscovery(service); + GattClientDiscoveryObserver::Subject().StartCharacteristicDiscovery(handle, endHandle); } - void GattClientDiscoveryDecorator::StartDescriptorDiscovery(const GattService& service) + void GattClientDiscoveryDecorator::StartDescriptorDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) { - GattClientDiscoveryObserver::Subject().StartDescriptorDiscovery(service); + GattClientDiscoveryObserver::Subject().StartDescriptorDiscovery(handle, endHandle); } } diff --git a/services/ble/GattClient.hpp b/services/ble/GattClient.hpp index f591abadb..9f16ce54b 100644 --- a/services/ble/GattClient.hpp +++ b/services/ble/GattClient.hpp @@ -50,14 +50,14 @@ namespace services , public infra::Subject { public: - virtual void Read(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onRead) const = 0; - virtual void Write(const GattClientCharacteristicOperationsObserver& characteristic, infra::ConstByteRange data, const infra::Function& onDone) const = 0; - virtual void WriteWithoutResponse(const GattClientCharacteristicOperationsObserver& characteristic, infra::ConstByteRange data) const = 0; - - virtual void EnableNotification(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) const = 0; - virtual void DisableNotification(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) const = 0; - virtual void EnableIndication(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) const = 0; - virtual void DisableIndication(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) const = 0; + virtual void Read(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onRead) = 0; + virtual void Write(const GattClientCharacteristicOperationsObserver& characteristic, infra::ConstByteRange data, const infra::Function& onDone) = 0; + virtual void WriteWithoutResponse(const GattClientCharacteristicOperationsObserver& characteristic, infra::ConstByteRange data) = 0; + + virtual void EnableNotification(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) = 0; + virtual void DisableNotification(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) = 0; + virtual void EnableIndication(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) = 0; + virtual void DisableIndication(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) = 0; }; class GattClientCharacteristic @@ -111,11 +111,10 @@ namespace services using infra::Observer::Observer; virtual void ServiceDiscovered(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle endHandle) = 0; - virtual void CharacteristicDiscovered(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle valueHandle, GattCharacteristic::PropertyFlags properties) = 0; - virtual void DescriptorDiscovered(const AttAttribute::Uuid& type, AttAttribute::Handle handle) = 0; - virtual void ServiceDiscoveryComplete() = 0; + virtual void CharacteristicDiscovered(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle valueHandle, GattCharacteristic::PropertyFlags properties) = 0; virtual void CharacteristicDiscoveryComplete() = 0; + virtual void DescriptorDiscovered(const AttAttribute::Uuid& type, AttAttribute::Handle handle) = 0; virtual void DescriptorDiscoveryComplete() = 0; }; @@ -124,8 +123,18 @@ namespace services { public: virtual void StartServiceDiscovery() = 0; - virtual void StartCharacteristicDiscovery(const GattService& service) = 0; - virtual void StartDescriptorDiscovery(const GattService& service) = 0; + virtual void StartCharacteristicDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) = 0; + virtual void StartDescriptorDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) = 0; + + void StartCharacteristicDiscovery(const GattService& service) + { + StartCharacteristicDiscovery(service.Handle(), service.EndHandle()); + } + + void StartDescriptorDiscovery(const GattService& service) + { + StartDescriptorDiscovery(service.Handle(), service.EndHandle()); + } }; class GattClientDiscoveryDecorator @@ -146,8 +155,8 @@ namespace services // Implementation of GattClientDiscovery void StartServiceDiscovery() override; - void StartCharacteristicDiscovery(const GattService& service) override; - void StartDescriptorDiscovery(const GattService& service) override; + void StartCharacteristicDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) override; + void StartDescriptorDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) override; }; } diff --git a/services/ble/GattServerCharacteristicImpl.hpp b/services/ble/GattServerCharacteristicImpl.hpp index 292cf4a76..ac01faec7 100644 --- a/services/ble/GattServerCharacteristicImpl.hpp +++ b/services/ble/GattServerCharacteristicImpl.hpp @@ -13,7 +13,7 @@ namespace services GattServerCharacteristicImpl(GattServerService& service, const AttAttribute::Uuid& type, uint16_t valueLength); GattServerCharacteristicImpl(GattServerService& service, const AttAttribute::Uuid& type, uint16_t valueLength, PropertyFlags properties); GattServerCharacteristicImpl(GattServerService& service, const AttAttribute::Uuid& type, uint16_t valueLength, PropertyFlags properties, PermissionFlags permissions); - ~GattServerCharacteristicImpl() override; + ~GattServerCharacteristicImpl(); // Implementation of GattServerCharacteristic void Update(infra::ConstByteRange data, infra::Function onDone) override; diff --git a/services/ble/test/TestGattClient.cpp b/services/ble/test/TestGattClient.cpp index a378f57ba..e40b3b33c 100644 --- a/services/ble/test/TestGattClient.cpp +++ b/services/ble/test/TestGattClient.cpp @@ -243,14 +243,12 @@ TEST_F(GattClientDiscoveryDecoratorTest, forward_descriptors_discovered_event_to TEST_F(GattClientDiscoveryDecoratorTest, forward_all_calls_to_subject) { - services::GattService service{ uuid16, 0x1, 0x9 }; - EXPECT_CALL(gattDiscovery, StartServiceDiscovery()); decorator.StartServiceDiscovery(); - EXPECT_CALL(gattDiscovery, StartCharacteristicDiscovery(::testing::Ref(service))); - decorator.StartCharacteristicDiscovery(service); + EXPECT_CALL(gattDiscovery, StartCharacteristicDiscovery(1, 9)); + decorator.StartCharacteristicDiscovery(1, 9); - EXPECT_CALL(gattDiscovery, StartDescriptorDiscovery(::testing::Ref(service))); - decorator.StartDescriptorDiscovery(service); + EXPECT_CALL(gattDiscovery, StartDescriptorDiscovery(1, 9)); + decorator.StartDescriptorDiscovery(1, 9); } \ No newline at end of file diff --git a/services/ble/test_doubles/GattClientMock.hpp b/services/ble/test_doubles/GattClientMock.hpp index 48882166f..77281d44f 100644 --- a/services/ble/test_doubles/GattClientMock.hpp +++ b/services/ble/test_doubles/GattClientMock.hpp @@ -14,18 +14,26 @@ namespace services MOCK_METHOD(void, UpdateReceived, (infra::ConstByteRange data), (override)); }; + class GattClientCharacteristicOperationsObserverMock + : public services::GattClientCharacteristicOperationsObserver + { + public: + MOCK_METHOD(AttAttribute::Handle, CharacteristicValueHandle, (), (const, override)); + MOCK_METHOD(GattCharacteristic::PropertyFlags, CharacteristicProperties, (), (const, override)); + }; + class GattClientCharacteristicOperationsMock : public services::GattClientCharacteristicOperations { public: - MOCK_METHOD(void, Read, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (const, override)); - MOCK_METHOD(void, Write, (const GattClientCharacteristicOperationsObserver&, infra::ConstByteRange, const infra::Function&), (const, override)); - MOCK_METHOD(void, WriteWithoutResponse, (const GattClientCharacteristicOperationsObserver&, infra::ConstByteRange), (const, override)); - - MOCK_METHOD(void, EnableNotification, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (const, override)); - MOCK_METHOD(void, DisableNotification, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (const, override)); - MOCK_METHOD(void, EnableIndication, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (const, override)); - MOCK_METHOD(void, DisableIndication, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (const, override)); + MOCK_METHOD(void, Read, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (override)); + MOCK_METHOD(void, Write, (const GattClientCharacteristicOperationsObserver&, infra::ConstByteRange, const infra::Function&), (override)); + MOCK_METHOD(void, WriteWithoutResponse, (const GattClientCharacteristicOperationsObserver&, infra::ConstByteRange), (override)); + + MOCK_METHOD(void, EnableNotification, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (override)); + MOCK_METHOD(void, DisableNotification, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (override)); + MOCK_METHOD(void, EnableIndication, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (override)); + MOCK_METHOD(void, DisableIndication, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (override)); }; class GattClientDiscoveryObserverMock @@ -48,8 +56,8 @@ namespace services { public: MOCK_METHOD(void, StartServiceDiscovery, (), (override)); - MOCK_METHOD(void, StartCharacteristicDiscovery, (const GattService& service), (override)); - MOCK_METHOD(void, StartDescriptorDiscovery, (const GattService& service), (override)); + MOCK_METHOD(void, StartCharacteristicDiscovery, (AttAttribute::Handle handle, AttAttribute::Handle endHandle), (override)); + MOCK_METHOD(void, StartDescriptorDiscovery, (AttAttribute::Handle handle, AttAttribute::Handle endHandle), (override)); }; } diff --git a/services/cucumber/test/TestCucumberWireProtocolServer.cpp b/services/cucumber/test/TestCucumberWireProtocolServer.cpp index 44550a6d7..58398e327 100644 --- a/services/cucumber/test/TestCucumberWireProtocolServer.cpp +++ b/services/cucumber/test/TestCucumberWireProtocolServer.cpp @@ -86,7 +86,7 @@ GIVEN("nothing happens for %d seconds") infra::StringInputStream secondsStream(secondsString); uint32_t seconds; secondsStream >> seconds; - Context().TimeoutTimer().Start(std::chrono::seconds(seconds), [=]() + Context().TimeoutTimer().Start(std::chrono::seconds(seconds), [this]() { Success(); }); From c08f6284f69930a98dc0b4a7949935eff481c560 Mon Sep 17 00:00:00 2001 From: Richard Peters Date: Tue, 8 Oct 2024 08:52:52 +0200 Subject: [PATCH 08/11] chore: increase test coverage (#726) --- hal/interfaces/Gpio.cpp | 4 +- hal/interfaces/Gpio.hpp | 2 +- hal/interfaces/test/CMakeLists.txt | 1 + hal/interfaces/test/TestGpio.cpp | 130 ++++++++++++++++++ .../protoc_echo_plugin/ProtoCEchoPlugin.cpp | 10 -- services/ble/test/TestGatt.cpp | 22 +++ services/ble/test/TestGattClient.cpp | 6 +- sonar-project.properties | 2 +- 8 files changed, 160 insertions(+), 17 deletions(-) create mode 100644 hal/interfaces/test/TestGpio.cpp diff --git a/hal/interfaces/Gpio.cpp b/hal/interfaces/Gpio.cpp index 308d2f81f..2102100f9 100644 --- a/hal/interfaces/Gpio.cpp +++ b/hal/interfaces/Gpio.cpp @@ -94,9 +94,9 @@ namespace hal return pin.IsInput(); } - void TriStatePin::EnableInterrupt(const infra::Function& action, InterruptTrigger trigger) + void TriStatePin::EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type) { - pin.EnableInterrupt(action, trigger); + pin.EnableInterrupt(action, trigger, type); } void TriStatePin::DisableInterrupt() diff --git a/hal/interfaces/Gpio.hpp b/hal/interfaces/Gpio.hpp index bf0aec326..eeaf2abd0 100644 --- a/hal/interfaces/Gpio.hpp +++ b/hal/interfaces/Gpio.hpp @@ -98,7 +98,7 @@ namespace hal void SetAsInput(); bool IsInput() const; - void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger); + void EnableInterrupt(const infra::Function& action, InterruptTrigger trigger, InterruptType type = InterruptType::dispatched); void DisableInterrupt(); private: diff --git a/hal/interfaces/test/CMakeLists.txt b/hal/interfaces/test/CMakeLists.txt index 952f564e9..3b7b29c5d 100644 --- a/hal/interfaces/test/CMakeLists.txt +++ b/hal/interfaces/test/CMakeLists.txt @@ -14,6 +14,7 @@ target_sources(hal.interfaces_test PRIVATE TestFlash.cpp TestFlashHeterogeneous.cpp TestFlashHomogeneous.cpp + TestGpio.cpp TestI2cRegisterAccess.cpp TestMacAddress.cpp TestQuadSpi.cpp diff --git a/hal/interfaces/test/TestGpio.cpp b/hal/interfaces/test/TestGpio.cpp new file mode 100644 index 000000000..ac09a9659 --- /dev/null +++ b/hal/interfaces/test/TestGpio.cpp @@ -0,0 +1,130 @@ +#include "hal/interfaces/Gpio.hpp" +#include "hal/interfaces/test_doubles/GpioMock.hpp" +#include "gtest/gtest.h" + +TEST(GpioTest, InputPin) +{ + testing::StrictMock pin; + + EXPECT_CALL(pin, Config(hal::PinConfigType::input)); + hal::InputPin inputPin(pin); + + EXPECT_CALL(pin, Get()).WillOnce(testing::Return(true)); + EXPECT_TRUE(inputPin.Get()); + + EXPECT_CALL(pin, EnableInterrupt(testing::_, hal::InterruptTrigger::bothEdges, hal::InterruptType::dispatched)); + inputPin.EnableInterrupt([]() {}, hal::InterruptTrigger::bothEdges, hal::InterruptType::dispatched); + + EXPECT_CALL(pin, DisableInterrupt()); + inputPin.DisableInterrupt(); + + EXPECT_CALL(pin, ResetConfig()); +} + +TEST(GpioTest, OutputPin) +{ + testing::StrictMock pin; + + EXPECT_CALL(pin, Config(hal::PinConfigType::output, true)); + hal::OutputPin outputPin(pin, true); + + EXPECT_CALL(pin, Set(true)); + outputPin.Set(true); + + EXPECT_CALL(pin, GetOutputLatch()).WillOnce(testing::Return(true)); + EXPECT_TRUE(outputPin.GetOutputLatch()); + + EXPECT_CALL(pin, ResetConfig()); +} + +TEST(GpioTest, TriStatePin_as_input) +{ + testing::StrictMock pin; + + EXPECT_CALL(pin, Config(hal::PinConfigType::triState)); + hal::TriStatePin inputPin(pin); + + EXPECT_CALL(pin, IsInput()).WillOnce(testing::Return(true)); + EXPECT_TRUE(inputPin.IsInput()); + + EXPECT_CALL(pin, Get()).WillOnce(testing::Return(true)); + EXPECT_TRUE(inputPin.Get()); + + EXPECT_CALL(pin, EnableInterrupt(testing::_, hal::InterruptTrigger::bothEdges, hal::InterruptType::dispatched)); + inputPin.EnableInterrupt([]() {}, hal::InterruptTrigger::bothEdges, hal::InterruptType::dispatched); + + EXPECT_CALL(pin, DisableInterrupt()); + inputPin.DisableInterrupt(); + + EXPECT_CALL(pin, ResetConfig()); +} + +TEST(GpioTest, TriStatePin_as_output) +{ + testing::StrictMock pin; + + EXPECT_CALL(pin, Config(hal::PinConfigType::triState, true)); + hal::TriStatePin outputPin(pin, true); + + EXPECT_CALL(pin, Set(true)); + outputPin.Set(true); + + EXPECT_CALL(pin, GetOutputLatch()).WillOnce(testing::Return(true)); + EXPECT_TRUE(outputPin.GetOutputLatch()); + + EXPECT_CALL(pin, SetAsInput()); + outputPin.SetAsInput(); + + EXPECT_CALL(pin, ResetConfig()); +} + +TEST(GpioTest, DummyPin) +{ + hal::DummyPin pin; + + EXPECT_FALSE(pin.Get()); + EXPECT_FALSE(pin.GetOutputLatch()); + + pin.Set(true); + pin.SetAsInput(); + EXPECT_FALSE(pin.IsInput()); + + pin.Config(hal::PinConfigType::input); + pin.Config(hal::PinConfigType::output, true); + pin.ResetConfig(); + + pin.EnableInterrupt([]() {}, hal::InterruptTrigger::bothEdges, hal::InterruptType::dispatched); + pin.DisableInterrupt(); +} + +TEST(GpioTest, ScopedHigh) +{ + testing::StrictMock pin; + + EXPECT_CALL(pin, Config(hal::PinConfigType::output, true)); + hal::OutputPin outputPin(pin, true); + + { + EXPECT_CALL(pin, Set(true)); + hal::ScopedHigh scoped(outputPin); + EXPECT_CALL(pin, Set(false)); + } + + EXPECT_CALL(pin, ResetConfig()); +} + +TEST(GpioTest, ScopedLow) +{ + testing::StrictMock pin; + + EXPECT_CALL(pin, Config(hal::PinConfigType::output, true)); + hal::OutputPin outputPin(pin, true); + + { + EXPECT_CALL(pin, Set(false)); + hal::ScopedLow scoped(outputPin); + EXPECT_CALL(pin, Set(true)); + } + + EXPECT_CALL(pin, ResetConfig()); +} diff --git a/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp b/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp index aa5870bf1..8690cf804 100644 --- a/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp +++ b/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp @@ -373,16 +373,6 @@ namespace application result = field.name; } - void VisitRepeated(const EchoFieldRepeated& field) override - { - result = field.name; - } - - void VisitUnboundedRepeated(const EchoFieldUnboundedRepeated& field) override - { - result = field.name; - } - protected: std::string& result; }; diff --git a/services/ble/test/TestGatt.cpp b/services/ble/test/TestGatt.cpp index 1a84bf417..d4ec0a0a2 100644 --- a/services/ble/test/TestGatt.cpp +++ b/services/ble/test/TestGatt.cpp @@ -8,6 +8,27 @@ namespace services::AttAttribute::Uuid16 uuid16{ 0x42 }; } +TEST(GattDescriptor, access) +{ + uint16_t type = 1; + services::AttAttribute::Handle handle = 2; + services::GattDescriptor descriptor{ type, handle }; + + EXPECT_EQ(services::AttAttribute::Uuid(infra::InPlaceType(), type), descriptor.Type()); + EXPECT_EQ(handle, descriptor.Handle()); + EXPECT_EQ(handle, const_cast(descriptor).Handle()); +} + +TEST(GattDescriptor, equality) +{ + uint16_t type = 1; + services::GattDescriptor descriptor1{ type, 2 }; + services::GattDescriptor descriptor2{ type, 3 }; + + EXPECT_TRUE(descriptor1 == descriptor1); + EXPECT_TRUE(descriptor1 != descriptor2); +} + TEST(GattTest, service_has_handle_and_type) { services::GattService s{ uuid16 }; @@ -15,6 +36,7 @@ TEST(GattTest, service_has_handle_and_type) EXPECT_EQ(0x42, s.Type().Get()); EXPECT_EQ(0, s.Handle()); EXPECT_EQ(0, s.EndHandle()); + EXPECT_EQ(0, const_cast(s).EndHandle()); EXPECT_EQ(0, s.GetAttributeCount()); } diff --git a/services/ble/test/TestGattClient.cpp b/services/ble/test/TestGattClient.cpp index e40b3b33c..aaf4a8f2d 100644 --- a/services/ble/test/TestGattClient.cpp +++ b/services/ble/test/TestGattClient.cpp @@ -247,8 +247,8 @@ TEST_F(GattClientDiscoveryDecoratorTest, forward_all_calls_to_subject) decorator.StartServiceDiscovery(); EXPECT_CALL(gattDiscovery, StartCharacteristicDiscovery(1, 9)); - decorator.StartCharacteristicDiscovery(1, 9); + static_cast(decorator).StartCharacteristicDiscovery(services::GattService{ services::AttAttribute::Uuid(uuid16), 1, 9 }); EXPECT_CALL(gattDiscovery, StartDescriptorDiscovery(1, 9)); - decorator.StartDescriptorDiscovery(1, 9); -} \ No newline at end of file + static_cast(decorator).StartDescriptorDiscovery(services::GattService{ services::AttAttribute::Uuid(uuid16), 1, 9 }); +} diff --git a/sonar-project.properties b/sonar-project.properties index 41e091897..07175e8f0 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -21,7 +21,7 @@ sonar.cfamily.threads=2 sonar.externalIssuesReportPaths=mutation-sonar.json sonar.testExecutionReportPaths=execution.xml sonar.coverageReportPaths=coverage.xml -sonar.coverage.exclusions=**/Tracing*.cpp,**/Main.cpp,hal/generic/*,hal/unix/*,hal/windows/*,lwip/**/*,services/echo_console/*,**/*_instantiations/* +sonar.coverage.exclusions=**/Tracing*.?pp,**/Main.cpp,hal/generic/*,hal/unix/*,hal/windows/*,lwip/**/*,services/echo_console/*,**/*_instantiations/* # Project specific ignored rules sonar.issue.ignore.multicriteria=e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12 From cff858c0e3fa5d6d81c151fb66a80e18ff220d77 Mon Sep 17 00:00:00 2001 From: Daan Timmer <8293597+daantimmer@users.noreply.github.com> Date: Tue, 8 Oct 2024 17:38:05 +0200 Subject: [PATCH 09/11] ci: build Continuous Integration on push to main (#728) --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9f2db25d..5fb331a3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,8 @@ name: Continuous Integration on: + push: + branches: [main] pull_request: types: [opened, synchronize, reopened] merge_group: From 5fb1b8eb572f66a78708e60b4805458e3aa5fb21 Mon Sep 17 00:00:00 2001 From: Daan Timmer <8293597+daantimmer@users.noreply.github.com> Date: Wed, 9 Oct 2024 07:36:03 +0200 Subject: [PATCH 10/11] ci: update Continuous Integration badge to use main branch results only (#729) ci: update Continuous Integration branch to use main branch results only --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8d87b0ed..b7bb69a9e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@
-[![Continuous Integration](https://github.com/philips-software/amp-embedded-infra-lib/workflows/Continuous%20Integration/badge.svg)](https://github.com/philips-software/amp-embedded-infra-lib/actions) [![Linting & Formatting](https://github.com/philips-software/amp-embedded-infra-lib/actions/workflows/linting-formatting.yml/badge.svg)](https://github.com/philips-software/amp-embedded-infra-lib/actions/workflows/linting-formatting.yml) [![Static Analysis](https://github.com/philips-software/amp-embedded-infra-lib/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/philips-software/amp-embedded-infra-lib/actions/workflows/static-analysis.yml) +[![Continuous Integration](https://github.com/philips-software/amp-embedded-infra-lib/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/philips-software/amp-embedded-infra-lib/actions/workflows/ci.yml) [![Linting & Formatting](https://github.com/philips-software/amp-embedded-infra-lib/actions/workflows/linting-formatting.yml/badge.svg)](https://github.com/philips-software/amp-embedded-infra-lib/actions/workflows/linting-formatting.yml) [![Static Analysis](https://github.com/philips-software/amp-embedded-infra-lib/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/philips-software/amp-embedded-infra-lib/actions/workflows/static-analysis.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=philips-software_embeddedinfralib&metric=alert_status)](https://sonarcloud.io/dashboard?id=philips-software_embeddedinfralib) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=philips-software_embeddedinfralib&metric=coverage)](https://sonarcloud.io/dashboard?id=philips-software_embeddedinfralib) [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=philips-software_embeddedinfralib&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=philips-software_embeddedinfralib) From 798ec3da653f955a1eb218279fa93f52f15fcfbf Mon Sep 17 00:00:00 2001 From: EkelmansPh <58972933+EkelmansPh@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:35:29 +0200 Subject: [PATCH 11/11] test: add NotifyingVerifyingFunctionMock (#708) * test: add NotifyingVerifyingFunctionMock * Rename VerifyingFunctionMock to VerifyingFunction, and NotifyingVerifyingFunctionMock to VerifyingInvoker * Update infra/util/test_helper/MockCallback.hpp Co-authored-by: fabiangottstein <75617853+fabiangottstein@users.noreply.github.com> --------- Co-authored-by: Richard Peters Co-authored-by: fabiangottstein <75617853+fabiangottstein@users.noreply.github.com> --- .../test/TestSerialCommunication.cpp | 2 +- .../test/TestI2cRegisterAccessMock.cpp | 20 ++++---- .../event/test/TestAtomicTriggerScheduler.cpp | 2 +- .../test/TestTickOnInterruptTimerService.cpp | 2 +- infra/util/test/TestMultiFunction.cpp | 8 ++-- infra/util/test_helper/MockCallback.hpp | 46 +++++++++++++++---- services/network/test/TestHttpClient.cpp | 4 +- .../test/TestHttpClientCachedConnection.cpp | 4 +- services/util/test/TestConfigurationStore.cpp | 4 +- services/util/test/TestCyclicStore.cpp | 2 +- .../util/test/TestFlashQuadSpiCypressFll.cpp | 2 +- .../util/test/TestFlashQuadSpiMicronN25q.cpp | 2 +- .../util/test/TestFlashQuadSpiSingleSpeed.cpp | 2 +- .../test/TestSerialCommunicationLoopback.cpp | 4 +- .../util/test/TestWritableConfiguration.cpp | 4 +- 15 files changed, 68 insertions(+), 40 deletions(-) diff --git a/hal/interfaces/test/TestSerialCommunication.cpp b/hal/interfaces/test/TestSerialCommunication.cpp index c23f42ab1..5c6b0b54d 100644 --- a/hal/interfaces/test/TestSerialCommunication.cpp +++ b/hal/interfaces/test/TestSerialCommunication.cpp @@ -31,7 +31,7 @@ class BufferedSerialCommunicationOnUnbufferedTest TEST_F(BufferedSerialCommunicationOnUnbufferedTest, SendData_is_forwarded) { - infra::VerifyingFunctionMock onDone; + infra::VerifyingFunction onDone; std::array data; EXPECT_CALL(serial, SendData(infra::MakeConstByteRange(data), testing::_)).WillOnce(testing::InvokeArgument<1>()); diff --git a/hal/interfaces/test_doubles/test/TestI2cRegisterAccessMock.cpp b/hal/interfaces/test_doubles/test/TestI2cRegisterAccessMock.cpp index 4a1d5537d..1a7e9540f 100644 --- a/hal/interfaces/test_doubles/test/TestI2cRegisterAccessMock.cpp +++ b/hal/interfaces/test_doubles/test/TestI2cRegisterAccessMock.cpp @@ -18,8 +18,8 @@ class RegisterAccessMockTest TEST_F(RegisterAccessMockTest, ReadRegisterInOneRead) { - infra::VerifyingFunctionMock sendDataDoneVerifier(hal::Result::complete, 1); - infra::VerifyingFunctionMock receiveDataDoneVerifier(hal::Result::complete); + infra::VerifyingFunction sendDataDoneVerifier(hal::Result::complete, 1); + infra::VerifyingFunction receiveDataDoneVerifier(hal::Result::complete); EXPECT_CALL(masterMock, ReadRegisterMock(3)).WillOnce(testing::Return(std::vector{ 1, 2, 3, 4 })); uint8_t dataRegister = 3; @@ -32,8 +32,8 @@ TEST_F(RegisterAccessMockTest, ReadRegisterInOneRead) TEST_F(RegisterAccessMockTest, ReadRegisterInTwoReads) { - infra::VerifyingFunctionMock receiveDataDone1Verifier(hal::Result::complete); - infra::VerifyingFunctionMock receiveDataDone2Verifier(hal::Result::complete); + infra::VerifyingFunction receiveDataDone1Verifier(hal::Result::complete); + infra::VerifyingFunction receiveDataDone2Verifier(hal::Result::complete); EXPECT_CALL(masterMock, ReadRegisterMock(3)).WillOnce(testing::Return(std::vector{ 1, 2, 3, 4 })); uint8_t dataRegister = 3; @@ -49,7 +49,7 @@ TEST_F(RegisterAccessMockTest, ReadRegisterInTwoReads) TEST_F(RegisterAccessMockTest, WriteRegisterInOneWrite) { - infra::VerifyingFunctionMock sendDataDoneVerifier(hal::Result::complete, 5); + infra::VerifyingFunction sendDataDoneVerifier(hal::Result::complete, 5); EXPECT_CALL(masterMock, WriteRegisterMock(3, std::vector{ 1, 2, 3, 4 })); std::array data = { 3, 1, 2, 3, 4 }; @@ -58,8 +58,8 @@ TEST_F(RegisterAccessMockTest, WriteRegisterInOneWrite) TEST_F(RegisterAccessMockTest, WriteRegisterInTwoWrites) { - infra::VerifyingFunctionMock sendDataDone1Verifier(hal::Result::complete, 1); - infra::VerifyingFunctionMock sendDataDone2Verifier(hal::Result::complete, 4); + infra::VerifyingFunction sendDataDone1Verifier(hal::Result::complete, 1); + infra::VerifyingFunction sendDataDone2Verifier(hal::Result::complete, 4); EXPECT_CALL(masterMock, WriteRegisterMock(3, std::vector{ 1, 2, 3, 4 })); uint8_t dataRegister = 3; @@ -70,9 +70,9 @@ TEST_F(RegisterAccessMockTest, WriteRegisterInTwoWrites) TEST_F(RegisterAccessMockTest, WriteRegisterInThreeWrites) { - infra::VerifyingFunctionMock sendDataDone1Verifier(hal::Result::complete, 1); - infra::VerifyingFunctionMock sendDataDone2Verifier(hal::Result::complete, 3); - infra::VerifyingFunctionMock sendDataDone3Verifier(hal::Result::complete, 1); + infra::VerifyingFunction sendDataDone1Verifier(hal::Result::complete, 1); + infra::VerifyingFunction sendDataDone2Verifier(hal::Result::complete, 3); + infra::VerifyingFunction sendDataDone3Verifier(hal::Result::complete, 1); EXPECT_CALL(masterMock, WriteRegisterMock(3, std::vector{ 1, 2, 3, 4 })); uint8_t dataRegister = 3; diff --git a/infra/event/test/TestAtomicTriggerScheduler.cpp b/infra/event/test/TestAtomicTriggerScheduler.cpp index 96c499068..f000a5c56 100644 --- a/infra/event/test/TestAtomicTriggerScheduler.cpp +++ b/infra/event/test/TestAtomicTriggerScheduler.cpp @@ -10,7 +10,7 @@ class AtomicTriggerSchedulerTest TEST_F(AtomicTriggerSchedulerTest, scheduled_once) { - infra::VerifyingFunctionMock mock; + infra::VerifyingFunction mock; infra::AtomicTriggerScheduler scheduler; scheduler.Schedule([&]() diff --git a/infra/timer/test/TestTickOnInterruptTimerService.cpp b/infra/timer/test/TestTickOnInterruptTimerService.cpp index 44f25a383..4baedfb08 100644 --- a/infra/timer/test/TestTickOnInterruptTimerService.cpp +++ b/infra/timer/test/TestTickOnInterruptTimerService.cpp @@ -19,7 +19,7 @@ class BaseTimerServiceTest TEST_F(BaseTimerServiceTest, set_resolution) { - infra::VerifyingFunctionMock verify; + infra::VerifyingFunction verify; infra::TimerSingleShot timer(std::chrono::seconds(1), verify); timerService.SetResolution(std::chrono::seconds(2)); diff --git a/infra/util/test/TestMultiFunction.cpp b/infra/util/test/TestMultiFunction.cpp index 6076ef4a3..25b98c7a4 100644 --- a/infra/util/test/TestMultiFunction.cpp +++ b/infra/util/test/TestMultiFunction.cpp @@ -22,7 +22,7 @@ TEST(MultiFunctionTest, construct_empty_with_nullptr) TEST(MultiFunctionTest, construct_with_function) { - infra::VerifyingFunctionMock m; + infra::VerifyingFunction m; infra::MultiFunction f([&]() { @@ -33,7 +33,7 @@ TEST(MultiFunctionTest, construct_with_function) TEST(MultiFunctionTest, multi_function_construct_with_first) { - infra::VerifyingFunctionMock m; + infra::VerifyingFunction m; infra::MultiFunction::And::And f([&]() { @@ -44,7 +44,7 @@ TEST(MultiFunctionTest, multi_function_construct_with_first) TEST(MultiFunctionTest, multi_function_construct_with_second) { - infra::VerifyingFunctionMock m(true); + infra::VerifyingFunction m(true); infra::MultiFunction::And f([&](bool v) { @@ -55,7 +55,7 @@ TEST(MultiFunctionTest, multi_function_construct_with_second) TEST(MultiFunctionTest, reassign_multi_function) { - infra::VerifyingFunctionMock m(true); + infra::VerifyingFunction m(true); infra::MultiFunction::And f([]() {}); f = [&](bool v) diff --git a/infra/util/test_helper/MockCallback.hpp b/infra/util/test_helper/MockCallback.hpp index 54ff1edd4..4b511148c 100644 --- a/infra/util/test_helper/MockCallback.hpp +++ b/infra/util/test_helper/MockCallback.hpp @@ -46,14 +46,14 @@ namespace infra }; template - class VerifyingFunctionMock; + class VerifyingFunction; template - class VerifyingFunctionMock + class VerifyingFunction : public MockCallback { public: - VerifyingFunctionMock() + VerifyingFunction() { EXPECT_CALL(*this, callback()); } @@ -68,11 +68,11 @@ namespace infra }; template - class VerifyingFunctionMock + class VerifyingFunction : public MockCallback { public: - VerifyingFunctionMock(P1 p1) + VerifyingFunction(P1 p1) { EXPECT_CALL(*this, callback(p1)); } @@ -87,11 +87,11 @@ namespace infra }; template - class VerifyingFunctionMock + class VerifyingFunction : public MockCallback { public: - VerifyingFunctionMock(P1 p1, P2 p2) + VerifyingFunction(P1 p1, P2 p2) { EXPECT_CALL(*this, callback(p1, p2)); } @@ -106,11 +106,11 @@ namespace infra }; template - class VerifyingFunctionMock + class VerifyingFunction : public MockCallback { public: - VerifyingFunctionMock(P1 p1, P2 p2, P3 p3) + VerifyingFunction(P1 p1, P2 p2, P3 p3) { EXPECT_CALL(*this, callback(p1, p2, p3)); } @@ -124,6 +124,34 @@ namespace infra } }; + template + class VerifyingInvoker; + + template + class VerifyingInvoker + { + public: + explicit VerifyingInvoker(infra::Function onCalled) + : onCalled(onCalled) + { + EXPECT_CALL(*this, callback()); + } + + MOCK_METHOD(Result, callback, (), (const override)); + + operator infra::Function() + { + return [this](Args&&... args) + { + onCalled(args...); + return callback(); + }; + } + + private: + infra::Function onCalled; + }; + template auto MockFunction = [] { diff --git a/services/network/test/TestHttpClient.cpp b/services/network/test/TestHttpClient.cpp index 466d047cf..fb16debdd 100644 --- a/services/network/test/TestHttpClient.cpp +++ b/services/network/test/TestHttpClient.cpp @@ -870,7 +870,7 @@ TEST_F(HttpClientTest, Stop_while_closed) EXPECT_CALL(client, Detaching()); client.Subject().CloseConnection(); - infra::VerifyingFunctionMock onDone; + infra::VerifyingFunction onDone; connector.Stop([&]() { onDone.callback(); @@ -881,7 +881,7 @@ TEST_F(HttpClientTest, Stop_while_connection_open) { Connect(); - infra::VerifyingFunctionMock onDone; + infra::VerifyingFunction onDone; EXPECT_CALL(connection, CloseAndDestroyMock()); EXPECT_CALL(client, Detaching()); connector.Stop([&]() diff --git a/services/network/test/TestHttpClientCachedConnection.cpp b/services/network/test/TestHttpClientCachedConnection.cpp index abd4d0a1d..98b2ae46c 100644 --- a/services/network/test/TestHttpClientCachedConnection.cpp +++ b/services/network/test/TestHttpClientCachedConnection.cpp @@ -430,7 +430,7 @@ TEST_F(HttpClientCachedConnectionTest, Stop_while_closed) CreateConnection(factory); CloseConnection(); - infra::VerifyingFunctionMock onDone; + infra::VerifyingFunction onDone; connector.Stop([&]() { onDone.callback(); @@ -441,7 +441,7 @@ TEST_F(HttpClientCachedConnectionTest, Stop_while_connection_open) { CreateConnection(factory); - infra::VerifyingFunctionMock onDone; + infra::VerifyingFunction onDone; EXPECT_CALL(clientSubject, CloseConnection()).WillOnce([this]() { clientSubject.Detach(); diff --git a/services/util/test/TestConfigurationStore.cpp b/services/util/test/TestConfigurationStore.cpp index 21ecebb69..b4b9ed592 100644 --- a/services/util/test/TestConfigurationStore.cpp +++ b/services/util/test/TestConfigurationStore.cpp @@ -158,7 +158,7 @@ TEST_F(ConfigurationBlobTest, Write_writes_to_flash) infra::ConstByteRange writeBuffer; EXPECT_CALL(flash, WriteBuffer(testing::_, 0, testing::_)).WillOnce(testing::DoAll(testing::SaveArg<0>(&writeBuffer), testing::SaveArg<2>(&onWriteDone))); - infra::VerifyingFunctionMock writeDone; + infra::VerifyingFunction writeDone; configurationBlob.Write(8, writeDone); std::array blobData = { 0x21, 0xf1, 0xfb, 0x20, 0xaf, 0x91, 0x92, 0x86, 8, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 0 }; @@ -190,7 +190,7 @@ TEST_F(ConfigurationBlobTest, Write_writes_to_flash) TEST_F(ConfigurationBlobTest, Erase_erases_flash) { EXPECT_CALL(flash, EraseSectors(0, 1, testing::_)).WillOnce(testing::SaveArg<2>(&onEraseDone)); - infra::VerifyingFunctionMock eraseDone; + infra::VerifyingFunction eraseDone; configurationBlob.Erase(eraseDone); onEraseDone(); diff --git a/services/util/test/TestCyclicStore.cpp b/services/util/test/TestCyclicStore.cpp index 1c53a2b72..24c387804 100644 --- a/services/util/test/TestCyclicStore.cpp +++ b/services/util/test/TestCyclicStore.cpp @@ -55,7 +55,7 @@ class CyclicStoreTest TEST_F(CyclicStoreTest, AddFirstItem) { - infra::VerifyingFunctionMock done; + infra::VerifyingFunction done; AddItem(KeepBytesAlive({ 11, 12 }), [&done]() { diff --git a/services/util/test/TestFlashQuadSpiCypressFll.cpp b/services/util/test/TestFlashQuadSpiCypressFll.cpp index 888f1f5a1..4be43987b 100644 --- a/services/util/test/TestFlashQuadSpiCypressFll.cpp +++ b/services/util/test/TestFlashQuadSpiCypressFll.cpp @@ -21,7 +21,7 @@ class FlashQuadSpiCypressFllTest } testing::StrictMock spiStub; - infra::VerifyingFunctionMock onInitialized; + infra::VerifyingFunction onInitialized; services::FlashQuadSpiCypressFll flash; testing::StrictMock> finished; diff --git a/services/util/test/TestFlashQuadSpiMicronN25q.cpp b/services/util/test/TestFlashQuadSpiMicronN25q.cpp index 36c60d9b6..e63a60940 100644 --- a/services/util/test/TestFlashQuadSpiMicronN25q.cpp +++ b/services/util/test/TestFlashQuadSpiMicronN25q.cpp @@ -23,7 +23,7 @@ class FlashQuadSpiMicronN25qTest } testing::StrictMock spiStub; - infra::VerifyingFunctionMock onInitialized; + infra::VerifyingFunction onInitialized; services::FlashQuadSpiMicronN25q flash; testing::StrictMock> finished; diff --git a/services/util/test/TestFlashQuadSpiSingleSpeed.cpp b/services/util/test/TestFlashQuadSpiSingleSpeed.cpp index 64716aa68..dbb77010f 100644 --- a/services/util/test/TestFlashQuadSpiSingleSpeed.cpp +++ b/services/util/test/TestFlashQuadSpiSingleSpeed.cpp @@ -18,7 +18,7 @@ class FlashQuadSpiSingleSpeedTest } testing::StrictMock spiStub; - infra::VerifyingFunctionMock onInitialized; + infra::VerifyingFunction onInitialized; services::FlashQuadSpiSingleSpeed flash; testing::StrictMock> finished; diff --git a/services/util/test/TestSerialCommunicationLoopback.cpp b/services/util/test/TestSerialCommunicationLoopback.cpp index 748bf5db8..2f799952b 100644 --- a/services/util/test/TestSerialCommunicationLoopback.cpp +++ b/services/util/test/TestSerialCommunicationLoopback.cpp @@ -20,7 +20,7 @@ class SerialCommunicationLoopbackTest TEST_F(SerialCommunicationLoopbackTest, SendFromServerReceiveByClient) { infra::ConstByteRange data = infra::MakeStringByteRange("hello"); - infra::VerifyingFunctionMock clientReceiveCallback{ data }; + infra::VerifyingFunction clientReceiveCallback{ data }; client.ReceiveData(clientReceiveCallback); server.SendData(data, infra::emptyFunction); @@ -31,7 +31,7 @@ TEST_F(SerialCommunicationLoopbackTest, SendFromServerReceiveByClient) TEST_F(SerialCommunicationLoopbackTest, SendFromClientReceiveByServer) { infra::ConstByteRange data = infra::MakeStringByteRange("world"); - infra::VerifyingFunctionMock serverReceiveCallback{ data }; + infra::VerifyingFunction serverReceiveCallback{ data }; server.ReceiveData(serverReceiveCallback); client.SendData(data, infra::emptyFunction); diff --git a/services/util/test/TestWritableConfiguration.cpp b/services/util/test/TestWritableConfiguration.cpp index 460b8a6d7..6b6009e65 100644 --- a/services/util/test/TestWritableConfiguration.cpp +++ b/services/util/test/TestWritableConfiguration.cpp @@ -93,7 +93,7 @@ TEST_F(FlashReadingWritableConfigurationTest, write_data_in_empty_flash) formatter.PutVarInt(15); })); - infra::VerifyingFunctionMock callback; + infra::VerifyingFunction callback; configuration->Write(newValue, [&callback]() { callback.callback(); @@ -140,7 +140,7 @@ TEST_F(MemoryMappedWritableConfigurationTest, write_data_in_empty_flash) formatter.PutVarInt(15); })); - infra::VerifyingFunctionMock callback; + infra::VerifyingFunction callback; configuration->Write(newValue, [&callback]() { callback.callback();