Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED true)

option(CMAKE_COMPILE_WARNING_AS_ERROR "Enable warnings-as-error" On)
option(HALST_BUILD_TESTS "Enable building the tests" Off)

include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
Expand All @@ -17,9 +18,18 @@ add_definitions(-DMEMP_NUM_UDP_PCB=10)

set(HALST_INCLUDE_DEFAULT_LINKER_SCRIPTS Off CACHE INTERNAL "")

if (POSTMASTER_BUILD_TESTS)
include(CTest)
endif()

add_subdirectory(amp-embedded-infra-lib)
add_subdirectory(amp-hal-st)
add_subdirectory(amp-preview)

if (POSTMASTER_BUILD_TESTS)
emil_enable_testing()
endif()

add_subdirectory(postmaster)

emil_folderize_all_targets()
Expand Down
1 change: 1 addition & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo",
"POSTMASTER_BUILD_TESTS": true,
"EMIL_BUILD_TESTS": true
}
},
Expand Down
2 changes: 1 addition & 1 deletion amp-embedded-infra-lib
Submodule amp-embedded-infra-lib updated 74 files
+1 −1 .clusterfuzzlite/Dockerfile
+1 −1 .devcontainer/Dockerfile
+20 −20 .github/workflows/ci.yml
+1 −1 .github/workflows/dependency-scanner.yml
+3 −3 .github/workflows/documentation.yml
+4 −4 .github/workflows/linting-formatting.yml
+3 −3 .github/workflows/release-please.yml
+2 −2 .github/workflows/security.yml
+5 −5 .github/workflows/static-analysis.yml
+2 −2 .github/workflows/validate-pr.yml
+1 −0 .mega-linter.yml
+4 −4 documents/modules/ROOT/pages/Sesame.adoc
+1 −0 external/protoc/CMakeLists.txt
+2 −2 hal/generic/FileSystemGeneric.cpp
+1 −1 hal/generic/FileSystemGeneric.hpp
+3 −1 hal/interfaces/FileSystem.hpp
+2 −2 hal/interfaces/test_doubles/FileSystemStub.cpp
+1 −1 hal/interfaces/test_doubles/FileSystemStub.hpp
+8 −0 infra/util/BoundedVector.hpp
+31 −1 infra/util/MemoryRange.hpp
+12 −0 infra/util/test/TestMemoryRange.cpp
+1 −1 lwip/lwip/CMakeLists.txt
+2 −0 protobuf/echo/CMakeLists.txt
+4 −229 protobuf/echo/Echo.cpp
+26 −51 protobuf/echo/Echo.hpp
+248 −0 protobuf/echo/EchoOnStreams.cpp
+72 −0 protobuf/echo/EchoOnStreams.hpp
+1 −1 protobuf/echo/TracingEcho.hpp
+1 −1 protobuf/echo/test_doubles/EchoMock.hpp
+1 −1 protobuf/echo/test_doubles/EchoSingleLoopback.hpp
+1 −0 services/CMakeLists.txt
+2 −6 services/ble/ClaimingGattClientAdapter.cpp
+7 −0 services/echo_console/CMakeLists.txt
+73 −2 services/echo_console/Console.cpp
+25 −0 services/echo_console/Console.hpp
+76 −11 services/echo_console/Main.cpp
+1 −1 services/network/EchoOnConnection.hpp
+1 −0 services/network/HttpClientBasic.cpp
+12 −0 services/network/TracingHttpClientImpl.cpp
+5 −0 services/network/TracingHttpClientImpl.hpp
+13 −0 services/sesame_key_generator/CMakeLists.txt
+101 −0 services/sesame_key_generator/Main.cpp
+4 −0 services/tracer/CMakeLists.txt
+52 −0 services/tracer/SerialCommunicationOnSeggerRtt.cpp
+29 −0 services/tracer/SerialCommunicationOnSeggerRtt.hpp
+11 −0 services/tracer/TracerOnSeggerRttSerialCommunicationInfrastructure.cpp
+22 −0 services/tracer/TracerOnSeggerRttSerialCommunicationInfrastructure.hpp
+19 −0 services/tracer/TracingEchoInstantiation.cpp
+27 −24 services/tracer/TracingEchoInstantiation.hpp
+33 −0 services/tracer/TracingEchoInstantiationSecured.cpp
+91 −25 services/tracer/TracingEchoInstantiationSecured.hpp
+4 −4 services/util/CMakeLists.txt
+19 −0 services/util/EchoInstantiation.cpp
+31 −39 services/util/EchoInstantiation.hpp
+34 −0 services/util/EchoInstantiationSecured.cpp
+65 −29 services/util/EchoInstantiationSecured.hpp
+1 −1 services/util/EchoOnMessageCommunication.hpp
+5 −0 services/util/EchoOnSesame.cpp
+3 −2 services/util/EchoOnSesame.hpp
+44 −25 services/util/EchoPolicyDiffieHellman.cpp
+26 −14 services/util/EchoPolicyDiffieHellman.hpp
+21 −20 services/util/EchoPolicySymmetricKey.cpp
+13 −12 services/util/EchoPolicySymmetricKey.hpp
+13 −2 services/util/SesameCobs.hpp
+10 −2 services/util/SesameCryptoMbedTls.cpp
+1 −0 services/util/SesameCryptoMbedTls.hpp
+46 −0 services/util/SesameSecured.cpp
+12 −1 services/util/SesameSecured.hpp
+12 −0 services/util/SesameSecurity.proto
+5 −0 services/util/SesameWindowed.hpp
+2 −2 services/util/test/CMakeLists.txt
+54 −2 services/util/test/TestEchoOnSesame.cpp
+35 −31 services/util/test/TestEchoPolicyDiffieHellman.cpp
+22 −15 services/util/test/TestEchoPolicySymmetricKey.cpp
6 changes: 3 additions & 3 deletions postmaster/instantiations/EchoServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace main_
infra::ProxyCreator<hal::SerialCommunication, void(const UartConfig& config)> serial;
services::MethodSerializerFactory::ForServices<>::AndProxies<> serializerFactory;
hal::BufferedSerialCommunicationOnUnbuffered::WithStorage<256> bufferedSerial{ *serial };
main_::EchoOnSesame<256> echoUart{ bufferedSerial, serializerFactory };
main_::EchoOnSesame::WithMessageSize<256> echoUart{ bufferedSerial, serializerFactory };
services::EchoOnConnection echoConnection{ serializerFactory };

