Skip to content

Commit

Permalink
test: add integration_test.flash_tested (#293)
Browse files Browse the repository at this point in the history
* Add cucumber submodule

* Add integration_test/test

* .github/workflows/ci.yml: Checkout submodules

* Update amp-embedded-infra-lib

* Update amp-embedded-infra-lib: fix: infra/util/Endian: fix comparison against C++ version

* Update amp-cucumber-cpp-runner-poc

* .github/workflows/ci.yml: Remove Visual Studio 2019 and gcc 7 from tested compilers since they can't handle C++20

* Do some work on integration tests

* Various fixes

* Fix compilation

* Run clang-format

* Update .github/workflows/ci.yml

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update devcontainer

* Exclude gherkin libraries from all target

* feat!: update MessageCommunication to Sesame

* integration_test/test/FixtureEcho: Adapt for Sesame

* CMakeLists: Don't set EXCLUDE_FROM_ALL on gherkin targets because otherwise they fail to install

* integration_test/logic/Gpio: Differentiate between GpioTester and GpioTested's GpioChanged

* integration_test/tested,tester/Main: Add tracing infrastructure

* chore: add integration test board pcb

(cherry picked from commit f20dc01)

* integration_test/logic/Gpio: Fix order of RequestSend and setting sending

* integration_test: Use UartStmDuplexDma

* CMakeLists: Update amp-embedded-infralib

* integration_test/{tester,tested}/Main: Add missing include

* integration_test/{tester,tested}: Add tracing on ECHO calls

* integration_test/test: Update and fix

* Update amp-cucumber-cpp-runner-poc

* Update amp-cucumber-cpp-runner

* Change amp-cucumber-cpp-runner-poc to amp-cucumber-cpp-runner

* Update amp-cucumber-cpp-runner

* CMakeLists: Rename amp-cucumber-cpp-runner-poc to amp-cucumber-cpp-runner

* launch.json: Set gdbPath to gdb-multiarch

* Apply clang-format

* Update amp-embedded-infralib, reset colour in GlobalTracer

* integration_test: Reset tested before starting a scenario

* Update amp-cucumber-cpp-runner

* integration_test/test: Run tests and EventDispatcher from single thread

* Remove integration_test/test/FixtureSystemChanges

* Move EventDispatcherThreadAware to amp-embedded-infra-lib

* integration_test: Add UART test

* integration_test/test/Hooks: Get serial port to use from command line arguments

* integration_test/test/FixtureEcho: Support Unix serial ports

* Extract FixtureEchoSerial from FixtureEcho

* integration_test/test/FixtureEcho: Refactor FixtureEchoSerial

* integration_test/test/FixtureEcho: Add EchoClientWebSocket

* Add integration_test/test/features/uart_duplex_dma.feature

* Update amp-cucumber-cpp-runner

* Rename integration_test.test to integration_test.runner

* integration_test/tested: Add main for stm32wb55

* integration_test/runner/FixtureEcho: Add EchoClientTcp

* integration_test: Adjust for DMA refactoring

(cherry picked from commit 14689d2)

* .github/workflows/ci.yml: fix merge mistake

* CMakeLists: Only build integration_test when building amp-hal-st standalone

* test: add integration_test.flash_tested

* integration_test/flash_tested/Flash: Reduce lambda context size

* Enable running tests on GitHub

* Update amp-embedded-infra-lib

* integration_test/logic/Tester: Add Ping

* Fix merge conflict

* Process review comments

* Update amp-embedded-infra-lib

* Update amp-cucumber-cpp-runner

* Update amp-cucumber-cpp-runner

* Update amp-cucumber-cpp-runner

* Move Flash into integration_test/logic

* Update amp-cucumber-cpp-runner

* Use EXPECT_TRUE around infra::WaitUntilDone and infra::WaitFor

* Disable compilation for stm32wb because it doesn't have Port::F

* Update amp-cucumber-cpp-runner

* Update .github/workflows/ci.yml

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Temporarily add amp-embedded-infra-lib as submodule

* Add integration_test/flasher

* Use submodule amp-embedded-infra-lib

* Fix merge mistakes

* Update for merge

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ron <45816308+rjaegers@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 6, 2024
1 parent bdd2507 commit ed21738
Show file tree
Hide file tree
Showing 34 changed files with 948 additions and 315 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ jobs:
with:
configurePreset: "host"
buildPreset: "host-Debug-WithPackage"
#testPreset: "host"
testPreset: "host"
configurePresetAdditionalArgs: "['-DCMAKE_C_COMPILER_LAUNCHER=sccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=sccache']"
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: hal_st
path: build/host/hal_st-*-Linux.tar.gz
if-no-files-found: error
#- name: Upload test logs
# if: ${{ failure() }}
# uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
# with:
# name: test-logs
# path: build/host/Testing/Temporary/
- name: Upload test logs
if: ${{ failure() }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: test-logs
path: build/host/Testing/Temporary/
host_build_test:
name: Host Build & Test
runs-on: ${{ matrix.os }}
Expand All @@ -58,14 +58,14 @@ jobs:
with:
configurePreset: "host-single-Debug"
buildPreset: "host-single-Debug"
#testPreset: "host-single-Debug"
testPreset: "host-single-Debug"
configurePresetAdditionalArgs: "['-DCMAKE_C_COMPILER_LAUNCHER=sccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=sccache']"
#- name: Upload test logs
# if: ${{ failure() }}
# uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
# with:
# name: test-logs
# path: build/host/Testing/Temporary/
- name: Upload test logs
if: ${{ failure() }}
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: test-logs
path: build/host/Testing/Temporary/
embedded_build:
name: Embedded Build
runs-on: ubuntu-latest
Expand Down
Empty file added .gitmodules
Empty file.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif()

option(CMAKE_COMPILE_WARNING_AS_ERROR "Enable warnings-as-error" ON)
option(HALST_BUILD_TESTS "Enable building the tests" Off)
option(HALST_INCLUDE_DEFAULT_INIT "Include default initialization code; turn off when providing custom initialization" ON)
option(HALST_BUILD_EXAMPLES "Enable build of the examples" OFF)
option(HALST_BUILD_EXAMPLES_FREERTOS "Enable build of the FreeRTOS example" OFF)
set(HALST_XML_GPIO "" CACHE STRING "XML GPIO table")
set(HALST_XML_STM32 "" CACHE STRING "XML STM32 table")

if (HALST_BUILD_TESTS)
# CTest cannot be included before the first project() statement, but amp-embedded-infa-lib
# needs to see that test utilities need to be built.
set(BUILD_TESTING On)
endif()

if (HALST_STANDALONE)
set(EMIL_INCLUDE_FREERTOS ${HALST_BUILD_EXAMPLES_FREERTOS})

Expand Down Expand Up @@ -49,6 +56,11 @@ else()
set(HALST_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
endif()

if (HALST_BUILD_TESTS)
include(CTest)
emil_enable_testing()
endif()

add_subdirectory(st)
add_subdirectory(hal_st)
add_subdirectory(hal_st_lwip)
Expand Down
9 changes: 5 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"inherits": "defaults",
"cacheVariables": {
"CMAKE_CONFIGURATION_TYPES": "Debug;Release;RelWithDebInfo;MinSizeRel",
"EMIL_BUILD_ECHO_COMPILERS": true,
"EMIL_FETCH_ECHO_COMPILERS": false
"HALST_BUILD_TESTS": true
},
"generator": "Ninja Multi-Config"
},
Expand All @@ -27,15 +26,17 @@
"displayName": "Configuration for Host Tooling and Tests, Single Config Generator, Debug",
"inherits": "defaults",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
"CMAKE_BUILD_TYPE": "Debug",
"HALST_BUILD_TESTS": true
}
},
{
"name": "host-single-MinSizeRel",
"displayName": "Configuration for Host Tooling and Tests, Single Config Generator, MinSizeRel",
"inherits": "defaults",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "MinSizeRel"
"CMAKE_BUILD_TYPE": "MinSizeRel",
"HALST_BUILD_TESTS": true
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion hal_st/stm32fxxx/FlashInternalStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace hal
infra::EventDispatcher::Instance().Schedule(onDone);
}

