Skip to content
7 changes: 6 additions & 1 deletion Svc/DpWriter/DpWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
return status;
}

void DpWriter::performProcessing(const Fw::DpContainer& container) {
void DpWriter::performProcessing(Fw::DpContainer& container) {
// Get the buffer
Fw::Buffer buffer = container.getBuffer();
// Get the bit mask for the processing types
Expand All @@ -169,6 +169,11 @@
this->procBufferSendOut_out(portNum, buffer);
}
}

// Update container buffer size
container.getBuffer().setSize(buffer.getSize());
container.setDataSize(buffer.getSize() - Fw::DpContainer::MIN_PACKET_SIZE);
container.serializeHeader();
}

Fw::Success::T DpWriter::writeFile(const Fw::DpContainer& container,
Expand Down
2 changes: 1 addition & 1 deletion Svc/DpWriter/DpWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DpWriter final : public DpWriterComponentBase {
);

//! Perform processing on a packet buffer
void performProcessing(const Fw::DpContainer& container //!< The container
void performProcessing(Fw::DpContainer& container //!< The container
);

//! Write the file
Expand Down
19 changes: 12 additions & 7 deletions Svc/DpWriter/test/ut/AbstractState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ namespace Svc {
//! Get a data product buffer backed by m_bufferData
//! \return The buffer
Fw::Buffer AbstractState::getDpBuffer() {
Fw::DpCfg::ProcType::SerialType procTypes = 0;
for (FwIndexType i = 0; i < Fw::DpCfg::ProcType::NUM_CONSTANTS; i++) {
const bool selector = static_cast<bool>(STest::Pick::lowerUpper(0, 1));
if (selector) {
procTypes = static_cast<Fw::DpCfg::ProcType::SerialType>(procTypes | (1 << i));
}
}

return getDpBufferWithProc(procTypes);
}

Fw::Buffer AbstractState::getDpBufferWithProc(Fw::DpCfg::ProcType::SerialType procTypes) {
// Generate the ID
const FwDpIdType id = static_cast<FwDpIdType>(STest::Pick::lowerUpper(
std::numeric_limits<FwDpIdType>::min(), static_cast<U32>(std::numeric_limits<FwDpIdType>::max())));
Expand All @@ -45,13 +57,6 @@ Fw::Buffer AbstractState::getDpBuffer() {
const U32 microseconds = STest::Pick::startLength(0, 1000000);
container.setTimeTag(Fw::Time(seconds, microseconds));
// Update the processing types
Fw::DpCfg::ProcType::SerialType procTypes = 0;
for (FwIndexType i = 0; i < Fw::DpCfg::ProcType::NUM_CONSTANTS; i++) {
const bool selector = static_cast<bool>(STest::Pick::lowerUpper(0, 1));
if (selector) {
procTypes = static_cast<Fw::DpCfg::ProcType::SerialType>(procTypes | (1 << i));
}
}
container.setProcTypes(procTypes);
// Update the data size
container.setDataSize(dataSize);
Expand Down
11 changes: 10 additions & 1 deletion Svc/DpWriter/test/ut/AbstractState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class AbstractState {
m_NumFailedWrites(0),
m_NumSuccessfulWrites(0),
m_NumErrors(0),
m_procTypes(0) {}
m_procTypes(0),
m_procShrinkDataSizeOpt() {}

public:
// ----------------------------------------------------------------------
Expand All @@ -66,10 +67,16 @@ class AbstractState {
//! Set the data size
void setDataSize(FwSizeType dataSize) { this->m_dataSizeOpt.set(dataSize); }

void clearDataSize() { this->m_dataSizeOpt.clear(); }

//! Get a data product buffer backed by bufferData
//! \return The buffer
Fw::Buffer getDpBuffer();

//! Get a data product buffer backed by bufferData
//! \return The buffer
Fw::Buffer getDpBufferWithProc(Fw::DpCfg::ProcType::SerialType procTypes);

private:
// ----------------------------------------------------------------------
// Private state variables
Expand Down Expand Up @@ -127,6 +134,8 @@ class AbstractState {

//! Bit mask for processing out port calls
Fw::DpCfg::ProcType::SerialType m_procTypes;

TestUtils::Option<FwSizeType> m_procShrinkDataSizeOpt;
};

} // namespace Svc
Expand Down
9 changes: 9 additions & 0 deletions Svc/DpWriter/test/ut/DpWriterTestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ TEST(BufferSendIn, OK) {
tester.OK();
}

TEST(BufferSendIn, OKProcShrink) {
COMMENT("Invoke bufferSendIn with nominal input. Shrink the buffer in processing");
REQUIREMENT("SVC-DPMANAGER-002");
REQUIREMENT("SVC-DPMANAGER-003");
REQUIREMENT("SVC-DPMANAGER-004");
BufferSendIn::Tester tester;
tester.OKProcShrink();
}

TEST(CLEAR_EVENT_THROTTLE, OK) {
COMMENT("Test the CLEAR_EVENT_THROTTLE command.");
REQUIREMENT("SVC-DPMANAGER-006");
Expand Down
4 changes: 4 additions & 0 deletions Svc/DpWriter/test/ut/DpWriterTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ void DpWriterTester::from_procBufferSendOut_handler(FwIndexType portNum, Fw::Buf
this->pushFromPortEntry_procBufferSendOut(buffer);
this->abstractState.m_procTypes =
static_cast<Fw::DpCfg::ProcType::SerialType>(this->abstractState.m_procTypes | (1 << portNum));

if (this->abstractState.m_procShrinkDataSizeOpt.hasValue()) {
buffer.setSize(Fw::DpContainer::MIN_PACKET_SIZE + this->abstractState.m_procShrinkDataSizeOpt.get());
}
}

// ----------------------------------------------------------------------
Expand Down
71 changes: 71 additions & 0 deletions Svc/DpWriter/test/ut/Rules/BufferSendIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,72 @@ void TestState ::action__BufferSendIn__OK() {
this->abstractState.m_NumSuccessfulWrites.value++;
}

bool TestState ::precondition__BufferSendIn__OKProcShrink() const {
const auto& fileData = Os::Stub::File::Test::StaticData::data;
bool result = true;
result &= (fileData.openStatus == Os::File::Status::OP_OK);
result &= (fileData.writeStatus == Os::File::Status::OP_OK);
return result;
}

void TestState ::action__BufferSendIn__OKProcShrink() {
// Clear the history
this->clearHistory();
// Reset the saved proc types
// These are updated in the from_procBufferSendOut handler
this->abstractState.m_procTypes = 0;
// Reset the file pointer in the stub file implementation
auto& fileData = Os::Stub::File::Test::StaticData::data;
fileData.pointer = 0;
// Update m_NumBuffersReceived
this->abstractState.m_NumBuffersReceived.value++;
// Construct a random buffer
const FwSizeType buffer_data_size =
STest::Pick::lowerUpper(AbstractState::MAX_DATA_SIZE / 2, AbstractState::MAX_DATA_SIZE);
const FwSizeType shrink_data_size = buffer_data_size / 2;
this->abstractState.setDataSize(buffer_data_size);
Fw::Buffer buffer = this->abstractState.getDpBufferWithProc(1);
// Instruct the proc handler to shrink the buffer
this->abstractState.m_procShrinkDataSizeOpt.set(shrink_data_size);
const FwSizeType exp_buffer_size = Fw::DpContainer::MIN_PACKET_SIZE + shrink_data_size;
// Send the buffer
this->invoke_to_bufferSendIn(0, buffer);
this->doDispatch();
// Deserialize the container header
Fw::DpContainer container;
container.setBuffer(buffer);
const Fw::SerializeStatus status = container.deserializeHeader();
ASSERT_EQ(status, Fw::FW_SERIALIZE_OK);
// Check events
ASSERT_EVENTS_SIZE(1);
ASSERT_EVENTS_FileWritten_SIZE(1);
Fw::FileNameString fileName;
this->constructDpFileName(container.getId(), container.getTimeTag(), fileName);
ASSERT_EVENTS_FileWritten(0, static_cast<U32>(exp_buffer_size), fileName.toChar());
// Check processing types
this->checkProcTypes(container);
// Check DP notification
ASSERT_from_dpWrittenOut_SIZE(1);
ASSERT_from_dpWrittenOut(0, fileName, container.getPriority(), exp_buffer_size);
// Check deallocation
ASSERT_from_deallocBufferSendOut_SIZE(1);
ASSERT_from_deallocBufferSendOut(0, buffer);
// Check file write
ASSERT_EQ(exp_buffer_size, fileData.pointer);
ASSERT_EQ(0, ::memcmp(buffer.getData(), fileData.writeResult, exp_buffer_size));
// Check data checksum is valid for the container buffer
Utils::HashBuffer storedHash;
Utils::HashBuffer computedHash;
ASSERT_EQ(Fw::Success::SUCCESS, container.checkDataHash(storedHash, computedHash));
// Update m_NumBytesWritten
this->abstractState.m_NumBytesWritten.value += exp_buffer_size;
// Update m_NumSuccessfulWrites
this->abstractState.m_NumSuccessfulWrites.value++;

this->abstractState.clearDataSize();
this->abstractState.m_procShrinkDataSizeOpt.clear();
}

bool TestState ::precondition__BufferSendIn__InvalidBuffer() const {
bool result = true;
return result;
Expand Down Expand Up @@ -444,6 +510,11 @@ void Tester::OK() {
this->testState.printEvents();
}

void Tester::OKProcShrink() {
this->ruleOKProcShrink.apply(this->testState);
this->testState.printEvents();
}

} // namespace BufferSendIn

} // namespace Svc
6 changes: 6 additions & 0 deletions Svc/DpWriter/test/ut/Rules/BufferSendIn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Tester {
//! OK
void OK();

//! OKProcShrink
void OKProcShrink();

//! Invalid buffer
void InvalidBuffer();

Expand Down Expand Up @@ -57,6 +60,9 @@ class Tester {
//! Rule BufferSendIn::OK
Rules::BufferSendIn::OK ruleOK;

//! Rule BufferSendIn::OKProcShrink
Rules::BufferSendIn::OKProcShrink ruleOKProcShrink;

//! Rule BufferSendIn::InvalidBuffer
Rules::BufferSendIn::InvalidBuffer ruleInvalidBuffer;

Expand Down
1 change: 1 addition & 0 deletions Svc/DpWriter/test/ut/Rules/Rules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ RULES_DEF_RULE(BufferSendIn, InvalidBuffer)
RULES_DEF_RULE(BufferSendIn, InvalidHeader)
RULES_DEF_RULE(BufferSendIn, InvalidHeaderHash)
RULES_DEF_RULE(BufferSendIn, OK)
RULES_DEF_RULE(BufferSendIn, OKProcShrink)
RULES_DEF_RULE(CLEAR_EVENT_THROTTLE, OK)
RULES_DEF_RULE(FileOpenStatus, Error)
RULES_DEF_RULE(FileOpenStatus, OK)
Expand Down
2 changes: 2 additions & 0 deletions Svc/DpWriter/test/ut/Scenarios/Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Rules::BufferSendIn::InvalidBuffer bufferSendInInvalidBuffer;
Rules::BufferSendIn::InvalidHeader bufferSendInInvalidHeader;
Rules::BufferSendIn::InvalidHeaderHash bufferSendInInvalidHeaderHash;
Rules::BufferSendIn::OK bufferSendInOK;
Rules::BufferSendIn::OKProcShrink bufferSendInOKProcShrink;
Rules::CLEAR_EVENT_THROTTLE::OK clearEventThrottleOK;
Rules::FileOpenStatus::Error fileOpenStatusError;
Rules::FileOpenStatus::OK fileOpenStatusOK;
Expand All @@ -52,6 +53,7 @@ void Tester ::run(U32 maxNumSteps) {
&bufferSendInInvalidHeader,
&bufferSendInInvalidHeaderHash,
&bufferSendInOK,
&bufferSendInOKProcShrink,
&clearEventThrottleOK,
&fileOpenStatusError,
&fileOpenStatusOK,
Expand Down
1 change: 1 addition & 0 deletions Svc/DpWriter/test/ut/TestState/TestState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TestState : public DpWriterTester {
TEST_STATE_DEF_RULE(BufferSendIn, InvalidHeader)
TEST_STATE_DEF_RULE(BufferSendIn, InvalidHeaderHash)
TEST_STATE_DEF_RULE(BufferSendIn, OK)
TEST_STATE_DEF_RULE(BufferSendIn, OKProcShrink)
TEST_STATE_DEF_RULE(CLEAR_EVENT_THROTTLE, OK)
TEST_STATE_DEF_RULE(FileOpenStatus, Error)
TEST_STATE_DEF_RULE(FileOpenStatus, OK)
Expand Down
Loading