fprime/Svc/DpWriter/test/ut/DpWriterTester.cpp
Rob Bocchino b89b5d91c4
Add DpWriter (#2593)
* Pull in framework changes from data-products branch

* Pull in changes to DpManager from data-products branch

* Pull in DpWriter from data-products branch

* Fix spelling

* Revise FileNameString

* Fix warnings in CI

* Fix static analysis warnings

* Fix static analysis warnings

* Revise formatting and comments

* Revise banner comments

* Revise FileNameString per PR comment

* Revise path names in config headers

If a header H.hpp exists in the F Prime source base, then

is dangerous. Because [project root] and [fprime root] are both
in the list of include paths, it's not clear whether this means "include
[project root]/config/H.hpp" or "include [fprime root]/config/H.hpp."

On the other hand,

or

has no such ambiguity, because only one of [project root]/config
and [fprime root]/config is in the list of include paths.

* Revise path names in config headers

If a header H.hpp exists in the F Prime source base, then

`#include "config/H.hpp"`

is dangerous. Because [project root] and [fprime root] are both
in the list of include paths, it's not clear whether this means "include
[project root]/config/H.hpp" or "include [fprime root]/config/H.hpp."

On the other hand,

include <config/H.hpp>

or

`#include "config/H.hpp"`

has no such ambiguity, because only one of [project root]/config
and [fprime root]/config is in the list of include paths.
2024-03-28 16:09:38 -07:00

101 lines
4.3 KiB
C++

// ======================================================================
// \title DpWriterTester.cpp
// \author bocchino
// \brief cpp file for DpWriter component test harness implementation class
// ======================================================================
#include "DpWriterTester.hpp"
#include "Os/Stub/test/File.hpp"
namespace Svc {
// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
DpWriterTester ::DpWriterTester()
: DpWriterGTestBase("DpWriterTester", DpWriterTester::MAX_HISTORY_SIZE), component("DpWriter") {
this->initComponents();
this->connectPorts();
Os::Stub::File::Test::StaticData::data.setNextStatus(Os::File::OP_OK);
Os::Stub::File::Test::StaticData::data.writeResult = this->abstractState.m_writeResultData;
Os::Stub::File::Test::StaticData::data.writeResultSize = sizeof(this->abstractState.m_writeResultData);
Os::Stub::File::Test::StaticData::data.pointer = 0;
}
DpWriterTester ::~DpWriterTester() {}
// ----------------------------------------------------------------------
// Handlers for typed from ports
// ----------------------------------------------------------------------
void DpWriterTester ::from_deallocBufferSendOut_handler(NATIVE_INT_TYPE portNum, Fw::Buffer& buffer) {
this->pushFromPortEntry_deallocBufferSendOut(buffer);
}
void DpWriterTester ::from_dpWrittenOut_handler(NATIVE_INT_TYPE portNum,
const fileNameString& fileName,
FwDpPriorityType priority,
FwSizeType size) {
this->pushFromPortEntry_dpWrittenOut(fileName, priority, size);
}
void DpWriterTester::from_procBufferSendOut_handler(NATIVE_INT_TYPE portNum, Fw::Buffer& buffer) {
this->pushFromPortEntry_procBufferSendOut(buffer);
this->abstractState.m_procTypes |= (1 << portNum);
}
// ----------------------------------------------------------------------
// Public member functions
// ----------------------------------------------------------------------
void DpWriterTester::printEvents() {
this->printTextLogHistory(stdout);
}
// ----------------------------------------------------------------------
// Protected helper functions
// ----------------------------------------------------------------------
Os::File::Status DpWriterTester::pickOsFileError() {
U32 u32Status = STest::Pick::lowerUpper(Os::File::OP_OK + 1, Os::File::MAX_STATUS - 1);
return static_cast<Os::File::Status>(u32Status);
}
#define TESTER_CHECK_CHANNEL(NAME) \
{ \
const auto changeStatus = this->abstractState.m_##NAME.updatePrev(); \
if (changeStatus == TestUtils::OnChangeStatus::CHANGED) { \
ASSERT_TLM_##NAME##_SIZE(1); \
ASSERT_TLM_##NAME(0, this->abstractState.m_##NAME.value); \
} else { \
ASSERT_TLM_##NAME##_SIZE(0); \
} \
}
void DpWriterTester::constructDpFileName(FwDpIdType id, const Fw::Time& timeTag, Fw::StringBase& fileName) {
fileName.format(DP_FILENAME_FORMAT, id, timeTag.getSeconds(), timeTag.getUSeconds());
}
void DpWriterTester::checkProcTypes(const Fw::DpContainer& container) {
FwIndexType expectedNumProcTypes = 0;
const Fw::DpCfg::ProcType::SerialType procTypes = container.getProcTypes();
for (FwIndexType i = 0; i < Fw::DpCfg::ProcType::NUM_CONSTANTS; i++) {
if (procTypes & (1 << i)) {
++expectedNumProcTypes;
}
}
ASSERT_from_procBufferSendOut_SIZE(expectedNumProcTypes);
ASSERT_EQ(container.getProcTypes(), this->abstractState.m_procTypes);
}
void DpWriterTester::checkTelemetry() {
TESTER_CHECK_CHANNEL(NumBuffersReceived);
TESTER_CHECK_CHANNEL(NumBytesWritten);
TESTER_CHECK_CHANNEL(NumSuccessfulWrites);
TESTER_CHECK_CHANNEL(NumFailedWrites);
TESTER_CHECK_CHANNEL(NumErrors);
}
} // namespace Svc