FlashInternalStm::FlashInternalStm(infra::MemoryRange<uint32_t> sectorSizes, infra::ConstByteRange flashMemory)
FlashInternalStm::FlashInternalStm(infra::MemoryRange<const uint32_t> sectorSizes, infra::ConstByteRange flashMemory)
: FlashInternalStmBase(flashMemory)
, sectorSizes(sectorSizes)
{}
Expand Down
4 changes: 2 additions & 2 deletions hal_st/stm32fxxx/FlashInternalStm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ namespace hal
: public FlashInternalStmBase
{
public:
FlashInternalStm(infra::MemoryRange<uint32_t> sectorSizes, infra::ConstByteRange flashMemory);
FlashInternalStm(infra::MemoryRange<const uint32_t> sectorSizes, infra::ConstByteRange flashMemory);

uint32_t NumberOfSectors() const override;
uint32_t SizeOfSector(uint32_t sectorIndex) const override;
uint32_t SectorOfAddress(uint32_t address) const override;
uint32_t AddressOfSector(uint32_t sectorIndex) const override;

private:
infra::MemoryRange<uint32_t> sectorSizes;
infra::MemoryRange<const uint32_t> sectorSizes;
};

class FlashHomogeneousInternalStm
Expand Down
1 change: 1 addition & 0 deletions integration_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ add_subdirectory(logic)
add_subdirectory(tested)
add_subdirectory(tester)
add_subdirectory(runner)
add_subdirectory(flasher)
21 changes: 21 additions & 0 deletions integration_test/flasher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
add_executable(integration_test.flasher)
emil_build_for(integration_test.flasher HOST All)

target_sources(integration_test.flasher PRIVATE
Main.cpp
)

