-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for SPI supervisor
- Loading branch information
Showing
7 changed files
with
131 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
add_program(SpiSupervisor SpiSupervisor.test.cpp) | ||
target_sources( | ||
Sts1CobcSwTests_SpiSupervisor | ||
PRIVATE ${CMAKE_SOURCE_DIR}/Sts1CobcSw/CobcSoftware/StartupTestThreadStubs.cpp | ||
${CMAKE_SOURCE_DIR}/Sts1CobcSw/CobcSoftware/SpiStartupTestAndSupervisorThread.cpp | ||
) | ||
target_link_libraries( | ||
Sts1CobcSwTests_SpiSupervisor PRIVATE rodos::rodos Sts1CobcSw_FramSections Sts1CobcSw_Hal | ||
Sts1CobcSw_Periphery Sts1CobcSw_Serial Sts1CobcSw_Utility | ||
) | ||
add_test(NAME SpiSupervisor COMMAND Sts1CobcSwTests_SpiSupervisor) | ||
|
||
# --- All integration tests --- | ||
|
||
get_property( | ||
all_integration_test_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS | ||
) | ||
add_custom_target(AllIntegrationTests) # Must be defined after getting all integration test targets | ||
add_dependencies(AllIntegrationTests ${all_integration_test_targets}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include <Sts1CobcSw/Hal/Spi.hpp> | ||
#include <Sts1CobcSw/Hal/SpiMock.hpp> | ||
#include <Sts1CobcSw/Periphery/Fram.hpp> | ||
#include <Sts1CobcSw/Periphery/FramMock.hpp> | ||
#include <Sts1CobcSw/Periphery/Spis.hpp> | ||
#include <Sts1CobcSw/Serial/Byte.hpp> | ||
#include <Sts1CobcSw/Utility/RodosTime.hpp> | ||
#include <Sts1CobcSw/Utility/Span.hpp> | ||
#include <Sts1CobcSw/Utility/TimeTypes.hpp> | ||
|
||
#include <strong_type/affine_point.hpp> | ||
#include <strong_type/difference.hpp> | ||
|
||
#include <rodos_no_using_namespace.h> | ||
|
||
#include <cstddef> | ||
|
||
|
||
namespace sts1cobcsw | ||
{ | ||
using RODOS::PRINTF; | ||
|
||
|
||
auto WriteThatFinishesInTime([[maybe_unused]] void const * data, | ||
[[maybe_unused]] std::size_t nBytes, | ||
Duration duration) -> void; | ||
auto WriteThatNeverFinishes([[maybe_unused]] void const * data, | ||
[[maybe_unused]] std::size_t nBytes, | ||
Duration duration) -> void; | ||
|
||
|
||
auto transferEnd = endOfTime; | ||
|
||
|
||
class SpiSupervisorTest : public RODOS::StaticThread<> | ||
{ | ||
// We cannot use dynamic_cast because RTTI is disabled | ||
// NOLINTBEGIN(*static-cast-downcast) | ||
hal::SpiMock & flashSpi_ = static_cast<hal::SpiMock &>(flashSpi); | ||
hal::SpiMock & framEpsSpi_ = static_cast<hal::SpiMock &>(framEpsSpi); | ||
hal::SpiMock & rfSpi_ = static_cast<hal::SpiMock &>(rfSpi); | ||
// NOLINTEND(*static-cast-downcast) | ||
|
||
|
||
public: | ||
SpiSupervisorTest() : StaticThread("SpiSupervisorTest", 200) | ||
{ | ||
} | ||
|
||
void init() override | ||
{ | ||
flashSpi_.SetTransferEnd([]() { return transferEnd; }); | ||
flashSpi_.SetWrite(WriteThatFinishesInTime); | ||
framEpsSpi_.SetTransferEnd([]() { return transferEnd; }); | ||
framEpsSpi_.SetWrite(WriteThatFinishesInTime); | ||
rfSpi_.SetTransferEnd([]() { return transferEnd; }); | ||
rfSpi_.SetWrite(WriteThatFinishesInTime); | ||
fram::ram::SetAllDoFunctions(); | ||
fram::Initialize(); | ||
} | ||
|
||
void run() override | ||
{ | ||
SuspendFor(1 * s); | ||
|
||
PRINTF("\nSPI supervisor test\n\n"); | ||
|
||
PRINTF("Writing with implementation that finishes in time ...\n"); | ||
WriteTo(&flashSpi_, Span(0x00_b), 10 * ms); | ||
WriteTo(&framEpsSpi_, Span(0x00_b), 100 * ms); | ||
// The supervision period is 1 s so this write will definitely be checked at least once by | ||
// the supervisor thread | ||
WriteTo(&rfSpi_, Span(0x00_b), 1500 * ms); | ||
PRINTF(" -> works\n"); | ||
|
||
PRINTF("Writing with implementation that never finishes ...\n"); | ||
flashSpi_.SetWrite(WriteThatNeverFinishes); | ||
WriteTo(&flashSpi_, Span(0x00_b), 1 * ms); | ||
} | ||
} spiSupervisorTest; | ||
|
||
|
||
auto WriteThatFinishesInTime([[maybe_unused]] void const * data, | ||
[[maybe_unused]] std::size_t nBytes, | ||
Duration duration) -> void | ||
{ | ||
transferEnd = CurrentRodosTime() + duration; | ||
SuspendFor(duration / 10 * 9); | ||
transferEnd = endOfTime; | ||
} | ||
|
||
|
||
auto WriteThatNeverFinishes([[maybe_unused]] void const * data, | ||
[[maybe_unused]] std::size_t nBytes, | ||
Duration duration) -> void | ||
{ | ||
transferEnd = CurrentRodosTime() + duration; | ||
SuspendUntil(endOfTime); | ||
} | ||
} |