Skip to content

Commit

Permalink
Clean up UpdateRingBuffer.test.cpp
Browse files Browse the repository at this point in the history
- Fix includes
- Rename some things
- Use proper types
  • Loading branch information
PatrickKa committed Nov 4, 2023
1 parent 770b44d commit c1855b1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 42 deletions.
1 change: 0 additions & 1 deletion Tests/GoldenTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ add_golden_test(
rodos::rodos
Sts1CobcSw_Edu
Sts1CobcSw_Utility
Sts1CobcSw_Dummy
)

add_golden_test(
Expand Down
68 changes: 27 additions & 41 deletions Tests/GoldenTests/UpdateRingBuffer.test.cpp
Original file line number Diff line number Diff line change
@@ -1,108 +1,94 @@
#include <Sts1CobcSw/Dummy.hpp>
#include <Sts1CobcSw/Edu/ProgramStatusHistory.hpp>

#include <ringbuffer.h>
#include <type_safe/types.hpp>

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

#include <algorithm>
#include <cstdint>
#include <string_view>


std::uint32_t printfMask = 0;


namespace sts1cobcsw
{

auto StatusToString(edu::ProgramStatus status) -> std::string
auto ToString(edu::ProgramStatus status) -> std::string_view
{
switch(status)
{
case edu::ProgramStatus::programRunning:
return {"programRunning"};
return "programRunning";
case edu::ProgramStatus::programExecutionFailed:
return {"programExecutionFailed"};
return "programExecutionFailed";
case edu::ProgramStatus::programExecutionSucceeded:
return {"programExecutionSucceeded"};
return "programExecutionSucceeded";
default:
break;
return "";
}
}


// Helper function for edu::programStatusHistory
void PrintBuffer()
{
for(int i = 0; i < edu::programStatusHistory.occupiedCnt; ++i)
for(std::uint32_t i = 0; i < edu::programStatusHistory.occupiedCnt; ++i)
{
RODOS::PRINTF("Vals[%d] = .id(%d), .status(%s)\n",
i,
edu::programStatusHistory.vals[i].programId.get(),
StatusToString(edu::programStatusHistory.vals[i].status).c_str());
ToString(edu::programStatusHistory.vals[i].status).data());
}
}


class HelloDummy : public RODOS::StaticThread<>
class UpdateRingBufferTest : public RODOS::StaticThread<>
{
void run() override
{
printfMask = 1;
edu::programStatusHistory.put(
edu::ProgramStatusHistoryEntry{.programId = static_cast<std::uint16_t>(1),
.queueId = static_cast<std::uint16_t>(1),
.status = edu::ProgramStatus::programExecutionFailed});
using type_safe::operator""_u16;

edu::programStatusHistory.put(
edu::ProgramStatusHistoryEntry{.programId = static_cast<std::uint16_t>(2),
.queueId = static_cast<std::uint16_t>(1),
.status = edu::ProgramStatus::programRunning});

edu::programStatusHistory.put(
edu::ProgramStatusHistoryEntry{.programId = static_cast<std::uint16_t>(3),
.queueId = static_cast<std::uint16_t>(1),
.status = edu::ProgramStatus::programRunning});
printfMask = 1;

edu::programStatusHistory.put(
edu::ProgramStatusHistoryEntry{.programId = static_cast<std::uint16_t>(4),
.queueId = static_cast<std::uint16_t>(1),
.status = edu::ProgramStatus::programRunning});
edu::ProgramStatusHistoryEntry{.programId = 1_u16,
.queueId = 1_u16,
.status = edu::ProgramStatus::programExecutionFailed});
edu::programStatusHistory.put(edu::ProgramStatusHistoryEntry{
.programId = 2_u16, .queueId = 1_u16, .status = edu::ProgramStatus::programRunning});
edu::programStatusHistory.put(edu::ProgramStatusHistoryEntry{
.programId = 3_u16, .queueId = 1_u16, .status = edu::ProgramStatus::programRunning});
edu::programStatusHistory.put(edu::ProgramStatusHistoryEntry{
.programId = 4_u16, .queueId = 1_u16, .status = edu::ProgramStatus::programRunning});


auto readCnt = edu::programStatusHistory.readCnt;
auto writeCnt = edu::programStatusHistory.writeCnt;
auto occupiedCnt = edu::programStatusHistory.occupiedCnt;


// Print RingBuffer
PrintBuffer();


edu::UpdateProgramStatusHistory(2, 1, edu::ProgramStatus::programExecutionSucceeded);
edu::UpdateProgramStatusHistory(4, 1, edu::ProgramStatus::programExecutionFailed);

edu::programStatusHistory.put(
edu::ProgramStatusHistoryEntry{.programId = static_cast<std::uint16_t>(5),
.queueId = static_cast<std::uint16_t>(1),
.status = edu::ProgramStatus::programRunning});

edu::programStatusHistory.put(edu::ProgramStatusHistoryEntry{
.programId = 5_u16, .queueId = 1_u16, .status = edu::ProgramStatus::programRunning});
edu::UpdateProgramStatusHistory(5, 1, edu::ProgramStatus::programExecutionSucceeded);

// 1, we did not read anything
// 1, because we did not read anything
RODOS::PRINTF("readCnt unchanged : %d\n",
static_cast<int>(edu::programStatusHistory.readCnt == readCnt));
// 0, bc we did write
// 0, because we did write
RODOS::PRINTF("writeCnt unchanged : %d\n",
static_cast<int>(edu::programStatusHistory.readCnt == writeCnt));
// 0
RODOS::PRINTF("OccupiedCnt unchanged : %d\n",
static_cast<int>(edu::programStatusHistory.occupiedCnt == occupiedCnt));

// Print RingBuffer
PrintBuffer();

RODOS::hwResetAndReboot();
}
} helloDummy;
} updateRingBufferTest;
}

0 comments on commit c1855b1

Please sign in to comment.