services::ServiceForwarderAll forwardLeft{ echoUart, echoConnection };
services::ServiceForwarderAll forwardRight{ echoConnection, echoUart };
services::ServiceForwarderAll forwardLeft{ echoUart.echo, echoConnection };
services::ServiceForwarderAll forwardRight{ echoConnection, echoUart.echo };

operator services::ConnectionObserver&();
operator const services::ConnectionObserver&() const;
Expand Down
6 changes: 3 additions & 3 deletions postmaster/instantiations/TargetUartEcho.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ namespace main_
infra::ProxyCreator<hal::SerialCommunication, void(const UartConfig& config)> serial;
services::MethodSerializerFactory::ForServices<>::AndProxies<> serializerFactory;
hal::BufferedSerialCommunicationOnUnbuffered::WithStorage<256> bufferedSerial{ *serial };
main_::EchoOnSesame<256> echoUart{ bufferedSerial, serializerFactory };
main_::EchoOnSesame::WithMessageSize<256> echoUart{ bufferedSerial, serializerFactory };
services::EchoOnConnection echoConnection{ serializerFactory };
WebSocketServerConnectionObserver webSocket{ *this };

services::ServiceForwarderAll forwardLeft{ echoUart, echoConnection };
services::ServiceForwarderAll forwardRight{ echoConnection, echoUart };
services::ServiceForwarderAll forwardLeft{ echoUart.echo, echoConnection };
services::ServiceForwarderAll forwardRight{ echoConnection, echoUart.echo };

