Skip to content

Commit

Permalink
Use strong types for time in some HW tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickKa committed Aug 28, 2024
1 parent 7fd392c commit 2ad7048
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Tests/HardwareTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ add_watchdog_version_of(Uart)

add_program(Watchdog Watchdog.test.cpp)
target_link_libraries(
Sts1CobcSwTests_Watchdog PRIVATE rodos::rodos Sts1CobcSw_Hal
Sts1CobcSwTests_Watchdog PRIVATE rodos::rodos Sts1CobcSw_Hal Sts1CobcSw_Utility
Sts1CobcSwTests_RfLatchupDisablePin
)

Expand Down
6 changes: 4 additions & 2 deletions Tests/HardwareTests/MaxPower.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <Sts1CobcSw/Utility/Span.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <strong_type/type.hpp>

#include <rodos/support/support-libs/random.h>
#include <rodos_no_using_namespace.h>

Expand All @@ -22,7 +24,7 @@ namespace sts1cobcsw
using RODOS::PRINTF;


constexpr auto uartTimeout = Duration(100 * RODOS::MILLISECONDS);
constexpr auto uartTimeout = 100 * ms;

auto led1GpioPin = hal::GpioPin(hal::led1Pin);
auto led2GpioPin = hal::GpioPin(hal::led2Pin);
Expand Down Expand Up @@ -54,7 +56,7 @@ class MaxPowerTestLedThread : public RODOS::StaticThread<>
PRINTF("\nMax. power test LED thread\n\n");
auto toggle = true;
led1GpioPin.Set();
TIME_LOOP(0, 100 * RODOS::MILLISECONDS)
TIME_LOOP(0, value_of(100 * ms))
{
toggle ? led2GpioPin.Set() : led2GpioPin.Reset();
toggle = not toggle;
Expand Down
71 changes: 32 additions & 39 deletions Tests/HardwareTests/Uart.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class UartTest : public RODOS::StaticThread<>

void run() override
{
using RODOS::MICROSECONDS;
using RODOS::MILLISECONDS;
using RODOS::NOW;
using RODOS::PRINTF;

#if HW_VERSION >= 27
Expand Down Expand Up @@ -85,21 +82,19 @@ class UartTest : public RODOS::StaticThread<>
PRINTF("Sending a message containing an update time command to the EDU.\n");
PRINTF("message.size() = %i\n", static_cast<int>(message.size()));

auto tWrite0 = NOW();
auto writeToResult1 =
hal::WriteTo(&eduUart, Span(message), Duration(100 * MILLISECONDS));
auto tWrite1 = NOW();
auto tWrite0 = CurrentRodosTime();
auto writeToResult1 = hal::WriteTo(&eduUart, Span(message), 100 * ms);
auto tWrite1 = CurrentRodosTime();

auto answer1 = std::array<char, 1>{};

auto tRead0 = NOW();
auto readFromResult1 =
hal::ReadFrom(&eduUart, Span(&answer1), Duration(100 * MILLISECONDS));
auto tRead1 = NOW();
auto tRead0 = CurrentRodosTime();
auto readFromResult1 = hal::ReadFrom(&eduUart, Span(&answer1), 100 * ms);
auto tRead1 = CurrentRodosTime();

PRINTF("\n");
PRINTF("tWrite1 - tWrite0 = %5" PRIi64 " us\n", (tWrite1 - tWrite0) / MICROSECONDS);
PRINTF("tRead1 - tRead0 = %5" PRIi64 " us\n", (tRead1 - tRead0) / MICROSECONDS);
PRINTF("tWrite1 - tWrite0 = %5" PRIi64 " us\n", (tWrite1 - tWrite0) / us);
PRINTF("tRead1 - tRead0 = %5" PRIi64 " us\n", (tRead1 - tRead0) / us);
PRINTF("writeToResult1.hasError() = %s\n",
writeToResult1.has_error() ? "true" : "false");
PRINTF("readFromResult1.hasError() = %s\n",
Expand All @@ -108,23 +103,23 @@ class UartTest : public RODOS::StaticThread<>

PRINTF("\n");
PRINTF("Sending the message again.");
auto writeTimeout = Duration(500 * MICROSECONDS);
auto writeTimeout = 500 * us;
PRINTF(" This time with a write timeout of %" PRIi64 " us which is too short.\n",
value_of(writeTimeout) / MICROSECONDS);
writeTimeout / us);

tWrite0 = NOW();
tWrite0 = CurrentRodosTime();
writeToResult1 = hal::WriteTo(&eduUart, Span(message), writeTimeout);
tWrite1 = NOW();
tWrite1 = CurrentRodosTime();

answer1[0] = 0x00;

tRead0 = NOW();
readFromResult1 = hal::ReadFrom(&eduUart, Span(&answer1), Duration(100 * MILLISECONDS));
tRead1 = NOW();
tRead0 = CurrentRodosTime();
readFromResult1 = hal::ReadFrom(&eduUart, Span(&answer1), 100 * ms));
tRead1 = CurrentRodosTime();

PRINTF("\n");
PRINTF("tWrite1 - tWrite0 = %5" PRIi64 " us\n", (tWrite1 - tWrite0) / MICROSECONDS);
PRINTF("tRead1 - tRead0 = %5" PRIi64 " us\n", (tRead1 - tRead0) / MICROSECONDS);
PRINTF("tWrite1 - tWrite0 = %5" PRIi64 " us\n", (tWrite1 - tWrite0) / us);
PRINTF("tRead1 - tRead0 = %5" PRIi64 " us\n", (tRead1 - tRead0) / us);
PRINTF("writeToResult1.hasError() = %s\n",
writeToResult1.has_error() ? "true" : "false");
PRINTF("readFromResult1.hasError() = %s\n",
Expand All @@ -133,31 +128,29 @@ class UartTest : public RODOS::StaticThread<>

PRINTF("\n");
PRINTF("Sending the message twice.");
auto readTimeout = Duration(1500 * MICROSECONDS);
auto readTimeout = 1500 * us;
PRINTF(" The first time with a read timeout of %" PRIi64 " us which is too short.\n",
value_of(readTimeout) / MICROSECONDS);
readTimeout / us);

tWrite0 = NOW();
writeToResult1 = hal::WriteTo(&eduUart, Span(message), Duration(100 * MILLISECONDS));
tWrite1 = NOW();
auto writeToResult2 =
hal::WriteTo(&eduUart, Span(message), Duration(100 * MILLISECONDS));
auto tWrite2 = NOW();
tWrite0 = CurrentRodosTime();
writeToResult1 = hal::WriteTo(&eduUart, Span(message), 100 * ms);
tWrite1 = CurrentRodosTime();
auto writeToResult2 = hal::WriteTo(&eduUart, Span(message), 100 * ms);
auto tWrite2 = CurrentRodosTime();

auto answer2 = std::array<char, 1>{};

tRead0 = NOW();
tRead0 = CurrentRodosTime();
readFromResult1 = hal::ReadFrom(&eduUart, Span(&answer1), readTimeout);
tRead1 = NOW();
auto readFromResult2 =
hal::ReadFrom(&eduUart, Span(&answer2), Duration(100 * MILLISECONDS));
auto tRead2 = NOW();
tRead1 = CurrentRodosTime();
auto readFromResult2 = hal::ReadFrom(&eduUart, Span(&answer2), 100 * ms);
auto tRead2 = CurrentRodosTime();

PRINTF("\n");
PRINTF("tWrite1 - tWrite0 = %5" PRIi64 " us\n", (tWrite1 - tWrite0) / MICROSECONDS);
PRINTF("tWrite2 - tWrite1 = %5" PRIi64 " us\n", (tWrite2 - tWrite1) / MICROSECONDS);
PRINTF("tRead1 - tRead0 = %5" PRIi64 " us\n", (tRead1 - tRead0) / MICROSECONDS);
PRINTF("tRead2 - tRead1 = %5" PRIi64 " us\n", (tRead2 - tRead1) / MICROSECONDS);
PRINTF("tWrite1 - tWrite0 = %5" PRIi64 " us\n", (tWrite1 - tWrite0) / us);
PRINTF("tWrite2 - tWrite1 = %5" PRIi64 " us\n", (tWrite2 - tWrite1) / us);
PRINTF("tRead1 - tRead0 = %5" PRIi64 " us\n", (tRead1 - tRead0) / us);
PRINTF("tRead2 - tRead1 = %5" PRIi64 " us\n", (tRead2 - tRead1) / us);
PRINTF("writeToResult1.hasError() = %s\n",
writeToResult1.has_error() ? "true" : "false");
PRINTF("writeToResult2.hasError() = %s\n",
Expand Down
3 changes: 2 additions & 1 deletion Tests/HardwareTests/Watchdog.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <Sts1CobcSw/Hal/GpioPin.hpp>
#include <Sts1CobcSw/Hal/IoNames.hpp>
#include <Sts1CobcSw/Utility/Time.hpp>

#include <rodos_no_using_namespace.h>

Expand All @@ -28,7 +29,7 @@ class WatchdogTest : public RODOS::StaticThread<>
rfLatchupDisableGpioPin.Reset();
#endif
led1Gpio.Reset();
RODOS::AT(RODOS::NOW() + 800 * RODOS::MILLISECONDS);
SuspendFor(800 * ms);
led1Gpio.Set();
}
} watchdogTest;
Expand Down

0 comments on commit 2ad7048

Please sign in to comment.