Skip to content

Commit

Permalink
feat: implemented ut for NoRecords Event
Browse files Browse the repository at this point in the history
  • Loading branch information
jsilveira1409 committed Nov 17, 2024
1 parent 8a2bca2 commit 8535003
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 1 deletion.
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
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

Check failure on line 3 in Svc/CmdSequencer/test/ut/NoRecords.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`Joaquim` is not a recognized word. (unrecognized-spelling)

Check failure on line 3 in Svc/CmdSequencer/test/ut/NoRecords.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`Silveira` is not a recognized word. (unrecognized-spelling)
// \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

Check failure on line 3 in Svc/CmdSequencer/test/ut/NoRecords.hpp

View workflow job for this annotation

GitHub Actions / Spell checking

`Joaquim` is not a recognized word. (unrecognized-spelling)

Check failure on line 3 in Svc/CmdSequencer/test/ut/NoRecords.hpp

View workflow job for this annotation

GitHub Actions / Spell checking

`Silveira` is not a recognized word. (unrecognized-spelling)
// \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)

Check failure on line 23 in Svc/CmdSequencer/test/ut/SequenceFiles/NoRecordsFile.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`norecords` is not a recognized word. (unrecognized-spelling)
{
}

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());
}

}

}
47 changes: 47 additions & 0 deletions Svc/CmdSequencer/test/ut/SequenceFiles/NoRecordsFile.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ======================================================================
// \title NoRecordsFile.hpp
// \author Joaquim Silveira

Check failure on line 3 in Svc/CmdSequencer/test/ut/SequenceFiles/NoRecordsFile.hpp

View workflow job for this annotation

GitHub Actions / Spell checking

`Joaquim` is not a recognized word. (unrecognized-spelling)

Check failure on line 3 in Svc/CmdSequencer/test/ut/SequenceFiles/NoRecordsFile.hpp

View workflow job for this annotation

GitHub Actions / Spell checking

`Silveira` is not a recognized word. (unrecognized-spelling)
// \brief NoRecords interface


#ifndef Svc_SequenceFiles_NoRecordsFile_HPP
#define Svc_SequenceFiles_NoRecordsFile_HPP

#include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp"
#include "Svc/CmdSequencer/CmdSequencerImpl.hpp"

namespace Svc {

namespace SequenceFiles {

//! A file containing no records
class NoRecordsFile :
public File
{

public:

//! Construct a NoRecordsFile
NoRecordsFile(
const Format::t format //!< The file format
);

public:

//! Serialize the file in F Prime format
void serializeFPrime(
Fw::SerializeBufferBase& buffer //!< The buffer
);

//! Serialize the file in AMPCS format
void serializeAMPCS(
Fw::SerializeBufferBase& buffer //!< The buffer
);

};

}

}

#endif

0 comments on commit 8535003

Please sign in to comment.