operator services::ConnectionObserver&();
operator const services::ConnectionObserver&() const;
Expand Down
2 changes: 2 additions & 0 deletions postmaster/programmer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ target_link_libraries(postmaster.programmer PUBLIC
services.st_util
protobuf.echo
)

add_subdirectory(test)
29 changes: 21 additions & 8 deletions postmaster/programmer/FlashAligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ namespace services

void FlashAligner::Flush(const infra::Function<void()>& onDone)
{
alignedBuffer.resize(alignedBuffer.max_size());
FlashDelegate::WriteBuffer(infra::MakeRange(alignedBuffer), address, onDone);
if (alignedBuffer.empty())
onDone();
else
{
auto size = alignedBuffer.size();
alignedBuffer.resize(alignedBuffer.max_size());
FlashDelegate::WriteBuffer(infra::MakeRange(alignedBuffer), address - size, onDone);
}
}

void FlashAligner::WriteBuffer(infra::ConstByteRange buffer, uint32_t address, infra::Function<void()> onDone)
Expand All @@ -20,6 +26,7 @@ namespace services
auto range = infra::Head(buffer, alignedBuffer.max_size() - alignedBuffer.size());
alignedBuffer.insert(alignedBuffer.end(), range.begin(), range.end());
buffer.pop_front(range.size());
address += range.size();
}

if (alignedBuffer.full())
Expand All @@ -28,21 +35,27 @@ namespace services
this->address = address;
this->onDone = onDone;

FlashDelegate::WriteBuffer(infra::MakeRange(alignedBuffer), address, [this]()
FlashDelegate::WriteBuffer(infra::MakeRange(alignedBuffer), address - alignedBuffer.size(), [this]()
{
alignedBuffer.clear();
auto onDoneCopy = this->onDone.Clone();
this->onDone = nullptr;
WriteBuffer(this->buffer, this->address + alignedBuffer.max_size(), onDoneCopy);
WriteBuffer(this->buffer, this->address, onDoneCopy);
});
}
else
{
auto range = infra::Head(buffer, buffer.size() - buffer.size() % alignedBuffer.max_size());
alignedBuffer.insert(alignedBuffer.end(), range.end(), buffer.end());
auto sendNowSize = buffer.size() - buffer.size() % alignedBuffer.max_size();
auto sendNow = infra::Head(buffer, sendNowSize);
auto sendLater = infra::DiscardHead(buffer, sendNowSize);
alignedBuffer.insert(alignedBuffer.end(), sendLater.begin(), sendLater.end());

this->address = address + buffer.size();

FlashDelegate::WriteBuffer(range, address, onDone);
this->address = address + range.size();
if (sendNow.empty())
onDone();
else
FlashDelegate::WriteBuffer(sendNow, address, onDone);
}
}
}
13 changes: 13 additions & 0 deletions postmaster/programmer/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
add_executable(postmaster.programmer.test)
emil_build_for(postmaster.programmer.test BOOL EMIL_BUILD_TESTS)
emil_add_test(postmaster.programmer.test)

target_link_libraries(postmaster.programmer.test PUBLIC
gmock_main
postmaster.programmer
hal.interfaces_test_doubles
)

target_sources(postmaster.programmer.test PRIVATE
TestFlashAligner.cpp
)
91 changes: 91 additions & 0 deletions postmaster/programmer/test/TestFlashAligner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "hal/interfaces/test_doubles/FlashMock.hpp"
#include "infra/util/test_helper/MemoryRangeMatcher.hpp"
#include "infra/util/test_helper/MockCallback.hpp"
#include "postmaster/programmer/FlashAligner.hpp"
#include "gtest/gtest.h"

class FlashAlignerTest
: public testing::Test
{
public:
testing::StrictMock<hal::CleanFlashMock> flash;
services::FlashAligner::WithAlignment<4> aligner{ flash };

std::array<uint8_t, 1> size1{ 99 };
std::array<uint8_t, 4> size4{ 1, 2, 3, 4 };
std::array<uint8_t, 6> size6{ 5, 6, 7, 8, 9, 10 };
std::array<uint8_t, 8> size8{ 11, 12, 13, 14, 15, 16, 17, 18 };
};