target_link_libraries(integration_test.flasher PRIVATE
args
integration_test.logic
hal.generic
services.network_instantiations
)

if (EMIL_BUILD_WIN)
target_link_libraries(integration_test.flasher PRIVATE hal.windows)
endif()

if (EMIL_BUILD_UNIX OR EMIL_BUILD_DARWIN)
target_link_libraries(integration_test.flasher PRIVATE hal.unix)
endif()
130 changes: 130 additions & 0 deletions integration_test/flasher/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include "args.hxx"
#include "generated/echo/Testing.pb.hpp"
#include "generated/echo/TracingFlash.pb.hpp"
#include "generated/echo/TracingTesting.pb.hpp"
#include "hal/generic/FileSystemGeneric.hpp"
#include "hal/generic/TimerServiceGeneric.hpp"
#include "integration_test/logic/Flash.hpp"
#include "services/network_instantiations/EchoInstantiation.hpp"
#include "services/network_instantiations/NetworkAdapter.hpp"
#include "services/tracer/GlobalTracer.hpp"
#include "services/tracer/TracerOnIoOutputInfrastructure.hpp"

namespace
{
const std::array<uint32_t, 12> stm32f767SectorSizes{ { 32 * 1024,
32 * 1024,
32 * 1024,
32 * 1024,
128 * 1024,
256 * 1024,
256 * 1024,
256 * 1024,
256 * 1024,
256 * 1024,
256 * 1024,
256 * 1024 } };
}

class FirmwareSender
{
public:
FirmwareSender(const std::vector<uint8_t>& firmware, services::Echo& echo)
: firmware(firmware)
, flash(echo, infra::MakeRange(stm32f767SectorSizes))
, tester(echo)
{
tester.RequestSend([this]()
{
tester.SetTestedMode(testing::TestedMode::reset);
tester.RequestSend([this]()
{
tester.SetTestedMode(testing::TestedMode::programming);

services::GlobalTracer().Trace() << "Erasing chip...";
flash.EraseAll([this]()
{
services::GlobalTracer().Trace() << "Writing firmware...";
flash.WriteBuffer(infra::MakeRange(this->firmware), 0, [this]()
{
services::GlobalTracer().Trace() << "Uploading done";
done = true;
});
});
});
});
}

bool Done() const
{
return done;
}

private:
std::vector<uint8_t> firmware;
application::FlashProxy flash;
testing::TesterProxy tester;
bool done = false;

infra::TimerSingleShot timeoutTimer{ std::chrono::minutes(2), [this]()
{
done = true;
} };
};

struct FlashTracer
{
FlashTracer(services::TracingEchoOnStreams& echoTracer)
: testerTracer(echoTracer)
, testerObserverTracer(echoTracer)
, flashTracer(echoTracer)
, flashResultTracer(echoTracer)
{}

testing::TesterTracer testerTracer;
testing::TesterObserverTracer testerObserverTracer;
flash::FlashTracer flashTracer;
flash::FlashResultTracer flashResultTracer;
};

int main(int argc, char** argv)
{
args::ArgumentParser parser("Flasher");
args::Group positionals(parser, "Positional arguments:");
args::Positional<std::string> targetArgument(positionals, "target", "COM port or hostname", args::Options::Required);
args::Positional<std::string> firmwareArgument(positionals, "firmware", "Binary firmware with which the target attached to Postmaster is upgraded");
args::HelpFlag help(parser, "help", "display this help menu.", { 'h', "help" });

try
{
parser.ParseCLI(argc, argv);

static hal::TimerServiceGeneric timerService;
static main_::TracerOnIoOutputInfrastructure tracer;
static main_::NetworkAdapter network;
static hal::FileSystemGeneric fileSystem;

auto firmware = firmwareArgument ? fileSystem.ReadBinaryFile(args::get(firmwareArgument)) : std::vector<uint8_t>{};
auto [echo, echoTracer] = application::OpenTracingEcho(args::get(targetArgument), network.ConnectionFactoryWithNameResolver(), tracer.tracer);

FlashTracer flashTracer(*echoTracer);
FirmwareSender sender(firmware, *echo);

network.ExecuteUntil([&]()
{
return sender.Done();
});
}
catch (const args::Help&)
{
std::cout << parser;
return 1;
}
catch (const std::exception& ex)
{
std::cout << ex.what() << std::endl;
return 1;
}

return 0;
}
5 changes: 5 additions & 0 deletions integration_test/logic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ target_include_directories(integration_test.logic PUBLIC
)

protocol_buffer_echo_cpp(integration_test.logic Testing.proto)
protocol_buffer_echo_cpp(integration_test.logic Flash.proto)

target_sources(integration_test.logic PRIVATE
Flash.cpp
Flash.hpp
Gpio.cpp
Gpio.hpp
Peripheral.cpp
Expand All @@ -23,3 +26,5 @@ target_link_libraries(integration_test.logic PUBLIC
services.util
protobuf.echo
)

add_subdirectory(test)
Loading

0 comments on commit ed21738

Please sign in to comment.