Skip to content

Commit

Permalink
Bugfix/empty seq (#3025)
Browse files Browse the repository at this point in the history
* feat: implemented empty cmd seq event

* feat: improved empty seq warnings

* feat: implemented ut for NoRecords Event

* sp

---------

Co-authored-by: M Starch <[email protected]>
  • Loading branch information
jsilveira1409 and LeStarch authored Nov 18, 2024
1 parent e2a59b0 commit 442e57a
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ jdperez
jenkins
jenkinsci
jishii
Joaquim
jobrestrictions
joshuaa
jpl
Expand Down Expand Up @@ -594,6 +595,7 @@ nogen
noncomma
NONINFRINGEMENT
noparent
norecords
normalwidths
NOSIZE
NOSPEC
Expand Down Expand Up @@ -842,6 +844,7 @@ showinitializer
sideeffect
sighandler
Signedness
Silveira
sinc
Sinha
sloc
Expand Down
5 changes: 4 additions & 1 deletion Svc/CmdSequencer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ set(SOURCE_FILES
)

register_fprime_module()
### UTs ###

# ## UTs ###
set(UT_SOURCE_FILES
"${FPRIME_FRAMEWORK_PATH}/Svc/CmdSequencer/CmdSequencer.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/AMPCS.cpp"
Expand All @@ -30,12 +31,14 @@ set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Mixed.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/MixedRelativeBase.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/NoFiles.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/NoRecords.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Relative.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SequenceFiles/AMPCS/CRCs.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SequenceFiles/AMPCS/Headers.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SequenceFiles/AMPCS/Records.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SequenceFiles/BadCRCFile.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SequenceFiles/BadDescriptorFile.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SequenceFiles/NoRecordsFile.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SequenceFiles/BadTimeBaseFile.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SequenceFiles/BadTimeContextFile.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/SequenceFiles/Buffers.cpp"
Expand Down
3 changes: 3 additions & 0 deletions Svc/CmdSequencer/CmdSequencerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ namespace Svc {
const FwTimeContextStoreType seqTimeContext //!< The sequence file time context
);

// No Records
void noRecords();

PRIVATE:

//! The enclosing component
Expand Down
11 changes: 11 additions & 0 deletions Svc/CmdSequencer/Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ namespace Svc {
);
component.error();
}

void CmdSequencerComponentImpl::Sequence::Events ::
noRecords()
{
Fw::LogStringArg& logFileName = this->m_sequence.getLogFileName();
CmdSequencerComponentImpl& component = this->m_sequence.m_component;
component.log_WARNING_LO_CS_NoRecords(
logFileName
);
component.error();
}

}

7 changes: 7 additions & 0 deletions Svc/CmdSequencer/Events.fppi
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,10 @@ event CS_JoinWaitingNotComplete() \
severity warning high \
id 24 \
format "Still waiting for sequence file to complete"

event CS_NoRecords(
fileName: string size 60 @< The name of the sequence file
) \
severity warning low \
id 25 \
format "Sequence file {} has no records. Ignoring."
8 changes: 7 additions & 1 deletion Svc/CmdSequencer/FPrimeSequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace Svc {
}