TEST_F(FlashAlignerTest, write_one_block)
{
EXPECT_CALL(flash, WriteBuffer(infra::MakeConstRange(size4), 0, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.WriteBuffer(size4, 0, infra::MockFunction<void()>());

aligner.Flush(infra::MockFunction<void()>());
}

TEST_F(FlashAlignerTest, write_small_block)
{
aligner.WriteBuffer(size1, 0, infra::MockFunction<void()>());

EXPECT_CALL(flash, WriteBuffer(infra::ContentsEqual(std::vector<uint8_t>{ 99, 0, 0, 0 }), 0, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.Flush(infra::MockFunction<void()>());
}

TEST_F(FlashAlignerTest, write_large_block)
{
EXPECT_CALL(flash, WriteBuffer(infra::Head(infra::MakeConstRange(size6), 4), 0, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.WriteBuffer(size6, 0, infra::MockFunction<void()>());

EXPECT_CALL(flash, WriteBuffer(infra::ContentsEqual(std::vector<uint8_t>{ 9, 10, 0, 0}), 4, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.Flush(infra::MockFunction<void()>());
}

TEST_F(FlashAlignerTest, write_double_block)
{
EXPECT_CALL(flash, WriteBuffer(infra::MakeConstRange(size8), 0, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.WriteBuffer(size8, 0, infra::MockFunction<void()>());

aligner.Flush(infra::MockFunction<void()>());
}

TEST_F(FlashAlignerTest, write_one_block_at_offset)
{
aligner.WriteBuffer(size1, 0, infra::MockFunction<void()>());

EXPECT_CALL(flash, WriteBuffer(infra::ContentsEqual(std::vector<uint8_t>{ 99, 1, 2, 3 }), 0, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.WriteBuffer(size4, 1, infra::MockFunction<void()>());
}

TEST_F(FlashAlignerTest, write_small_block_at_offset)
{
aligner.WriteBuffer(size1, 0, infra::MockFunction<void()>());
aligner.WriteBuffer(size1, 1, infra::MockFunction<void()>());

EXPECT_CALL(flash, WriteBuffer(infra::ContentsEqual(std::vector<uint8_t>{ 99, 99, 0, 0 }), 0, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.Flush(infra::MockFunction<void()>());
}

TEST_F(FlashAlignerTest, write_large_block_at_offset)
{
aligner.WriteBuffer(size1, 0, infra::MockFunction<void()>());

EXPECT_CALL(flash, WriteBuffer(infra::ContentsEqual(std::vector<uint8_t>{ 99, 5, 6, 7 }), 0, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.WriteBuffer(size6, 1, infra::MockFunction<void()>());

EXPECT_CALL(flash, WriteBuffer(infra::ContentsEqual(std::vector<uint8_t>{ 8, 9, 10, 0 }), 4, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.Flush(infra::MockFunction<void()>());
}

TEST_F(FlashAlignerTest, write_double_block_at_offset)
{
aligner.WriteBuffer(size1, 0, infra::MockFunction<void()>());

EXPECT_CALL(flash, WriteBuffer(infra::ContentsEqual(std::vector<uint8_t>{ 99, 11, 12, 13 }), 0, testing::_)).WillOnce(testing::InvokeArgument<2>());
EXPECT_CALL(flash, WriteBuffer(infra::ContentsEqual(std::vector<uint8_t>{ 14, 15, 16, 17 }), 4, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.WriteBuffer(size8, 1, infra::MockFunction<void()>());

EXPECT_CALL(flash, WriteBuffer(infra::ContentsEqual(std::vector<uint8_t>{ 18, 0, 0, 0 }), 8, testing::_)).WillOnce(testing::InvokeArgument<2>());
aligner.Flush(infra::MockFunction<void()>());
}