Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
Fw/Buffer
Fw/Cmd
Fw/Com
Svc/Ccsds
run: |
fprime-util format --check --dirs $CHECKED_DIRS
shell: bash
2 changes: 1 addition & 1 deletion Svc/Ccsds/ApidManager/ApidManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#ifndef Svc_Ccsds_ApidManager_HPP
#define Svc_Ccsds_ApidManager_HPP

#include "Svc/Ccsds/ApidManager/ApidManagerComponentAc.hpp"
#include "Fw/Com/ComPacket.hpp"
#include "Svc/Ccsds/ApidManager/ApidManagerComponentAc.hpp"

namespace Svc {

Expand Down
25 changes: 6 additions & 19 deletions Svc/Ccsds/ApidManager/test/ut/ApidManagerTestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,24 @@ TEST(ApidManager, ValidateSequenceCounts) {

// Randomized testing
TEST(ApidManager, RandomizedTesting) {

Svc::Ccsds::ApidManagerTester tester;

Svc::Ccsds::ApidManagerTester::GetExistingSeqCount getExistingSeqCountRule;
Svc::Ccsds::ApidManagerTester::GetNewSeqCountOk getNewSeqCountOkRule;
Svc::Ccsds::ApidManagerTester::GetNewSeqCountTableFull getNewSeqCountTableFullRule;
Svc::Ccsds::ApidManagerTester::ValidateSeqCountOk validateSeqCountOkRule;
Svc::Ccsds::ApidManagerTester::ValidateSeqCountFailure validateSeqCountFailureRule;

// Place these rules into a list of rules
STest::Rule<Svc::Ccsds::ApidManagerTester>* rules[] = {
&getExistingSeqCountRule,
&getNewSeqCountOkRule,
&getNewSeqCountTableFullRule,
&validateSeqCountOkRule,
&validateSeqCountFailureRule
};
STest::Rule<Svc::Ccsds::ApidManagerTester>* rules[] = {&getExistingSeqCountRule, &getNewSeqCountOkRule,
&getNewSeqCountTableFullRule, &validateSeqCountOkRule,
&validateSeqCountFailureRule};

// Take the rules and place them into a random scenario
STest::RandomScenario<Svc::Ccsds::ApidManagerTester> random(
"Random Rules",
rules,
FW_NUM_ARRAY_ELEMENTS(rules)
);
STest::RandomScenario<Svc::Ccsds::ApidManagerTester> random("Random Rules", rules, FW_NUM_ARRAY_ELEMENTS(rules));

// Create a bounded scenario wrapping the random scenario
STest::BoundedScenario<Svc::Ccsds::ApidManagerTester> bounded(
"Bounded Random Rules Scenario",
random,
1000
);
STest::BoundedScenario<Svc::Ccsds::ApidManagerTester> bounded("Bounded Random Rules Scenario", random, 1000);
// Run!
const U32 numSteps = bounded.run(tester);
printf("Ran %u steps.\n", numSteps);
Expand Down
47 changes: 22 additions & 25 deletions Svc/Ccsds/ApidManager/test/ut/ApidManagerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ namespace Svc {

namespace Ccsds {

static constexpr ComCfg::APID::T TEST_REGISTERED_APIDS[] = {
ComCfg::APID::FW_PACKET_COMMAND,
ComCfg::APID::FW_PACKET_TELEM,
ComCfg::APID::FW_PACKET_LOG,
ComCfg::APID::FW_PACKET_FILE
};
static constexpr ComCfg::APID::T TEST_REGISTERED_APIDS[] = {ComCfg::APID::FW_PACKET_COMMAND,
ComCfg::APID::FW_PACKET_TELEM, ComCfg::APID::FW_PACKET_LOG,
ComCfg::APID::FW_PACKET_FILE};

// ----------------------------------------------------------------------
// Construction and destruction
// ----------------------------------------------------------------------
Expand All @@ -30,7 +28,6 @@ ApidManagerTester ::ApidManagerTester()
for (FwIndexType i = 0; i < static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(TEST_REGISTERED_APIDS)); i++) {
this->component.m_apidSequences[i].apid = TEST_REGISTERED_APIDS[i];
this->shadow_seqCounts[TEST_REGISTERED_APIDS[i]] = 0; // Initialize shadow sequence counts to 0

}
}

Expand All @@ -41,20 +38,19 @@ ApidManagerTester ::~ApidManagerTester() {}
// ----------------------------------------------------------------------

bool ApidManagerTester::GetExistingSeqCount::precondition(const ApidManagerTester& testerState) {
return true; // Can always get existing sequence count
return true; // Can always get existing sequence count
}

void ApidManagerTester::GetExistingSeqCount::action(ApidManagerTester& testerState) {
testerState.clearHistory();
ComCfg::APID::T apid = testerState.shadow_getRandomTrackedApid();
U16 seqCount = testerState.invoke_to_getApidSeqCountIn(0, apid, 0);
U16 shadowSeqCount = testerState.shadow_getAndIncrementSeqCount(apid);
ASSERT_EQ(seqCount, shadowSeqCount)
<< "Sequence count for APID " << static_cast<U16>(apid) << " does not match shadow value."
<< " Shadow: " << shadowSeqCount << ", Actual: " << seqCount;
ASSERT_EQ(seqCount, shadowSeqCount) << "Sequence count for APID " << static_cast<U16>(apid)
<< " does not match shadow value."
<< " Shadow: " << shadowSeqCount << ", Actual: " << seqCount;
}


bool ApidManagerTester::GetNewSeqCountOk::precondition(const ApidManagerTester& testerState) {
return testerState.shadow_isTableFull == false;
}
Expand All @@ -66,15 +62,15 @@ void ApidManagerTester::GetNewSeqCountOk::action(ApidManagerTester& testerState)
bool isTableFull = !(testerState.shadow_seqCounts.size() < maxTrackedApidsVal);
if (isTableFull) {
testerState.shadow_isTableFull = true;
return; // Cannot get new sequence count if table is full - skip action
return; // Cannot get new sequence count if table is full - skip action
}

ComCfg::APID::T apid = testerState.shadow_getRandomUntrackedApid();
U16 seqCount = testerState.invoke_to_getApidSeqCountIn(0, apid, 0);
U16 shadowSeqCount = testerState.shadow_getAndIncrementSeqCount(apid);
ASSERT_EQ(seqCount, shadowSeqCount)
<< "Sequence count for APID " << static_cast<U16>(apid) << " does not match shadow value."
<< " Shadow: " << shadowSeqCount << ", Actual: " << seqCount;
ASSERT_EQ(seqCount, shadowSeqCount) << "Sequence count for APID " << static_cast<U16>(apid)
<< " does not match shadow value."
<< " Shadow: " << shadowSeqCount << ", Actual: " << seqCount;
}

bool ApidManagerTester::GetNewSeqCountTableFull::precondition(const ApidManagerTester& testerState) {
Expand All @@ -88,8 +84,7 @@ void ApidManagerTester::GetNewSeqCountTableFull::action(ApidManagerTester& teste
// Use local constexpr to potentially avoid ODR-use of ApidManager::SEQUENCE_COUNT_ERROR
constexpr U16 sequenceCountErrorVal = ApidManager::SEQUENCE_COUNT_ERROR;
ASSERT_EQ(seqCount, sequenceCountErrorVal)
<< "Expected SEQUENCE_COUNT_ERROR for untracked APID " << static_cast<U16>(apid)
<< ", but got " << seqCount;
<< "Expected SEQUENCE_COUNT_ERROR for untracked APID " << static_cast<U16>(apid) << ", but got " << seqCount;
testerState.assertEvents_ApidTableFull_size(__FILE__, __LINE__, 1);
testerState.assertEvents_ApidTableFull(__FILE__, __LINE__, 0, static_cast<U16>(apid));
}
Expand All @@ -103,7 +98,7 @@ void ApidManagerTester::ValidateSeqCountOk::action(ApidManagerTester& testerStat
ComCfg::APID::T apid = testerState.shadow_getRandomTrackedApid();
U16 shadow_expectedSeqCount = testerState.shadow_seqCounts[apid];
testerState.invoke_to_validateApidSeqCountIn(0, apid, shadow_expectedSeqCount);
testerState.shadow_validateApidSeqCount(apid, shadow_expectedSeqCount); // keep shadow state in sync
testerState.shadow_validateApidSeqCount(apid, shadow_expectedSeqCount); // keep shadow state in sync

testerState.assertEvents_UnexpectedSequenceCount_size(__FILE__, __LINE__, 0);
}
Expand All @@ -116,16 +111,17 @@ void ApidManagerTester::ValidateSeqCountFailure::action(ApidManagerTester& teste
testerState.clearHistory();
ComCfg::APID::T apid = testerState.shadow_getRandomTrackedApid();
U16 shadow_expectedSeqCount = testerState.shadow_seqCounts.at(apid);
U16 invalidSeqCount = static_cast<U16>((shadow_expectedSeqCount + 1) % (1 << SpacePacketSubfields::SeqCountWidth)); // Or any other value that's different, ensure wrap around
U16 invalidSeqCount = static_cast<U16>(
(shadow_expectedSeqCount + 1) %
(1 << SpacePacketSubfields::SeqCountWidth)); // Or any other value that's different, ensure wrap around

// Invoke the port with the deliberately incorrect sequence count
testerState.invoke_to_validateApidSeqCountIn(0, apid, invalidSeqCount);
testerState.shadow_validateApidSeqCount(apid, invalidSeqCount); // keep shadow state in sync
testerState.shadow_validateApidSeqCount(apid, invalidSeqCount); // keep shadow state in sync

// Now, the event should be logged
testerState.assertEvents_UnexpectedSequenceCount_size(__FILE__, __LINE__, 1);
testerState.assertEvents_UnexpectedSequenceCount(__FILE__, __LINE__, 0, invalidSeqCount, shadow_expectedSeqCount);

}

// ----------------------------------------------------------------------
Expand All @@ -138,14 +134,15 @@ U16 ApidManagerTester::shadow_getAndIncrementSeqCount(ComCfg::APID::T apid) {
auto found = this->shadow_seqCounts.find(apid);
if (found != this->shadow_seqCounts.end()) {
U16 seqCount = found->second;
found->second = static_cast<U16>((seqCount + 1) % (1 << SpacePacketSubfields::SeqCountWidth)); // Increment for next call
return seqCount; // Return the current sequence count
found->second =
static_cast<U16>((seqCount + 1) % (1 << SpacePacketSubfields::SeqCountWidth)); // Increment for next call
return seqCount; // Return the current sequence count
}
// If APID not found, initialize a new entry
if (this->shadow_seqCounts.size() < this->component.MAX_TRACKED_APIDS) {
U16 seqCount = 0;
this->shadow_seqCounts[apid] = static_cast<U16>(seqCount + 1); // increment for next call
return seqCount; // Return the initialized sequence count
return seqCount; // Return the initialized sequence count
}
return this->component.SEQUENCE_COUNT_ERROR; // Return error if APID not found
}
Expand Down
2 changes: 1 addition & 1 deletion Svc/Ccsds/SpacePacketDeframer/SpacePacketDeframer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void SpacePacketDeframer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data,

// Set data buffer to be of the encapsulated data: HEADER (6 bytes) | PACKET DATA
data.setData(data.getData() + SpacePacketHeader::SERIALIZED_SIZE);
data.setSize(pkt_length);
data.setSize(pkt_length);

this->dataOut_out(0, data, contextCopy);
}
Expand Down
5 changes: 2 additions & 3 deletions Svc/Ccsds/SpacePacketDeframer/SpacePacketDeframer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace Svc {
namespace Ccsds {

class SpacePacketDeframer final : public SpacePacketDeframerComponentBase {
friend class SpacePacketDeframerTester;
friend class SpacePacketDeframerTester;

public:
public:
// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -46,7 +46,6 @@ class SpacePacketDeframer final : public SpacePacketDeframerComponentBase {
void dataReturnIn_handler(FwIndexType portNum, //!< The port number
Fw::Buffer& data,
const ComCfg::FrameContext& context) override;

};

} // namespace Ccsds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ void SpacePacketDeframerTester ::testDataReturnPassthrough() {
void SpacePacketDeframerTester ::testNominalDeframing() {
ComCfg::APID::T apid = static_cast<ComCfg::APID::T>(STest::Random::lowerUpper(0, 0x7FF)); // random 11 bit APID
U16 seqCount = static_cast<U8>(STest::Random::lowerUpper(0, 0x3FFF)); // random 14 bit sequence count
U16 dataLength = static_cast<U8>(STest::Random::lowerUpper(1, MAX_TEST_PACKET_DATA_SIZE)); // bytes of data, random length
U16 dataLength =
static_cast<U8>(STest::Random::lowerUpper(1, MAX_TEST_PACKET_DATA_SIZE)); // bytes of data, random length
U8 data[dataLength];
U16 lengthToken = static_cast<U16>(dataLength - 1); // Length token is length - 1
for (FwIndexType i = 0; i < static_cast<FwIndexType>(dataLength); ++i) {
Expand Down Expand Up @@ -73,8 +74,10 @@ void SpacePacketDeframerTester ::testNominalDeframing() {
void SpacePacketDeframerTester ::testDeframingIncorrectLength() {
ComCfg::APID::T apid = static_cast<ComCfg::APID::T>(STest::Random::lowerUpper(0, 0x7FF)); // random 11 bit APID
U16 seqCount = static_cast<U8>(STest::Random::lowerUpper(0, 0x3FFF)); // random 14 bit sequence count
U16 realDataLength = static_cast<U8>(STest::Random::lowerUpper(1, MAX_TEST_PACKET_DATA_SIZE)); // bytes of data, random length
U16 invalidLengthToken = static_cast<U16>(realDataLength + 1); // Length token is greater than actual data available
U16 realDataLength =
static_cast<U8>(STest::Random::lowerUpper(1, MAX_TEST_PACKET_DATA_SIZE)); // bytes of data, random length
U16 invalidLengthToken =
static_cast<U16>(realDataLength + 1); // Length token is greater than actual data available
U8 data[realDataLength];

Fw::Buffer buffer = this->assemblePacket(apid, seqCount, invalidLengthToken, data, realDataLength);
Expand All @@ -91,25 +94,31 @@ void SpacePacketDeframerTester ::testDeframingIncorrectLength() {
ASSERT_EQ(this->fromPortHistory_dataReturnOut->at(0).context, nullContext); // Data should be the same as input

// Event logging failure
ASSERT_EVENTS_SIZE(1); // No events should be generated in the nominal case
ASSERT_EVENTS_SIZE(1); // No events should be generated in the nominal case
ASSERT_EVENTS_InvalidLength_SIZE(1); // No events should be generated in the nominal case
ASSERT_EVENTS_InvalidLength(0, static_cast<U16>(invalidLengthToken + 1), realDataLength); // Event logs the size in bytes, so add 1 to length token
ASSERT_EVENTS_InvalidLength(0, static_cast<U16>(invalidLengthToken + 1),
realDataLength); // Event logs the size in bytes, so add 1 to length token
}

// ----------------------------------------------------------------------
// Helper functions
// ----------------------------------------------------------------------

Fw::Buffer SpacePacketDeframerTester ::assemblePacket(U16 apid, U16 seqCount, U16 lengthToken, U8* packetData, U16 packetDataLen) {
Fw::Buffer SpacePacketDeframerTester ::assemblePacket(U16 apid,
U16 seqCount,
U16 lengthToken,
U8* packetData,
U16 packetDataLen) {
SpacePacketHeader header;
header.setpacketIdentification(apid);
header.setpacketSequenceControl(seqCount); // Sequence Flags = 0b11 (unsegmented) & unused Seq count
header.setpacketSequenceControl(seqCount); // Sequence Flags = 0b11 (unsegmented) & unused Seq count
header.setpacketDataLength(lengthToken);

Fw::ExternalSerializeBuffer serializer(static_cast<U8*>(this->m_packetBuffer), sizeof(this->m_packetBuffer));
serializer.serialize(header);
serializer.serialize(packetData, packetDataLen, Fw::Serialization::OMIT_LENGTH);
return Fw::Buffer(this->m_packetBuffer, static_cast<Fw::Buffer::SizeType>(packetDataLen + SpacePacketHeader::SERIALIZED_SIZE));
return Fw::Buffer(this->m_packetBuffer,
static_cast<Fw::Buffer::SizeType>(packetDataLen + SpacePacketHeader::SERIALIZED_SIZE));
}

} // namespace Ccsds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#define Svc_Ccsds_SpacePacketDeframerTester_HPP

#include "Svc/Ccsds/SpacePacketDeframer/SpacePacketDeframer.hpp"
#include "Svc/Ccsds/Types/SpacePacketHeaderSerializableAc.hpp"
#include "Svc/Ccsds/SpacePacketDeframer/SpacePacketDeframerGTestBase.hpp"
#include "Svc/Ccsds/Types/SpacePacketHeaderSerializableAc.hpp"

namespace Svc {

Expand Down Expand Up @@ -71,7 +71,7 @@ class SpacePacketDeframerTester final : public SpacePacketDeframerGTestBase {
SpacePacketDeframer component;

//! Test buffer
static const FwSizeType MAX_TEST_PACKET_DATA_SIZE = 200; // this value needs to fit in a U8 for testing
static const FwSizeType MAX_TEST_PACKET_DATA_SIZE = 200; // this value needs to fit in a U8 for testing
U8 m_packetBuffer[SpacePacketHeader::SERIALIZED_SIZE + MAX_TEST_PACKET_DATA_SIZE];
};

Expand Down
Loading
Loading