mirror of
https://github.com/nasa/fprime.git
synced 2025-12-15 14:05:24 -06:00
* Deprecating Fw::Buffer::getSerializeRepr in favour of Fw::Buffer::getSerializer and Fw::Buffer::getDeserializer (#2714) * Addressing PR comments. * Add workflow for running fpp-to-json on Ref (#3430) * Add workflow for running fpp-to-json on Ref * Update working dirs * Add FPP v3.0.0a4 * fpp v3.0.0a5 * Use setup action * Rename workflow for better display --------- Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com> * Return cmd repsonse and UT check (#3438) Co-authored-by: Zimri Leisher <zimri.leisher@fireflyspace.com> * Update Ref to use FPP telemetry packets (#3440) * Revise Ref app Convert Ref packets to FPP * Remove header include for XML packets * Remove trailing spaces * Delete RefPackets.xml * Update Ref packets * Update fpp version * Update fpp version --------- Co-authored-by: M Starch <LeStarch@googlemail.com> * Refactored type organization (#3422) * Refactored type organization * Creating better configuration/types header hierarchy * Replace FpConfig type aliases with FPP generated aliases * Add the aliases to the FPP model * Config + Type Aliases builds * Renamed Fw/Types.h,hpp to Fw/FPrimeBasicTypes.h,hpp * Updating to FPP-a7 * Adding newline * sp * Fixing minor nit from review * Spurious ; --------- Co-authored-by: Andrei Tumbar <andrei.tumbar@jpl.nasa.gov> * Deprecating Fw::Buffer::getSerializeRepr in favour of Fw::Buffer::getSerializer and Fw::Buffer::getDeserializer (#2714) * Incorporating PR suggested fixes * Adding the setting of m_serLoc and m_deserLoc to the copy constructor. Moving those members from private to protected. * Adding m_serLoc and m_deserLoc copying to = operator function. Fixing FPP tests to explicitly move deserialize location to offset. * File typo (#3464) * typo. SeekType does not have a CURRENT value but it does have a RELATIVE value * applied formatter * Incorporating PR comments * Incorporating PR comments --------- Co-authored-by: Justine West <35715959+jwest115@users.noreply.github.com> Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com> Co-authored-by: Zimri Leisher <zimri.leisher@gmail.com> Co-authored-by: Zimri Leisher <zimri.leisher@fireflyspace.com> Co-authored-by: Rob Bocchino <bocchino@jpl.nasa.gov> Co-authored-by: M Starch <LeStarch@googlemail.com> Co-authored-by: Andrei Tumbar <andrei.tumbar@jpl.nasa.gov> Co-authored-by: kevin-f-ortega <kevin.f.ortega@gmail.com>
131 lines
5.9 KiB
C++
131 lines
5.9 KiB
C++
// ======================================================================
|
||
// \title FprimeDeframerTester.cpp
|
||
// \author thomas-bc
|
||
// \brief cpp file for FprimeDeframer component test harness implementation class
|
||
// ======================================================================
|
||
|
||
#include "FprimeDeframerTester.hpp"
|
||
#include "STest/Random/Random.hpp"
|
||
|
||
namespace Svc {
|
||
|
||
// ----------------------------------------------------------------------
|
||
// Construction and destruction
|
||
// ----------------------------------------------------------------------
|
||
|
||
FprimeDeframerTester ::FprimeDeframerTester()
|
||
: FprimeDeframerGTestBase("FprimeDeframerTester", FprimeDeframerTester::MAX_HISTORY_SIZE), component("FprimeDeframer") {
|
||
this->initComponents();
|
||
this->connectPorts();
|
||
}
|
||
|
||
FprimeDeframerTester ::~FprimeDeframerTester() {}
|
||
|
||
// ----------------------------------------------------------------------
|
||
// Tests
|
||
// ----------------------------------------------------------------------
|
||
|
||
void FprimeDeframerTester ::testNominalFrame() {
|
||
// Get random byte of data
|
||
U8 randomByte = static_cast<U8>(STest::Random::lowerUpper(0, 255));
|
||
// | F´ start word | Length (= 1) | Data | Checksum (4 bytes) |
|
||
U8 data[13] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x00, 0x00, 0x01, randomByte, 0x00, 0x00, 0x00, 0x00};
|
||
// Inject the checksum into the data and send it to the component under test
|
||
this->injectChecksum(data, sizeof(data));
|
||
this->mockReceiveData(data, sizeof(data));
|
||
|
||
ASSERT_from_deframedOut_SIZE(1); // something emitted on deframedOut
|
||
ASSERT_from_bufferDeallocate_SIZE(0); // nothing emitted on bufferDeallocate
|
||
// Assert that the data that was emitted on deframedOut is equal to Data field above (randomByte)
|
||
ASSERT_EQ(this->fromPortHistory_deframedOut->at(0).data.getData()[0], randomByte);
|
||
ASSERT_EVENTS_SIZE(0); // no events emitted
|
||
}
|
||
|
||
void FprimeDeframerTester ::testIncorrectLengthToken() {
|
||
// Frame: | F´ start word | INCORRECT Length=5 | Data | Checksum (4 bytes) |
|
||
U8 data[13] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||
// Inject the checksum into the data and send it to the component under test
|
||
this->injectChecksum(data, sizeof(data));
|
||
this->mockReceiveData(data, sizeof(data));
|
||
|
||
ASSERT_from_deframedOut_SIZE(0); // nothing emitted on deframedOut
|
||
ASSERT_from_bufferDeallocate_SIZE(1); // invalid buffer was deallocated
|
||
// Check which event was emitted
|
||
ASSERT_EVENTS_SIZE(1); // exactly 1 event emitted
|
||
ASSERT_EVENTS_InvalidLengthReceived_SIZE(1); // event was emitted for invalid length
|
||
}
|
||
|
||
void FprimeDeframerTester ::testIncorrectStartWord() {
|
||
// Frame: | INCORRECT start word | Length = 1 | Data | Checksum (4 bytes) |
|
||
U8 data[13] = {0x00, 0x11, 0x22, 0x33, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||
// Inject the checksum into the data and send it to the component under test
|
||
this->injectChecksum(data, sizeof(data));
|
||
this->mockReceiveData(data, sizeof(data));
|
||
|
||
ASSERT_from_deframedOut_SIZE(0); // nothing emitted on deframedOut
|
||
ASSERT_from_bufferDeallocate_SIZE(1); // invalid buffer was deallocated
|
||
// Check which event was emitted
|
||
ASSERT_EVENTS_SIZE(1); // exactly 1 event emitted
|
||
ASSERT_EVENTS_InvalidStartWord_SIZE(1); // event was emitted for invalid start word
|
||
}
|
||
|
||
void FprimeDeframerTester ::testIncorrectCrc() {
|
||
// Frame: | F´ start word | Length = 1 | Data | INCORRECT Checksum |
|
||
U8 data[13] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||
this->mockReceiveData(data, sizeof(data));
|
||
ASSERT_from_deframedOut_SIZE(0); // nothing emitted on deframedOut
|
||
ASSERT_from_bufferDeallocate_SIZE(1); // invalid buffer was deallocated
|
||
// Check which event was emitted
|
||
ASSERT_EVENTS_SIZE(1); // exactly 1 event emitted
|
||
ASSERT_EVENTS_InvalidChecksum_SIZE(1); // event was emitted for invalid checksum
|
||
}
|
||
|
||
void FprimeDeframerTester::testTruncatedFrame() {
|
||
// Send a truncated frame, too short to be valid
|
||
U8 data[11] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||
this->mockReceiveData(data, sizeof(data));
|
||
ASSERT_from_deframedOut_SIZE(0); // nothing emitted on deframedOut
|
||
ASSERT_from_bufferDeallocate_SIZE(1); // invalid buffer was deallocated
|
||
// Check which event was emitted
|
||
ASSERT_EVENTS_SIZE(1); // exactly 1 event emitted
|
||
ASSERT_EVENTS_InvalidBufferReceived_SIZE(1); // event was emitted for invalid buffer
|
||
}
|
||
|
||
void FprimeDeframerTester::testZeroSizeFrame() {
|
||
// Send an empty frame, too short to be valid
|
||
this->mockReceiveData(nullptr, 0);
|
||
ASSERT_from_deframedOut_SIZE(0); // nothing emitted on deframedOut
|
||
ASSERT_from_bufferDeallocate_SIZE(1); // invalid buffer was deallocated
|
||
// Check which event was emitted
|
||
ASSERT_EVENTS_SIZE(1); // exactly 1 event emitted
|
||
ASSERT_EVENTS_InvalidBufferReceived_SIZE(1); // event was emitted for invalid buffer
|
||
}
|
||
|
||
// ----------------------------------------------------------------------
|
||
// Test Helpers
|
||
// ----------------------------------------------------------------------
|
||
|
||
void FprimeDeframerTester::injectChecksum(U8* data, FwSizeType size) {
|
||
// Needs 4 bytes for the checksum field and at least 1 byte of data to checksum
|
||
if (size < 5) {
|
||
return;
|
||
}
|
||
// Compute the checksum
|
||
Utils::Hash crc_calculator;
|
||
Utils::HashBuffer crc_result;
|
||
crc_calculator.update(data, size - 4);
|
||
crc_calculator.final(crc_result);
|
||
// Inject the checksum into the data
|
||
for (FwSizeType i = 0; i < 4; i++) {
|
||
data[size - 4 + i] = static_cast<U8>(crc_result.asBigEndianU32() >> (8 * (3 - i)) & 0xFF);
|
||
}
|
||
}
|
||
|
||
void FprimeDeframerTester::mockReceiveData(U8* data, FwSizeType size) {
|
||
Fw::Buffer nullContext;
|
||
Fw::Buffer buffer(data, static_cast<Fw::Buffer::SizeType>(size));
|
||
this->invoke_to_framedIn(0, buffer, nullContext);
|
||
}
|
||
|
||
} // namespace Svc
|