void CmdSequencerComponentImpl::FPrimeSequence ::
nextRecord(Record& record)
nextRecord(Record& record)
{
Fw::SerializeStatus status = this->deserializeRecord(record);
FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
Expand Down Expand Up @@ -423,6 +423,12 @@ namespace Svc {
const U32 numRecords = this->m_header.m_numRecords;
Sequence::Record record;

if (numRecords == 0)
{
this->m_events.noRecords();
return false;
}

// Deserialize all records
for (NATIVE_UINT_TYPE recordNumber = 0; recordNumber < numRecords; recordNumber++) {
Fw::SerializeStatus status = this->deserializeRecord(record);
Expand Down
11 changes: 11 additions & 0 deletions Svc/CmdSequencer/test/ut/CmdSequencerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Svc/CmdSequencer/test/ut/Immediate.hpp"
#include "Svc/CmdSequencer/test/ut/ImmediateEOS.hpp"
#include "Svc/CmdSequencer/test/ut/InvalidFiles.hpp"
#include "Svc/CmdSequencer/test/ut/NoRecords.hpp"
#include "Svc/CmdSequencer/test/ut/NoFiles.hpp"
#include "Svc/CmdSequencer/test/ut/Relative.hpp"
#include "Svc/CmdSequencer/test/ut/SequenceFiles/SequenceFiles.hpp"
Expand Down Expand Up @@ -316,6 +317,7 @@ TEST(InvalidFiles, USecFieldTooShort) {
tester.USecFieldTooShort();
}


TEST(Mixed, AutoByCommand) {
TEST_CASE(103.1.4,"Nominal Timed Relative Commands");
Svc::Mixed::CmdSequencerTester tester;
Expand Down Expand Up @@ -390,6 +392,15 @@ TEST(JoinWait, JoinWaitWithActiveSeq) {
tester.test_join_wait_with_active_seq();
}

TEST(InvalidFiles, RunNoRecords) {
Svc::NoRecords::CmdSequencerTester tester;
tester.RunNoRecords();
}

TEST(InvalidFiles, ValidateNoRecords) {
Svc::NoRecords::CmdSequencerTester tester;
tester.ValidateNoRecords();
}

int main(int argc, char **argv) {
// Create ./bin directory for test files
Expand Down
99 changes: 99 additions & 0 deletions Svc/CmdSequencer/test/ut/NoRecords.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// ======================================================================
// \title NoRecords.hpp
// \author Joaquim Silveira
// \brief Test command sequence with no records
//
// ======================================================================

#include "Svc/CmdSequencer/test/ut/CommandBuffers.hpp"
#include "Svc/CmdSequencer/test/ut/NoRecords.hpp"
#include "Svc/CmdSequencer/test/ut/SequenceFiles/NoRecordsFile.hpp"

namespace Svc {

namespace NoRecords {

// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------

CmdSequencerTester ::
CmdSequencerTester(const SequenceFiles::File::Format::t format) :
Svc::CmdSequencerTester(format)
{

}

// ----------------------------------------------------------------------
// Tests
// ----------------------------------------------------------------------

void CmdSequencerTester ::
Init()
{
// Nothing to do
}

void CmdSequencerTester ::
ValidateNoRecords()
{
SequenceFiles::NoRecordsFile file(this->format);

// Set the time
Fw::Time testTime(TB_WORKSTATION_TIME, 0, 0);
this->setTestTime(testTime);

// Write the file
const char* const fileName = file.getName().toChar();
file.write();

// Validate the file
this->sendCmd_CS_VALIDATE(0, 0, Fw::CmdStringArg(fileName));
this->clearAndDispatch();

// Assert command response
ASSERT_CMD_RESPONSE_SIZE(1);
ASSERT_CMD_RESPONSE(
0,
CmdSequencerComponentBase::OPCODE_CS_VALIDATE,
0,
Fw::CmdResponse::EXECUTION_ERROR
);
// Assert events
ASSERT_EVENTS_SIZE(1);
ASSERT_EVENTS_CS_NoRecords(0, fileName);
}

void CmdSequencerTester ::
RunNoRecords()
{
SequenceFiles::NoRecordsFile file(this->format);

// Set the time
Fw::Time testTime(TB_WORKSTATION_TIME, 0, 0);
this->setTestTime(testTime);

// Write the file
const char* const fileName = file.getName().toChar();
file.write();

// Send run command
this->sendCmd_CS_RUN(0, 0, Fw::CmdStringArg(fileName), Svc::CmdSequencer_BlockState::NO_BLOCK);
this->clearAndDispatch();
// Assert command response
ASSERT_CMD_RESPONSE_SIZE(1);
ASSERT_CMD_RESPONSE(
0,
CmdSequencerComponentBase::OPCODE_CS_RUN,
0,
Fw::CmdResponse::EXECUTION_ERROR
);
// Assert events
ASSERT_EVENTS_SIZE(1);
ASSERT_EVENTS_CS_NoRecords(0, fileName);

}

}

}
54 changes: 54 additions & 0 deletions Svc/CmdSequencer/test/ut/NoRecords.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// ======================================================================
// \title NoRecords.hpp
// \author Joaquim Silveira
// \brief Test command sequence with no records
//
// ======================================================================

#ifndef Svc_NoRecords_HPP
#define Svc_NoRecords_HPP

#include "CmdSequencerTester.hpp"

namespace Svc {

namespace NoRecords {

//! Test sequencer behavior with no input files
class CmdSequencerTester :
public Svc::CmdSequencerTester
{

public:

// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------

//! Construct object CmdSequencerTester
CmdSequencerTester(
const SequenceFiles::File::Format::t format =
SequenceFiles::File::Format::F_PRIME //!< The file format to use
);

public:

// ----------------------------------------------------------------------
// Tests
// ----------------------------------------------------------------------

//! Initialization
void Init();

//! Issue a validate command on an empty sequence
void ValidateNoRecords();

//! Issue a run command on an empty sequence
void RunNoRecords();
};

}

}

#endif
55 changes: 55 additions & 0 deletions Svc/CmdSequencer/test/ut/SequenceFiles/NoRecordsFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// ======================================================================
// \title NoRecordsFile.cpp
// \author Rob Bocchino
// \brief NoRecordsFile implementation
//
// \copyright
// Copyright (C) 2009-2018 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.

#include "Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/AMPCS.hpp"
#include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp"
#include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp"
#include "Svc/CmdSequencer/test/ut/SequenceFiles/NoRecordsFile.hpp"
#include "gtest/gtest.h"

namespace Svc {

namespace SequenceFiles {

NoRecordsFile ::
NoRecordsFile(const Format::t format) :
File("norecords", format)
{
}

void NoRecordsFile::serializeFPrime(Fw::SerializeBufferBase& buffer) {
// Header
const NATIVE_INT_TYPE numRecs = 0;
const U32 recordDataSize = numRecs * FPrime::Records::STANDARD_SIZE;
const U32 dataSize = recordDataSize + FPrime::CRCs::SIZE;
const TimeBase timeBase = TB_WORKSTATION_TIME;
const U32 timeContext = 0;
FPrime::Headers::serialize(dataSize, numRecs, timeBase, timeContext, buffer);

// No Records

// CRC
FPrime::CRCs::serialize(buffer);
}

void NoRecordsFile ::
serializeAMPCS(Fw::SerializeBufferBase& buffer)
{
// Header
AMPCS::Headers::serialize(buffer);
// No Records

// CRC
AMPCS::CRCs::createFile(buffer, this->getName().toChar());
}

}

}
Loading

0 comments on commit 442e57a

Please sign in to comment.