repo_name
stringclasses
10 values
file_path
stringlengths
29
222
content
stringlengths
24
926k
extention
stringclasses
5 values
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/Mixed.hpp
// ====================================================================== // \title Mixed.hpp // \author Canham/Bocchino // \brief Test mixed immediate, relative, and absolute commands // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #ifndef Svc_Mixed_HPP #define Svc_Mixed_HPP #include "Svc/CmdSequencer/test/ut/MixedRelativeBase.hpp" namespace Svc { namespace Mixed { //! Test sequences with mixed absolute and relative commands class CmdSequencerTester : public MixedRelativeBase::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 // ---------------------------------------------------------------------- //! Run an automatic sequence by command void AutoByCommand(); //! Validate a sequence file void Validate(); private: // ---------------------------------------------------------------------- // Private helper methods // ---------------------------------------------------------------------- //! Execute sequence commands for an automatic sequence void executeCommandsAuto( const char *const fileName, //!< The file name const U32 numCommands, //!< The number of commands in the sequence const U32 bound, //!< The number of commands to run const CmdExecMode::t mode //!< The mode ); //! Execute command 1 (immediate) void executeCommand1( const char *const fileName //!< The file name ); //! Execute command 2 (absolute) void executeCommand2( const char *const fileName //!< The file name ); //! Execute command 3 (relative) void executeCommand3( const char *const fileName //!< The file name ); //! Execute command 4 (immediate) void executeCommand4( const char *const fileName //!< The file name ); }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/Interceptors.cpp
// ====================================================================== // \title Interceptors.cpp // \author Canham/Bocchino // \brief Implementation for CmdSequencerTester::Interceptors // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #include "Os/Stub/test/File.hpp" #include "CmdSequencerTester.hpp" #include "gtest/gtest.h" namespace Svc { CmdSequencerTester::Interceptor* CmdSequencerTester::Interceptor::PosixFileInterceptor::s_current_interceptor = nullptr; CmdSequencerTester::Interceptor::Interceptor() : enabled(EnableType::NONE), errorType(ErrorType::NONE), waitCount(0), size(0), fileStatus(Os::File::OP_OK) { CmdSequencerTester::Interceptor::PosixFileInterceptor::s_current_interceptor = this; } void CmdSequencerTester::Interceptor::enable(EnableType::t enableType) { this->enabled = enableType; } void CmdSequencerTester::Interceptor::disable() { this->enabled = EnableType::t::NONE; } Os::FileInterface::Status CmdSequencerTester::Interceptor::PosixFileInterceptor::open(const char *path, Mode mode, OverwriteType overwrite) { if ((s_current_interceptor != nullptr) && (s_current_interceptor ->enabled == EnableType::t::OPEN)) { return s_current_interceptor->fileStatus; } return this->Os::Posix::File::PosixFile::open(path, mode, overwrite); } Os::File::Status CmdSequencerTester::Interceptor::PosixFileInterceptor::read( U8 *buffer, FwSignedSizeType &requestSize, Os::File::WaitType waitType ) { (void) waitType; Os::File::Status status = this->Os::Posix::File::PosixFile::read(buffer, requestSize, waitType); if (s_current_interceptor == nullptr) { return status; } else if ((s_current_interceptor->enabled == EnableType::READ) && (s_current_interceptor->errorType != ErrorType::NONE)) { if (s_current_interceptor->waitCount > 0) { // Not time to inject an error yet: decrement wait count --s_current_interceptor->waitCount; } else { // Time to inject an error: check test scenario switch (s_current_interceptor->errorType) { case ErrorType::READ: status = s_current_interceptor->fileStatus; break; case ErrorType::SIZE: requestSize = s_current_interceptor->size; status = Os::File::OP_OK; break; case ErrorType::DATA: memcpy(buffer, s_current_interceptor->data, s_current_interceptor->size); status = Os::File::OP_OK; break; default: EXPECT_TRUE(false); break; } } } return status; } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/ImmediateBase.cpp
// ====================================================================== // \title ImmediateBase.cpp // \author Canham/Bocchino // \brief Base class for Immediate and ImmediateEOS // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Svc/CmdSequencer/test/ut/CommandBuffers.hpp" #include "Svc/CmdSequencer/test/ut/ImmediateBase.hpp" namespace Svc { namespace ImmediateBase { // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- CmdSequencerTester :: CmdSequencerTester(const SequenceFiles::File::Format::t format) : Svc::CmdSequencerTester(format) { } // ---------------------------------------------------------------------- // Tests parameterized by file type // ---------------------------------------------------------------------- void CmdSequencerTester :: parameterizedAutoByCommand( SequenceFiles::File& file, const U32 numCommands, const U32 bound ) { REQUIREMENT("ISF-CMDS-003"); // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Validate the file this->validateFile(0, fileName); // Assert that timer is clear ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); // Run the sequence this->runSequence(0, fileName); // Execute commands this->executeCommandsAuto( fileName, numCommands, bound, CmdExecMode::NO_NEW_SEQUENCE ); // Assert that timer is clear ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); // Check for command complete on seqDone ASSERT_from_seqDone_SIZE(1); ASSERT_from_seqDone(0, 0U, 0U, Fw::CmdResponse(Fw::CmdResponse::OK)); } void CmdSequencerTester :: parameterizedAutoByPort( SequenceFiles::File& file, const U32 numCommands, const U32 bound ) { // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Validate the file this->validateFile(0, fileName); // Run the sequence by port call this->runSequenceByPortCall(fileName); // Execute commands this->executeCommandsAuto( fileName, numCommands, bound, CmdExecMode::NO_NEW_SEQUENCE ); // Check for command complete on seqDone ASSERT_from_seqDone_SIZE(1); ASSERT_from_seqDone(0, 0U, 0U, Fw::CmdResponse(Fw::CmdResponse::OK)); } void CmdSequencerTester :: parameterizedInvalidManualCommands(SequenceFiles::File& file) { // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Attempt to start manual mode without a sequence - should fail const U32 startCmdSeq = 14; this->sendCmd_CS_START(0, startCmdSeq); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_START, startCmdSeq, Fw::CmdResponse::EXECUTION_ERROR ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_NoSequenceActive_SIZE(1); // Validate the file this->validateFile(0, fileName); // Assert that timer is clear ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); // Run the sequence this->runSequence(0, fileName); // Check command buffers Fw::ComBuffer comBuff; CommandBuffers::create(comBuff, 0, 1); ASSERT_from_comCmdOut_SIZE(1); ASSERT_from_comCmdOut(0, comBuff, 0U); // Assert that timer is set ASSERT_EQ( CmdSequencerComponentImpl::Timer::SET, this->component.m_cmdTimeoutTimer.m_state ); // Attempt to start a manual sequence - should fail this->sendCmd_CS_START(0, startCmdSeq); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_START, startCmdSeq, Fw::CmdResponse::EXECUTION_ERROR ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_InvalidMode_SIZE(1); // Attempt to go to auto mode - should fail const U32 autoCmdSeq = 14; this->sendCmd_CS_AUTO(0, autoCmdSeq); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_AUTO, autoCmdSeq, Fw::CmdResponse::EXECUTION_ERROR ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_InvalidMode_SIZE(1); // Attempt to go to manual mode - should fail const U32 manualCmdSeq = 14; this->sendCmd_CS_MANUAL(0, manualCmdSeq); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_MANUAL, manualCmdSeq, Fw::CmdResponse::EXECUTION_ERROR ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_InvalidMode_SIZE(1); } void CmdSequencerTester :: parameterizedLoadRunRun( SequenceFiles::File& file, const U32 numCommands, const U32 bound ) { // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Load the sequence this->loadSequence(fileName); // Run another sequence this->parameterizedAutoByPort(file, numCommands, bound); // Try to run a loaded sequence Fw::String fArg(""); this->invoke_to_seqRunIn(0, fArg); this->clearAndDispatch(); // Assert seqDone response ASSERT_from_seqDone_SIZE(1); ASSERT_from_seqDone(0U, 0U, 0U, Fw::CmdResponse(Fw::CmdResponse::EXECUTION_ERROR)); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_NoSequenceActive_SIZE(1); // Assert telemetry ASSERT_TLM_SIZE(1); ASSERT_TLM_CS_Errors(0, 1); } void CmdSequencerTester :: parameterizedManual(SequenceFiles::File& file, const U32 numCommands) { // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Validate the file this->validateFile(0, fileName); // Assert that timer is clear ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); // Go to manual mode this->goToManualMode(10); // Run sequence // This should validate and load the sequence, then stop this->runSequence(0, fileName); // Assert no command buffer ASSERT_from_comCmdOut_SIZE(0); // Send start command to load first command this->startSequence(14, fileName); // Execute commands this->executeCommandsManual(fileName, numCommands); // Assert that timer is clear ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); // Check for command complete on seqDone ASSERT_from_seqDone_SIZE(1); ASSERT_from_seqDone(0, 0U, 0U, Fw::CmdResponse(Fw::CmdResponse::OK)); // Send step command. Should return error since no active sequence const U32 stepCmdSeq = 12; this->sendCmd_CS_STEP(0, stepCmdSeq); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_STEP, stepCmdSeq, Fw::CmdResponse::EXECUTION_ERROR ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_InvalidMode_SIZE(1); // Go back to auto mode this->goToAutoMode(stepCmdSeq); } void CmdSequencerTester :: parameterizedNewSequence( SequenceFiles::File& file, const U32 numCommands, const U32 bound ) { // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Validate the file this->validateFile(0, fileName); // Assert that timer is clear ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); // Run the sequence this->runSequence(0, fileName); // Execute commands this->executeCommandsAuto( fileName, numCommands, bound, CmdExecMode::NEW_SEQUENCE ); // Assert that timer is clear ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); // Check for command complete on seqDone ASSERT_from_seqDone_SIZE(1); ASSERT_from_seqDone(0, 0U, 0U, Fw::CmdResponse(Fw::CmdResponse::OK)); } void CmdSequencerTester :: parameterizedLoadOnInit( SequenceFiles::File& file, const U32 numCommands, const U32 bound ) { // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Load the sequence this->loadSequence(fileName); // Run the loaded sequence this->runLoadedSequence(); // Execute commands this->executeCommandsAuto( fileName, numCommands, bound, CmdExecMode::NO_NEW_SEQUENCE ); // Check for command complete on seqDone ASSERT_from_seqDone_SIZE(1); ASSERT_from_seqDone(0, 0U, 0U, Fw::CmdResponse(Fw::CmdResponse::OK)); } // ---------------------------------------------------------------------- // Protected helper methods // ---------------------------------------------------------------------- void CmdSequencerTester :: executeCommandsAuto( const char *const fileName, const U32 numCommands, const U32 bound, const CmdExecMode::t mode ) { for (U32 i = 0; i < bound; ++i) { PRINT("REC %d\n", i); // Check command buffer Fw::ComBuffer comBuff; CommandBuffers::create(comBuff, i, i + 1); ASSERT_from_comCmdOut_SIZE(1); ASSERT_from_comCmdOut(0, comBuff, 0U); // Assert that timer is set ASSERT_EQ( CmdSequencerComponentImpl::Timer::SET, this->component.m_cmdTimeoutTimer.m_state ); // Start a new sequence if necessary if (i == 0 and mode == CmdExecMode::NEW_SEQUENCE) { this->startNewSequence(fileName); } // Send status back this->invoke_to_cmdResponseIn(0, i, 0, Fw::CmdResponse(Fw::CmdResponse::OK)); this->clearAndDispatch(); if (i < numCommands - 1) { // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_CommandComplete(0, fileName, i, i); // Assert telemetry ASSERT_TLM_SIZE(1); ASSERT_TLM_CS_CommandsExecuted(0, i + 1); } else { // Assert events ASSERT_EVENTS_SIZE(2); ASSERT_EVENTS_CS_CommandComplete(0, fileName, i, i); ASSERT_EVENTS_CS_SequenceComplete_SIZE(1); // Assert telemetry ASSERT_TLM_SIZE(2); ASSERT_TLM_CS_CommandsExecuted(0, i + 1); ASSERT_TLM_CS_SequencesCompleted(0, 1); } } } void CmdSequencerTester :: executeCommandsError( const char *const fileName, const U32 numCommands ) { for (U32 i = 0; i < numCommands - 1; ++i) { // Check command buffer Fw::ComBuffer comBuff; CommandBuffers::create(comBuff, i, i + 1); ASSERT_from_comCmdOut_SIZE(1); ASSERT_from_comCmdOut(0, comBuff, 0U); if (i == 0) { // Send good status back this->invoke_to_cmdResponseIn(0, i, 0, Fw::CmdResponse(Fw::CmdResponse::OK)); this->clearAndDispatch(); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_CommandComplete(0, fileName, i, i); // Assert telemetry ASSERT_TLM_SIZE(1); ASSERT_TLM_CS_CommandsExecuted(0, i + 1); } else { // Send failed status back this->invoke_to_cmdResponseIn( 0, i, 0, Fw::CmdResponse(Fw::CmdResponse::EXECUTION_ERROR) ); this->clearAndDispatch(); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_CommandError_SIZE(1); ASSERT_EVENTS_CS_CommandError( 0, fileName, 1, i, Fw::CmdResponse::EXECUTION_ERROR ); // Assert telemetry ASSERT_TLM_SIZE(1); ASSERT_TLM_CS_Errors_SIZE(1); ASSERT_TLM_CS_Errors(0, 1); // Check for command complete on seqDone ASSERT_from_seqDone_SIZE(1); ASSERT_from_seqDone(0, 0U, 0U, Fw::CmdResponse(Fw::CmdResponse::EXECUTION_ERROR)); } } } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/JoinWait.cpp
// ====================================================================== // \title JoinWait.hpp // \author janamian // \brief cpp file for CmdSequencer test harness implementation class // // \copyright // Copyright 2009-2021, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Svc/CmdSequencer/test/ut/JoinWait.hpp" #include "Svc/CmdSequencer/test/ut/Relative.hpp" namespace Svc { namespace JoinWait { // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- CmdSequencerTester :: CmdSequencerTester(const SequenceFiles::File::Format::t format) : Svc::CmdSequencerTester(format) { } // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void CmdSequencerTester :: test_join_wait_without_active_seq() { // Send join wait command when there is no active seq this->sendCmd_CS_JOIN_WAIT(0, 0); this->clearAndDispatch(); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_NoSequenceActive_SIZE(1); } void CmdSequencerTester ::test_join_wait_with_active_seq() { const U32 numRecords = 1; SequenceFiles::RelativeFile file(numRecords, 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->validateFile(0, fileName); // Run the sequence this->runSequence(0, fileName); // Assert that timer is set ASSERT_EQ( CmdSequencerComponentImpl::Timer::SET, this->component.m_cmdTimer.m_state ); // Run one cycle to make sure nothing is dispatched yet this->invoke_to_schedIn(0, 0); this->clearAndDispatch(); ASSERT_from_comCmdOut_SIZE(0); ASSERT_EVENTS_SIZE(0); // Assert that timer hasn't expired ASSERT_EQ( CmdSequencerComponentImpl::Timer::SET, this->component.m_cmdTimer.m_state ); // Request join wait this->sendCmd_CS_JOIN_WAIT(0, 0); this->clearAndDispatch(); // Make sure JOIN_WAIT is active ASSERT_EVENTS_CS_NoSequenceActive_SIZE(0); ASSERT_TRUE(this->component.m_join_waiting); // Send status back this->invoke_to_cmdResponseIn(0, 0, 0, Fw::CmdResponse::OK); this->clearAndDispatch(); // Make sure we received completion for both command and join_wait ASSERT_EVENTS_SIZE(2); // Make sure join wait has been cleared ASSERT_FALSE(this->component.m_join_waiting); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/CmdSequencerTester.cpp
// ====================================================================== // \title CmdSequencer.cpp // \author Canham/Bocchino // \brief CmdSequencer test implementation // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "Fw/Com/ComPacket.hpp" #include "Svc/CmdSequencer/test/ut/CommandBuffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp" #include "CmdSequencerTester.hpp" namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- CmdSequencerTester :: CmdSequencerTester(const SequenceFiles::File::Format::t format) : CmdSequencerGTestBase("Tester", MAX_HISTORY_SIZE), component("CmdSequencer"), format(format), sequences(this->component) { this->initComponents(); this->connectPorts(); this->setComponentSequenceFormat(); this->component.allocateBuffer( ALLOCATOR_ID, this->mallocator, BUFFER_SIZE ); this->component.preamble(); this->component.setTimeout(TIMEOUT); this->component.regCommands(); } CmdSequencerTester :: ~CmdSequencerTester() { this->component.deallocateBuffer(this->mallocator); } // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- void CmdSequencerTester :: from_seqDone_handler( const NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdResponse& response ) { this->pushFromPortEntry_seqDone(opCode, cmdSeq, response); } void CmdSequencerTester :: from_comCmdOut_handler( const NATIVE_INT_TYPE portNum, Fw::ComBuffer &data, U32 context ) { this->pushFromPortEntry_comCmdOut(data, context); } void CmdSequencerTester :: from_pingOut_handler( const NATIVE_INT_TYPE portNum, U32 key ) { this->pushFromPortEntry_pingOut(key); } // ---------------------------------------------------------------------- // Virtual function interface // ---------------------------------------------------------------------- void CmdSequencerTester :: executeCommandsAuto( const char *const fileName, const U32 numCommands, const U32 bound, const CmdExecMode::t mode ) { ASSERT_TRUE(false) << "executeCommandsAuto is not implemented\n"; } void CmdSequencerTester :: executeCommandsError( const char *const fileName, const U32 numCommands ) { ASSERT_TRUE(false) << "executeCommandsError is not implemented\n"; } void CmdSequencerTester :: executeCommandsManual( const char *const fileName, const U32 numCommands ) { ASSERT_TRUE(false) << "executeCommandsManual is not implemented\n"; } // ---------------------------------------------------------------------- // Tests parameterized by file type // ---------------------------------------------------------------------- void CmdSequencerTester :: parameterizedAutoByCommand( SequenceFiles::File& file, const U32 numCommands, const U32 bound ) { ASSERT_TRUE(false) << "parameterizedAutoByCommand is not implemented\n"; } void CmdSequencerTester :: parameterizedCancel( SequenceFiles::File& file, const U32 numCommands, const U32 bound ) { REQUIREMENT("ISF-CMDS-005"); // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Validate the file this->validateFile(0, fileName); // Run the sequence this->runSequence(0, fileName); // Execute commands this->executeCommandsAuto( fileName, numCommands, bound, CmdExecMode::NO_NEW_SEQUENCE ); // Cancel sequence this->cancelSequence(100, fileName); } void CmdSequencerTester :: parameterizedFailedCommands( SequenceFiles::File& file, const U32 numCommands ) { REQUIREMENT("ISF-CMDS-004"); // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Validate the file this->validateFile(0, fileName); // Start the sequence this->runSequence(0, fileName); // Execute commands this->executeCommandsError(fileName, numCommands); // Check to see if the component has cleaned up ASSERT_EQ( CmdSequencerComponentImpl::STOPPED, this->component.m_runMode ); ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); } void CmdSequencerTester :: parameterizedFileErrors(SequenceFiles::File& file) { this->parameterizedFileOpenErrors(file); this->parameterizedHeaderReadErrors(file); this->parameterizedDataReadErrors(file); } void CmdSequencerTester :: parameterizedFileOpenErrors(SequenceFiles::File& file) { // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Get error info SequenceFiles::File::ErrorInfo errorInfo; file.getErrorInfo(errorInfo); const char *const errorFileName = errorInfo.open.fileName.toChar(); // Enable open interceptor this->interceptor.enable(Interceptor::EnableType::OPEN); // DOESNT_EXIST { this->interceptor.fileStatus = Os::File::Status::DOESNT_EXIST; // Validate the file this->sendCmd_CS_VALIDATE(0, 0, fileName); this->clearAndDispatch(); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_FileNotFound_SIZE(1); ASSERT_EVENTS_CS_FileNotFound(0, errorFileName); } // NO_PERMISSION { this->interceptor.fileStatus = Os::File::NO_PERMISSION; // Validate the file const U32 validateCmdSeq = 14; this->sendCmd_CS_VALIDATE(0, validateCmdSeq, fileName); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_VALIDATE, validateCmdSeq, Fw::CmdResponse::EXECUTION_ERROR ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_FileReadError_SIZE(1); ASSERT_EVENTS_CS_FileReadError(0, errorFileName); } // Disable open interceptor this->interceptor.disable(); } void CmdSequencerTester :: parameterizedHeaderReadErrors(SequenceFiles::File& file) { // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Get error info SequenceFiles::File::ErrorInfo errorInfo; file.getErrorInfo(errorInfo); const char *const errorFileName = errorInfo.headerRead.fileName.toChar(); // Enable read interceptor this->interceptor.enable(Interceptor::EnableType::READ); // Read error reading header { // Set up fault injection state this->interceptor.waitCount = errorInfo.headerRead.waitCount; this->interceptor.fileStatus = Os::File::NO_SPACE; this->interceptor.errorType = Interceptor::ErrorType::READ; //TODO: fix me Os::setLastError(Os::File::NO_SPACE); // Validate file const U32 validateCmdSeq = 14; this->sendCmd_CS_VALIDATE(0, validateCmdSeq, fileName); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_VALIDATE, validateCmdSeq, Fw::CmdResponse::EXECUTION_ERROR ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_FileInvalid( 0, errorFileName, CmdSequencer_FileReadStage::READ_HEADER, Os::File::NO_SPACE ); } // Disable read interceptor this->interceptor.disable(); } void CmdSequencerTester :: parameterizedDataReadErrors(SequenceFiles::File& file) { // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Get error info SequenceFiles::File::ErrorInfo errorInfo; file.getErrorInfo(errorInfo); const char *const errorFileName = errorInfo.dataRead.fileName.toChar(); // Enable read interceptor this->interceptor.enable(Interceptor::EnableType::READ); // Read error reading data { // Set up fault injection state this->interceptor.waitCount = errorInfo.dataRead.waitCount; this->interceptor.fileStatus = Os::File::NO_SPACE; this->interceptor.errorType = Interceptor::ErrorType::READ; // Validate file const U32 validateCmdSeq = 14; this->sendCmd_CS_VALIDATE(0, validateCmdSeq, fileName); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_VALIDATE, validateCmdSeq, Fw::CmdResponse::EXECUTION_ERROR ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_FileInvalid_SIZE(1); ASSERT_EVENTS_CS_FileInvalid( 0, errorFileName, CmdSequencer_FileReadStage::READ_SEQ_DATA, Os::File::NO_SPACE ); } // Size error reading data { // Set up fault injection state this->interceptor.waitCount = errorInfo.dataRead.waitCount; this->interceptor.fileStatus = Os::File::OP_OK; this->interceptor.errorType = Interceptor::ErrorType::SIZE; this->interceptor.size = 2; // Validate file const U32 validateCmdSeq = 14; this->sendCmd_CS_VALIDATE(0, validateCmdSeq, fileName); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_VALIDATE, validateCmdSeq, Fw::CmdResponse(Fw::CmdResponse::EXECUTION_ERROR) ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_FileInvalid_SIZE(1); ASSERT_EVENTS_CS_FileInvalid( 0, errorFileName, CmdSequencer_FileReadStage::READ_SEQ_DATA_SIZE, 2 ); } // Disable read interceptor this->interceptor.disable(); } void CmdSequencerTester :: parameterizedNeverLoaded() { // Try to run a sequence Fw::String fArg(""); this->invoke_to_seqRunIn(0, fArg); this->clearAndDispatch(); // Assert seqDone response ASSERT_from_seqDone_SIZE(1); ASSERT_from_seqDone(0U, 0U, 0U, Fw::CmdResponse(Fw::CmdResponse(Fw::CmdResponse::EXECUTION_ERROR))); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_NoSequenceActive_SIZE(1); // Assert telemetry ASSERT_TLM_SIZE(1); ASSERT_TLM_CS_Errors(0, 1); } void CmdSequencerTester :: parameterizedSequenceTimeout(SequenceFiles::File& file) { REQUIREMENT("ISF-CMDS-006"); // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Validate the file this->validateFile(0, fileName); // Assert that timer is clear ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); // Run the sequence this->runSequence(0, fileName); // Check command buffers Fw::ComBuffer comBuff; CommandBuffers::create(comBuff, 0, 1); ASSERT_from_comCmdOut_SIZE(1); ASSERT_from_comCmdOut(0, comBuff, 0U); // Assert that timer is set ASSERT_EQ( CmdSequencerComponentImpl::Timer::SET, this->component.m_cmdTimeoutTimer.m_state ); // Set the test time to be after the timeout testTime.set(TB_WORKSTATION_TIME, 2 * TIMEOUT, 1); this->setTestTime(testTime); // Call the schedule port this->invoke_to_schedIn(0, 0); this->clearAndDispatch(); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_SequenceTimeout(0, fileName, 0); // Verify that the sequencer is idle again ASSERT_EQ( CmdSequencerComponentImpl::STOPPED, this->component.m_runMode ); ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimer.m_state ); ASSERT_EQ(0U, this->component.m_executedCount); // Assert command response on seqDone ASSERT_from_seqDone_SIZE(1); ASSERT_from_seqDone(0, 0U, 0U, Fw::CmdResponse(Fw::CmdResponse(Fw::CmdResponse::EXECUTION_ERROR))); } void CmdSequencerTester :: parameterizedUnexpectedCommandResponse( SequenceFiles::File& file, const U32 numCommands, const U32 bound ) { // Run the sequence this->parameterizedAutoByCommand(file, numCommands, bound); // Send unexpected command response this->invoke_to_cmdResponseIn(0, 0x10, 0, Fw::CmdResponse(Fw::CmdResponse::OK)); this->clearAndDispatch(); // Check events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_UnexpectedCompletion_SIZE(1); ASSERT_EVENTS_CS_UnexpectedCompletion(0, 0x10); } void CmdSequencerTester :: parameterizedValidate(SequenceFiles::File& file) { // Set the time Fw::Time testTime(TB_WORKSTATION_TIME, 1, 1); this->setTestTime(testTime); // Write the file const char *const fileName = file.getName().toChar(); file.write(); // Validate the file this->validateFile(0, fileName); } // ---------------------------------------------------------------------- // Instance helper methods // ---------------------------------------------------------------------- void CmdSequencerTester :: connectPorts() { // LogText this->component.set_LogText_OutputPort(0, this->get_from_LogText(0)); // cmdIn this->connect_to_cmdIn(0, this->component.get_cmdIn_InputPort(0)); // cmdRegOut this->component.set_cmdRegOut_OutputPort(0, this->get_from_cmdRegOut(0)); // cmdResponseIn this->connect_to_cmdResponseIn( 0, this->component.get_cmdResponseIn_InputPort(0) ); // cmdResponseOut this->component.set_cmdResponseOut_OutputPort(0, this->get_from_cmdResponseOut(0)); // comCmdOut this->component.set_comCmdOut_OutputPort( 0, this->get_from_comCmdOut(0) ); // logOut this->component.set_logOut_OutputPort(0, this->get_from_logOut(0)); // pingIn this->connect_to_pingIn( 0, this->component.get_pingIn_InputPort(0) ); // pingOut this->component.set_pingOut_OutputPort( 0, this->get_from_pingOut(0) ); // schedIn this->connect_to_schedIn(0, this->component.get_schedIn_InputPort(0)); // seqDone this->component.set_seqDone_OutputPort( 0, this->get_from_seqDone(0) ); // seqRunIn this->connect_to_seqRunIn( 0, this->component.get_seqRunIn_InputPort(0) ); // timeCaller this->component.set_timeCaller_OutputPort(0, this->get_from_timeCaller(0)); // tlmOut this->component.set_tlmOut_OutputPort(0, this->get_from_tlmOut(0)); } #if VERBOSE void CmdSequencerTester :: textLogIn( const FwEventIdType id, //!< The event ID Fw::Time& timeTag, //!< The time const Fw::LogSeverity severity, //!< The severity const Fw::TextLogString& text //!< The event string ) { TextLogEntry e = { id, timeTag, severity, text }; printTextLogHistoryEntry(e, stdout); } #endif void CmdSequencerTester :: initComponents() { this->init(); this->component.init(QUEUE_DEPTH, INSTANCE); } void CmdSequencerTester :: setComponentSequenceFormat() { switch (this->format) { case SequenceFiles::File::Format::F_PRIME: // Use default format break; case SequenceFiles::File::Format::AMPCS: this->component.setSequenceFormat(this->sequences.ampcsSequence); break; default: ASSERT_TRUE(0) << "Invalid sequence format " << format << "\n"; break; } } void CmdSequencerTester :: clearAndDispatch() { this->clearHistory(); ASSERT_EQ( Fw::QueuedComponentBase::MSG_DISPATCH_OK, this->component.doDispatch() ); } void CmdSequencerTester :: validateFile(const U32 cmdSeq, const char* const fileName) { // Validate the file this->sendCmd_CS_VALIDATE(0, cmdSeq, fileName); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_VALIDATE, cmdSeq, Fw::CmdResponse::OK ); // Assert events ASSERT_EVENTS_SIZE(2); ASSERT_EVENTS_CS_SequenceValid(0, fileName); ASSERT_EVENTS_CS_SequenceLoaded(0, fileName); } void CmdSequencerTester :: loadSequence(const char* const fileName) { // Invoke the port Fw::String fArg(fileName); this->clearHistory(); this->component.loadSequence(fileName); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_SequenceLoaded(0, fileName); } void CmdSequencerTester :: runSequence(const U32 cmdSeq, const char* const fileName) { // Send run command this->sendCmd_CS_RUN(0, cmdSeq, fileName,Svc::CmdSequencer_BlockState::NO_BLOCK); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_RUN, cmdSeq, Fw::CmdResponse::OK ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_SequenceLoaded(0, fileName); } void CmdSequencerTester :: runSequenceByPortCall(const char* const fileName) { // Invoke the port Fw::String fArg(fileName); this->invoke_to_seqRunIn(0, fArg); this->clearAndDispatch(); // Assert no command response ASSERT_CMD_RESPONSE_SIZE(0); // Assert events ASSERT_EVENTS_SIZE(2); ASSERT_EVENTS_CS_SequenceLoaded(0, fileName); ASSERT_EVENTS_CS_PortSequenceStarted(0, fileName); } void CmdSequencerTester :: runLoadedSequence() { // Invoke the port Fw::String fArg(""); this->invoke_to_seqRunIn(0, fArg); this->clearAndDispatch(); // Assert no command response ASSERT_CMD_RESPONSE_SIZE(0); // Assert events ASSERT_EVENTS_SIZE(1); const Fw::LogStringArg& fileName = this->component.m_sequence->getLogFileName(); ASSERT_EVENTS_CS_PortSequenceStarted(0, fileName.toChar()); } void CmdSequencerTester :: startNewSequence(const char *const fileName) { // Start the sequence this->sendCmd_CS_RUN(0, 0, 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_SIZE(1); ASSERT_EVENTS_CS_InvalidMode_SIZE(1); // Validate the file this->sendCmd_CS_VALIDATE(0, 0, 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_InvalidMode_SIZE(1); // Invoke sequence port Fw::String fArg(fileName); this->invoke_to_seqRunIn(0, fArg); this->clearAndDispatch(); // Assert response on seqDone ASSERT_from_seqDone_SIZE(1); ASSERT_from_seqDone(0, 0U, 0U, Fw::CmdResponse(Fw::CmdResponse::EXECUTION_ERROR)); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_InvalidMode_SIZE(1); } void CmdSequencerTester :: startSequence(const U32 cmdSeq, const char* const fileName) { // Send start command this->sendCmd_CS_START(0, cmdSeq); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_START, cmdSeq, Fw::CmdResponse::OK ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_CmdStarted(0, fileName); } void CmdSequencerTester :: cancelSequence(const U32 cmdSeq, const char* const fileName) { // Send cancel command this->sendCmd_CS_CANCEL(0, cmdSeq); this->clearAndDispatch(); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_SequenceCanceled(0, fileName); // Verify state ASSERT_EQ( CmdSequencerComponentImpl::STOPPED, this->component.m_runMode ); ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); } void CmdSequencerTester :: goToManualMode(const U32 cmdSeq) { // Send manual command this->sendCmd_CS_MANUAL(0, cmdSeq); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_MANUAL, cmdSeq, Fw::CmdResponse(Fw::CmdResponse::OK) ); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_ModeSwitched( 0, CmdSequencer_SeqMode::STEP ); } void CmdSequencerTester :: goToAutoMode(const U32 cmdSeq) { // Send auto command this->sendCmd_CS_AUTO(0, cmdSeq); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_AUTO, cmdSeq, Fw::CmdResponse(Fw::CmdResponse::OK) ); } void CmdSequencerTester :: stepSequence(const U32 cmdSeq) { // Send step command this->sendCmd_CS_STEP(0, cmdSeq); this->clearAndDispatch(); // Assert command response ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, CmdSequencerComponentBase::OPCODE_CS_STEP, cmdSeq, Fw::CmdResponse(Fw::CmdResponse::OK) ); } } // namespace Svc namespace Os { //! Overrides the default delegate function with this one as it is defined in the local compilation archive //! \param aligned_placement_new_memory: memory to fill //! \param to_copy: possible copy //! \return: new interceptor FileInterface *FileInterface::getDelegate(U8 *aligned_placement_new_memory, const FileInterface* to_copy) { FW_ASSERT(aligned_placement_new_memory != nullptr); const Svc::CmdSequencerTester::Interceptor::PosixFileInterceptor* copy_me = reinterpret_cast<const Svc::CmdSequencerTester::Interceptor::PosixFileInterceptor*>(to_copy); // Placement-new the file handle into the opaque file-handle storage static_assert(sizeof(Svc::CmdSequencerTester::Interceptor::PosixFileInterceptor) <= sizeof Os::File::m_handle_storage, "Handle size not large enough"); static_assert((FW_HANDLE_ALIGNMENT % alignof(Svc::CmdSequencerTester::Interceptor::PosixFileInterceptor)) == 0, "Handle alignment invalid"); Svc::CmdSequencerTester::Interceptor::PosixFileInterceptor *interface = nullptr; if (to_copy == nullptr) { interface = new(aligned_placement_new_memory) Svc::CmdSequencerTester::Interceptor::PosixFileInterceptor; } else { interface = new(aligned_placement_new_memory) Svc::CmdSequencerTester::Interceptor::PosixFileInterceptor(*copy_me); } FW_ASSERT(interface != nullptr); return interface; } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/ImmediateEOS.cpp
// ====================================================================== // \title ImmediateEOS.cpp // \author Canham/Bocchino // \brief Test immediate command sequences with EOS record // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #include "Svc/CmdSequencer/test/ut/CommandBuffers.hpp" #include "Svc/CmdSequencer/test/ut/ImmediateEOS.hpp" namespace Svc { namespace ImmediateEOS { // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- CmdSequencerTester :: CmdSequencerTester(const SequenceFiles::File::Format::t format) : ImmediateBase::CmdSequencerTester(format) { } // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void CmdSequencerTester :: AutoByCommand() { const U32 numRecords = 5; SequenceFiles::ImmediateEOSFile file(numRecords, this->format); const U32 numCommands = numRecords - 1; const U32 bound = numCommands; this->parameterizedAutoByCommand(file, numCommands, bound); } void CmdSequencerTester :: Cancel() { const U32 numRecords = 5; SequenceFiles::ImmediateEOSFile file(numRecords, this->format); const U32 numCommands = numRecords - 1; const U32 bound = numCommands - 1; this->parameterizedCancel(file, numCommands, bound); } void CmdSequencerTester :: FileErrors() { const U32 numRecords = 5; SequenceFiles::ImmediateEOSFile file(numRecords, this->format); this->parameterizedFileErrors(file); } void CmdSequencerTester :: InvalidManualCommands() { const U32 numRecords = 5; SequenceFiles::ImmediateEOSFile file(numRecords, this->format); this->parameterizedInvalidManualCommands(file); } void CmdSequencerTester :: Manual() { const U32 numRecords = 5; const U32 numCommands = numRecords - 1; SequenceFiles::ImmediateEOSFile file(numRecords, this->format); this->parameterizedManual(file, numCommands); } void CmdSequencerTester :: NewSequence() { const U32 numRecords = 5; const U32 numCommands = numRecords - 1; const U32 bound = numCommands; SequenceFiles::ImmediateEOSFile file(numRecords, this->format); this->parameterizedNewSequence(file, numCommands, bound); } void CmdSequencerTester :: AutoByPort() { const U32 numRecords = 5; const U32 numCommands = numRecords - 1; const U32 bound = numCommands; SequenceFiles::ImmediateEOSFile file(numRecords, this->format); this->parameterizedAutoByPort(file, numCommands, bound); } void CmdSequencerTester :: SequenceTimeout() { const U32 numRecords = 5; SequenceFiles::ImmediateEOSFile file(numRecords, this->format); this->parameterizedSequenceTimeout(file); } void CmdSequencerTester :: UnexpectedCommandResponse() { const U32 numRecords = 5; const U32 numCommands = numRecords - 1; const U32 bound = numCommands; SequenceFiles::ImmediateEOSFile file(numRecords, this->format); this->parameterizedUnexpectedCommandResponse(file, numCommands, bound); } void CmdSequencerTester :: Validate() { const U32 numRecords = 5; SequenceFiles::ImmediateEOSFile file(numRecords, this->format); this->parameterizedValidate(file); } // ---------------------------------------------------------------------- // Private helper methods // ---------------------------------------------------------------------- void CmdSequencerTester :: executeCommandsManual( const char *const fileName, const U32 numCommands ) { for (U32 i = 0; i < numCommands; ++i) { PRINT("REC %d\n", i); // Check command buffer Fw::ComBuffer comBuff; CommandBuffers::create(comBuff, i, i + 1); ASSERT_from_comCmdOut_SIZE(1); ASSERT_from_comCmdOut(0, comBuff, 0U); // Assert that timer is clear ASSERT_EQ( CmdSequencerComponentImpl::Timer::CLEAR, this->component.m_cmdTimeoutTimer.m_state ); // Send command response this->invoke_to_cmdResponseIn(0, i, 0, Fw::CmdResponse::OK); this->clearAndDispatch(); // Assert events ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_CommandComplete(0, fileName, i, i); // Assert telemetry ASSERT_TLM_SIZE(1); ASSERT_TLM_CS_CommandsExecuted(0, i + 1); // Step sequence this->stepSequence(12); // Assert events if (i < numCommands - 1) { ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_CmdStepped(0, fileName, i + 1); } else { ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_CS_SequenceComplete_SIZE(1); } } } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/MissingCRCFile.hpp
// ====================================================================== // \title MissingCRCFile.hpp // \author Rob Bocchino // \brief MissingCRCFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_MissingCRCFile_HPP #define Svc_SequenceFiles_MissingCRCFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { class MissingCRCFile : public File { public: //! Construct a MissingCRCFile MissingCRCFile( 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
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/BadTimeContextFile.hpp
// ====================================================================== // \title BadTimeContextFile.hpp // \author Rob Bocchino // \brief BadTimeContextFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_BadTimeContextFile_HPP #define Svc_SequenceFiles_BadTimeContextFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { // A file containing records with bad time bases class BadTimeContextFile : public File { public: //! Construct a BadTimeContextFile BadTimeContextFile( const U32 n, //!< The number of records const Format::t format //!< The file format ); public: //! Serialize the file in F Prime format void serializeFPrime( Fw::SerializeBufferBase& buffer //!< The buffer ); public: //! The number of records const U32 n; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/File.cpp
// ====================================================================== // \title File.cpp // \author Rob Bocchino // \brief File implementation // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #include "Fw/Types/String.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/AMPCS.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "gtest/gtest.h" #define BAD_FILE_FORMAT \ ASSERT_TRUE(0) << "Bad file format " << this->format << "\n" namespace Svc { namespace SequenceFiles { File :: File(const Format::t format) : format(format) { } File :: File (const char* const baseName, const Format::t format) : format(format) { this->setName(baseName); } File :: ~File() { } void File :: setName(const char *const baseName) { this->name = "bin/"; switch (this->format) { case Format::F_PRIME: this->name += "f_prime_"; break; case Format::AMPCS: this->name += "ampcs_"; break; default: BAD_FILE_FORMAT; break; } this->name += baseName; this->name += ".bin"; } const Fw::StringBase& File :: getName() const { return this->name; } void File ::getErrorInfo(ErrorInfo& errorInfo) { switch (this->format) { case Format::F_PRIME: errorInfo.open.fileName = this->name; errorInfo.headerRead.waitCount = 0; errorInfo.headerRead.fileName = this->name; errorInfo.dataRead.waitCount = 1; errorInfo.dataRead.fileName = this->name; break; case Format::AMPCS: errorInfo.open.fileName = this->name; errorInfo.open.fileName += ".CRC32"; errorInfo.headerRead.waitCount = 1; errorInfo.headerRead.fileName = this->name; errorInfo.dataRead.waitCount = 2; errorInfo.dataRead.fileName = this->name; break; default: BAD_FILE_FORMAT; break; } } void File :: write() { Buffers::FileBuffer buffer; switch (this->format) { case Format::F_PRIME: this->serializeFPrime(buffer); break; case Format::AMPCS: this->serializeAMPCS(buffer); break; default: BAD_FILE_FORMAT; break; }; Buffers::write(buffer, this->name.toChar()); } void File :: remove() { Fw::String s("rm -f "); s += this->getName(); int status = system(s.toChar()); ASSERT_EQ(0, status); } void File :: serializeFPrime(Fw::SerializeBufferBase& buffer) { ASSERT_TRUE(0) << "serializeFPrime is not implemented for " << this->name << "\n"; } void File :: serializeAMPCS(Fw::SerializeBufferBase& buffer) { ASSERT_TRUE(0) << "serializeAMPCS is not implemented for " << this->name << "\n"; } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/TooLargeFile.cpp
// ====================================================================== // \title TooLargeFile.cpp // \author Rob Bocchino // \brief TooLargeFile implementation // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #include "Fw/Types/SerialBuffer.hpp" #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/TooLargeFile.hpp" namespace Svc { namespace SequenceFiles { TooLargeFile :: TooLargeFile(const U32 bufferSize, const Format::t format) : File("too_large", format), bufferSize(bufferSize) { } void TooLargeFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const U32 dataSize = this->getDataSize(); const U32 numRecords = 16; const TimeBase timeBase = TB_WORKSTATION_TIME; const U32 timeContext = 0; FPrime::Headers::serialize( dataSize, numRecords, timeBase, timeContext, buffer ); } void TooLargeFile :: serializeAMPCS(Fw::SerializeBufferBase& buffer) { // Header AMPCS::Headers::serialize(buffer); // Data const AMPCSSequence::Record::TimeFlag::t timeFlag = AMPCSSequence::Record::TimeFlag::RELATIVE; const AMPCSSequence::Record::Time::t time = 0; const U32 dataSize = this->getDataSize(); const U32 cmdFieldSize = dataSize - sizeof(AMPCSSequence::Record::TimeFlag::Serial::t) - sizeof(AMPCSSequence::Record::Time::t) - sizeof(AMPCSSequence::Record::CmdLength::t); U8 cmdFieldBuffer[cmdFieldSize]; ::memset(cmdFieldBuffer, 0, cmdFieldSize); Fw::SerialBuffer cmdField(cmdFieldBuffer, sizeof(cmdFieldBuffer)); cmdField.setBuffLen(cmdFieldSize); AMPCS::Records::serialize(timeFlag, time, cmdField, buffer); ASSERT_EQ( sizeof(AMPCSSequence::SequenceHeader::t) + dataSize, buffer.getBuffLength() ); // CRC AMPCS::CRCs::createFile(buffer, this->getName().toChar()); } U32 TooLargeFile :: getDataSize() const { return 2 * this->bufferSize; } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/USecFieldTooShortFile.hpp
// ====================================================================== // \title USecFieldTooShortFile.hpp // \author Rob Bocchino // \brief USecFieldTooShortFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_USecFieldTooShortFile_HPP #define Svc_SequenceFiles_USecFieldTooShortFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A file with a microseconds field that is too short class USecFieldTooShortFile : public File { public: //! Construct a USecFieldTooShortFile USecFieldTooShortFile( const Format::t format //!< The file format ); public: //! Serialize the file in F Prime format void serializeFPrime( Fw::SerializeBufferBase& buffer //!< The buffer ); }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/MissingFile.cpp
// ====================================================================== // \title MissingFile.cpp // \author Rob Bocchino // \brief MissingFile 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/MissingFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { MissingFile :: MissingFile(const Format::t format) : File("missing", format) { } void MissingFile :: serializeAMPCS(Fw::SerializeBufferBase& buffer) { // CRC AMPCS::CRCs::createFile(buffer, this->getName().toChar()); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/SizeFieldTooLargeFile.cpp
// ====================================================================== // \title SizeFieldTooLargeFile.cpp // \author Rob Bocchino // \brief SizeFieldTooLargeFile implementation // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/SizeFieldTooLargeFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { SizeFieldTooLargeFile :: SizeFieldTooLargeFile( const U32 bufferSize, const Format::t format ) : File("size_field_too_large", format), bufferSize(bufferSize) { } void SizeFieldTooLargeFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const U32 recordSize = sizeof(U8) + // Descriptor sizeof(U32) + // Seconds sizeof(U32) + // Microseconds sizeof(U32); // Size const U32 dataSize = recordSize + FPrime::CRCs::SIZE; const U32 numRecs = 1; const TimeBase timeBase = TB_WORKSTATION_TIME; const U32 timeContext = 0; FPrime::Headers::serialize( dataSize, numRecs, timeBase, timeContext, buffer ); // Records { // Descriptor const FPrime::Records::Descriptor descriptor = CmdSequencerComponentImpl::Sequence::Record::RELATIVE; ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U8>(descriptor)) ); // Seconds ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U32>(0)) ); // Microseconds ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U32>(0)) ); // Record size ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U32>(2 * this->bufferSize)) ); } // CRC FPrime::CRCs::serialize(buffer); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/MissingFile.hpp
// ====================================================================== // \title MissingFile.hpp // \author Rob Bocchino // \brief MissingFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_MissingFile_HPP #define Svc_SequenceFiles_MissingFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A missing file class MissingFile : public File { public: //! Construct a MissingFile MissingFile( const Format::t format //!< The file format ); public: //! Serialize the file in AMPCS format void serializeAMPCS( Fw::SerializeBufferBase& buffer //!< The buffer ); }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/SizeFieldTooSmallFile.cpp
// ====================================================================== // \title SizeFieldTooSmallFile.cpp // \author Rob Bocchino // \brief SizeFieldTooSmallFile implementation // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/SizeFieldTooSmallFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { SizeFieldTooSmallFile :: SizeFieldTooSmallFile(const Format::t format) : File("size_field_too_small", format) { } void SizeFieldTooSmallFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const U32 dataSize = FPrime::Records::RECORD_DESCRIPTOR_SIZE + sizeof(U32) + // seconds sizeof(U32) + // subseconds (CRC should land here) sizeof(U16); // short size const U32 numRecs = 1; const TimeBase timeBase = TB_WORKSTATION_TIME; const U32 timeContext = 0; FPrime::Headers::serialize( dataSize, numRecs, timeBase, timeContext, buffer ); // Records const FPrime::Records::Descriptor descriptor = CmdSequencerComponentImpl::Sequence::Record::RELATIVE; ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U8>(descriptor)) ); ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U32>(0)) ); ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U16>(0)) ); // CRC FPrime::CRCs::serialize(buffer); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/BadTimeBaseFile.hpp
// ====================================================================== // \title BadTimeBaseFile.hpp // \author Rob Bocchino // \brief BadTimeBaseFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_BadTimeBaseFile_HPP #define Svc_SequenceFiles_BadTimeBaseFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { // A file containing records with bad time bases class BadTimeBaseFile : public File { public: //! Construct a BadTimeBaseFile BadTimeBaseFile( const U32 n, //!< The number of records const Format::t format //!< The file format ); public: //! Serialize the file in F Prime format void serializeFPrime( Fw::SerializeBufferBase& buffer //!< The buffer ); public: //! The number of records const U32 n; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/MixedFile.hpp
// ====================================================================== // \title MixedFile.hpp // \author Rob Bocchino // \brief MixedFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_MixedFile_HPP #define Svc_SequenceFiles_MixedFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A file containing mixed immediate, relative, and absolute commands: // 1. An absolute command // 2. An immediate command // 3. A relative command // 4. An immediate command class MixedFile : public File { public: //! Construct a MixedFile MixedFile( 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
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/ImmediateEOSFile.cpp
// ====================================================================== // \title ImmediateEOSFile.cpp // \author Rob Bocchino // \brief ImmediateEOSFile implementation // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/ImmediateEOSFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { ImmediateEOSFile :: ImmediateEOSFile(const U32 n, const Format::t format) : File(format), n(n) { Fw::String s; s.format("immediate_%u_eos", n); this->setName(s.toChar()); } void ImmediateEOSFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { ASSERT_GE(this->n, 2U); // Header const U32 recordDataSize = // n - 1 standard records (this->n-1) * FPrime::Records::STANDARD_SIZE + // 1 end-of-sequence record FPrime::Records::EOS_SIZE; const U32 dataSize = recordDataSize + FPrime::CRCs::SIZE; FPrime::Headers::serialize( dataSize, this->n, TB_WORKSTATION_TIME, 0, buffer ); // Standard records Fw::Time t(TB_WORKSTATION_TIME, 0, 0); for (U32 i = 0; i < this->n - 1; i++) { const FwOpcodeType opcode = i; const U32 argument = i + 1; FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::RELATIVE, t, opcode, argument, buffer ); } // EOS record FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::END_OF_SEQUENCE, t, buffer ); // CRC FPrime::CRCs::serialize(buffer); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/ImmediateFile.cpp
// ====================================================================== // \title ImmediateFile.cpp // \author Rob Bocchino // \brief ImmediateFile 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/ImmediateFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { ImmediateFile :: ImmediateFile(const U32 n, const Format::t format) : File(format), n(n) { Fw::String s; s.format("immediate_%u", n); this->setName(s.toChar()); } void ImmediateFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const U32 recordDataSize = this->n * 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, this->n, timeBase, timeContext, buffer ); // Records for (U32 i = 0; i < this->n; i++) { Fw::Time t(TB_WORKSTATION_TIME, 0, 0); const FwOpcodeType opcode = i; const U32 argument = i + 1; FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::RELATIVE, t, opcode, argument, buffer ); } // CRC FPrime::CRCs::serialize(buffer); } void ImmediateFile :: serializeAMPCS(Fw::SerializeBufferBase& buffer) { // Header AMPCS::Headers::serialize(buffer); // Records for (U32 i = 0; i < this->n; ++i) { const AMPCSSequence::Record::Time::t time = 0; const AMPCSSequence::Record::Opcode::t opcode = i; const U32 argument = i + 1; AMPCS::Records::serialize( AMPCSSequence::Record::TimeFlag::RELATIVE, time, opcode, argument, buffer ); } // CRC AMPCS::CRCs::createFile(buffer, this->getName().toChar()); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp
// ====================================================================== // \title File.hpp // \author Rob Bocchino // \brief File interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #ifndef Svc_SequenceFiles_File_HPP #define Svc_SequenceFiles_File_HPP #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A sequence file class File { public: // ---------------------------------------------------------------------- // Types // ---------------------------------------------------------------------- //! Binary file formats struct Format { typedef enum { //! F Prime format F_PRIME, //! AMPCS format AMPCS, } t; }; //! Information for error reporting struct ErrorInfo { //! The type of open errors struct Open { //! The name of the file for error reporting Fw::String fileName; }; //! The type of header read errors struct HeaderRead { //! The wait count U32 waitCount; //! The name of the file for error reporting Fw::String fileName; }; //! The type of data read errors struct DataRead { //! The wait count U32 waitCount; //! The name of the file for error reporting Fw::String fileName; }; //! Open errors Open open; //! Header read errors HeaderRead headerRead; //! Data read errors DataRead dataRead; }; public: // ---------------------------------------------------------------------- // Constructors and destructors // ---------------------------------------------------------------------- //! Construct a File with default initialization File( const Format::t format = Format::F_PRIME //!< The file format ); //! Construct a File with the given base name File( const char* const baseName, //!< The base name const Format::t format = Format::F_PRIME //!< The file format ); //! Destroy a file virtual ~File(); public: // ---------------------------------------------------------------------- // Public instance methods // ---------------------------------------------------------------------- // Set the name from the given base name void setName( const char* const baseName //!< The base name ); //! Write the file to the disk void write(); //! Remove the file from the disk void remove(); //! Get the file name const Fw::StringBase& getName() const; //! Get error info for the file void getErrorInfo( ErrorInfo& errorInfo //!< The error info ); public: // ---------------------------------------------------------------------- // Virtual interface // ---------------------------------------------------------------------- //! Serialize the file in F Prime format virtual void serializeFPrime( Fw::SerializeBufferBase& buffer //!< The buffer ); //! Serialize the file in AMPCS format virtual void serializeAMPCS( Fw::SerializeBufferBase& buffer //!< The buffer ); private: // ---------------------------------------------------------------------- // Private member variables // ---------------------------------------------------------------------- //! The file name Fw::String name; public: // ---------------------------------------------------------------------- // Public member variables // ---------------------------------------------------------------------- //! The file format const Format::t format; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/BadDescriptorFile.cpp
// ====================================================================== // \title BadDescriptorFile.cpp // \author Rob Bocchino // \brief BadDescriptorFile 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/BadDescriptorFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { BadDescriptorFile :: BadDescriptorFile(const U32 n, const Format::t format) : File(format), n(n) { Fw::String baseName; baseName.format("bad_descriptor_%u", n); this->setName(baseName.toChar()); } void BadDescriptorFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const TimeBase timeBase = TB_WORKSTATION_TIME; const U32 timeContext = 0; const U32 recordDataSize = this->n * SequenceFiles::FPrime::Records::STANDARD_SIZE; const U32 dataSize = recordDataSize + FPrime::CRCs::SIZE; FPrime::Headers::serialize( dataSize, this->n, timeBase, timeContext, buffer ); // Records for (U32 record = 0; record < this->n; record++) { Fw::Time t(TB_WORKSTATION_TIME, 0, 0); // Force an invalid record descriptor FPrime::Records::Descriptor descriptor = static_cast<FPrime::Records::Descriptor>(10); FPrime::Records::serialize( descriptor, t, record, record + 1, buffer ); } // CRC FPrime::CRCs::serialize(buffer); } void BadDescriptorFile :: serializeAMPCS(Fw::SerializeBufferBase& buffer) { // Header AMPCS::Headers::serialize(buffer); // Records for (U32 i = 0; i < this->n; ++i) { // Force an invalid time flag const AMPCSSequence::Record::TimeFlag::t timeFlag = static_cast<AMPCSSequence::Record::TimeFlag::t>(10); const AMPCSSequence::Record::Time::t time = 0; const AMPCSSequence::Record::Opcode::t opcode = i; const U32 argument = i + 1; AMPCS::Records::serialize( timeFlag, time, opcode, argument, buffer ); } // CRC AMPCS::CRCs::createFile(buffer, this->getName().toChar()); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/TooLargeFile.hpp
// ====================================================================== // \title TooLargeFile.hpp // \author Rob Bocchino // \brief TooLargeFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #ifndef Svc_SequenceFiles_TooLargeFile_HPP #define Svc_SequenceFiles_TooLargeFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A file that is too large for the sequence buffer class TooLargeFile : public File { public: //! Construct a TooLargeFile TooLargeFile( const U32 bufferSize, //!< The sequence buffer size 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 ); //! Get the data size U32 getDataSize() const; public: //! The sequence buffer size const U32 bufferSize; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/SizeFieldTooLargeFile.hpp
// ====================================================================== // \title SizeFieldTooLargeFile.hpp // \author Rob Bocchino // \brief SizeFieldTooLargeFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_SizeFieldTooLargeFile_HPP #define Svc_SequenceFiles_SizeFieldTooLargeFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A file with a size field that is too large class SizeFieldTooLargeFile : public File { public: //! Construct a SizeFieldTooLargeFile SizeFieldTooLargeFile( const U32 bufferSize, //!< The buffer size const Format::t format //!< The file format ); public: //! Serialize the file in F Prime format void serializeFPrime( Fw::SerializeBufferBase& buffer //!< The buffer ); public: //! The buffer size const U32 bufferSize; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/RelativeFile.cpp
// ====================================================================== // \title RelativeFile.cpp // \author Rob Bocchino // \brief RelativeFile 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/RelativeFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { RelativeFile :: RelativeFile(const U32 n, const Format::t format) : File(format), n(n) { Fw::String s; s.format("relative_%u", n); this->setName(s.toChar()); } void RelativeFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const U32 recordDataSize = this->n * 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, this->n, timeBase, timeContext, buffer ); // Records for (U32 i = 0; i < n; ++i) { const U32 seconds = 2; const U32 microseconds = 0; const FwOpcodeType opcode = i; const U32 argument = i + 1; Fw::Time t(TB_WORKSTATION_TIME, seconds, microseconds); FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::RELATIVE, t, opcode, argument, buffer ); } // CRC FPrime::CRCs::serialize(buffer); } void RelativeFile :: serializeAMPCS(Fw::SerializeBufferBase& buffer) { // Header AMPCS::Headers::serialize(buffer); // Records for (U32 i = 0; i < this->n; ++i) { const AMPCSSequence::Record::Time::t time = 2; const AMPCSSequence::Record::Opcode::t opcode = i; const U32 argument = i + 1; AMPCS::Records::serialize( AMPCSSequence::Record::TimeFlag::RELATIVE, time, opcode, argument, buffer ); } // CRC AMPCS::CRCs::createFile(buffer, this->getName().toChar()); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/BadCRCFile.hpp
// ====================================================================== // \title BadCRCFile.hpp // \author Rob Bocchino // \brief BadCRCFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #ifndef Svc_SequenceFiles_BadCRCFile_HPP #define Svc_SequenceFiles_BadCRCFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A file with a bad CRC class BadCRCFile : public File { public: //! Construct a BadCRCFile BadCRCFile( 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 ); //! Get the CRC const CmdSequencerComponentImpl::FPrimeSequence::CRC& getCRC() const; private: //! The CRC CmdSequencerComponentImpl::FPrimeSequence::CRC crc; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/ImmediateEOSFile.hpp
// ====================================================================== // \title ImmediateEOSFile.hpp // \author Rob Bocchino // \brief ImmediateEOSFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_ImmediateEOSFile_HPP #define Svc_SequenceFiles_ImmediateEOSFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A file containing n records. Each of the first n-1 records //! is a relative command with a zero time tag. //! The last record is END_OF_SEQUENCE. class ImmediateEOSFile : public File { public: //! Construct an ImmediateEOSFile ImmediateEOSFile( const U32 n, //!< The number of records const Format::t format //!< The file format ); public: //! Serialize the file in F Prime format void serializeFPrime( Fw::SerializeBufferBase& buffer //!< The buffer ); public: //! The number of records const U32 n; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/EmptyFile.hpp
// ====================================================================== // \title EmptyFile.hpp // \author Rob Bocchino // \brief EmptyFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_EmptyFile_HPP #define Svc_SequenceFiles_EmptyFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! An empty file class EmptyFile : public File { public: //! Construct an empty file EmptyFile( const Format::t format //!< The file format ); public: //! Serialize an empty file in F Prime format void serializeFPrime( Fw::SerializeBufferBase& buffer //!< The buffer ); //! Serialize an empty file in AMPCS format void serializeAMPCS( Fw::SerializeBufferBase& buffer //!< The buffer ); }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp
// ====================================================================== // \title Buffers.hpp // \author Rob Bocchino // \brief Sequence file buffers // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #ifndef Svc_SequenceFiles_Buffers_HPP #define Svc_SequenceFiles_Buffers_HPP #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { namespace Buffers { //! A file buffer class FileBuffer : public Fw::SerializeBufferBase { public: enum Constants { CAPACITY = 4096 }; public: NATIVE_UINT_TYPE getBuffCapacity() const; U8* getBuffAddr(); const U8* getBuffAddr() const; private: U8 m_buff[CAPACITY]; }; //! Write a buffer to a file void write( const Fw::SerializeBufferBase& buffer, //!< The buffer const char* fileName //!< The file name ); } } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/MixedFile.cpp
// ====================================================================== // \title MixedFile.cpp // \author Rob Bocchino // \brief MixedFile 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/MixedFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { MixedFile :: MixedFile(const Format::t format) : File("mixed", format) { } void MixedFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const NATIVE_INT_TYPE numRecs = 4; 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 ); // Records { Fw::Time t; // Record 1: Absolute command t.set(TB_WORKSTATION_TIME, 2, 0); FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::ABSOLUTE, t, 0, 1, buffer ); // Record 2: Immediate command t.set(TB_WORKSTATION_TIME, 0, 0); FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::RELATIVE, t, 2, 3, buffer ); // Record 3: Relative command t.set(TB_WORKSTATION_TIME, 1, 0); FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::RELATIVE, t, 4, 5, buffer ); // Record 4: Immediate command t.set(TB_WORKSTATION_TIME, 0, 0); FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::RELATIVE, t, 6, 7, buffer ); } // CRC FPrime::CRCs::serialize(buffer); } void MixedFile :: serializeAMPCS(Fw::SerializeBufferBase& buffer) { // Header AMPCS::Headers::serialize(buffer); // Records { // Record 1: Absolute command const AMPCSSequence::Record::Time::t time = 2; const AMPCSSequence::Record::Opcode::t opcode = 0; const U32 argument = 1; AMPCS::Records::serialize( AMPCSSequence::Record::TimeFlag::ABSOLUTE, time, opcode, argument, buffer ); } { // Record 2: Immediate command const AMPCSSequence::Record::Time::t time = 0; const AMPCSSequence::Record::Opcode::t opcode = 2; const U32 argument = 3; AMPCS::Records::serialize( AMPCSSequence::Record::TimeFlag::RELATIVE, time, opcode, argument, buffer ); } { // Record 3: Relative command const AMPCSSequence::Record::Time::t time = 1; const AMPCSSequence::Record::Opcode::t opcode = 4; const U32 argument = 5; AMPCS::Records::serialize( AMPCSSequence::Record::TimeFlag::RELATIVE, time, opcode, argument, buffer ); } { // Record 4: Immediate command const AMPCSSequence::Record::Time::t time = 0; const AMPCSSequence::Record::Opcode::t opcode = 6; const U32 argument = 7; AMPCS::Records::serialize( AMPCSSequence::Record::TimeFlag::RELATIVE, time, opcode, argument, buffer ); } // CRC AMPCS::CRCs::createFile(buffer, this->getName().toChar()); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/BadTimeBaseFile.cpp
// ====================================================================== // \title BadTimeBaseFile.cpp // \author Rob Bocchino // \brief BadTimeBaseFile implementation // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/BadTimeBaseFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { BadTimeBaseFile :: BadTimeBaseFile(const U32 n, const Format::t format) : File(format), n(n) { Fw::String s; s.format("bad_time_base_%u", n); this->setName(s.toChar()); } void BadTimeBaseFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const U32 recordDataSize = (this->n-1) * FPrime::Records::STANDARD_SIZE + FPrime::Records::RECORD_DESCRIPTOR_SIZE; const U32 dataSize = recordDataSize + FPrime::CRCs::SIZE; const TimeBase headerTimeBase = TB_PROC_TIME; const TimeBase recordTimeBase = static_cast<TimeBase>(static_cast<U32>(headerTimeBase) + 1); const U32 timeContext = 0; FPrime::Headers::serialize( dataSize, this->n, headerTimeBase, timeContext, buffer ); // Records Fw::Time t(recordTimeBase, 0, 0); for (U32 i = 0; i < this->n - 1; ++i) { const FwOpcodeType opcode = i; const U32 argument = i + 1; FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::RELATIVE, t, opcode, argument, buffer ); } FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::END_OF_SEQUENCE, t, buffer ); // CRC FPrime::CRCs::serialize(buffer); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/EmptyFile.cpp
// ====================================================================== // \title EmptyFile.cpp // \author Rob Bocchino // \brief EmptyFile 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/EmptyFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { EmptyFile :: EmptyFile(const Format::t format) : File("empty", format) { } void EmptyFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Do nothing } void EmptyFile :: serializeAMPCS(Fw::SerializeBufferBase& buffer) { // CRC AMPCS::CRCs::createFile(buffer, this->getName().toChar()); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/DataAfterRecordsFile.hpp
// ====================================================================== // \title DataAfterRecordsFile.hpp // \author Rob Bocchino // \brief DataAfterRecordsFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_DataAfterRecordsFile_HPP #define Svc_SequenceFiles_DataAfterRecordsFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { // A file containing records with bad time bases class DataAfterRecordsFile : public File { public: //! Construct a DataAfterRecordsFile DataAfterRecordsFile( const U32 n, //!< The number of records const Format::t format //!< The file format ); public: //! Serialize the file in F Prime format void serializeFPrime( Fw::SerializeBufferBase& buffer //!< The buffer ); public: //! The number of records const U32 n; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/SizeFieldTooSmallFile.hpp
// ====================================================================== // \title SizeFieldTooSmallFile.hpp // \author Rob Bocchino // \brief SizeFieldTooSmallFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_SizeFieldTooSmallFile_HPP #define Svc_SequenceFiles_SizeFieldTooSmallFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A file with a size field that is too small class SizeFieldTooSmallFile : public File { public: //! Construct a SizeFieldTooSmallFile SizeFieldTooSmallFile( const Format::t format //!< The file format ); public: //! Serialize the file in F Prime format void serializeFPrime( Fw::SerializeBufferBase& buffer //!< The buffer ); }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/USecFieldTooShortFile.cpp
// ====================================================================== // \title USecFieldTooShortFile.cpp // \author Rob Bocchino // \brief USecFieldTooShortFile implementation // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/USecFieldTooShortFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { USecFieldTooShortFile :: USecFieldTooShortFile(const Format::t format) : File("usec_field_too_short", format) { } void USecFieldTooShortFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const TimeBase timeBase = TB_WORKSTATION_TIME; const U32 timeContext = 0; const U32 numRecords = 1; const U32 recordSize = FPrime::Records::RECORD_DESCRIPTOR_SIZE + // descriptor sizeof(U32) + // seconds (CRC should land here) sizeof(U16); // short microseconds const U32 dataSize = numRecords * recordSize; FPrime::Headers::serialize( dataSize, numRecords, timeBase, timeContext, buffer ); // Records const FPrime::Records::Descriptor descriptor = CmdSequencerComponentImpl::Sequence::Record::RELATIVE; ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U8>(descriptor)) ); ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U16>(0)) ); // CRC FPrime::CRCs::serialize(buffer); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/DataAfterRecordsFile.cpp
// ====================================================================== // \title DataAfterRecordsFile.cpp // \author Rob Bocchino // \brief DataAfterRecordsFile implementation // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/DataAfterRecordsFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { DataAfterRecordsFile :: DataAfterRecordsFile(const U32 n, const Format::t format) : File(format), n(n) { Fw::String s; s.format("data_after_records_%u", n); this->setName(s.toChar()); } void DataAfterRecordsFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { ASSERT_GE(this->n, 2U); // Header const U32 recordDataSize = (this->n-1) * FPrime::Records::STANDARD_SIZE + FPrime::Records::EOS_SIZE; const U32 junkDataSize = 2 * sizeof(U32); const U32 dataSize = recordDataSize + junkDataSize + FPrime::CRCs::SIZE; const TimeBase timeBase = TB_WORKSTATION_TIME; const U32 timeContext = 0; FPrime::Headers::serialize( dataSize, this->n, timeBase, timeContext, buffer ); // Standard records Fw::Time t(TB_WORKSTATION_TIME, 0, 0); for (U32 i = 0; i < this->n - 1; ++i) { const FwOpcodeType opcode = i; const U32 argument = i + 1; FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::RELATIVE, t, opcode, argument, buffer ); } // EOS record FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::END_OF_SEQUENCE, t, buffer ); // Extra junk data ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U32>(0x12345678)) ); ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(static_cast<U32>(0x87654321)) ); // CRC FPrime::CRCs::serialize(buffer); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/BadTimeContextFile.cpp
// ====================================================================== // \title BadTimeContextFile.cpp // \author Rob Bocchino // \brief BadTimeContextFile implementation // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/BadTimeContextFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { BadTimeContextFile :: BadTimeContextFile(const U32 n, const Format::t format) : File(format), n(n) { Fw::String s; s.format("bad_time_context_%u", n); this->setName(s.toChar()); } void BadTimeContextFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { ASSERT_GE(this->n, 2U); // Header const U32 recordDataSize = (this->n-1) * FPrime::Records::STANDARD_SIZE + FPrime::Records::EOS_SIZE; const U32 dataSize = recordDataSize + FPrime::CRCs::SIZE; const TimeBase timeBase = TB_WORKSTATION_TIME; const U32 headerTimeContext = 1; FPrime::Headers::serialize( dataSize, this->n, timeBase, headerTimeContext, buffer ); // Standard records Fw::Time t(TB_WORKSTATION_TIME, 0, 0); for (U32 i = 0; i < this->n - 1; ++i) { const FwOpcodeType opcode = i; const U32 argument = i + 1; FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::RELATIVE, t, opcode, argument, buffer ); } // EOS record FPrime::Records::serialize( CmdSequencerComponentImpl::Sequence::Record::END_OF_SEQUENCE, t, buffer ); // CRC FPrime::CRCs::serialize(buffer); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/BadCRCFile.cpp
// ====================================================================== // \title BadCRCFile.cpp // \author Rob Bocchino // \brief BadCRCFile 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/BadCRCFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { BadCRCFile :: BadCRCFile(const Format::t format) : File("bad_crc", format) { } void BadCRCFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const U32 recordData = 0x10; const U32 dataSize = sizeof recordData + FPrime::CRCs::SIZE; const U32 numRecords = 1; const TimeBase timeBase = TB_WORKSTATION_TIME; const U32 timeContext = 0; FPrime::Headers::serialize( dataSize, numRecords, timeBase, timeContext, buffer ); // Records ASSERT_EQ(Fw::FW_SERIALIZE_OK, buffer.serialize(recordData)); // CRC const U8 *const addr = buffer.getBuffAddr(); const U32 size = buffer.getBuffLength(); this->crc.init(); this->crc.update(addr, size); this->crc.finalize(); crc.m_stored = this->crc.m_computed + 1; ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(this->crc.m_stored) ); } void BadCRCFile :: serializeAMPCS(Fw::SerializeBufferBase& buffer) { // Header AMPCS::Headers::serialize(buffer); // Records const U32 recordData = 0x10; ASSERT_EQ(Fw::FW_SERIALIZE_OK, buffer.serialize(recordData)); // CRC AMPCS::CRCs::computeCRC(buffer, this->crc); this->crc.m_stored = this->crc.m_computed + 1; AMPCS::CRCs::writeCRC(this->crc.m_stored, this->getName().toChar()); } const CmdSequencerComponentImpl::FPrimeSequence::CRC& BadCRCFile :: getCRC() const { return this->crc; } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/ImmediateFile.hpp
// ====================================================================== // \title ImmediateFile.hpp // \author Rob Bocchino // \brief ImmediateFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_ImmediateFile_HPP #define Svc_SequenceFiles_ImmediateFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { // A file containing three immediate commands (i.e., // commands with zero time tags) class ImmediateFile : public File { public: //! Construct an ImmediateFile ImmediateFile( const U32 n, //!< The number of records 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 ); public: //! The number of records const U32 n; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/RelativeFile.hpp
// ====================================================================== // \title RelativeFile.hpp // \author Rob Bocchino // \brief RelativeFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_RelativeFile_HPP #define Svc_SequenceFiles_RelativeFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A file containing n commands, each of which has a non-zero //! relative time. class RelativeFile : public File { public: //! Construct a RelativeFile RelativeFile( const U32 n, //!< The number of records 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 ); public: //! The number of records const U32 n; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/SequenceFiles.hpp
// ====================================================================== // \title SequenceFiles.hpp // \author Rob Bocchino // \brief Interface for F Prime sequence files // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_SequenceFiles_HPP #define Svc_SequenceFiles_SequenceFiles_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/BadCRCFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/BadDescriptorFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/BadTimeBaseFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/BadTimeContextFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/DataAfterRecordsFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/EmptyFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/ImmediateEOSFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/ImmediateFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/MissingCRCFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/MissingFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/MixedFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/RelativeFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/SizeFieldTooLargeFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/SizeFieldTooSmallFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/TooLargeFile.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/USecFieldTooShortFile.hpp" #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.cpp
// ====================================================================== // \title Buffers.cpp // \author Rob Bocchino // \brief F Prime sequence file headers // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #include "gtest/gtest.h" #include "Os/File.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/Buffers.hpp" namespace Svc { namespace SequenceFiles { namespace Buffers { NATIVE_UINT_TYPE FileBuffer :: getBuffCapacity() const { return sizeof(m_buff); } U8* FileBuffer :: getBuffAddr() { return m_buff; } const U8* FileBuffer :: getBuffAddr() const { return m_buff; } void write( const Fw::SerializeBufferBase& buffer, const char* fileName ) { Os::File file; ASSERT_EQ(file.open(fileName, Os::File::OPEN_WRITE), Os::File::OP_OK); FwSignedSizeType size = buffer.getBuffLength(); const U32 expectedSize = size; const U8 *const buffAddr = buffer.getBuffAddr(); ASSERT_EQ( file.write(buffAddr, size, Os::File::WaitType::WAIT), Os::File::OP_OK ); ASSERT_EQ(expectedSize, static_cast<U32>(size)); file.close(); } } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/MissingCRCFile.cpp
// ====================================================================== // \title MissingCRCFile.cpp // \author Rob Bocchino // \brief MissingCRCFile 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/MissingCRCFile.hpp" #include "gtest/gtest.h" namespace Svc { namespace SequenceFiles { MissingCRCFile :: MissingCRCFile(const Format::t format) : File("invalid_record", format) { } void MissingCRCFile :: serializeFPrime(Fw::SerializeBufferBase& buffer) { // Header const U8 data = 1; const U32 numRecords = 1; const TimeBase timeBase = TB_WORKSTATION_TIME; const U32 timeContext = 0; FPrime::Headers::serialize( sizeof data, numRecords, timeBase, timeContext, buffer ); // Records + CRC ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(data) ); } void MissingCRCFile :: serializeAMPCS(Fw::SerializeBufferBase& buffer) { // Header AMPCS::Headers::serialize(buffer); // Records const U8 data = 1; ASSERT_EQ( Fw::FW_SERIALIZE_OK, buffer.serialize(data) ); // CRC AMPCS::CRCs::removeFile(this->getName().toChar()); } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/BadDescriptorFile.hpp
// ====================================================================== // \title BadDescriptorFile.hpp // \author Rob Bocchino // \brief BadDescriptorFile interface // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_BadDescriptorFile_HPP #define Svc_SequenceFiles_BadDescriptorFile_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/File.hpp" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { //! A file with a bad record descriptor class BadDescriptorFile : public File { public: //! Construct a BadDescriptorFile BadDescriptorFile( const U32 n, //!< The number of records const Format::t = Format::F_PRIME //!< 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 ); public: //! The number of records const U32 n; }; } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/CRCs.cpp
// ====================================================================== // \title CRCs.hpp // \author Rob Bocchino // \brief AMPCS CRC files // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Fw/Types/String.hpp" #include "Fw/Types/SerialBuffer.hpp" #include "Os/File.hpp" #include "Os/FileSystem.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/CRCs.hpp" #include "gtest/gtest.h" #define BUFFER_SIZE 256 namespace Svc { namespace SequenceFiles { namespace AMPCS { namespace CRCs { namespace { //! Open a file void openFile( Os::File& file, //!< The file const char *const fileName, //!< The file name const Os::File::Mode mode //!< The mode ) { const Os::File::Status fileStatus = file.open(fileName, mode); ASSERT_EQ(Os::File::OP_OK, fileStatus); } //! Write a file void writeFile( Os::File& file, //!< The file const U8 *buffer, //!< The buffer const U32 size //!< The number of bytes to write ) { FwSignedSizeType sizeThenActualSize = size; const Os::File::Status status = file.write( buffer, sizeThenActualSize, Os::File::WaitType::WAIT ); ASSERT_EQ(Os::File::OP_OK, status); const U32 actualSize = sizeThenActualSize; ASSERT_EQ(size, actualSize); } } void createFile( Fw::SerializeBufferBase& buffer, const char *const fileName ) { CRC crc; computeCRC(buffer, crc); writeCRC(crc.m_computed, fileName); } void computeCRC( Fw::SerializeBufferBase& buffer, CRC& crc ) { crc.init(); const U8 *const addr = buffer.getBuffAddr(); const U32 size = buffer.getBuffLength(); crc.update(addr, size); crc.finalize(); } void removeFile( const char *const fileName ) { Fw::String s("rm -f "); s += fileName; s += ".CRC32"; int status = system(s.toChar()); ASSERT_EQ(0, status); } void writeCRC( const U32 crc, const char *const fileName ) { Os::File file; U8 buffer[sizeof crc]; Fw::SerialBuffer serialBuffer(buffer, sizeof(buffer)); serialBuffer.serialize(crc); const U8 *const addr = serialBuffer.getBuffAddr(); Fw::String hashFileName(fileName); hashFileName += ".CRC32"; openFile(file, hashFileName.toChar(), Os::File::OPEN_WRITE); writeFile(file, addr, sizeof(crc)); file.close(); } } } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/CRCs.hpp
// ====================================================================== // \title CRCs.hpp // \author Rob Bocchino // \brief AMPCS CRCs // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_AMPCS_CRCs_HPP #define Svc_SequenceFiles_AMPCS_CRCs_HPP #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { namespace AMPCS { namespace CRCs { //! Type alias typedef CmdSequencerComponentImpl::FPrimeSequence::CRC CRC; //! Compute a CRC void computeCRC( Fw::SerializeBufferBase& buffer, //!< Buffer containing the data CRC& crc //!< The CRC ); //! Create a CRC32 file void createFile( Fw::SerializeBufferBase& buffer, //!< Buffer containing the data const char *const fileName //!< The source file name ); //! Remove a CRC file void removeFile( const char *const fileName //!< The source file name ); //! Write a computed CRC to a file void writeCRC( const U32 crc, //!< The CRC value const char *const fileName //!< The source file name ); } } } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/Headers.cpp
// ====================================================================== // \title Headers.cpp // \author Rob Bocchino // \brief AMPCS sequence file headers // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "gtest/gtest.h" #include "Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/Headers.hpp" namespace Svc { namespace SequenceFiles { namespace AMPCS { namespace Headers { void serialize(Fw::SerializeBufferBase& buffer) { serialize(0x11223344, buffer); } void serialize( const U32 value, Fw::SerializeBufferBase& buffer ) { ASSERT_EQ(Fw::FW_SERIALIZE_OK, buffer.serialize(value)); } } } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/AMPCS.hpp
// ====================================================================== // \title AMPCS.hpp // \author Rob Bocchino // \brief Interface for AMPCS sequence files // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_AMPCS_AMPCS_HPP #define Svc_SequenceFiles_AMPCS_AMPCS_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/CRCs.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/Headers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/Records.hpp" #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/Records.hpp
// ====================================================================== // \title Records.hpp // \author Rob Bocchino // \brief AMPCS sequence file records // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_AMPCS_Records_HPP #define Svc_SequenceFiles_AMPCS_Records_HPP #include "gtest/gtest.h" #include "Svc/CmdSequencer/formats/AMPCSSequence.hpp" namespace Svc { namespace SequenceFiles { namespace AMPCS { namespace Records { enum Constants { //! Size of standard arguments STANDARD_ARG_SIZE = sizeof(U32), //! Standard record size STANDARD_SIZE = sizeof(AMPCSSequence::Record::TimeFlag::t) + sizeof(AMPCSSequence::Record::Time::t) + sizeof(AMPCSSequence::Record::CmdLength::t) + sizeof(AMPCSSequence::Record::Opcode::t) + STANDARD_ARG_SIZE }; //! Serialize a record with a binary command field void serialize( const AMPCSSequence::Record::TimeFlag::t timeFlag, //!< Time flag const AMPCSSequence::Record::Time::t time, //!< Time const Fw::SerializeBufferBase &cmdField, //!< Command field Fw::SerializeBufferBase& dest //!< Destination buffer ); //! Serialize a record with a command field containing an opcode //! and one U32 argument void serialize( const AMPCSSequence::Record::TimeFlag::t timeFlag, //!< Time flag const AMPCSSequence::Record::Time::t time, //!< Time const AMPCSSequence::Record::Opcode::t opcode, //!< Opcode const U32 argument, //!< Argument Fw::SerializeBufferBase& dest //!< Destination buffer ); //! Serialize a record with an empty command field void serialize( const AMPCSSequence::Record::TimeFlag::t timeFlag, //!< Time flag const AMPCSSequence::Record::Time::t time, //!< Time Fw::SerializeBufferBase& dest //!< Destination buffer ); } } } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/Headers.hpp
// ====================================================================== // \title Headers.hpp // \author Rob Bocchino // \brief AMPCS sequence file headers // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_AMPCS_Headers_HPP #define Svc_SequenceFiles_AMPCS_Headers_HPP #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { namespace AMPCS { namespace Headers { //! Serialize a header with a standard U32 value void serialize( Fw::SerializeBufferBase& buffer //!< The destination buffer ); //! Serialize a header from a U32 value void serialize( const U32 value, //!< The value Fw::SerializeBufferBase& buffer //!< The destination buffer ); } } } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/Records.cpp
// ====================================================================== // \title Records.cpp // \author Rob Bocchino // \brief AMPCS sequence file records // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "Fw/Com/ComPacket.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/Records.hpp" namespace Svc { namespace SequenceFiles { namespace AMPCS { namespace Records { void serialize( const AMPCSSequence::Record::TimeFlag::t timeFlag, const AMPCSSequence::Record::Time::t time, const Fw::SerializeBufferBase &cmdField, Fw::SerializeBufferBase& dest ) { const AMPCSSequence::Record::TimeFlag::Serial::t serialTimeFlag = timeFlag; const AMPCSSequence::Record::CmdLength::t cmdLength = cmdField.getBuffLength(); const U8 *const addr = cmdField.getBuffAddr(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, dest.serialize(serialTimeFlag)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, dest.serialize(time)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, dest.serialize(cmdLength)); ASSERT_EQ( Fw::FW_SERIALIZE_OK, // true means "don't serialize the length" dest.serialize(addr, cmdLength, true) ); } void serialize( const AMPCSSequence::Record::TimeFlag::t timeFlag, const AMPCSSequence::Record::Time::t time, const AMPCSSequence::Record::Opcode::t opcode, const U32 argument, Fw::SerializeBufferBase& dest ) { Fw::ComBuffer cmdField; ASSERT_EQ(Fw::FW_SERIALIZE_OK, cmdField.serialize(opcode)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, cmdField.serialize(argument)); Records::serialize(timeFlag, time, cmdField, dest); } void serialize( const AMPCSSequence::Record::TimeFlag::t timeFlag, const AMPCSSequence::Record::Time::t time, Fw::SerializeBufferBase& dest ) { Fw::ComBuffer cmdField; Records::serialize(timeFlag, time, cmdField, dest); } } } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/CRCs.cpp
// ====================================================================== // \title CRCs.hpp // \author Rob Bocchino // \brief F Prime sequence file CRCs // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "gtest/gtest.h" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/CRCs.hpp" namespace Svc { namespace SequenceFiles { namespace FPrime { namespace CRCs { void serialize(Fw::SerializeBufferBase& destBuffer) { CmdSequencerComponentImpl::FPrimeSequence::CRC crc; crc.init(); crc.update(destBuffer.getBuffAddr(), destBuffer.getBuffLength()); crc.finalize(); ASSERT_EQ(destBuffer.serialize(crc.m_computed), Fw::FW_SERIALIZE_OK); } } } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/CRCs.hpp
// ====================================================================== // \title CRCs.hpp // \author Rob Bocchino // \brief F Prime sequence file CRCs // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_FPrime_CRCs_HPP #define Svc_SequenceFiles_FPrime_CRCs_HPP #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { namespace FPrime { namespace CRCs { enum Constants { //! CRC size SIZE = sizeof(U32) }; //! Compute and serialize a CRC //! destBuffer contains the input data; CRC gets added to the end void serialize( Fw::SerializeBufferBase& destBuffer //!< The buffer ); } } } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/Headers.cpp
// ====================================================================== // \title Headers.cpp // \author Rob Bocchino // \brief F Prime sequence file headers // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "gtest/gtest.h" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/Headers.hpp" namespace Svc { namespace SequenceFiles { namespace FPrime { namespace Headers { void serialize( U32 dataSize, U32 numRecords, FwTimeBaseStoreType timeBase, FwTimeContextStoreType timeContext, Fw::SerializeBufferBase& destBuffer ) { ASSERT_EQ(Fw::FW_SERIALIZE_OK, destBuffer.serialize(dataSize)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, destBuffer.serialize(numRecords)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, destBuffer.serialize(timeBase)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, destBuffer.serialize(timeContext)); } } } } }
cpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/Records.hpp
// ====================================================================== // \title Records.hpp // \author Rob Bocchino // \brief F Prime sequence file records // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_FPrime_Records_HPP #define Svc_SequenceFiles_FPrime_Records_HPP #include "gtest/gtest.h" #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { namespace FPrime { namespace Records { typedef CmdSequencerComponentImpl::Sequence::Record::Descriptor Descriptor; enum Constants { //! Record descriptor size RECORD_DESCRIPTOR_SIZE = sizeof(U8), //! Seconds size SECONDS_SIZE = sizeof(U32), //! Microseconds size MICROSECONDS_SIZE = sizeof(U32), //! Size of record size RECORD_SIZE_SIZE = sizeof(U32), //! Size of standard arguments STANDARD_ARG_SIZE = sizeof(U32), //! Standard record size STANDARD_SIZE = RECORD_DESCRIPTOR_SIZE + SECONDS_SIZE + MICROSECONDS_SIZE + RECORD_SIZE_SIZE + sizeof(FwPacketDescriptorType) + sizeof(FwOpcodeType) + STANDARD_ARG_SIZE, //! EOS record size EOS_SIZE = RECORD_DESCRIPTOR_SIZE }; //! Serialize a record with pre-serialized opcode and argument void serialize( Records::Descriptor desc, //!< Descriptor const Fw::Time &time, //!< Time const Fw::ComBuffer &opcodeAndArgument, //!< Serialized opcode and argument Fw::SerializeBufferBase& destBuffer //!< Destination buffer ); //! Serialize a record with an opcode and one U32 argument void serialize( Descriptor desc, //!< Descriptor const Fw::Time &time, //!< Time const FwOpcodeType opcode, //!< Opcode const U32 argument, //!< Argument Fw::SerializeBufferBase& destBuffer //!< Destination buffer ); //! Serialize a record with empty opcode and argument void serialize( Descriptor desc, //!< Descriptor const Fw::Time &time, //!< Time Fw::SerializeBufferBase& destBuffer //!< Destination buffer ); } } } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/Headers.hpp
// ====================================================================== // \title Headers.hpp // \author Rob Bocchino // \brief F Prime sequence file headers // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_FPrime_Headers_HPP #define Svc_SequenceFiles_FPrime_Headers_HPP #include "Svc/CmdSequencer/CmdSequencerImpl.hpp" namespace Svc { namespace SequenceFiles { namespace FPrime { namespace Headers { //! Serialize a header void serialize( U32 dataSize, //!< Size of data following header, including CRC U32 numRecords, //!< Number of records FwTimeBaseStoreType timeBase, //!< Time base FwTimeContextStoreType timeContext, //!< Time context Fw::SerializeBufferBase& destBuffer //!< Destination buffer ); } } } } #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/FPrime.hpp
// ====================================================================== // \title FPrime.hpp // \author Rob Bocchino // \brief Interface for F Prime sequence files // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef Svc_SequenceFiles_FPrime_FPrime_HPP #define Svc_SequenceFiles_FPrime_FPrime_HPP #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/CRCs.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/Headers.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/Records.hpp" #endif
hpp
fprime
data/projects/fprime/Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/Records.cpp
// ====================================================================== // \title Records.cpp // \author Rob Bocchino // \brief F Prime sequence file records // // \copyright // Copyright (C) 2009-2018 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "Fw/Com/ComPacket.hpp" #include "Svc/CmdSequencer/test/ut/SequenceFiles/FPrime/Records.hpp" namespace Svc { namespace SequenceFiles { namespace FPrime { namespace Records { void serialize( Records::Descriptor desc, const Fw::Time &time, const Fw::ComBuffer &opcodeAndArgument, Fw::SerializeBufferBase& destBuffer ) { const U8 descU8 = desc; ASSERT_EQ(Fw::FW_SERIALIZE_OK, destBuffer.serialize(descU8)); if (desc != CmdSequencerComponentImpl::Sequence::Record::END_OF_SEQUENCE) { const U8 *const buffAddr = opcodeAndArgument.getBuffAddr(); const U32 size = opcodeAndArgument.getBuffLength(); const U32 recSize = sizeof(FwPacketDescriptorType) + size; const FwPacketDescriptorType cmdDescriptor = Fw::ComPacket::FW_PACKET_COMMAND; const U32 seconds = time.getSeconds(); const U32 uSeconds = time.getUSeconds(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, destBuffer.serialize(seconds)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, destBuffer.serialize(uSeconds)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, destBuffer.serialize(recSize)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, destBuffer.serialize(cmdDescriptor)); ASSERT_EQ( Fw::FW_SERIALIZE_OK, // true means "don't serialize the size" destBuffer.serialize(buffAddr, size, true) ); } } void serialize( Descriptor desc, const Fw::Time &time, const FwOpcodeType opcode, const U32 argument, Fw::SerializeBufferBase& destBuffer ) { Fw::ComBuffer opcodeAndArgument; ASSERT_EQ(Fw::FW_SERIALIZE_OK, opcodeAndArgument.serialize(opcode)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, opcodeAndArgument.serialize(argument)); Records::serialize(desc, time, opcodeAndArgument, destBuffer); } void serialize( Descriptor desc, const Fw::Time &time, Fw::SerializeBufferBase& destBuffer ) { Fw::ComBuffer opcodeAndArgument; Records::serialize(desc, time, opcodeAndArgument, destBuffer); } } } } }
cpp
fprime
data/projects/fprime/Svc/FileManager/FileManager.cpp
// ====================================================================== // \title FileManager.hpp // \author bocchino // \brief hpp file for FileManager component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include <cstdio> #include <cstdlib> #include "Svc/FileManager/FileManager.hpp" #include "Fw/Types/Assert.hpp" #include <FpConfig.hpp> namespace Svc { // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- FileManager :: FileManager( const char *const compName //!< The component name ) : FileManagerComponentBase(compName), commandCount(0), errorCount(0) { } void FileManager :: init( const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE instance ) { FileManagerComponentBase::init(queueDepth, instance); } FileManager :: ~FileManager() { } // ---------------------------------------------------------------------- // Command handler implementations // ---------------------------------------------------------------------- void FileManager :: CreateDirectory_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq, const Fw::CmdStringArg& dirName ) { Fw::LogStringArg logStringDirName(dirName.toChar()); this->log_ACTIVITY_HI_CreateDirectoryStarted(logStringDirName); const Os::FileSystem::Status status = Os::FileSystem::createDirectory(dirName.toChar()); if (status != Os::FileSystem::OP_OK) { this->log_WARNING_HI_DirectoryCreateError( logStringDirName, status ); } else { this->log_ACTIVITY_HI_CreateDirectorySucceeded(logStringDirName); } this->emitTelemetry(status); this->sendCommandResponse(opCode, cmdSeq, status); } void FileManager :: RemoveFile_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq, const Fw::CmdStringArg& fileName, const bool ignoreErrors ) { Fw::LogStringArg logStringFileName(fileName.toChar()); this->log_ACTIVITY_HI_RemoveFileStarted(logStringFileName); const Os::FileSystem::Status status = Os::FileSystem::removeFile(fileName.toChar()); if (status != Os::FileSystem::OP_OK) { this->log_WARNING_HI_FileRemoveError( logStringFileName, status ); if (ignoreErrors == true) { ++this->errorCount; this->tlmWrite_Errors(this->errorCount); this->cmdResponse_out( opCode, cmdSeq, Fw::CmdResponse::OK ); return; } } else { this->log_ACTIVITY_HI_RemoveFileSucceeded(logStringFileName); } this->emitTelemetry(status); this->sendCommandResponse(opCode, cmdSeq, status); } void FileManager :: MoveFile_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq, const Fw::CmdStringArg& sourceFileName, const Fw::CmdStringArg& destFileName ) { Fw::LogStringArg logStringSource(sourceFileName.toChar()); Fw::LogStringArg logStringDest(destFileName.toChar()); this->log_ACTIVITY_HI_MoveFileStarted(logStringSource, logStringDest); const Os::FileSystem::Status status = Os::FileSystem::moveFile( sourceFileName.toChar(), destFileName.toChar() ); if (status != Os::FileSystem::OP_OK) { this->log_WARNING_HI_FileMoveError( logStringSource, logStringDest, status ); } else { this->log_ACTIVITY_HI_MoveFileSucceeded(logStringSource, logStringDest); } this->emitTelemetry(status); this->sendCommandResponse(opCode, cmdSeq, status); } void FileManager :: RemoveDirectory_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq, const Fw::CmdStringArg& dirName ) { Fw::LogStringArg logStringDirName(dirName.toChar()); this->log_ACTIVITY_HI_RemoveDirectoryStarted(logStringDirName); const Os::FileSystem::Status status = Os::FileSystem::removeDirectory(dirName.toChar()); if (status != Os::FileSystem::OP_OK) { this->log_WARNING_HI_DirectoryRemoveError( logStringDirName, status ); } else { this->log_ACTIVITY_HI_RemoveDirectorySucceeded(logStringDirName); } this->emitTelemetry(status); this->sendCommandResponse(opCode, cmdSeq, status); } void FileManager :: ShellCommand_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq, const Fw::CmdStringArg& command, const Fw::CmdStringArg& logFileName ) { Fw::LogStringArg logStringCommand(command.toChar()); this->log_ACTIVITY_HI_ShellCommandStarted( logStringCommand ); NATIVE_INT_TYPE status = this->systemCall(command, logFileName); if (status == 0) { this->log_ACTIVITY_HI_ShellCommandSucceeded( logStringCommand ); } else { this->log_WARNING_HI_ShellCommandFailed( logStringCommand, status ); } this->emitTelemetry( status == 0 ? Os::FileSystem::OP_OK : Os::FileSystem::OTHER_ERROR ); this->sendCommandResponse( opCode, cmdSeq, status == 0 ? Os::FileSystem::OP_OK : Os::FileSystem::OTHER_ERROR ); } void FileManager :: AppendFile_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq, const Fw::CmdStringArg& source, const Fw::CmdStringArg& target ) { Fw::LogStringArg logStringSource(source.toChar()); Fw::LogStringArg logStringTarget(target.toChar()); this->log_ACTIVITY_HI_AppendFileStarted(logStringSource, logStringTarget); Os::FileSystem::Status status; status = Os::FileSystem::appendFile(source.toChar(), target.toChar(), true); if (status != Os::FileSystem::OP_OK) { this->log_WARNING_HI_AppendFileFailed( logStringSource, logStringTarget, status ); } else { this->log_ACTIVITY_HI_AppendFileSucceeded( logStringSource, logStringTarget ); } this->emitTelemetry(status); this->sendCommandResponse(opCode, cmdSeq, status); } void FileManager :: FileSize_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq, const Fw::CmdStringArg& fileName ) { Fw::LogStringArg logStringFileName(fileName.toChar()); this->log_ACTIVITY_HI_FileSizeStarted(logStringFileName); FwSignedSizeType size_arg; const Os::FileSystem::Status status = Os::FileSystem::getFileSize(fileName.toChar(), size_arg); if (status != Os::FileSystem::OP_OK) { this->log_WARNING_HI_FileSizeError( logStringFileName, status ); } else { U64 size = static_cast<U64>(size_arg); this->log_ACTIVITY_HI_FileSizeSucceeded(logStringFileName, size); } this->emitTelemetry(status); this->sendCommandResponse(opCode, cmdSeq, status); } void FileManager :: pingIn_handler( const NATIVE_INT_TYPE portNum, U32 key ) { // return key this->pingOut_out(0,key); } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- NATIVE_INT_TYPE FileManager :: systemCall( const Fw::CmdStringArg& command, const Fw::CmdStringArg& logFileName ) const { const char evalStr[] = "eval '%s' 1>>%s 2>&1\n"; const U32 bufferSize = sizeof(evalStr) - 4 + 2 * FW_CMD_STRING_MAX_SIZE; char buffer[bufferSize]; NATIVE_INT_TYPE bytesCopied = snprintf( buffer, sizeof(buffer), evalStr, command.toChar(), logFileName.toChar() ); FW_ASSERT(static_cast<NATIVE_UINT_TYPE>(bytesCopied) < sizeof(buffer)); const int status = system(buffer); return status; } void FileManager :: emitTelemetry(const Os::FileSystem::Status status) { if (status == Os::FileSystem::OP_OK) { ++this->commandCount; this->tlmWrite_CommandsExecuted(this->commandCount); } else { ++this->errorCount; this->tlmWrite_Errors(this->errorCount); } } void FileManager :: sendCommandResponse( const FwOpcodeType opCode, const U32 cmdSeq, const Os::FileSystem::Status status ) { this->cmdResponse_out( opCode, cmdSeq, (status == Os::FileSystem::OP_OK) ? Fw::CmdResponse::OK : Fw::CmdResponse::EXECUTION_ERROR ); } }
cpp
fprime
data/projects/fprime/Svc/FileManager/FileManager.hpp
// ====================================================================== // \title FileManager.hpp // \author bocchino // \brief hpp file for FileManager component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef Svc_FileManager_HPP #define Svc_FileManager_HPP #include "Svc/FileManager/FileManagerComponentAc.hpp" #include "Os/FileSystem.hpp" namespace Svc { class FileManager : public FileManagerComponentBase { public: // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Construct object FileManager //! FileManager( const char *const compName //!< The component name ); //! Initialize object FileManager //! void init( const NATIVE_INT_TYPE queueDepth, //!< The queue depth const NATIVE_INT_TYPE instance //!< The instance number ); //! Destroy object FileManager //! ~FileManager(); PRIVATE: // ---------------------------------------------------------------------- // Command handler implementations // ---------------------------------------------------------------------- //! Implementation for CreateDirectory command handler //! void CreateDirectory_cmdHandler( const FwOpcodeType opCode, //!< The opcode const U32 cmdSeq, //!< The command sequence number const Fw::CmdStringArg& dirName //!< The directory to create ); //! Implementation for RemoveFile command handler //! void RemoveFile_cmdHandler( const FwOpcodeType opCode, //!< The opcode const U32 cmdSeq, //!< The command sequence number const Fw::CmdStringArg& fileName, //!< The file to remove const bool ignoreErrors //!< Ignore missing files ); //! Implementation for MoveFile command handler //! void MoveFile_cmdHandler( const FwOpcodeType opCode, //!< The opcode const U32 cmdSeq, //!< The command sequence number const Fw::CmdStringArg& sourceFileName, //!< The source file name const Fw::CmdStringArg& destFileName //!< The destination file name ); //! Implementation for RemoveDirectory command handler //! void RemoveDirectory_cmdHandler( const FwOpcodeType opCode, //!< The opcode const U32 cmdSeq, //!< The command sequence number const Fw::CmdStringArg& dirName //!< The directory to remove ); //! Implementation for ShellCommand command handler //! void ShellCommand_cmdHandler( const FwOpcodeType opCode, //!< The opcode const U32 cmdSeq, //!< The command sequence number const Fw::CmdStringArg& command, //!< The shell command string const Fw::CmdStringArg& logFileName //!< The name of the log file ); //! Implementation for ConcatFiles command handler //! Append 1 file's contents to the end of another. void AppendFile_cmdHandler( const FwOpcodeType opCode, //!< The opcode const U32 cmdSeq, //!< The command sequence number const Fw::CmdStringArg& source, //! The name of the file to take content from const Fw::CmdStringArg& target //! The name of the file to append to ); //! Implementation for FileSize command handler //! void FileSize_cmdHandler( const FwOpcodeType opCode, //!< The opcode const U32 cmdSeq, //!< The command sequence number const Fw::CmdStringArg& fileName //!< The file to get the size of ); //! Handler implementation for pingIn //! void pingIn_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 key /*!< Value to return to pinger*/ ); PRIVATE: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! A system command with no arguments //! NATIVE_INT_TYPE systemCall( const Fw::CmdStringArg& command, //!< The command const Fw::CmdStringArg& logFileName //!< The log file name ) const; //! Emit telemetry based on status //! void emitTelemetry( const Os::FileSystem::Status status //!< The status ); //! Send command response based on status //! void sendCommandResponse( const FwOpcodeType opCode, //!< The opcode const U32 cmdSeq, //!< The command sequence value const Os::FileSystem::Status status //!< The status ); PRIVATE: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The total number of commands successfully executed //! U32 commandCount; //! The total number of errors //! U32 errorCount; }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/FileManager/test/ut/FileManagerTester.hpp
// ====================================================================== // \title FileManager/test/ut/Tester.hpp // \author bocchino // \brief hpp file for FileManager test harness implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef TESTER_HPP #define TESTER_HPP #include "FileManagerGTestBase.hpp" #include "Svc/FileManager/FileManager.hpp" namespace Svc { class FileManagerTester : public FileManagerGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: //! Construct object FileManagerTester //! FileManagerTester(); //! Destroy object FileManagerTester //! ~FileManagerTester(); public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! Create directory (succeed) //! void createDirectorySucceed(); //! Create directory (fail) //! void createDirectoryFail(); //! Move file (succeed) //! void moveFileSucceed(); //! Move file (fail) //! void moveFileFail(); //! Remove directory (succeed) //! void removeDirectorySucceed(); //! Remove directory (fail) //! void removeDirectoryFail(); //! Remove file (succeed) //! void removeFileSucceed(); //! Remove file (fail) //! void removeFileFail(); //! Shell command (succeed) //! void shellCommandSucceed(); //! Shell command (fail) //! void shellCommandFail(); //! Append file (succeed, append to new file) //! void appendFileSucceed_newFile(); //! Append file (succeed, append to existing file) //! void appendFileSucceed_existingFile(); //! Append file (fail) //! void appendFileFail(); //! File size (succeed) //! void fileSizeSucceed(); //! File size (fail) //! void fileSizeFail(); private: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(); //! Initialize components //! void initComponents(); //! Perform a system call and assert success //! static void system(const char *const cmd); //! Create a directory void createDirectory( const char *const dirName ); //! Move a file void moveFile( const char *const sourceFileName, const char *const destFileName ); //! Remove a directory void removeDirectory( const char *const dirName ); //! Remove a file void removeFile( const char *const fileName, bool ignoreErrors ); //! Perform a shell command void shellCommand( const char *const command, const char *const logFileName ); //! Append 2 files together void appendFile( const char *const source, const char *const target ); //! Assert successful command execution void assertSuccess( const FwOpcodeType opcode, const U32 eventSize = 2 // Starting event + Error or Success msg ) const; //! Assert file content matches the expected string (up to the given size) void assertFileContent( const char *const fileName, const char *const expectedString, const U32 length ) const; //! Assert failed command execution void assertFailure(const FwOpcodeType opcode) const; //! Handler for from_pingOut //! void from_pingOut_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 key /*!< Value to return to pinger*/ ); private: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! FileManager component; }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/FileManager/test/ut/FileManagerMain.cpp
// ---------------------------------------------------------------------- // Main.cpp // ---------------------------------------------------------------------- #include "FileManagerTester.hpp" TEST(Test, createDirectorySucceed) { Svc::FileManagerTester tester; tester.createDirectorySucceed(); } TEST(Test, createDirectoryFail) { Svc::FileManagerTester tester; tester.createDirectoryFail(); } TEST(Test, moveFileSucceed) { Svc::FileManagerTester tester; tester.moveFileSucceed(); } TEST(Test, moveFileFail) { Svc::FileManagerTester tester; tester.moveFileFail(); } TEST(Test, removeDirectorySucceed) { Svc::FileManagerTester tester; tester.removeDirectorySucceed(); } TEST(Test, removeDirectoryFail) { Svc::FileManagerTester tester; tester.removeDirectoryFail(); } TEST(Test, removeFileSucceed) { Svc::FileManagerTester tester; tester.removeFileSucceed(); } TEST(Test, removeFileFail) { Svc::FileManagerTester tester; tester.removeFileFail(); } TEST(Test, shellCommandSucceed) { Svc::FileManagerTester tester; tester.shellCommandSucceed(); } TEST(Test, shellCommandFail) { Svc::FileManagerTester tester; tester.shellCommandFail(); } TEST(Test, appendFileSucceedNewFile) { Svc::FileManagerTester tester; tester.appendFileSucceed_newFile(); } TEST(Test, appendFileSucceedExistingFile) { Svc::FileManagerTester tester; tester.appendFileSucceed_existingFile(); } TEST(Test, appendFileFail) { Svc::FileManagerTester tester; tester.appendFileFail(); } TEST(Test, fileSizeSucceed) { Svc::FileManagerTester tester; tester.fileSizeSucceed(); } TEST(Test, fileSizeFail) { Svc::FileManagerTester tester; tester.fileSizeFail(); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
cpp
fprime
data/projects/fprime/Svc/FileManager/test/ut/FileManagerTester.cpp
// ====================================================================== // \title FileManagerTester.cpp // \author bocchino // \brief cpp file for FileManager test harness implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include <fstream> #include "FileManagerTester.hpp" #define INSTANCE 0 #define CMD_SEQ 0 #define MAX_HISTORY_SIZE 10 #define QUEUE_DEPTH 10 #define LOG_FILE "log.txt" namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- FileManagerTester :: FileManagerTester() : FileManagerGTestBase("Tester", MAX_HISTORY_SIZE), component("FileManager") { this->connectPorts(); this->initComponents(); } FileManagerTester :: ~FileManagerTester() { } // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void FileManagerTester :: createDirectorySucceed() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove test_dir, if it exists this->system("rm -rf test_dir"); // Create test_dir this->createDirectory("test_dir"); #else FAIL(); // Commands not implemented for this OS #endif // Assert success this->assertSuccess( FileManager::OPCODE_CREATEDIRECTORY ); #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Check that test_dir exists this->system("test -d test_dir"); // Clean up this->system("rmdir test_dir"); #else FAIL(); // Commands not implemented for this OS #endif } void FileManagerTester :: createDirectoryFail() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Create test_dir this->system("rm -rf test_dir"); this->system("mkdir test_dir"); #else FAIL(); // Commands not implemented for this OS #endif // Attempt to create test_dir (should fail) this->createDirectory("test_dir"); // Assert failure this->assertFailure( FileManager::OPCODE_CREATEDIRECTORY ); ASSERT_EVENTS_SIZE(2); // Starting event + Error ASSERT_EVENTS_DirectoryCreateError( 0, "test_dir", Os::FileSystem::ALREADY_EXISTS ); } void FileManagerTester :: moveFileSucceed() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove file1 and file2, if they exist this->system("rm -rf file1 file2"); // Create file1 this->system("touch file1"); #else FAIL(); // Commands not implemented for this OS #endif // Move file1 to file2 this->moveFile("file1", "file2"); // Assert success this->assertSuccess( FileManager::OPCODE_MOVEFILE ); #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Check that file name changed this->system("! test -e file1"); this->system("test -f file2"); // Clean up this->system("rm file2"); #else FAIL(); // Commands not implemented for this OS #endif } void FileManagerTester :: moveFileFail() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove file1, if it exists this->system("rm -rf file1"); #else FAIL(); // Commands not implemented for this OS #endif // Attempt to move file1 to file2 (should fail) this->moveFile("file1", "file2"); // Assert failure this->assertFailure( FileManager::OPCODE_MOVEFILE ); ASSERT_EVENTS_FileMoveError_SIZE(1); ASSERT_EVENTS_FileMoveError( 0, "file1", "file2", Os::FileSystem::INVALID_PATH ); } void FileManagerTester :: removeDirectorySucceed() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove test_dir, if it exists this->system("rm -rf test_dir"); // Create test_dir this->system("mkdir test_dir"); #else FAIL(); // Commands not implemented for this OS #endif // Remove test_dir this->removeDirectory("test_dir"); // Assert success this->assertSuccess( FileManager::OPCODE_REMOVEDIRECTORY ); #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Check that test_dir is not there this->system("! test -e test_dir"); #else FAIL(); // Commands not implemented for this OS #endif } void FileManagerTester :: removeDirectoryFail() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove test_dir, if it exists this->system("rm -rf test_dir"); #else FAIL(); // Commands not implemented for this OS #endif // Attempt to remove test_dir (should fail) this->removeDirectory("test_dir"); // Assert failure this->assertFailure( FileManager::OPCODE_REMOVEDIRECTORY ); ASSERT_EVENTS_SIZE(2); // Starting event + Error ASSERT_EVENTS_DirectoryRemoveError( 0, "test_dir", Os::FileSystem::INVALID_PATH ); } void FileManagerTester :: removeFileSucceed() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove test_file, if it exists this->system("rm -rf test_file"); // Create test_file this->system("touch test_file"); #else FAIL(); // Commands not implemented for this OS #endif // Remove test_file this->removeFile("test_file", false); // Assert success this->assertSuccess( FileManager::OPCODE_REMOVEFILE ); #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Check that test_file is not there this->system("! test -e test_file"); #else FAIL(); // Commands not implemented for this OS #endif } void FileManagerTester :: removeFileFail() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove test_file, if it exists this->system("rm -rf test_file"); #else FAIL(); // Commands not implemented for this OS #endif // Attempt to remove test_file (should fail) this->removeFile("test_file", false); // Assert failure this->assertFailure( FileManager::OPCODE_REMOVEFILE ); ASSERT_EVENTS_SIZE(2); // Starting event + Error ASSERT_EVENTS_FileRemoveError( 0, "test_file", Os::FileSystem::INVALID_PATH ); } void FileManagerTester :: shellCommandSucceed() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove test_file, if it exists this->system("rm -rf test_file"); // Create test_file this->shellCommand("touch test_file", LOG_FILE); #else FAIL(); // Commands not implemented for this OS #endif // Assert success this->assertSuccess(FileManager::OPCODE_SHELLCOMMAND); ASSERT_EVENTS_ShellCommandSucceeded_SIZE(1); ASSERT_EVENTS_ShellCommandSucceeded(0, "touch test_file"); #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Check that test_file is there this->system("test -f test_file"); // Clean up this->system("rm test_file"); #else FAIL(); // Commands not implemented for this OS #endif } void FileManagerTester :: shellCommandFail() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove test_file, if it exists this->system("rm -rf test_file"); // Attempt to remove test_file (should fail) this->shellCommand("rm test_file", LOG_FILE); #else FAIL(); // Commands not implemented for this OS #endif { // Assert failure this->assertFailure( FileManager::OPCODE_SHELLCOMMAND ); ASSERT_EVENTS_ShellCommandFailed_SIZE(1); const EventEntry_ShellCommandFailed& e = this->eventHistory_ShellCommandFailed->at(0); const U32 status = e.status; ASSERT_NE(static_cast<U32>(0), status); ASSERT_EVENTS_ShellCommandFailed( 0, "rm test_file", status ); } } void FileManagerTester :: appendFileSucceed_newFile() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove testing files, if they exist this->system("rm -rf file1 file2"); //================================================================ // Case 1: 1 normal files appended, new file created this->system("echo 'file1 text' > file1"); #else FAIL(); // Commands not implemented for this OS #endif this->appendFile("file1", "file2"); this->assertSuccess(FileManager::OPCODE_APPENDFILE); #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // check new file exists and has correct text inside this->system("test -e file2"); assertFileContent("file2", "file1 text\n", 12); // Clean up this->system("rm -rf file1 file2"); #else FAIL(); // Commands not implemented for this OS #endif } void FileManagerTester :: appendFileSucceed_existingFile() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove testing files, if they exist this->system("rm -rf file1 file2"); //================================================================ // Case 2: 2 normal files appended, stored in existing file // create existing files this->system("echo 'file1 text' > file1"); this->system("echo 'file2 text' > file2"); #else FAIL(); // Commands not implemented for this OS #endif this->appendFile("file1", "file2"); this->assertSuccess(FileManager::OPCODE_APPENDFILE); #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // check file still exists and has new text inside this->system("test -e file2"); assertFileContent("file2", "file2 text\nfile1 text\n", 23); // Clean up this->system("rm -rf file1 file2"); #else FAIL(); // Commands not implemented for this OS #endif } void FileManagerTester :: appendFileFail() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove testing files, if they exist this->system("rm -rf file1 file2"); #else FAIL(); // Commands not implemented for this OS #endif // Attempt to append from a non-existing source this->appendFile("file1", "file2"); // Assert failure this->assertFailure( FileManager::OPCODE_APPENDFILE ); ASSERT_EVENTS_SIZE(2); // Starting event + Error ASSERT_EVENTS_AppendFileFailed( 0, "file1", "file2", Os::FileSystem::INVALID_PATH ); } void FileManagerTester :: fileSizeSucceed() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove testing files, if they exist this->system("rm -rf file1"); this->system("echo 'file1 text' > file1"); #else FAIL(); // Commands not implemented for this OS #endif Fw::CmdStringArg cmdStringFile("file1"); this->sendCmd_FileSize( INSTANCE, CMD_SEQ, cmdStringFile ); this->component.doDispatch(); this->assertSuccess(FileManager::OPCODE_FILESIZE, 2); ASSERT_EVENTS_FileSizeSucceeded(0, "file1", 11); } void FileManagerTester :: fileSizeFail() { #if defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN // Remove testing files, if they exist this->system("rm -rf file1"); #else FAIL(); // Commands not implemented for this OS #endif Fw::CmdStringArg cmdStringFile("file1"); this->sendCmd_FileSize( INSTANCE, CMD_SEQ, cmdStringFile ); this->component.doDispatch(); this->assertFailure( FileManager::OPCODE_FILESIZE ); } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void FileManagerTester :: connectPorts() { // cmdIn this->connect_to_cmdIn( 0, this->component.get_cmdIn_InputPort(0) ); // timeCaller this->component.set_timeCaller_OutputPort( 0, this->get_from_timeCaller(0) ); // tlmOut this->component.set_tlmOut_OutputPort( 0, this->get_from_tlmOut(0) ); // cmdResponseOut this->component.set_cmdResponseOut_OutputPort( 0, this->get_from_cmdResponseOut(0) ); // eventOut this->component.set_eventOut_OutputPort( 0, this->get_from_eventOut(0) ); // cmdRegOut this->component.set_cmdRegOut_OutputPort( 0, this->get_from_cmdRegOut(0) ); // LogText this->component.set_LogText_OutputPort( 0, this->get_from_LogText(0) ); } void FileManagerTester :: initComponents() { this->init(); this->component.init( QUEUE_DEPTH, INSTANCE ); } void FileManagerTester :: system(const char *const cmd) { const NATIVE_INT_TYPE status = ::system(cmd); ASSERT_EQ(static_cast<NATIVE_INT_TYPE>(0), status); } void FileManagerTester :: createDirectory(const char *const dirName) { Fw::CmdStringArg cmdStringDir(dirName); this->sendCmd_CreateDirectory( INSTANCE, CMD_SEQ, cmdStringDir ); this->component.doDispatch(); } void FileManagerTester :: moveFile( const char *const sourceFileName, const char *const destFileName ) { Fw::CmdStringArg cmdStringSource(sourceFileName); Fw::CmdStringArg cmdStringDest(destFileName); this->sendCmd_MoveFile( INSTANCE, CMD_SEQ, cmdStringSource, cmdStringDest ); this->component.doDispatch(); } void FileManagerTester :: removeDirectory(const char *const dirName) { Fw::CmdStringArg cmdStringDir(dirName); this->sendCmd_RemoveDirectory( INSTANCE, CMD_SEQ, cmdStringDir ); this->component.doDispatch(); } void FileManagerTester :: removeFile(const char *const fileName, bool ignoreErrors) { Fw::CmdStringArg cmdStringFile(fileName); this->sendCmd_RemoveFile( INSTANCE, CMD_SEQ, cmdStringFile, ignoreErrors ); this->component.doDispatch(); } void FileManagerTester :: shellCommand( const char *const command, const char *const logFileName ) { Fw::CmdStringArg cmdStringCommand(command); Fw::CmdStringArg cmdStringLogFile(logFileName); this->sendCmd_ShellCommand( INSTANCE, CMD_SEQ, cmdStringCommand, cmdStringLogFile ); this->component.doDispatch(); } void FileManagerTester :: appendFile( const char *const source, const char *const target ) { Fw::CmdStringArg cmdSource(source); Fw::CmdStringArg cmdTarget(target); this->sendCmd_AppendFile( INSTANCE, CMD_SEQ, cmdSource, cmdTarget ); this->component.doDispatch(); } void FileManagerTester :: assertSuccess( const FwOpcodeType opcode, const U32 eventSize ) const { ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, opcode, CMD_SEQ, Fw::CmdResponse::OK ); ASSERT_EVENTS_SIZE(eventSize); ASSERT_TLM_SIZE(1); ASSERT_TLM_CommandsExecuted_SIZE(1); ASSERT_TLM_CommandsExecuted(0, 1); } void FileManagerTester :: assertFileContent( const char *const fileName, const char *const expectedString, const U32 length ) const { char fileString[length]; memset(fileString, 0, length); std::ifstream file; file.open(fileName); file.read(fileString, length); file.close(); ASSERT_STREQ(expectedString, fileString); } void FileManagerTester :: assertFailure(const FwOpcodeType opcode) const { ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, opcode, CMD_SEQ, Fw::CmdResponse::EXECUTION_ERROR ); ASSERT_EVENTS_SIZE(2); // Starting event + Error ASSERT_TLM_SIZE(1); ASSERT_TLM_Errors_SIZE(1); ASSERT_TLM_Errors(0, 1); } void FileManagerTester :: from_pingOut_handler( const NATIVE_INT_TYPE portNum, U32 key ) { this->pushFromPortEntry_pingOut(key); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/Cycle/TimerVal.hpp
/* * TimerVal.hpp * * Created on: Aug 5, 2015 * Author: timothycanham */ #ifndef TIMERVAL_HPP_ #define TIMERVAL_HPP_ #include <Fw/Types/Serializable.hpp> #include <Os/IntervalTimer.hpp> namespace Svc { //! \class TimerVal //! \brief Serializable class for carrying timer values //! //! This class carries a timer value. It is meant to be //! passed through ports that carry timing info. class TimerVal: public Fw::Serializable { public: enum { SERIALIZED_SIZE = sizeof(U32) + sizeof(U32) //!< size of TimerVal private members }; TimerVal(); //!< Default constructor //! \brief Timer copy constructor //! //! constructs a TimerVal with another timer as the source //! //! \param other source timer value TimerVal(const TimerVal& other); //!< copy constructor //! \brief Timer equal operator //! //! copies timer value from another timer as the source //! //! \param other source timer value TimerVal& operator=(const TimerVal& other); //!< equal operator //! \brief Destructor //! //! Does nothing //! virtual ~TimerVal() {} //! \brief Serialization function //! //! Serializes timer values //! //! \param buffer destination buffer for serialization data Fw::SerializeStatus serialize(Fw::SerializeBufferBase& buffer) const; //!< serialize contents //! \brief Deserialization function //! //! Deserializes timer values //! //! \param buffer source buffer for serialization data Fw::SerializeStatus deserialize(Fw::SerializeBufferBase& buffer); //!< deserialize to contents //! \brief Returns the current timer value //! //! Os::IntervalTimer::RawTime getTimerVal() const; //! \brief Function to store a timer value //! //! This function calls the Os::IntervalTimer function to store a timer value in the private data of the object //! void take(); //!< Take raw time //! \brief Compute difference function //! //! This function computes the difference in time between the internal //! value and the passed value. It is computed as internal - time parameter. //! //! \param time time to compute difference from U32 diffUSec(const TimerVal& time); //!< takes difference between stored time and passed time PRIVATE: TimerVal(U32 upper, U32 lower); //!< Private constructor for testing Os::IntervalTimer::RawTime m_timerVal; //!< Stored timer value }; } /* namespace Svc */ #endif /* TIMERVAL_HPP_ */
hpp
fprime
data/projects/fprime/Svc/Cycle/TimerVal.cpp
/* * TimerVal.cpp * * Created on: Aug 5, 2015 * Author: timothycanham */ #include <Svc/Cycle/TimerVal.hpp> #include <cstring> namespace Svc { TimerVal::TimerVal() : Fw::Serializable() { this->m_timerVal.upper = 0; this->m_timerVal.lower = 0; } TimerVal::TimerVal(U32 upper, U32 lower) { this->m_timerVal.upper = upper; this->m_timerVal.lower = lower; } TimerVal::TimerVal(const TimerVal& other) : Fw::Serializable() { this->m_timerVal.upper = other.m_timerVal.upper; this->m_timerVal.lower = other.m_timerVal.lower; } TimerVal& TimerVal::operator=(const TimerVal& other) { this->m_timerVal.upper = other.m_timerVal.upper; this->m_timerVal.lower = other.m_timerVal.lower; return *this; } Os::IntervalTimer::RawTime TimerVal::getTimerVal() const { return this->m_timerVal; } void TimerVal::take() { Os::IntervalTimer::getRawTime(this->m_timerVal); } U32 TimerVal::diffUSec(const TimerVal& time) { return Os::IntervalTimer::getDiffUsec(this->m_timerVal,time.m_timerVal); } Fw::SerializeStatus TimerVal::serialize(Fw::SerializeBufferBase& buffer) const { Fw::SerializeStatus stat = buffer.serialize(this->m_timerVal.upper); if (stat != Fw::FW_SERIALIZE_OK) { return stat; } return buffer.serialize(this->m_timerVal.lower); } Fw::SerializeStatus TimerVal::deserialize(Fw::SerializeBufferBase& buffer) { Fw::SerializeStatus stat = buffer.deserialize(this->m_timerVal.upper); if (stat != Fw::FW_SERIALIZE_OK) { return stat; } return buffer.deserialize(this->m_timerVal.lower); } } /* namespace Svc */
cpp
fprime
data/projects/fprime/Svc/TlmPacketizer/TlmPacketizer.hpp
// ====================================================================== // \title TlmPacketizerImpl.hpp // \author tcanham // \brief hpp file for TlmPacketizer component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef TlmPacketizer_HPP #define TlmPacketizer_HPP #include "Os/Mutex.hpp" #include "Svc/TlmPacketizer/TlmPacketizerComponentAc.hpp" #include "Svc/TlmPacketizer/TlmPacketizerTypes.hpp" #include "TlmPacketizerCfg.hpp" namespace Svc { class TlmPacketizer : public TlmPacketizerComponentBase { public: // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Construct object TlmPacketizer //! TlmPacketizer(const char* const compName /*!< The component name*/ ); //! Initialize object TlmPacketizer //! void init(const NATIVE_INT_TYPE queueDepth, /*!< The queue depth*/ const NATIVE_INT_TYPE instance = 0 /*!< The instance number*/ ); void setPacketList( const TlmPacketizerPacketList& packetList, // channels to packetize const Svc::TlmPacketizerPacket& ignoreList, // channels to ignore (i.e. no warning event if not packetized) const NATIVE_UINT_TYPE startLevel); // starting level of packets to send //! Destroy object TlmPacketizer //! ~TlmPacketizer(void); PRIVATE: // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- //! Handler implementation for TlmRecv //! void TlmRecv_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ FwChanIdType id, /*!< Telemetry Channel ID*/ Fw::Time& timeTag, /*!< Time Tag*/ Fw::TlmBuffer& val /*!< Buffer containing serialized telemetry value*/ ); //! Handler implementation for Run //! void Run_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 context /*!< The call order*/ ); //! Handler implementation for pingIn //! void pingIn_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 key /*!< Value to return to pinger*/ ); //! Implementation for SET_LEVEL command handler //! Set telemetry send leve void SET_LEVEL_cmdHandler(const FwOpcodeType opCode, /*!< The opcode*/ const U32 cmdSeq, /*!< The command sequence number*/ U32 level /*!< The I32 command argument*/ ); //! Implementation for SEND_PKT command handler //! Force a packet to be sent void SEND_PKT_cmdHandler(const FwOpcodeType opCode, /*!< The opcode*/ const U32 cmdSeq, /*!< The command sequence number*/ U32 id /*!< The packet ID*/ ); // number of packets to fill NATIVE_UINT_TYPE m_numPackets; // Array of packet buffers to send // Double-buffered to fill one while sending one struct BufferEntry { Fw::ComBuffer buffer; //!< buffer for packetized channels Fw::Time latestTime; //!< latest update time NATIVE_UINT_TYPE id; //!< channel id NATIVE_UINT_TYPE level; //!< channel level bool updated; //!< if packet had any updates during last cycle bool requested; //!< if the packet was requested with SEND_PKT in the last cycle }; // buffers for filling with telemetry BufferEntry m_fillBuffers[MAX_PACKETIZER_PACKETS]; // buffers for sending - will be copied from fill buffers BufferEntry m_sendBuffers[MAX_PACKETIZER_PACKETS]; struct TlmEntry { FwChanIdType id; //!< telemetry id stored in slot // Offsets into packet buffers. // -1 means that channel is not in that packet NATIVE_INT_TYPE packetOffset[MAX_PACKETIZER_PACKETS]; TlmEntry* next; //!< pointer to next bucket in table bool used; //!< if entry has been used bool ignored; //!< ignored packet id NATIVE_UINT_TYPE bucketNo; //!< for testing }; struct TlmSet { TlmEntry* slots[TLMPACKETIZER_NUM_TLM_HASH_SLOTS]; //!< set of hash slots in hash table TlmEntry buckets[TLMPACKETIZER_HASH_BUCKETS]; //!< set of buckets used in hash table NATIVE_UINT_TYPE free; //!< next free bucket } m_tlmEntries; // hash function for looking up telemetry channel NATIVE_UINT_TYPE doHash(FwChanIdType id); Os::Mutex m_lock; //!< used to lock access to packet buffers bool m_configured; //!< indicates a table has been passed and packets configured struct MissingTlmChan { FwChanIdType id; bool checked; } m_missTlmCheck[TLMPACKETIZER_MAX_MISSING_TLM_CHECK]; void missingChannel(FwChanIdType id); //!< Helper to check to see if missing channel warning was sent TlmEntry* findBucket(FwChanIdType id); NATIVE_UINT_TYPE m_startLevel; //!< initial level for sending packets NATIVE_UINT_TYPE m_maxLevel; //!< maximum level in all packets }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/TlmPacketizer/TlmPacketizerTypes.hpp
/* * TlmPacketizerTypes.hpp * * Created on: Dec 10, 2017 * Author: tim */ // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef SVC_TLMPACKETIZER_TLMPACKETIZERTYPES_HPP_ #define SVC_TLMPACKETIZER_TLMPACKETIZERTYPES_HPP_ #include <FpConfig.hpp> #include <TlmPacketizerCfg.hpp> namespace Svc { struct TlmPacketizerChannelEntry { FwChanIdType id; //!< Id of channel NATIVE_UINT_TYPE size; //!< serialized size of channel in bytes }; struct TlmPacketizerPacket { const TlmPacketizerChannelEntry* list; //!< pointer to a channel entry FwTlmPacketizeIdType id; //!< packet ID NATIVE_UINT_TYPE level; //!< packet level - used to select set of packets to send NATIVE_UINT_TYPE numEntries; //!< number of channels in packet }; struct TlmPacketizerPacketList { const TlmPacketizerPacket* list[MAX_PACKETIZER_PACKETS]; //!< NATIVE_UINT_TYPE numEntries; }; } // namespace Svc #endif /* SVC_TLMPACKETIZER_TLMPACKETIZERTYPES_HPP_ */
hpp
fprime
data/projects/fprime/Svc/TlmPacketizer/TlmPacketizer.cpp
// ====================================================================== // \title TlmPacketizerImpl.cpp // \author tcanham // \brief cpp file for TlmPacketizer component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include <FpConfig.hpp> #include <Fw/Com/ComPacket.hpp> #include <Svc/TlmPacketizer/TlmPacketizer.hpp> namespace Svc { // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- TlmPacketizer ::TlmPacketizer(const char* const compName) : TlmPacketizerComponentBase(compName), m_numPackets(0), m_configured(false), m_startLevel(0), m_maxLevel(0) { // clear slot pointers for (NATIVE_UINT_TYPE entry = 0; entry < TLMPACKETIZER_NUM_TLM_HASH_SLOTS; entry++) { this->m_tlmEntries.slots[entry] = nullptr; } // clear buckets for (NATIVE_UINT_TYPE entry = 0; entry < TLMPACKETIZER_HASH_BUCKETS; entry++) { this->m_tlmEntries.buckets[entry].used = false; this->m_tlmEntries.buckets[entry].bucketNo = entry; this->m_tlmEntries.buckets[entry].next = nullptr; this->m_tlmEntries.buckets[entry].id = 0; } // clear free index this->m_tlmEntries.free = 0; // clear missing tlm channel check for (NATIVE_UINT_TYPE entry = 0; entry < TLMPACKETIZER_MAX_MISSING_TLM_CHECK; entry++) { this->m_missTlmCheck[entry].checked = false; this->m_missTlmCheck[entry].id = 0; } // clear packet buffers for (NATIVE_UINT_TYPE buffer = 0; buffer < MAX_PACKETIZER_PACKETS; buffer++) { this->m_fillBuffers[buffer].updated = false; this->m_fillBuffers[buffer].requested = false; this->m_sendBuffers[buffer].updated = false; } } void TlmPacketizer ::init(const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE instance) { TlmPacketizerComponentBase::init(queueDepth, instance); } TlmPacketizer ::~TlmPacketizer() {} void TlmPacketizer::setPacketList(const TlmPacketizerPacketList& packetList, const Svc::TlmPacketizerPacket& ignoreList, const NATIVE_UINT_TYPE startLevel) { FW_ASSERT(packetList.list); FW_ASSERT(ignoreList.list); FW_ASSERT(packetList.numEntries <= MAX_PACKETIZER_PACKETS, packetList.numEntries); // validate packet sizes against maximum com buffer size and populate hash // table for (NATIVE_UINT_TYPE pktEntry = 0; pktEntry < packetList.numEntries; pktEntry++) { // Initial size is packetized telemetry descriptor + size of time tag + sizeof packet ID NATIVE_UINT_TYPE packetLen = sizeof(FwPacketDescriptorType) + Fw::Time::SERIALIZED_SIZE + sizeof(FwTlmPacketizeIdType); FW_ASSERT(packetList.list[pktEntry]->list, pktEntry); // add up entries for each defined packet for (NATIVE_UINT_TYPE tlmEntry = 0; tlmEntry < packetList.list[pktEntry]->numEntries; tlmEntry++) { // get hash value for id FwChanIdType id = packetList.list[pktEntry]->list[tlmEntry].id; TlmEntry* entryToUse = this->findBucket(id); // copy into entry FW_ASSERT(entryToUse); entryToUse->used = true; // not ignored channel entryToUse->ignored = false; entryToUse->id = id; // the offset into the buffer will be the current packet length entryToUse->packetOffset[pktEntry] = packetLen; packetLen += packetList.list[pktEntry]->list[tlmEntry].size; } // end channel in packet FW_ASSERT(packetLen <= FW_COM_BUFFER_MAX_SIZE, packetLen, pktEntry); // clear contents memset(this->m_fillBuffers[pktEntry].buffer.getBuffAddr(), 0, packetLen); // serialize packet descriptor and packet ID now since it will always be the same Fw::SerializeStatus stat = this->m_fillBuffers[pktEntry].buffer.serialize( static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM)); FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, stat); stat = this->m_fillBuffers[pktEntry].buffer.serialize(packetList.list[pktEntry]->id); FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, stat); // set packet buffer length stat = this->m_fillBuffers[pktEntry].buffer.setBuffLen(packetLen); FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, stat); // save ID this->m_fillBuffers[pktEntry].id = packetList.list[pktEntry]->id; // save level this->m_fillBuffers[pktEntry].level = packetList.list[pktEntry]->level; // store max level if (packetList.list[pktEntry]->level > this->m_maxLevel) { this->m_maxLevel = packetList.list[pktEntry]->level; } // save start level this->m_startLevel = startLevel; } // end packet list // populate hash table with ignore list for (NATIVE_UINT_TYPE channelEntry = 0; channelEntry < ignoreList.numEntries; channelEntry++) { // get hash value for id FwChanIdType id = ignoreList.list[channelEntry].id; TlmEntry* entryToUse = this->findBucket(id); // copy into entry FW_ASSERT(entryToUse); entryToUse->used = true; // is ignored channel entryToUse->ignored = true; entryToUse->id = id; } // end ignore list // store number of packets this->m_numPackets = packetList.numEntries; // indicate configured this->m_configured = true; } TlmPacketizer::TlmEntry* TlmPacketizer::findBucket(FwChanIdType id) { NATIVE_UINT_TYPE index = this->doHash(id); FW_ASSERT(index < TLMPACKETIZER_HASH_BUCKETS); TlmEntry* entryToUse = nullptr; TlmEntry* prevEntry = nullptr; // Search to see if channel has already been stored or a bucket needs to be added if (this->m_tlmEntries.slots[index]) { entryToUse = this->m_tlmEntries.slots[index]; for (NATIVE_UINT_TYPE bucket = 0; bucket < TLMPACKETIZER_HASH_BUCKETS; bucket++) { if (entryToUse) { if (entryToUse->id == id) { // found the matching entry break; } else { // try next entry prevEntry = entryToUse; entryToUse = entryToUse->next; } } else { // Make sure that we haven't run out of buckets FW_ASSERT(this->m_tlmEntries.free < TLMPACKETIZER_HASH_BUCKETS, this->m_tlmEntries.free); // add new bucket from free list entryToUse = &this->m_tlmEntries.buckets[this->m_tlmEntries.free++]; // Coverity warning about null dereference - see if it happens FW_ASSERT(prevEntry); prevEntry->next = entryToUse; // clear next pointer entryToUse->next = nullptr; // set all packet offsets to -1 for new entry for (NATIVE_UINT_TYPE pktOffsetEntry = 0; pktOffsetEntry < MAX_PACKETIZER_PACKETS; pktOffsetEntry++) { entryToUse->packetOffset[pktOffsetEntry] = -1; } break; } } } else { // Make sure that we haven't run out of buckets FW_ASSERT(this->m_tlmEntries.free < TLMPACKETIZER_HASH_BUCKETS, this->m_tlmEntries.free); // create new entry at slot head this->m_tlmEntries.slots[index] = &this->m_tlmEntries.buckets[this->m_tlmEntries.free++]; entryToUse = this->m_tlmEntries.slots[index]; entryToUse->next = nullptr; // set all packet offsets to -1 for new entry for (NATIVE_UINT_TYPE pktOffsetEntry = 0; pktOffsetEntry < MAX_PACKETIZER_PACKETS; pktOffsetEntry++) { entryToUse->packetOffset[pktOffsetEntry] = -1; } } return entryToUse; } // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- void TlmPacketizer ::TlmRecv_handler(const NATIVE_INT_TYPE portNum, FwChanIdType id, Fw::Time& timeTag, Fw::TlmBuffer& val) { FW_ASSERT(this->m_configured); // get hash value for id NATIVE_UINT_TYPE index = this->doHash(id); TlmEntry* entryToUse = nullptr; // Search to see if the channel is being sent entryToUse = this->m_tlmEntries.slots[index]; // if no entries at hash, channel not part of a packet or is not ignored if (not entryToUse) { this->missingChannel(id); return; } for (NATIVE_UINT_TYPE bucket = 0; bucket < TLMPACKETIZER_HASH_BUCKETS; bucket++) { if (entryToUse) { if (entryToUse->id == id) { // found the matching entry // check to see if the channel is ignored. If so, just return. if (entryToUse->ignored) { return; } break; } else { // try next entry entryToUse = entryToUse->next; } } else { // telemetry channel not in any packets this->missingChannel(id); return; } } // copy telemetry value into active buffers for (NATIVE_UINT_TYPE pkt = 0; pkt < MAX_PACKETIZER_PACKETS; pkt++) { // check if current packet has this channel if (entryToUse->packetOffset[pkt] != -1) { // get destination address // printf("PK %d CH: %d\n",this->m_fillBuffers[pkt].id,id); this->m_lock.lock(); this->m_fillBuffers[pkt].updated = true; this->m_fillBuffers[pkt].latestTime = timeTag; U8* ptr = &this->m_fillBuffers[pkt].buffer.getBuffAddr()[entryToUse->packetOffset[pkt]]; memcpy(ptr, val.getBuffAddr(), val.getBuffLength()); this->m_lock.unLock(); } } } void TlmPacketizer ::Run_handler(const NATIVE_INT_TYPE portNum, U32 context) { FW_ASSERT(this->m_configured); // Only write packets if connected if (not this->isConnected_PktSend_OutputPort(0)) { return; } // lock mutex long enough to modify active telemetry buffer // so the data can be read without worrying about updates this->m_lock.lock(); // copy buffers from fill side to send side for (NATIVE_UINT_TYPE pkt = 0; pkt < this->m_numPackets; pkt++) { if ((this->m_fillBuffers[pkt].updated) and ((this->m_fillBuffers[pkt].level <= this->m_startLevel) or (this->m_fillBuffers[pkt].requested))) { this->m_sendBuffers[pkt] = this->m_fillBuffers[pkt]; if (PACKET_UPDATE_ON_CHANGE == PACKET_UPDATE_MODE) { this->m_fillBuffers[pkt].updated = false; } this->m_fillBuffers[pkt].requested = false; // PACKET_UPDATE_AFTER_FIRST_CHANGE will be this case - updated flag will not be cleared } else if ((PACKET_UPDATE_ALWAYS == PACKET_UPDATE_MODE) and (this->m_fillBuffers[pkt].level <= this->m_startLevel)) { this->m_sendBuffers[pkt] = this->m_fillBuffers[pkt]; this->m_sendBuffers[pkt].updated = true; } else { this->m_sendBuffers[pkt].updated = false; } } this->m_lock.unLock(); // push all updated packet buffers for (NATIVE_UINT_TYPE pkt = 0; pkt < this->m_numPackets; pkt++) { if (this->m_sendBuffers[pkt].updated) { // serialize time into time offset in packet Fw::ExternalSerializeBuffer buff( &this->m_sendBuffers[pkt] .buffer.getBuffAddr()[sizeof(FwPacketDescriptorType) + sizeof(FwTlmPacketizeIdType)], Fw::Time::SERIALIZED_SIZE); Fw::SerializeStatus stat = buff.serialize(this->m_sendBuffers[pkt].latestTime); FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, stat); this->PktSend_out(0, this->m_sendBuffers[pkt].buffer, 0); } } } void TlmPacketizer ::pingIn_handler(const NATIVE_INT_TYPE portNum, U32 key) { // return key this->pingOut_out(0, key); } // ---------------------------------------------------------------------- // Command handler implementations // ---------------------------------------------------------------------- void TlmPacketizer ::SET_LEVEL_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq, U32 level) { this->m_startLevel = level; if (level > this->m_maxLevel) { this->log_WARNING_LO_MaxLevelExceed(level, this->m_maxLevel); } this->tlmWrite_SendLevel(level); this->log_ACTIVITY_HI_LevelSet(level); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } void TlmPacketizer ::SEND_PKT_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq, U32 id) { NATIVE_UINT_TYPE pkt = 0; for (pkt = 0; pkt < this->m_numPackets; pkt++) { if (this->m_fillBuffers[pkt].id == id) { this->m_lock.lock(); this->m_fillBuffers[pkt].updated = true; this->m_fillBuffers[pkt].latestTime = this->getTime(); this->m_fillBuffers[pkt].requested = true; this->m_lock.unLock(); this->log_ACTIVITY_LO_PacketSent(id); break; } } // couldn't find it if (pkt == this->m_numPackets) { log_WARNING_LO_PacketNotFound(id); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR); return; } this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } NATIVE_UINT_TYPE TlmPacketizer::doHash(FwChanIdType id) { return (id % TLMPACKETIZER_HASH_MOD_VALUE) % TLMPACKETIZER_NUM_TLM_HASH_SLOTS; } void TlmPacketizer::missingChannel(FwChanIdType id) { // search to see if missing channel has already been sent for (NATIVE_UINT_TYPE slot = 0; slot < TLMPACKETIZER_MAX_MISSING_TLM_CHECK; slot++) { // if it's been checked, return if (this->m_missTlmCheck[slot].checked and (this->m_missTlmCheck[slot].id == id)) { return; } else if (not this->m_missTlmCheck[slot].checked) { this->m_missTlmCheck[slot].checked = true; this->m_missTlmCheck[slot].id = id; this->log_WARNING_LO_NoChan(id); return; } } } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/TlmPacketizer/test/ut/main.cpp
// \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include <gtest/gtest.h> #include <Fw/Test/UnitTest.hpp> #include "TlmPacketizerTester.hpp" TEST(TestNominal, Initialization) { TEST_CASE(100.1.1, "Initialization"); Svc::TlmPacketizerTester tester; tester.initTest(); } TEST(TestNominal, PushTlm) { TEST_CASE(100.1.2, "Push Telemetry"); Svc::TlmPacketizerTester tester; tester.pushTlmTest(); } TEST(TestNominal, SendPackets) { TEST_CASE(100.1.2, "Send Packets"); Svc::TlmPacketizerTester tester; tester.sendPacketsTest(); } // TEST(TestNominal,SendPacketLevels) { // // TEST_CASE(100.1.3,"Send Packets with levels"); // Svc::TlmPacketizerTester tester; // tester.sendPacketLevelsTest(); // } TEST(TestNominal, UpdatePacketsTest) { TEST_CASE(100.1.4, "Update Packets"); Svc::TlmPacketizerTester tester; tester.updatePacketsTest(); } TEST(TestNominal, PingTest) { TEST_CASE(100.1.5, "Ping"); Svc::TlmPacketizerTester tester; tester.pingTest(); } TEST(TestNominal, IgnoredChannelTest) { TEST_CASE(100.1.6, "Ignored Channels"); Svc::TlmPacketizerTester tester; tester.ignoreTest(); } TEST(TestNominal, SendPacketTest) { TEST_CASE(100.1.7, "Manually sent packets"); Svc::TlmPacketizerTester tester; tester.sendManualPacketTest(); } #if 0 TEST(TestNominal,SetPacketLevelTest) { TEST_CASE(100.1.78,"Set packet level"); Svc::TlmPacketizerTester tester; tester.setPacketLevelTest(); } #endif TEST(TestOffNominal, NonPacketizedChannelTest) { TEST_CASE(100.2.1, "Non-packetized Channels"); Svc::TlmPacketizerTester tester; tester.nonPacketizedChannelTest(); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
cpp
fprime
data/projects/fprime/Svc/TlmPacketizer/test/ut/TlmPacketizerTester.hpp
// ====================================================================== // \title TlmPacketizer/test/ut/Tester.hpp // \author tcanham // \brief hpp file for TlmPacketizer test harness implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef TESTER_HPP #define TESTER_HPP #include "TlmPacketizerGTestBase.hpp" #include "Svc/TlmPacketizer/TlmPacketizer.hpp" namespace Svc { class TlmPacketizerTester : public TlmPacketizerGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: //! Construct object TlmPacketizerTester //! TlmPacketizerTester(void); //! Destroy object TlmPacketizerTester //! ~TlmPacketizerTester(void); public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! Initialization test //! void initTest(void); //! push telemetry test //! void pushTlmTest(void); //! send packets test //! void sendPacketsTest(void); //! send packets with levels test //! void sendPacketLevelsTest(void); //! update packets test //! void updatePacketsTest(void); //! non-packetized channel test //! void nonPacketizedChannelTest(void); //! ping test //! void pingTest(void); //! ignore test //! void ignoreTest(void); //! manually send packet test //! void sendManualPacketTest(void); //! set packet level test //! void setPacketLevelTest(void); private: // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- //! Handler for from_PktSend //! void from_PktSend_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::ComBuffer& data, /*!< Buffer containing packet data*/ U32 context /*!< Call context value; meaning chosen by user*/ ) override; //! Handler for from_pingOut //! void from_pingOut_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 key /*!< Value to return to pinger*/ ) override; virtual void textLogIn(const FwEventIdType id, /*!< The event ID*/ const Fw::Time& timeTag, /*!< The time*/ const Fw::LogSeverity severity, /*!< The severity*/ const Fw::TextLogString& text /*!< The event string*/ ) override; private: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(void); //! Initialize components //! void initComponents(void); private: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! TlmPacketizer component; Fw::Time m_testTime; //!< store test time for packets }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/TlmPacketizer/test/ut/TlmPacketizerTester.cpp
// ====================================================================== // \title TlmPacketizer.hpp // \author tcanham // \brief cpp file for TlmPacketizer test harness implementation class // // \copyright // Copyright 2009-2021, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "TlmPacketizerTester.hpp" #define INSTANCE 0 #define MAX_HISTORY_SIZE 10 #define QUEUE_DEPTH 10 #include <Fw/Com/ComPacket.hpp> namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- TlmPacketizerTester ::TlmPacketizerTester() : TlmPacketizerGTestBase("Tester", MAX_HISTORY_SIZE), component("TlmPacketizer") { this->initComponents(); this->connectPorts(); } TlmPacketizerTester ::~TlmPacketizerTester() {} // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- // Some Test tables TlmPacketizerChannelEntry packet1List[] = {{10, 4}, {100, 2}, {333, 1}}; TlmPacketizerChannelEntry packet2List[] = {{10, 4}, {13, 8}, {250, 2}, {22, 1}}; TlmPacketizerPacket packet1 = {packet1List, 4, 1, FW_NUM_ARRAY_ELEMENTS(packet1List)}; TlmPacketizerPacket packet2 = {packet2List, 8, 2, FW_NUM_ARRAY_ELEMENTS(packet2List)}; TlmPacketizerPacketList packetList = {{&packet1, &packet2}, 2}; TlmPacketizerChannelEntry ignoreList[] = {{25, 0}, {50, 0}}; TlmPacketizerPacket ignore = {ignoreList, 0, 0, FW_NUM_ARRAY_ELEMENTS(ignoreList)}; void TlmPacketizerTester ::initTest() { this->component.setPacketList(packetList, ignore, 2); } void TlmPacketizerTester ::pushTlmTest() { this->component.setPacketList(packetList, ignore, 2); Fw::Time ts; Fw::TlmBuffer buff; // first channel ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U32>(20))); this->invoke_to_TlmRecv(0, 10, ts, buff); buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(15))); this->invoke_to_TlmRecv(0, 100, ts, buff); buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(14))); this->invoke_to_TlmRecv(0, 333, ts, buff); // second channel ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U32>(50))); this->invoke_to_TlmRecv(0, 10, ts, buff); buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U64>(1000000))); this->invoke_to_TlmRecv(0, 13, ts, buff); buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(1010))); this->invoke_to_TlmRecv(0, 250, ts, buff); buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(15))); this->invoke_to_TlmRecv(0, 22, ts, buff); } void TlmPacketizerTester ::sendPacketsTest() { this->component.setPacketList(packetList, ignore, 2); Fw::Time ts; Fw::TlmBuffer buff; // first channel ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U32>(20))); this->invoke_to_TlmRecv(0, 10, ts, buff); // second channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(15))); this->invoke_to_TlmRecv(0, 100, ts, buff); // third channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(14))); this->invoke_to_TlmRecv(0, 333, ts, buff); // fifth channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U64>(1000000))); this->invoke_to_TlmRecv(0, 13, ts, buff); // sixth channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(1010))); this->invoke_to_TlmRecv(0, 250, ts, buff); // seventh channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(15))); this->invoke_to_TlmRecv(0, 22, ts, buff); this->setTestTime(this->m_testTime); // run scheduler port to send packets this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_FROM_PORT_HISTORY_SIZE(2); ASSERT_from_PktSend_SIZE(2); // construct the packet buffers and make sure they are correct Fw::ComBuffer comBuff; ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(this->m_testTime)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(15))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(14))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(this->m_testTime)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(1000000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(1010))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(15))); ASSERT_from_PktSend(1, comBuff, static_cast<U32>(0)); } void TlmPacketizerTester ::sendPacketLevelsTest() { this->component.setPacketList(packetList, ignore, 1); Fw::Time ts; Fw::TlmBuffer buff; // first channel ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U32>(20))); this->invoke_to_TlmRecv(0, 10, ts, buff); // second channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(15))); this->invoke_to_TlmRecv(0, 100, ts, buff); // third channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(14))); this->invoke_to_TlmRecv(0, 333, ts, buff); // fifth channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U64>(1000000))); this->invoke_to_TlmRecv(0, 13, ts, buff); // sixth channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(1010))); this->invoke_to_TlmRecv(0, 250, ts, buff); // seventh channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(15))); this->invoke_to_TlmRecv(0, 22, ts, buff); this->setTestTime(this->m_testTime); // run scheduler port to send packets this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_FROM_PORT_HISTORY_SIZE(2); ASSERT_from_PktSend_SIZE(2); // construct the packet buffers and make sure they are correct Fw::ComBuffer comBuff; ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(this->m_testTime)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(15))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(14))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(this->m_testTime)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(1000000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(1010))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(15))); ASSERT_from_PktSend(1, comBuff, static_cast<U32>(0)); } void TlmPacketizerTester ::updatePacketsTest() { this->component.setPacketList(packetList, ignore, 2); Fw::Time ts; Fw::TlmBuffer buff; Fw::ComBuffer comBuff; // Initially no packets should be pushed this->invoke_to_Run(0, 0); this->component.doDispatch(); // Should be no packets pushed ASSERT_from_PktSend_SIZE(0); // first channel ts.set(100, 1000); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U32>(20))); this->invoke_to_TlmRecv(0, 10, ts, buff); this->m_testTime.add(1, 0); this->setTestTime(this->m_testTime); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(2); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(0))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(0))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(0))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(0))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(0))); ASSERT_from_PktSend(1, comBuff, static_cast<U32>(0)); // second channel buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(15))); this->invoke_to_TlmRecv(0, 100, ts, buff); this->m_testTime.add(1, 0); this->setTestTime(this->m_testTime); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); // only one should be pushed ASSERT_from_PktSend_SIZE(1); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(15))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(0))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(14))); this->invoke_to_TlmRecv(0, 333, ts, buff); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); // only one should be pushed ASSERT_from_PktSend_SIZE(1); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(15))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(14))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U64>(1000000))); this->invoke_to_TlmRecv(0, 13, ts, buff); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(1); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(1000000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(0))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(0))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(1010))); this->invoke_to_TlmRecv(0, 250, ts, buff); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(1); comBuff.resetSer(); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(1000000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(1010))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(0))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(15))); this->invoke_to_TlmRecv(0, 22, ts, buff); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(1); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(1000000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(1010))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(15))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); //** Update all the packets again with new values // first channel buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U32>(1000))); this->invoke_to_TlmRecv(0, 10, ts, buff); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(2); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(1000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(15))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(14))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(1000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(1000000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(1010))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(15))); ASSERT_from_PktSend(1, comBuff, static_cast<U32>(0)); // second channel buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(550))); this->invoke_to_TlmRecv(0, 100, ts, buff); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(1); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(1000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(550))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(14))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(211))); this->invoke_to_TlmRecv(0, 333, ts, buff); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(1); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(1000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(550))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(211))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U64>(34441))); this->invoke_to_TlmRecv(0, 13, ts, buff); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(1); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(1000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(34441))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(1010))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(15))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(8649))); this->invoke_to_TlmRecv(0, 250, ts, buff); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(1); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(1000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(34441))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(8649))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(15))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(65))); this->invoke_to_TlmRecv(0, 22, ts, buff); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(1); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(1000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(34441))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(8649))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(65))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); } void TlmPacketizerTester ::ignoreTest() { this->component.setPacketList(packetList, ignore, 2); Fw::Time ts; Fw::TlmBuffer buff; Fw::ComBuffer comBuff; // Initially no packets should be pushed this->invoke_to_Run(0, 0); this->component.doDispatch(); // Should be no packets pushed ASSERT_from_PktSend_SIZE(0); // first channel ts.set(100, 1000); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U32>(20))); this->invoke_to_TlmRecv(0, 10, ts, buff); this->m_testTime.add(1, 0); this->setTestTime(this->m_testTime); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(2); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(0))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(0))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(ts)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(0))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(0))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(0))); ASSERT_from_PktSend(1, comBuff, static_cast<U32>(0)); // ignored channel buff.resetSer(); ts.add(1, 0); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(20))); this->invoke_to_TlmRecv(0, 25, ts, buff); this->m_testTime.add(1, 0); this->setTestTime(this->m_testTime); this->clearFromPortHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); // no packets should be pushed ASSERT_from_PktSend_SIZE(0); } void TlmPacketizerTester ::sendManualPacketTest() { this->component.setPacketList(packetList, ignore, 2); Fw::Time ts; Fw::TlmBuffer buff; // first channel ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U32>(20))); this->invoke_to_TlmRecv(0, 10, ts, buff); // second channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(15))); this->invoke_to_TlmRecv(0, 100, ts, buff); // third channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(14))); this->invoke_to_TlmRecv(0, 333, ts, buff); // fifth channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U64>(1000000))); this->invoke_to_TlmRecv(0, 13, ts, buff); // sixth channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(1010))); this->invoke_to_TlmRecv(0, 250, ts, buff); // seventh channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(15))); this->invoke_to_TlmRecv(0, 22, ts, buff); this->setTestTime(this->m_testTime); // run scheduler port to send packets this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_FROM_PORT_HISTORY_SIZE(2); ASSERT_from_PktSend_SIZE(2); // construct the packet buffers and make sure they are correct Fw::ComBuffer comBuff1; ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(this->m_testTime)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(static_cast<U16>(15))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(static_cast<U8>(14))); ASSERT_from_PktSend(0, comBuff1, static_cast<U32>(0)); Fw::ComBuffer comBuff2; ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff2.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff2.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff2.serialize(this->m_testTime)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff2.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff2.serialize(static_cast<U64>(1000000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff2.serialize(static_cast<U16>(1010))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff2.serialize(static_cast<U8>(15))); ASSERT_from_PktSend(1, comBuff2, static_cast<U32>(0)); // should not be any new packets this->clearHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_FROM_PORT_HISTORY_SIZE(0); ASSERT_from_PktSend_SIZE(0); // send command to manually send a packet this->sendCmd_SEND_PKT(0, 12, 4); this->component.doDispatch(); ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_PacketSent(0, 4); ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE(0, TlmPacketizerComponentBase::OPCODE_SEND_PKT, 12, Fw::CmdResponse::OK); // dispatch run call to send packet this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(1); ASSERT_from_PktSend(0, comBuff1, static_cast<U32>(0)); // another packet this->clearHistory(); this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_FROM_PORT_HISTORY_SIZE(0); ASSERT_from_PktSend_SIZE(0); // send command to manually send a packet this->clearHistory(); this->sendCmd_SEND_PKT(0, 12, 8); this->component.doDispatch(); ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_PacketSent(0, 8); ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE(0, TlmPacketizerComponentBase::OPCODE_SEND_PKT, 12, Fw::CmdResponse::OK); // dispatch run call to send packet this->invoke_to_Run(0, 0); this->component.doDispatch(); ASSERT_from_PktSend_SIZE(1); ASSERT_from_PktSend(0, comBuff2, static_cast<U32>(0)); // Try to send invalid packet // send command to manually send a packet this->clearHistory(); this->sendCmd_SEND_PKT(0, 12, 20); this->component.doDispatch(); ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_PacketNotFound(0, 20); ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE(0, TlmPacketizerComponentBase::OPCODE_SEND_PKT, 12, Fw::CmdResponse::VALIDATION_ERROR); } void TlmPacketizerTester ::setPacketLevelTest() { this->component.setPacketList(packetList, ignore, 0); Fw::Time ts; Fw::TlmBuffer buff; // first channel ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U32>(0x20))); this->invoke_to_TlmRecv(0, 10, ts, buff); // second channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(0x15))); this->invoke_to_TlmRecv(0, 100, ts, buff); // third channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(0x14))); this->invoke_to_TlmRecv(0, 333, ts, buff); // fifth channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U64>(0x1000000))); this->invoke_to_TlmRecv(0, 13, ts, buff); // sixth channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(0x1010))); this->invoke_to_TlmRecv(0, 250, ts, buff); // seventh channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(0x15))); this->invoke_to_TlmRecv(0, 22, ts, buff); this->setTestTime(this->m_testTime); // run scheduler port to send packets this->invoke_to_Run(0, 0); this->component.doDispatch(); // should be no packets sent since packet level is 0 ASSERT_FROM_PORT_HISTORY_SIZE(0); ASSERT_from_PktSend_SIZE(0); // send the command to select packet level 1 this->clearHistory(); this->sendCmd_SET_LEVEL(0, 13, 1); this->component.doDispatch(); ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_LevelSet_SIZE(1); ASSERT_EVENTS_LevelSet(0, 1); ASSERT_TLM_SIZE(1); ASSERT_TLM_SendLevel_SIZE(1); ASSERT_TLM_SendLevel(0, 1); // send the packets // first channel ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U32>(0x20))); this->invoke_to_TlmRecv(0, 10, ts, buff); // second channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(0x15))); this->invoke_to_TlmRecv(0, 100, ts, buff); // third channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(0x14))); this->invoke_to_TlmRecv(0, 333, ts, buff); // fifth channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U64>(0x1000000))); this->invoke_to_TlmRecv(0, 13, ts, buff); // sixth channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U16>(0x1010))); this->invoke_to_TlmRecv(0, 250, ts, buff); // seventh channel buff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, buff.serialize(static_cast<U8>(0x15))); this->invoke_to_TlmRecv(0, 22, ts, buff); this->setTestTime(this->m_testTime); // run scheduler port to send packets this->invoke_to_Run(0, 0); this->component.doDispatch(); // should be one packet sent since packet level is 1 ASSERT_FROM_PORT_HISTORY_SIZE(1); ASSERT_from_PktSend_SIZE(1); // Should be packet 4 Fw::ComBuffer comBuff1; ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(this->m_testTime)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(static_cast<U32>(0x20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(static_cast<U16>(0x15))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff1.serialize(static_cast<U8>(0x14))); ASSERT_from_PktSend(0, comBuff1, static_cast<U32>(0)); return; ASSERT_FROM_PORT_HISTORY_SIZE(2); ASSERT_from_PktSend_SIZE(2); // construct the packet buffers and make sure they are correct Fw::ComBuffer comBuff; ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(4))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(this->m_testTime)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(15))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(14))); ASSERT_from_PktSend(0, comBuff, static_cast<U32>(0)); comBuff.resetSer(); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_PACKETIZED_TLM))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<FwTlmPacketizeIdType>(8))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(this->m_testTime)); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U32>(20))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U64>(1000000))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U16>(1010))); ASSERT_EQ(Fw::FW_SERIALIZE_OK, comBuff.serialize(static_cast<U8>(15))); ASSERT_from_PktSend(1, comBuff, static_cast<U32>(0)); } void TlmPacketizerTester ::nonPacketizedChannelTest() { this->component.setPacketList(packetList, ignore, 2); Fw::Time ts; Fw::TlmBuffer buff; // start at non-used channel for (NATIVE_UINT_TYPE channel = 1000; channel < 1000 + TLMPACKETIZER_MAX_MISSING_TLM_CHECK; channel++) { this->clearEvents(); this->invoke_to_TlmRecv(0, channel, ts, buff); ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_NoChan_SIZE(1); ASSERT_EVENTS_NoChan(0, channel); } // One more channel should not emit event this->clearEvents(); this->invoke_to_TlmRecv(0, 1000 + TLMPACKETIZER_MAX_MISSING_TLM_CHECK, ts, buff); ASSERT_EVENTS_SIZE(0); ASSERT_EVENTS_NoChan_SIZE(0); // sending the missing channels again should emit no events for (NATIVE_UINT_TYPE channel = 1000; channel < 1000 + TLMPACKETIZER_MAX_MISSING_TLM_CHECK; channel++) { this->clearEvents(); this->invoke_to_TlmRecv(0, channel, ts, buff); ASSERT_EVENTS_SIZE(0); ASSERT_EVENTS_NoChan_SIZE(0); } } void TlmPacketizerTester ::pingTest() { this->component.setPacketList(packetList, ignore, 2); // ping component this->clearFromPortHistory(); this->invoke_to_pingIn(0, static_cast<U32>(0x1234)); this->component.doDispatch(); ASSERT_from_pingOut_SIZE(1); ASSERT_from_pingOut(0, static_cast<U32>(0x1234)); } // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- void TlmPacketizerTester ::from_PktSend_handler(const NATIVE_INT_TYPE portNum, Fw::ComBuffer& data, U32 context) { this->pushFromPortEntry_PktSend(data, context); } void TlmPacketizerTester ::from_pingOut_handler(const NATIVE_INT_TYPE portNum, U32 key) { this->pushFromPortEntry_pingOut(key); } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void TlmPacketizerTester ::connectPorts() { // PktSend this->component.set_PktSend_OutputPort(0, this->get_from_PktSend(0)); // Run this->connect_to_Run(0, this->component.get_Run_InputPort(0)); // TlmRecv this->connect_to_TlmRecv(0, this->component.get_TlmRecv_InputPort(0)); // cmdIn this->connect_to_cmdIn(0, this->component.get_cmdIn_InputPort(0)); // cmdRegOut this->component.set_cmdRegOut_OutputPort(0, this->get_from_cmdRegOut(0)); // cmdResponseOut this->component.set_cmdResponseOut_OutputPort(0, this->get_from_cmdResponseOut(0)); // eventOut this->component.set_eventOut_OutputPort(0, this->get_from_eventOut(0)); // pingIn this->connect_to_pingIn(0, this->component.get_pingIn_InputPort(0)); // pingOut this->component.set_pingOut_OutputPort(0, this->get_from_pingOut(0)); // textEventOut this->component.set_textEventOut_OutputPort(0, this->get_from_textEventOut(0)); // timeGetOut this->component.set_timeGetOut_OutputPort(0, this->get_from_timeGetOut(0)); // tlmOut this->component.set_tlmOut_OutputPort(0, this->get_from_tlmOut(0)); } void TlmPacketizerTester::textLogIn(const FwEventIdType id, //!< The event ID const Fw::Time& timeTag, //!< The time const Fw::LogSeverity severity, //!< The severity const Fw::TextLogString& text //!< The event string ) { TextLogEntry e = {id, timeTag, severity, text}; printTextLogHistoryEntry(e, stdout); } void TlmPacketizerTester ::initComponents() { this->init(); this->component.init(QUEUE_DEPTH, INSTANCE); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/StaticMemory/StaticMemoryComponentImpl.hpp
// ====================================================================== // \title StaticMemoryComponentImpl.hpp // \author mstarch // \brief hpp file for StaticMemory component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef StaticMemory_HPP #define StaticMemory_HPP #include "StaticMemoryConfig.hpp" #include "Svc/StaticMemory/StaticMemoryComponentAc.hpp" namespace Svc { class StaticMemoryComponentImpl : public StaticMemoryComponentBase { public: // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Construct object StaticMemory //! StaticMemoryComponentImpl(const char* const compName /*!< The component name*/ ); //! Initialize object StaticMemory //! void init(const NATIVE_INT_TYPE instance = 0 /*!< The instance number*/ ); //! Destroy object StaticMemory //! ~StaticMemoryComponentImpl(); PRIVATE: // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- //! Handler implementation for bufferDeallocate //! void bufferDeallocate_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::Buffer& fwBuffer); //! Handler implementation for bufferAllocate //! Fw::Buffer bufferAllocate_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 size); bool m_allocated[NUM_BUFFERALLOCATE_INPUT_PORTS]; U8 m_static_memory[NUM_BUFFERALLOCATE_INPUT_PORTS][STATIC_MEMORY_ALLOCATION_SIZE]; }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/StaticMemory/StaticMemory.hpp
// ====================================================================== // StaticMemory.hpp // Standardization header for StaticMemory // ====================================================================== #ifndef Svc_StaticMemory_HPP #define Svc_StaticMemory_HPP #include "Svc/StaticMemory/StaticMemoryComponentImpl.hpp" namespace Svc { typedef StaticMemoryComponentImpl StaticMemory; } #endif
hpp
fprime
data/projects/fprime/Svc/StaticMemory/StaticMemoryComponentImpl.cpp
// ====================================================================== // \title StaticMemoryComponentImpl.cpp // \author mstarch // \brief cpp file for StaticMemory component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include <Svc/StaticMemory/StaticMemoryComponentImpl.hpp> #include <FpConfig.hpp> #include "Fw/Types/Assert.hpp" namespace Svc { // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- StaticMemoryComponentImpl ::StaticMemoryComponentImpl(const char* const compName) : StaticMemoryComponentBase(compName) { for (U32 i = 0; i < FW_NUM_ARRAY_ELEMENTS(m_allocated); i++) { m_allocated[i] = false; } } void StaticMemoryComponentImpl ::init(const NATIVE_INT_TYPE instance) { StaticMemoryComponentBase::init(instance); } StaticMemoryComponentImpl ::~StaticMemoryComponentImpl() {} // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- void StaticMemoryComponentImpl ::bufferDeallocate_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) { FW_ASSERT(static_cast<NATIVE_UINT_TYPE>(portNum) < FW_NUM_ARRAY_ELEMENTS(m_static_memory)); FW_ASSERT(m_allocated[portNum], portNum); // It is also an error to deallocate before returning // Check the memory returned is within the region FW_ASSERT(fwBuffer.getData() >= m_static_memory[portNum]); FW_ASSERT((fwBuffer.getData() + fwBuffer.getSize()) <= (m_static_memory[portNum] + sizeof(m_static_memory[0])), fwBuffer.getSize(), sizeof(m_static_memory[0])); m_allocated[portNum] = false; } Fw::Buffer StaticMemoryComponentImpl ::bufferAllocate_handler(const NATIVE_INT_TYPE portNum, U32 size) { FW_ASSERT(static_cast<NATIVE_UINT_TYPE>(portNum) < FW_NUM_ARRAY_ELEMENTS(m_static_memory)); FW_ASSERT(size <= sizeof(m_static_memory[portNum])); // It is a topology error to ask for too much from this component FW_ASSERT(not m_allocated[portNum], portNum); // It is also an error to allocate again before returning m_allocated[portNum] = true; Fw::Buffer buffer(m_static_memory[portNum], sizeof(m_static_memory[0])); return buffer; } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/StaticMemory/test/ut/StaticMemoryMain.cpp
// ---------------------------------------------------------------------- // TestMain.cpp // ---------------------------------------------------------------------- #include "StaticMemoryTester.hpp" TEST(Nominal, BasicAllocation) { Svc::StaticMemoryTester tester; tester.test_allocate(); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
cpp
fprime
data/projects/fprime/Svc/StaticMemory/test/ut/StaticMemoryTester.hpp
// ====================================================================== // \title StaticMemory/test/ut/Tester.hpp // \author mstarch // \brief hpp file for StaticMemory test harness implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef TESTER_HPP #define TESTER_HPP #include <STest/Pick/Pick.hpp> #include "StaticMemoryGTestBase.hpp" #include "Svc/StaticMemory/StaticMemoryComponentImpl.hpp" namespace Svc { class StaticMemoryTester : public StaticMemoryGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: //! Construct object StaticMemoryTester //! StaticMemoryTester(); //! Destroy object StaticMemoryTester //! ~StaticMemoryTester(); public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! Basic allocation and deallocation //! void test_allocate(); private: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(); //! Initialize components //! void initComponents(); private: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! StaticMemoryComponentImpl component; }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/StaticMemory/test/ut/StaticMemoryTester.cpp
// ====================================================================== // \title StaticMemory.hpp // \author mstarch // \brief cpp file for StaticMemory test harness implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "StaticMemoryTester.hpp" #define INSTANCE 0 #define MAX_HISTORY_SIZE 10 namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- StaticMemoryTester :: StaticMemoryTester() : StaticMemoryGTestBase("Tester", MAX_HISTORY_SIZE), component("StaticMemory") { this->initComponents(); this->connectPorts(); } StaticMemoryTester :: ~StaticMemoryTester() { } // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void StaticMemoryTester :: test_allocate() { Fw::Buffer allocations[StaticMemoryComponentBase::NUM_BUFFERALLOCATE_INPUT_PORTS]; for (U32 i = 0; i < StaticMemoryComponentBase::NUM_BUFFERALLOCATE_INPUT_PORTS; i++) { U32 random_size = STest::Pick::lowerUpper(1, StaticMemoryConfig::STATIC_MEMORY_ALLOCATION_SIZE); allocations[i] = invoke_to_bufferAllocate(i, random_size); // Test allocated, correct pointer ASSERT_TRUE(component.m_allocated[i]) << "Did not mark buffer as allocated"; ASSERT_EQ(allocations[i].getData(), component.m_static_memory[i]) << "Sent incorrect buffer"; ASSERT_GE(allocations[i].getSize(), random_size) << "Did not allocate enough"; } for (U32 i = 0; i < StaticMemoryComponentBase::NUM_BUFFERALLOCATE_INPUT_PORTS; i++) { // Set size to zero, and adjust the data pointer to ensure user can modify these values allocations[i].setSize(0); allocations[i].setData(allocations[i].getData() + 1); invoke_to_bufferDeallocate(i, allocations[i]); // Test allocated, correct pointer ASSERT_FALSE(component.m_allocated[i]) << "Did not mark buffer as allocated"; } } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void StaticMemoryTester :: connectPorts() { // bufferDeallocate for (NATIVE_INT_TYPE i = 0; i < StaticMemoryComponentBase::NUM_BUFFERALLOCATE_INPUT_PORTS; ++i) { this->connect_to_bufferDeallocate( i, this->component.get_bufferDeallocate_InputPort(i) ); } // bufferAllocate for (NATIVE_INT_TYPE i = 0; i < StaticMemoryComponentBase::NUM_BUFFERALLOCATE_INPUT_PORTS; ++i) { this->connect_to_bufferAllocate( i, this->component.get_bufferAllocate_InputPort(i) ); } } void StaticMemoryTester :: initComponents() { this->init(); this->component.init( INSTANCE ); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/ComStub/ComStub.hpp
// ====================================================================== // \title ComStub.hpp // \author mstarch // \brief hpp file for ComStub component implementation class // ====================================================================== #ifndef Svc_ComStub_HPP #define Svc_ComStub_HPP #include "Svc/ComStub/ComStubComponentAc.hpp" namespace Svc { class ComStub : public ComStubComponentBase { public: const NATIVE_UINT_TYPE RETRY_LIMIT = 10; // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Construct object ComStub //! ComStub(const char* const compName /*!< The component name*/ ); //! Initialize object ComStub //! void init(const NATIVE_INT_TYPE instance = 0 /*!< The instance number*/ ); //! Destroy object ComStub //! ~ComStub() override; private: // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- //! Handler implementation for comDataIn //! Drv::SendStatus comDataIn_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::Buffer& sendBuffer) override; //! Handler implementation for drvConnected //! void drvConnected_handler(const NATIVE_INT_TYPE portNum) override; //! Handler implementation for drvDataIn //! void drvDataIn_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::Buffer& recvBuffer, const Drv::RecvStatus& recvStatus) override; bool m_reinitialize; //!< Stores if a ready signal is needed on connection }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/ComStub/ComStub.cpp
// ====================================================================== // \title ComStub.cpp // \author mstarch // \brief cpp file for ComStub component implementation class // ====================================================================== #include <Svc/ComStub/ComStub.hpp> #include "Fw/Types/Assert.hpp" #include "Fw/Types/BasicTypes.hpp" namespace Svc { // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- ComStub::ComStub(const char* const compName) : ComStubComponentBase(compName), m_reinitialize(true) {} void ComStub::init(const NATIVE_INT_TYPE instance) { ComStubComponentBase::init(instance); } ComStub::~ComStub() {} // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- Drv::SendStatus ComStub::comDataIn_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& sendBuffer) { FW_ASSERT(!this->m_reinitialize || !this->isConnected_comStatus_OutputPort(0)); // A message should never get here if we need to reinitialize is needed Drv::SendStatus driverStatus = Drv::SendStatus::SEND_RETRY; for (NATIVE_UINT_TYPE i = 0; driverStatus == Drv::SendStatus::SEND_RETRY && i < RETRY_LIMIT; i++) { driverStatus = this->drvDataOut_out(0, sendBuffer); } FW_ASSERT(driverStatus != Drv::SendStatus::SEND_RETRY); // If it is still in retry state, there is no good answer Fw::Success comSuccess = (driverStatus.e == Drv::SendStatus::SEND_OK) ? Fw::Success::SUCCESS : Fw::Success::FAILURE; this->m_reinitialize = driverStatus.e != Drv::SendStatus::SEND_OK; if (this->isConnected_comStatus_OutputPort(0)) { this->comStatus_out(0, comSuccess); } return Drv::SendStatus::SEND_OK; // Always send ok to deframer as it does not handle this anyway } void ComStub::drvConnected_handler(const NATIVE_INT_TYPE portNum) { Fw::Success radioSuccess = Fw::Success::SUCCESS; if (this->isConnected_comStatus_OutputPort(0) && m_reinitialize) { this->m_reinitialize = false; this->comStatus_out(0, radioSuccess); } } void ComStub::drvDataIn_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& recvBuffer, const Drv::RecvStatus& recvStatus) { this->comDataOut_out(0, recvBuffer, recvStatus); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/ComStub/test/ut/ComStubTester.cpp
// ====================================================================== // \title ComStub.hpp // \author mstarch // \brief cpp file for ComStub test harness implementation class // ====================================================================== #include "ComStubTester.hpp" #include <STest/Pick/Pick.hpp> #define INSTANCE 0 #define MAX_HISTORY_SIZE 100 #define RETRIES 3 U8 storage[RETRIES][10240]; namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- ComStubTester ::ComStubTester() : ComStubGTestBase("Tester", MAX_HISTORY_SIZE), m_component("ComStub"), m_send_mode(Drv::SendStatus::SEND_OK), m_retries(0) { this->initComponents(); this->connectPorts(); } ComStubTester ::~ComStubTester() {} // ---------------------------------------------------------------------- // Helpers // ---------------------------------------------------------------------- void ComStubTester ::fill(Fw::Buffer& buffer_to_fill) { U8 size = STest::Pick::lowerUpper(1, sizeof(buffer_to_fill.getSize())); for (U32 i = 0; i < size; i++) { buffer_to_fill.getData()[i] = STest::Pick::any(); } buffer_to_fill.setSize(size); } // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void ComStubTester ::test_initial() { Fw::Success condition = Fw::Success::SUCCESS; invoke_to_drvConnected(0); ASSERT_from_comStatus_SIZE(1); ASSERT_from_comStatus(0, condition); this->fromPortHistory_comStatus->clear(); } void ComStubTester ::test_basic() { this->test_initial(); Fw::Buffer buffer(storage[0], sizeof(storage[0])); Fw::Success condition = Fw::Success::SUCCESS; this->fill(buffer); // Downlink ASSERT_EQ(invoke_to_comDataIn(0, buffer), Drv::SendStatus::SEND_OK); ASSERT_from_drvDataOut_SIZE(1); ASSERT_from_drvDataOut(0, buffer); ASSERT_from_comStatus(0, condition); // Uplink Drv::RecvStatus status = Drv::RecvStatus::RECV_OK; invoke_to_drvDataIn(0, buffer, status); ASSERT_from_comDataOut_SIZE(1); ASSERT_from_comDataOut(0, buffer, status); } void ComStubTester ::test_fail() { this->test_initial(); Fw::Buffer buffer(storage[0], sizeof(storage[0])); this->fill(buffer); Fw::Success condition = Fw::Success::FAILURE; m_send_mode = Drv::SendStatus::SEND_ERROR; // Downlink ASSERT_EQ(invoke_to_comDataIn(0, buffer), Drv::SendStatus::SEND_OK); ASSERT_from_drvDataOut_SIZE(1); ASSERT_from_drvDataOut(0, buffer); ASSERT_from_drvDataOut_SIZE(1); ASSERT_from_comStatus(0, condition); // Uplink Drv::RecvStatus status = Drv::RecvStatus::RECV_ERROR; invoke_to_drvDataIn(0, buffer, status); ASSERT_from_comDataOut_SIZE(1); ASSERT_from_comDataOut(0, buffer, status); } void ComStubTester ::test_retry() { this->test_initial(); Fw::Buffer buffers[RETRIES]; Fw::Success condition = Fw::Success::SUCCESS; m_send_mode = Drv::SendStatus::SEND_RETRY; for (U32 i = 0; i < RETRIES; i++) { buffers[i].setData(storage[i]); buffers[i].setSize(sizeof(storage[i])); buffers[i].setContext(i); this->fill(buffers[i]); invoke_to_comDataIn(0, buffers[i]); ASSERT_from_drvDataOut_SIZE((i + 1) * RETRIES); m_retries = 0; } ASSERT_from_drvDataOut_SIZE(RETRIES * RETRIES); ASSERT_from_comStatus_SIZE(3); for (U32 i = 0; i < RETRIES; i++) { for (U32 j = 0; j < RETRIES; j++) { ASSERT_from_drvDataOut((i * RETRIES) + j, buffers[i]); } ASSERT_from_comStatus(i, condition); } } // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- void ComStubTester ::from_comDataOut_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& recvBuffer, const Drv::RecvStatus& recvStatus) { this->pushFromPortEntry_comDataOut(recvBuffer, recvStatus); } void ComStubTester ::from_comStatus_handler(const NATIVE_INT_TYPE portNum, Fw::Success& condition) { this->pushFromPortEntry_comStatus(condition); } Drv::SendStatus ComStubTester ::from_drvDataOut_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& sendBuffer) { this->pushFromPortEntry_drvDataOut(sendBuffer); m_retries = (m_send_mode == Drv::SendStatus::SEND_RETRY) ? (m_retries + 1) : m_retries; if (m_retries < RETRIES) { return m_send_mode; } return Drv::SendStatus::SEND_OK; } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void ComStubTester ::connectPorts() { // comDataIn this->connect_to_comDataIn(0, this->m_component.get_comDataIn_InputPort(0)); // drvConnected this->connect_to_drvConnected(0, this->m_component.get_drvConnected_InputPort(0)); // drvDataIn this->connect_to_drvDataIn(0, this->m_component.get_drvDataIn_InputPort(0)); // comDataOut this->m_component.set_comDataOut_OutputPort(0, this->get_from_comDataOut(0)); // comStatus this->m_component.set_comStatus_OutputPort(0, this->get_from_comStatus(0)); // drvDataOut this->m_component.set_drvDataOut_OutputPort(0, this->get_from_drvDataOut(0)); } void ComStubTester ::initComponents() { this->init(); this->m_component.init(INSTANCE); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/ComStub/test/ut/ComStubTestMain.cpp
// ---------------------------------------------------------------------- // TestMain.cpp // ---------------------------------------------------------------------- #include "ComStubTester.hpp" TEST(Nominal, Initial) { Svc::ComStubTester tester; tester.test_initial(); } TEST(Nominal, BasicIo) { Svc::ComStubTester tester; tester.test_basic(); } TEST(Nominal, Fail) { Svc::ComStubTester tester; tester.test_fail(); } TEST(OffNominal, Retry) { Svc::ComStubTester tester; tester.test_retry(); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
cpp
fprime
data/projects/fprime/Svc/ComStub/test/ut/ComStubTester.hpp
// ====================================================================== // \title ComStub/test/ut/Tester.hpp // \author mstarch // \brief hpp file for ComStub test harness implementation class // ====================================================================== #ifndef TESTER_HPP #define TESTER_HPP #include "ComStubGTestBase.hpp" #include "Svc/ComStub/ComStub.hpp" namespace Svc { class ComStubTester : public ComStubGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: //! Construct object ComStubTester //! ComStubTester(); //! Destroy object ComStubTester //! ~ComStubTester(); public: //! Buffer to fill with data //! void fill(Fw::Buffer& buffer_to_fill); // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! Test initial READY setup //! void test_initial(); //! Tests the basic input and output of the component //! void test_basic(); //! Tests the basic failure case for the component //! void test_fail(); //! Tests the basic failure retry component //! void test_retry(); private: // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- //! Handler for from_comDataOut //! void from_comDataOut_handler(const NATIVE_INT_TYPE portNum, //!< The port number Fw::Buffer& recvBuffer, const Drv::RecvStatus& recvStatus); //! Handler for from_comStatus //! void from_comStatus_handler(const NATIVE_INT_TYPE portNum, //!< The port number Fw::Success& condition //!< Status of communication state ); //! Handler for from_drvDataOut //! Drv::SendStatus from_drvDataOut_handler(const NATIVE_INT_TYPE portNum, //!< The port number Fw::Buffer& sendBuffer); private: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(); //! Initialize components //! void initComponents(); private: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! ComStub m_component; Drv::SendStatus m_send_mode; //! Send mode U32 m_retries; //! Number of retries to test }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/CmdDispatcher/CommandDispatcher.hpp
// ====================================================================== // CommandDispatcher.hpp // Standardization header for CommandDispatcher // ====================================================================== #ifndef Svc_CommandDispatcher_HPP #define Svc_CommandDispatcher_HPP #include "Svc/CmdDispatcher/CommandDispatcherImpl.hpp" namespace Svc { typedef CommandDispatcherImpl CommandDispatcher; } #endif
hpp
fprime
data/projects/fprime/Svc/CmdDispatcher/CommandDispatcherImpl.hpp
/** * \file * \author T.Canham * \brief Component responsible for dispatching incoming commands to registered components * * \copyright * Copyright 2009-2015, by the California Institute of Technology. * ALL RIGHTS RESERVED. United States Government Sponsorship * acknowledged. * <br /><br /> */ #ifndef COMMANDDISPATCHERIMPL_HPP_ #define COMMANDDISPATCHERIMPL_HPP_ #include <Svc/CmdDispatcher/CommandDispatcherComponentAc.hpp> #include <Os/Mutex.hpp> #include <CommandDispatcherImplCfg.hpp> namespace Svc { //! \class CommandDispatcherImpl //! \brief Command Dispatcher component class //! //! The command dispatcher takes incoming Fw::Com packets that contain //! encoded commands. It extracts the opcode and looks it up in a table //! that is populated by components at registration time. If a component //! is connected to the seqCmdStatus port with the same number //! as the port that submitted the command, the command status will be returned. class CommandDispatcherImpl : public CommandDispatcherComponentBase { public: //! \brief Command Dispatcher constructor //! //! The constructor initializes the state of the component. //! In this component, the opcode dispatch and tracking tables //! are initialized. //! //! \param name the component instance name CommandDispatcherImpl(const char* name); //! \brief Component initialization routine //! //! The initialization function calls the initialization //! routine for the base class. //! //! \param queueDepth the depth of the message queue for the component void init( NATIVE_INT_TYPE queueDepth, /*!< The queue depth*/ NATIVE_INT_TYPE instance /*!< The instance number*/ ); //!< initialization function //! \brief Component destructor //! //! The destructor for this component is empty virtual ~CommandDispatcherImpl(); PROTECTED: PRIVATE: //! \brief component command status handler //! //! The command status handler is called when a component //! reports the completion of a command. //! //! \param portNum the number of the incoming port. //! \param opCode the opcode of the completed command. //! \param cmdSeq the sequence number assigned to the command when it was dispatched //! \param response the completion status of the command void compCmdStat_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdResponse &response); //! \brief component command buffer handler //! //! The command buffer handler is called to submit a new //! command packet to be decoded //! //! \param portNum the number of the incoming port. //! \param data the buffer containing the command. //! \param context a user value returned with the status void seqCmdBuff_handler(NATIVE_INT_TYPE portNum, Fw::ComBuffer &data, U32 context); //! \brief component command registration handler //! //! The command registration handler is called to register //! new opcodes. The port number called is used to indicate //! which port should be used to dispatch the opcode. //! //! \param portNum the number of the incoming port. //! \param opCode the opcode being registered. void compCmdReg_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode); //! \brief component ping handler //! //! The ping handler responds to messages to verify that the task //! is still executing. Will call output ping port //! //! \param portNum the number of the incoming port. //! \param opCode the opcode being registered. //! \param key the key value that is returned with the ping response void pingIn_handler(NATIVE_INT_TYPE portNum, U32 key); //! \brief NO_OP command handler //! //! A test command that does nothing //! //! \param opCode the NO_OP opcode. //! \param cmdSeq the assigned sequence number for the command void CMD_NO_OP_cmdHandler(FwOpcodeType opCode, U32 cmdSeq); //! \brief NO_OP with string command handler //! //! A test command that receives a string and sends an event //! with the string as an argument //! //! \param opCode the NO_OP_STRING opcode. //! \param cmdSeq the assigned sequence number for the command //! \param arg1 the string argument void CMD_NO_OP_STRING_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdStringArg& arg1); //! \brief A test command with different argument types //! //! A test command that receives a set of arguments of different types //! //! \param opCode the TEST_CMD_1 opcode. //! \param cmdSeq the assigned sequence number for the command //! \param arg1 the I32 argument //! \param arg2 the F32 argument //! \param arg3 the U8 argument void CMD_TEST_CMD_1_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, F32 arg2, U8 arg3); //! \brief A command to clear the command tracking //! //! This command will clear the table tracking the completion of commands. //! It is meant to be used if the tracking table has gotten full because of //! a software failure. It is dangerous in that it can clear a command //! that a sequencer is waiting for. //! //! \param opCode the CLEAR_TRACKING opcode. //! \param cmdSeq the assigned sequence number for the command void CMD_CLEAR_TRACKING_cmdHandler(FwOpcodeType opCode, U32 cmdSeq); //! \struct DispatchEntry //! \brief table used to store opcode to port mappings //! //! The DispatchEntry table is used to map incoming opcodes to the port //! connected to the component that implements the opcode. //! As each command opcode is registered, a new entry is found //! in the table by checking for the "used" flag. The opcode //! member is set to the opcode, and the port member set to the //! port to dispatch to. When a new opcode is received for //! execution, the table is traversed until the opcode is located. struct DispatchEntry { bool used; //!< if entry has been used yet U32 opcode; //!< opcode of entry NATIVE_INT_TYPE port; //!< which port the entry invokes } m_entryTable[CMD_DISPATCHER_DISPATCH_TABLE_SIZE]; //!< table of dispatch entries //! \struct SequenceTracker //! \brief table used to store opcode that are being executed //! //! The SequenceTracker table is used to track commands that are being executed //! but are not yet complete. When a new command opcode is received, //! the status port that would be used to report the completion status //! is checked. If it is connected, then an entry is placed in this table. //! The "used" flag is set, and the "seq" member is set to the //! assigned sequence number for the command. The "opCode" field is //! used for the opcode, and the "callerPort" field is used to store //! the port number of the caller so the status can be reported back to //! correct port. struct SequenceTracker { bool used; //!< if this slot is used U32 seq; //!< command sequence number FwOpcodeType opCode; //!< opcode being tracked U32 context; //!< context passed by user NATIVE_INT_TYPE callerPort; //!< port command source port } m_sequenceTracker[CMD_DISPATCHER_SEQUENCER_TABLE_SIZE]; //!< sequence tracking port for command completions; I32 m_seq; //!< current command sequence number U32 m_numCmdsDispatched; //!< number of commands dispatched U32 m_numCmdErrors; //!< number of commands with an error }; } #endif /* COMMANDDISPATCHERIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Svc/CmdDispatcher/CommandDispatcherImpl.cpp
/* * CommandDispatcherImpl.cpp * * Created on: May 13, 2014 * Author: Timothy Canham */ #include <Svc/CmdDispatcher/CommandDispatcherImpl.hpp> #include <Fw/Cmd/CmdPacket.hpp> #include <Fw/Types/Assert.hpp> #include <cstdio> namespace Svc { CommandDispatcherImpl::CommandDispatcherImpl(const char* name) : CommandDispatcherComponentBase(name), m_seq(0), m_numCmdsDispatched(0), m_numCmdErrors(0) { memset(this->m_entryTable,0,sizeof(this->m_entryTable)); memset(this->m_sequenceTracker,0,sizeof(this->m_sequenceTracker)); } CommandDispatcherImpl::~CommandDispatcherImpl() { } void CommandDispatcherImpl::init( NATIVE_INT_TYPE queueDepth, /*!< The queue depth*/ NATIVE_INT_TYPE instance /*!< The instance number*/ ) { CommandDispatcherComponentBase::init(queueDepth); } void CommandDispatcherImpl::compCmdReg_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode) { // search for an empty slot bool slotFound = false; for (U32 slot = 0; slot < FW_NUM_ARRAY_ELEMENTS(this->m_entryTable); slot++) { if ((not this->m_entryTable[slot].used) and (not slotFound)) { this->m_entryTable[slot].opcode = opCode; this->m_entryTable[slot].port = portNum; this->m_entryTable[slot].used = true; this->log_DIAGNOSTIC_OpCodeRegistered(opCode,portNum,slot); slotFound = true; } else if ((this->m_entryTable[slot].used) && (this->m_entryTable[slot].opcode == opCode) && (this->m_entryTable[slot].port == portNum) && (not slotFound)) { slotFound = true; this->log_DIAGNOSTIC_OpCodeReregistered(opCode,portNum); } else if (this->m_entryTable[slot].used) { // make sure no duplicates FW_ASSERT(this->m_entryTable[slot].opcode != opCode, opCode); } } FW_ASSERT(slotFound,opCode); } void CommandDispatcherImpl::compCmdStat_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdResponse &response) { // check response and log if (Fw::CmdResponse::OK == response.e) { this->log_COMMAND_OpCodeCompleted(opCode); } else { this->m_numCmdErrors++; this->tlmWrite_CommandErrors(this->m_numCmdErrors); FW_ASSERT(response.e != Fw::CmdResponse::OK); this->log_COMMAND_OpCodeError(opCode,response); } // look for command source NATIVE_INT_TYPE portToCall = -1; U32 context; for (U32 pending = 0; pending < FW_NUM_ARRAY_ELEMENTS(this->m_sequenceTracker); pending++) { if ( (this->m_sequenceTracker[pending].seq == cmdSeq) && (this->m_sequenceTracker[pending].used) ) { portToCall = this->m_sequenceTracker[pending].callerPort; context = this->m_sequenceTracker[pending].context; FW_ASSERT(opCode == this->m_sequenceTracker[pending].opCode); FW_ASSERT(portToCall < this->getNum_seqCmdStatus_OutputPorts()); this->m_sequenceTracker[pending].used = false; break; } } if (portToCall != -1) { // call port to report status if (this->isConnected_seqCmdStatus_OutputPort(portToCall)) { this->seqCmdStatus_out(portToCall,opCode,context,response); } } } void CommandDispatcherImpl::seqCmdBuff_handler(NATIVE_INT_TYPE portNum, Fw::ComBuffer &data, U32 context) { Fw::CmdPacket cmdPkt; Fw::SerializeStatus stat = cmdPkt.deserialize(data); if (stat != Fw::FW_SERIALIZE_OK) { Fw::DeserialStatus serErr(static_cast<Fw::DeserialStatus::t>(stat)); this->log_WARNING_HI_MalformedCommand(serErr); if (this->isConnected_seqCmdStatus_OutputPort(portNum)) { this->seqCmdStatus_out(portNum,cmdPkt.getOpCode(),context,Fw::CmdResponse::VALIDATION_ERROR); } return; } // search for opcode in dispatch table U32 entry; bool entryFound = false; for (entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_entryTable); entry++) { if ((this->m_entryTable[entry].used) and (cmdPkt.getOpCode() == this->m_entryTable[entry].opcode)) { entryFound = true; break; } } if (entryFound and this->isConnected_compCmdSend_OutputPort(this->m_entryTable[entry].port)) { // register command in command tracker only if response port is connect if (this->isConnected_seqCmdStatus_OutputPort(portNum)) { bool pendingFound = false; for (U32 pending = 0; pending < FW_NUM_ARRAY_ELEMENTS(this->m_sequenceTracker); pending++) { if (not this->m_sequenceTracker[pending].used) { pendingFound = true; this->m_sequenceTracker[pending].used = true; this->m_sequenceTracker[pending].opCode = cmdPkt.getOpCode(); this->m_sequenceTracker[pending].seq = this->m_seq; this->m_sequenceTracker[pending].context = context; this->m_sequenceTracker[pending].callerPort = portNum; break; } } // if we couldn't find a slot to track the command, quit if (not pendingFound) { this->log_WARNING_HI_TooManyCommands(cmdPkt.getOpCode()); if (this->isConnected_seqCmdStatus_OutputPort(portNum)) { this->seqCmdStatus_out(portNum,cmdPkt.getOpCode(),context,Fw::CmdResponse::EXECUTION_ERROR); } return; } } // end if status port connected // pass arguments to argument buffer this->compCmdSend_out(this->m_entryTable[entry].port,cmdPkt.getOpCode(),this->m_seq,cmdPkt.getArgBuffer()); // log dispatched command this->log_COMMAND_OpCodeDispatched(cmdPkt.getOpCode(),this->m_entryTable[entry].port); // increment command count this->m_numCmdsDispatched++; // write telemetry channel for dispatched commands this->tlmWrite_CommandsDispatched(this->m_numCmdsDispatched); } else { this->log_WARNING_HI_InvalidCommand(cmdPkt.getOpCode()); this->m_numCmdErrors++; // Fail command back to port, if connected if (this->isConnected_seqCmdStatus_OutputPort(portNum)) { this->seqCmdStatus_out(portNum,cmdPkt.getOpCode(),context,Fw::CmdResponse::INVALID_OPCODE); } this->tlmWrite_CommandErrors(this->m_numCmdErrors); } // increment sequence number this->m_seq++; } void CommandDispatcherImpl::CMD_NO_OP_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { Fw::LogStringArg no_op_string("Hello, World!"); // Log event for NO_OP here. this->log_ACTIVITY_HI_NoOpReceived(); this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK); } void CommandDispatcherImpl::CMD_NO_OP_STRING_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdStringArg& arg1) { Fw::LogStringArg msg(arg1.toChar()); // Echo the NO_OP_STRING args here. this->log_ACTIVITY_HI_NoOpStringReceived(msg); this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK); } void CommandDispatcherImpl::CMD_TEST_CMD_1_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, I32 arg1, F32 arg2, U8 arg3) { this->log_ACTIVITY_HI_TestCmd1Args(arg1,arg2,arg3); this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK); } void CommandDispatcherImpl::CMD_CLEAR_TRACKING_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { // clear tracking table for (NATIVE_INT_TYPE entry = 0; entry < CMD_DISPATCHER_SEQUENCER_TABLE_SIZE; entry++) { this->m_sequenceTracker[entry].used = false; } this->cmdResponse_out(opCode,cmdSeq,Fw::CmdResponse::OK); } void CommandDispatcherImpl::pingIn_handler(NATIVE_INT_TYPE portNum, U32 key) { // respond to ping this->pingOut_out(0,key); } }
cpp
fprime
data/projects/fprime/Svc/CmdDispatcher/test/ut/CommandDispatcherImplTester.cpp
/* * CommandDispatcherImplTester.cpp * * Created on: Mar 18, 2015 * Author: tcanham */ #include <Svc/CmdDispatcher/test/ut/CommandDispatcherImplTester.hpp> #include <Fw/Com/ComBuffer.hpp> #include <Fw/Com/ComPacket.hpp> #include <Os/IntervalTimer.hpp> #include <cstdio> #include <gtest/gtest.h> #include <Fw/Test/UnitTest.hpp> namespace Svc { void CommandDispatcherImplTester::init(NATIVE_INT_TYPE instance) { CommandDispatcherGTestBase::init(); } CommandDispatcherImplTester::CommandDispatcherImplTester(Svc::CommandDispatcherImpl& inst) : CommandDispatcherGTestBase("testerbase",100), m_impl(inst) { } CommandDispatcherImplTester::~CommandDispatcherImplTester() { } void CommandDispatcherImplTester::from_compCmdSend_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, Fw::CmdArgBuffer &args) { this->m_cmdSendOpCode = opCode; this->m_cmdSendCmdSeq = cmdSeq; this->m_cmdSendArgs = args; this->m_cmdSendRcvd = true; } void CommandDispatcherImplTester::from_seqCmdStatus_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdResponse &response) { this->m_seqStatusRcvd = true; this->m_seqStatusOpCode = opCode; this->m_seqStatusCmdSeq = cmdSeq; this->m_seqStatusCmdResponse = response; } void CommandDispatcherImplTester::runNominalDispatch() { // verify dispatch table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_entryTable); entry++) { ASSERT_TRUE(this->m_impl.m_entryTable[entry].used == false); } // verify sequence tracker table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_sequenceTracker); entry++) { ASSERT_TRUE(this->m_impl.m_sequenceTracker[entry].used == false); } // clear reg events this->clearEvents(); // register built-in commands this->m_impl.regCommands(); // verify registrations ASSERT_TRUE(this->m_impl.m_entryTable[0].used); ASSERT_EQ(this->m_impl.m_entryTable[0].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP); ASSERT_EQ(this->m_impl.m_entryTable[0].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[1].used); ASSERT_EQ(this->m_impl.m_entryTable[1].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING); ASSERT_EQ(this->m_impl.m_entryTable[1].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[2].used); ASSERT_EQ(this->m_impl.m_entryTable[2].opcode,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1); ASSERT_EQ(this->m_impl.m_entryTable[2].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[3].used); ASSERT_EQ(this->m_impl.m_entryTable[3].opcode,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING); ASSERT_EQ(this->m_impl.m_entryTable[3].port,1); // verify event printTextLogHistory(stdout); ASSERT_EVENTS_SIZE(4); ASSERT_EVENTS_OpCodeRegistered_SIZE(4); ASSERT_EVENTS_OpCodeRegistered(0,CommandDispatcherImpl::OPCODE_CMD_NO_OP,1,0); ASSERT_EVENTS_OpCodeRegistered(1,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING,1,1); ASSERT_EVENTS_OpCodeRegistered(2,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1,1,2); ASSERT_EVENTS_OpCodeRegistered(3,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING,1,3); REQUIREMENT("CD-003"); // register our own command FwOpcodeType testOpCode = 0x50; this->clearEvents(); this->invoke_to_compCmdReg(0,0x50); ASSERT_TRUE(this->m_impl.m_entryTable[4].used); ASSERT_EQ(this->m_impl.m_entryTable[4].opcode,testOpCode); ASSERT_EQ(this->m_impl.m_entryTable[4].port,0); // verify registration event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeRegistered_SIZE(1); ASSERT_EVENTS_OpCodeRegistered(0,testOpCode,0,4); // dispatch a test command REQUIREMENT("CD-001"); U32 testCmdArg = 100; U32 testContext = 110; this->clearEvents(); Fw::ComBuffer buff; ASSERT_EQ(buff.serialize(FwPacketDescriptorType(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testOpCode),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testCmdArg),Fw::FW_SERIALIZE_OK); this->invoke_to_seqCmdBuff(0,buff,testContext); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); REQUIREMENT("CD-002"); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeDispatched_SIZE(1); ASSERT_EVENTS_OpCodeDispatched(0,testOpCode,0); // verify sequence table entry ASSERT_TRUE(this->m_impl.m_sequenceTracker[0].used); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].seq, 0u); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].opCode,testOpCode); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].callerPort, 0); // verify command received ASSERT_TRUE(this->m_cmdSendRcvd); ASSERT_EQ(this->m_cmdSendOpCode,testOpCode); ASSERT_EQ(this->m_cmdSendCmdSeq,0); // check argument U32 checkVal; ASSERT_EQ(this->m_cmdSendArgs.deserialize(checkVal),Fw::FW_SERIALIZE_OK); ASSERT_EQ(checkVal,testCmdArg); this->clearEvents(); this->m_seqStatusRcvd = false; // perform command response this->invoke_to_compCmdStat(0,testOpCode,this->m_cmdSendCmdSeq,Fw::CmdResponse::OK); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // Check dispatch table ASSERT_FALSE(this->m_impl.m_sequenceTracker[0].used); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].seq,0u); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].opCode,testOpCode); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].context,testContext); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].callerPort,0); // Verify completed event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeCompleted_SIZE(1); ASSERT_EVENTS_OpCodeCompleted(0u,testOpCode); REQUIREMENT("CD-004"); // Verify status passed back to port ASSERT_TRUE(this->m_seqStatusRcvd); ASSERT_EQ(this->m_seqStatusOpCode,testOpCode); ASSERT_EQ(this->m_seqStatusCmdSeq,testContext); ASSERT_EQ(this->m_seqStatusCmdResponse,Fw::CmdResponse::OK); } void CommandDispatcherImplTester::runNopCommands() { // verify dispatch table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_entryTable); entry++) { ASSERT_TRUE(this->m_impl.m_entryTable[entry].used == false); } // verify sequence tracker table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_sequenceTracker); entry++) { ASSERT_TRUE(this->m_impl.m_sequenceTracker[entry].used == false); } // clear reg events this->clearEvents(); // register built-in commands this->m_impl.regCommands(); // verify registrations ASSERT_TRUE(this->m_impl.m_entryTable[0].used); ASSERT_EQ(this->m_impl.m_entryTable[0].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP); ASSERT_EQ(this->m_impl.m_entryTable[0].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[1].used); ASSERT_EQ(this->m_impl.m_entryTable[1].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING); ASSERT_EQ(this->m_impl.m_entryTable[1].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[2].used); ASSERT_EQ(this->m_impl.m_entryTable[2].opcode,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1); ASSERT_EQ(this->m_impl.m_entryTable[2].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[3].used); ASSERT_EQ(this->m_impl.m_entryTable[3].opcode,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING); ASSERT_EQ(this->m_impl.m_entryTable[3].port,1); // verify event ASSERT_EVENTS_SIZE(4); ASSERT_EVENTS_OpCodeRegistered_SIZE(4); ASSERT_EVENTS_OpCodeRegistered(0,CommandDispatcherImpl::OPCODE_CMD_NO_OP,1,0); ASSERT_EVENTS_OpCodeRegistered(1,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING,1,1); ASSERT_EVENTS_OpCodeRegistered(2,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1,1,2); ASSERT_EVENTS_OpCodeRegistered(3,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING,1,3); // send NO_OP command this->m_seqStatusRcvd = false; Fw::ComBuffer buff; ASSERT_EQ(buff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(static_cast<FwOpcodeType>(CommandDispatcherImpl::OPCODE_CMD_NO_OP)),Fw::FW_SERIALIZE_OK); this->clearEvents(); this->invoke_to_seqCmdBuff(0,buff,12); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeDispatched_SIZE(1); ASSERT_EVENTS_OpCodeDispatched(0,CommandDispatcherImpl::OPCODE_CMD_NO_OP,1); // dispatch for async command ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // dispatch for async command response ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // Verify status passed back to port ASSERT_TRUE(this->m_seqStatusRcvd); ASSERT_EQ(CommandDispatcherImpl::OPCODE_CMD_NO_OP,this->m_seqStatusOpCode); // Verify correct context value is passed back. ASSERT_EQ(12u,this->m_seqStatusCmdSeq); ASSERT_EQ(this->m_seqStatusCmdResponse,Fw::CmdResponse::OK); // send NO_OP_STRING command this->clearEvents(); this->m_seqStatusRcvd = false; buff.resetSer(); ASSERT_EQ(buff.serialize(FwPacketDescriptorType(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(FwOpcodeType(CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING)),Fw::FW_SERIALIZE_OK); // serialize arg1 Fw::CmdStringArg argString("BOO!"); ASSERT_EQ(buff.serialize(argString),Fw::FW_SERIALIZE_OK); this->invoke_to_seqCmdBuff(0,buff,13); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeDispatched_SIZE(1); ASSERT_EVENTS_OpCodeDispatched(0,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING,1); // dispatch for async command ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // dispatch for async command response ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // Verify status passed back to port ASSERT_TRUE(this->m_seqStatusRcvd); ASSERT_EQ(CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING,this->m_seqStatusOpCode); ASSERT_EQ(13u,this->m_seqStatusCmdSeq); ASSERT_EQ(this->m_seqStatusCmdResponse,Fw::CmdResponse::OK); // send TEST_CMD_1 command this->m_seqStatusRcvd = false; buff.resetSer(); ASSERT_EQ(buff.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(static_cast<FwOpcodeType>(CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1)),Fw::FW_SERIALIZE_OK); // serialize arg1 ASSERT_EQ(buff.serialize(static_cast<I32>(1)),Fw::FW_SERIALIZE_OK); // serialize arg2 ASSERT_EQ(buff.serialize(static_cast<F32>(2.3)),Fw::FW_SERIALIZE_OK); // serialize arg3 ASSERT_EQ(buff.serialize(static_cast<U8>(4)),Fw::FW_SERIALIZE_OK); this->clearEvents(); this->invoke_to_seqCmdBuff(0,buff,14); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeDispatched_SIZE(1); ASSERT_EVENTS_OpCodeDispatched(0,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1,1); // dispatch for async command ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // dispatch for async command response ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // Verify status passed back to port ASSERT_TRUE(this->m_seqStatusRcvd); ASSERT_EQ(CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1,this->m_seqStatusOpCode); ASSERT_EQ(14u,this->m_seqStatusCmdSeq); ASSERT_EQ(this->m_seqStatusCmdResponse,Fw::CmdResponse::OK); } void CommandDispatcherImplTester::runCommandReregister() { // register built-in commands this->m_impl.regCommands(); // clear reg events this->clearEvents(); // register our own command FwOpcodeType testOpCode = 0x50; this->invoke_to_compCmdReg(0,0x50); ASSERT_TRUE(this->m_impl.m_entryTable[4].used); ASSERT_EQ(this->m_impl.m_entryTable[4].opcode,testOpCode); ASSERT_EQ(this->m_impl.m_entryTable[4].port,0); // verify registration event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeRegistered_SIZE(1); ASSERT_EVENTS_OpCodeRegistered(0,testOpCode,0,4); // clear reg events this->clearEvents(); // verify we can call cmdReg port again with the same opcode this->invoke_to_compCmdReg(0,0x50); ASSERT_TRUE(this->m_impl.m_entryTable[4].used); ASSERT_EQ(this->m_impl.m_entryTable[4].opcode,testOpCode); ASSERT_EQ(this->m_impl.m_entryTable[4].port,0); // verify re-registration event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeReregistered_SIZE(1); ASSERT_EVENTS_OpCodeReregistered(0,testOpCode,0); } void CommandDispatcherImplTester::runInvalidOpcodeDispatch() { // verify dispatch table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_entryTable); entry++) { ASSERT_TRUE(this->m_impl.m_entryTable[entry].used == false); } // verify sequence tracker table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_sequenceTracker); entry++) { ASSERT_TRUE(this->m_impl.m_sequenceTracker[entry].used == false); } // clear reg events this->clearEvents(); // register built-in commands this->m_impl.regCommands(); // verify registrations ASSERT_TRUE(this->m_impl.m_entryTable[0].used); ASSERT_EQ(this->m_impl.m_entryTable[0].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP); ASSERT_EQ(this->m_impl.m_entryTable[0].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[1].used); ASSERT_EQ(this->m_impl.m_entryTable[1].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING); ASSERT_EQ(this->m_impl.m_entryTable[1].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[2].used); ASSERT_EQ(this->m_impl.m_entryTable[2].opcode,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1); ASSERT_EQ(this->m_impl.m_entryTable[2].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[3].used); ASSERT_EQ(this->m_impl.m_entryTable[3].opcode,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING); ASSERT_EQ(this->m_impl.m_entryTable[3].port,1); // verify event ASSERT_EVENTS_SIZE(4); ASSERT_EVENTS_OpCodeRegistered_SIZE(4); ASSERT_EVENTS_OpCodeRegistered(0,CommandDispatcherImpl::OPCODE_CMD_NO_OP,1,0); ASSERT_EVENTS_OpCodeRegistered(1,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING,1,1); ASSERT_EVENTS_OpCodeRegistered(2,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1,1,2); ASSERT_EVENTS_OpCodeRegistered(3,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING,1,3); // register our own command FwOpcodeType testOpCode = 0x50; this->clearEvents(); this->invoke_to_compCmdReg(0,0x50); ASSERT_TRUE(this->m_impl.m_entryTable[4].used); ASSERT_EQ(this->m_impl.m_entryTable[4].opcode,testOpCode); ASSERT_EQ(this->m_impl.m_entryTable[4].port,0); // verify registration event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeRegistered_SIZE(1); ASSERT_EVENTS_OpCodeRegistered(0,testOpCode,0,4); // dispatch a test command with a bad opcode U32 testCmdArg = 100; U32 testContext = 13; this->clearEvents(); this->m_seqStatusRcvd = false; Fw::ComBuffer buff; ASSERT_EQ(buff.serialize(FwPacketDescriptorType(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(FwOpcodeType(testOpCode + 1)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testCmdArg),Fw::FW_SERIALIZE_OK); this->clearEvents(); this->invoke_to_seqCmdBuff(0,buff,testContext); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_InvalidCommand_SIZE(1); ASSERT_EVENTS_InvalidCommand(0u,testOpCode+1); // Verify status passed back to port ASSERT_TRUE(this->m_seqStatusRcvd); ASSERT_EQ(this->m_seqStatusOpCode,testOpCode+1); ASSERT_EQ(this->m_seqStatusCmdSeq,testContext); ASSERT_EQ(this->m_seqStatusCmdResponse,Fw::CmdResponse::INVALID_OPCODE); } void CommandDispatcherImplTester::runFailedCommand() { // verify dispatch table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_entryTable); entry++) { ASSERT_TRUE(this->m_impl.m_entryTable[entry].used == false); } // verify sequence tracker table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_sequenceTracker); entry++) { ASSERT_TRUE(this->m_impl.m_sequenceTracker[entry].used == false); } // clear reg events this->clearEvents(); // register built-in commands this->m_impl.regCommands(); // verify registrations ASSERT_TRUE(this->m_impl.m_entryTable[0].used); ASSERT_EQ(this->m_impl.m_entryTable[0].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP); ASSERT_EQ(this->m_impl.m_entryTable[0].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[1].used); ASSERT_EQ(this->m_impl.m_entryTable[1].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING); ASSERT_EQ(this->m_impl.m_entryTable[1].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[2].used); ASSERT_EQ(this->m_impl.m_entryTable[2].opcode,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1); ASSERT_EQ(this->m_impl.m_entryTable[2].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[3].used); ASSERT_EQ(this->m_impl.m_entryTable[3].opcode,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING); ASSERT_EQ(this->m_impl.m_entryTable[3].port,1); // verify event ASSERT_EVENTS_SIZE(4); ASSERT_EVENTS_OpCodeRegistered_SIZE(4); ASSERT_EVENTS_OpCodeRegistered(0,CommandDispatcherImpl::OPCODE_CMD_NO_OP,1,0); ASSERT_EVENTS_OpCodeRegistered(1,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING,1,1); ASSERT_EVENTS_OpCodeRegistered(2,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1,1,2); ASSERT_EVENTS_OpCodeRegistered(3,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING,1,3); // register our own command FwOpcodeType testOpCode = 0x50; this->clearEvents(); this->invoke_to_compCmdReg(0,0x50); ASSERT_TRUE(this->m_impl.m_entryTable[4].used); ASSERT_EQ(this->m_impl.m_entryTable[4].opcode,testOpCode); ASSERT_EQ(this->m_impl.m_entryTable[4].port,0); // verify registration event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeRegistered_SIZE(1); ASSERT_EVENTS_OpCodeRegistered(0,testOpCode,0,4); U32 currSeq = 0; // dispatch a test command U32 testCmdArg = 100; U32 testContext = 13; this->clearEvents(); Fw::ComBuffer buff; ASSERT_EQ(buff.serialize(FwPacketDescriptorType(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testOpCode),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testCmdArg),Fw::FW_SERIALIZE_OK); this->invoke_to_seqCmdBuff(0,buff,testContext); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeDispatched_SIZE(1); ASSERT_EVENTS_OpCodeDispatched(0,testOpCode,0); // verify sequence table entry ASSERT_TRUE(this->m_impl.m_sequenceTracker[0].used); ASSERT_EQ(currSeq,this->m_impl.m_sequenceTracker[0].seq); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].opCode,testOpCode); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].context,testContext); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].callerPort,0); // verify command received ASSERT_TRUE(this->m_cmdSendRcvd); ASSERT_EQ(this->m_cmdSendOpCode,testOpCode); ASSERT_EQ(currSeq,this->m_cmdSendCmdSeq); // check argument U32 checkVal; ASSERT_EQ(this->m_cmdSendArgs.deserialize(checkVal),Fw::FW_SERIALIZE_OK); ASSERT_EQ(checkVal,testCmdArg); this->clearEvents(); this->m_seqStatusRcvd = false; // perform command response this->invoke_to_compCmdStat(0,testOpCode,this->m_cmdSendCmdSeq,Fw::CmdResponse::EXECUTION_ERROR); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // Check dispatch table ASSERT_FALSE(this->m_impl.m_sequenceTracker[0].used); ASSERT_EQ(currSeq,this->m_impl.m_sequenceTracker[0].seq); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].opCode,testOpCode); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].callerPort,0); // Verify completed event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeError_SIZE(1); ASSERT_EVENTS_OpCodeError(0,testOpCode, Fw::CmdResponse::EXECUTION_ERROR); // Verify status passed back to port ASSERT_TRUE(this->m_seqStatusRcvd); ASSERT_EQ(this->m_seqStatusCmdSeq,testContext); ASSERT_EQ(this->m_seqStatusCmdResponse,Fw::CmdResponse::EXECUTION_ERROR); // dispatch a test command currSeq++; this->clearEvents(); buff.resetSer(); ASSERT_EQ(buff.serialize(FwPacketDescriptorType(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testOpCode),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testCmdArg),Fw::FW_SERIALIZE_OK); this->invoke_to_seqCmdBuff(0,buff,testContext); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeDispatched_SIZE(1); ASSERT_EVENTS_OpCodeDispatched(0,testOpCode,0); // verify sequence table entry ASSERT_TRUE(this->m_impl.m_sequenceTracker[0].used); ASSERT_EQ(currSeq,this->m_impl.m_sequenceTracker[0].seq); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].opCode,testOpCode); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].context,testContext); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].callerPort,0); // verify command received ASSERT_TRUE(this->m_cmdSendRcvd); ASSERT_EQ(this->m_cmdSendOpCode,testOpCode); ASSERT_EQ(currSeq,this->m_cmdSendCmdSeq); // check argument ASSERT_EQ(this->m_cmdSendArgs.deserialize(checkVal),Fw::FW_SERIALIZE_OK); ASSERT_EQ(checkVal,testCmdArg); this->clearEvents(); this->m_seqStatusRcvd = false; // perform command response this->invoke_to_compCmdStat(0,testOpCode,this->m_cmdSendCmdSeq,Fw::CmdResponse::INVALID_OPCODE); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // Check dispatch table ASSERT_FALSE(this->m_impl.m_sequenceTracker[0].used); ASSERT_EQ(currSeq,this->m_impl.m_sequenceTracker[0].seq); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].opCode,testOpCode); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].callerPort,0); // Verify completed event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeError_SIZE(1); ASSERT_EVENTS_OpCodeError(0,testOpCode,Fw::CmdResponse::INVALID_OPCODE); // Verify status passed back to port ASSERT_TRUE(this->m_seqStatusRcvd); ASSERT_EQ(this->m_seqStatusOpCode,testOpCode); ASSERT_EQ(testContext,this->m_seqStatusCmdSeq); ASSERT_EQ(this->m_seqStatusCmdResponse,Fw::CmdResponse::INVALID_OPCODE); currSeq++; // dispatch a test command this->clearEvents(); buff.resetSer(); ASSERT_EQ(buff.serialize(FwPacketDescriptorType(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testOpCode),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testCmdArg),Fw::FW_SERIALIZE_OK); this->invoke_to_seqCmdBuff(0,buff,testContext); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeDispatched_SIZE(1); ASSERT_EVENTS_OpCodeDispatched(0,testOpCode,0); // verify sequence table entry ASSERT_TRUE(this->m_impl.m_sequenceTracker[0].used); ASSERT_EQ(currSeq,this->m_impl.m_sequenceTracker[0].seq); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].opCode,testOpCode); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].callerPort,0); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].context,testContext); // verify command received ASSERT_TRUE(this->m_cmdSendRcvd); ASSERT_EQ(this->m_cmdSendOpCode,testOpCode); ASSERT_EQ(currSeq,this->m_cmdSendCmdSeq); // check argument ASSERT_EQ(this->m_cmdSendArgs.deserialize(checkVal),Fw::FW_SERIALIZE_OK); ASSERT_EQ(checkVal,testCmdArg); this->clearEvents(); this->m_seqStatusRcvd = false; // perform command response this->invoke_to_compCmdStat(0,testOpCode,this->m_cmdSendCmdSeq,Fw::CmdResponse::VALIDATION_ERROR); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // Check dispatch table ASSERT_FALSE(this->m_impl.m_sequenceTracker[0].used); ASSERT_EQ(currSeq,this->m_impl.m_sequenceTracker[0].seq); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].opCode,testOpCode); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].callerPort,0); // Verify completed event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeError_SIZE(1); ASSERT_EVENTS_OpCodeError(0,testOpCode,Fw::CmdResponse::VALIDATION_ERROR); // Verify status passed back to port ASSERT_TRUE(this->m_seqStatusRcvd); ASSERT_EQ(this->m_seqStatusOpCode,testOpCode); ASSERT_EQ(testContext,this->m_seqStatusCmdSeq); ASSERT_EQ(this->m_seqStatusCmdResponse,Fw::CmdResponse::VALIDATION_ERROR); } void CommandDispatcherImplTester::runInvalidCommand() { // verify dispatch table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_entryTable); entry++) { ASSERT_TRUE(this->m_impl.m_entryTable[entry].used == false); } // verify sequence tracker table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_sequenceTracker); entry++) { ASSERT_TRUE(this->m_impl.m_sequenceTracker[entry].used == false); } // clear reg events this->clearEvents(); // dispatch a flawed command U32 testCmdArg = 100; U32 testContext = 13; FwOpcodeType testOpCode = 0x50; this->clearEvents(); Fw::ComBuffer buff; ASSERT_EQ(buff.serialize(U32(100)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testOpCode),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testCmdArg),Fw::FW_SERIALIZE_OK); this->invoke_to_seqCmdBuff(0,buff,testContext); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_MalformedCommand_SIZE(1); ASSERT_EVENTS_MalformedCommand(0,Fw::DeserialStatus::TYPE_MISMATCH); } void CommandDispatcherImplTester::runOverflowCommands() { // verify dispatch table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_entryTable); entry++) { ASSERT_TRUE(this->m_impl.m_entryTable[entry].used == false); } // verify sequence tracker table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_sequenceTracker); entry++) { ASSERT_TRUE(this->m_impl.m_sequenceTracker[entry].used == false); } // clear reg events this->clearEvents(); // register built-in commands this->m_impl.regCommands(); // verify registrations ASSERT_TRUE(this->m_impl.m_entryTable[0].used); ASSERT_EQ(this->m_impl.m_entryTable[0].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP); ASSERT_EQ(this->m_impl.m_entryTable[0].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[1].used); ASSERT_EQ(this->m_impl.m_entryTable[1].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING); ASSERT_EQ(this->m_impl.m_entryTable[1].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[2].used); ASSERT_EQ(this->m_impl.m_entryTable[2].opcode,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1); ASSERT_EQ(this->m_impl.m_entryTable[2].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[3].used); ASSERT_EQ(this->m_impl.m_entryTable[3].opcode,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING); ASSERT_EQ(this->m_impl.m_entryTable[3].port,1); // verify event ASSERT_EVENTS_SIZE(4); ASSERT_EVENTS_OpCodeRegistered_SIZE(4); ASSERT_EVENTS_OpCodeRegistered(0,CommandDispatcherImpl::OPCODE_CMD_NO_OP,1,0); ASSERT_EVENTS_OpCodeRegistered(1,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING,1,1); ASSERT_EVENTS_OpCodeRegistered(2,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1,1,2); ASSERT_EVENTS_OpCodeRegistered(3,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING,1,3); // register our own command FwOpcodeType testOpCode = 0x50; this->clearEvents(); this->invoke_to_compCmdReg(0,0x50); ASSERT_TRUE(this->m_impl.m_entryTable[4].used); ASSERT_EQ(this->m_impl.m_entryTable[4].opcode,testOpCode); ASSERT_EQ(this->m_impl.m_entryTable[4].port,0); // verify registration event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeRegistered_SIZE(1); ASSERT_EVENTS_OpCodeRegistered(0,testOpCode,0,4); for (NATIVE_UINT_TYPE disp = 0; disp < CMD_DISPATCHER_SEQUENCER_TABLE_SIZE + 1; disp++) { // dispatch a test command U32 testCmdArg = 100; U32 testContext = 13; this->clearEvents(); Fw::ComBuffer buff; ASSERT_EQ(buff.serialize(FwPacketDescriptorType(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testOpCode),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testCmdArg),Fw::FW_SERIALIZE_OK); this->invoke_to_seqCmdBuff(0,buff,testContext); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); if (disp < CMD_DISPATCHER_SEQUENCER_TABLE_SIZE) { // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeDispatched_SIZE(1); ASSERT_EVENTS_OpCodeDispatched(0,testOpCode,0); // verify sequence table entry ASSERT_TRUE(this->m_impl.m_sequenceTracker[disp].used); ASSERT_EQ(disp,this->m_impl.m_sequenceTracker[disp].seq); ASSERT_EQ(this->m_impl.m_sequenceTracker[disp].opCode,testOpCode); ASSERT_EQ(this->m_impl.m_sequenceTracker[disp].context,testContext); ASSERT_EQ(this->m_impl.m_sequenceTracker[disp].callerPort,0); // verify command received ASSERT_TRUE(this->m_cmdSendRcvd); ASSERT_EQ(this->m_cmdSendOpCode,testOpCode); ASSERT_EQ(disp,this->m_cmdSendCmdSeq); // check argument U32 checkVal; ASSERT_EQ(this->m_cmdSendArgs.deserialize(checkVal),Fw::FW_SERIALIZE_OK); ASSERT_EQ(checkVal,testCmdArg); } else { // verify failed to find slot ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_TooManyCommands_SIZE(1); } } } void CommandDispatcherImplTester::runClearCommandTracking() { // verify dispatch table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_entryTable); entry++) { ASSERT_TRUE(this->m_impl.m_entryTable[entry].used == false); } // verify sequence tracker table is empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_sequenceTracker); entry++) { ASSERT_TRUE(this->m_impl.m_sequenceTracker[entry].used == false); } // clear reg events this->clearEvents(); // register built-in commands this->m_impl.regCommands(); // verify registrations ASSERT_TRUE(this->m_impl.m_entryTable[0].used); ASSERT_EQ(this->m_impl.m_entryTable[0].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP); ASSERT_EQ(this->m_impl.m_entryTable[0].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[1].used); ASSERT_EQ(this->m_impl.m_entryTable[1].opcode,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING); ASSERT_EQ(this->m_impl.m_entryTable[1].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[2].used); ASSERT_EQ(this->m_impl.m_entryTable[2].opcode,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1); ASSERT_EQ(this->m_impl.m_entryTable[2].port,1); ASSERT_TRUE(this->m_impl.m_entryTable[3].used); ASSERT_EQ(this->m_impl.m_entryTable[3].opcode,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING); ASSERT_EQ(this->m_impl.m_entryTable[3].port,1); // verify event ASSERT_EVENTS_SIZE(4); ASSERT_EVENTS_OpCodeRegistered_SIZE(4); ASSERT_EVENTS_OpCodeRegistered(0,CommandDispatcherImpl::OPCODE_CMD_NO_OP,1,0); ASSERT_EVENTS_OpCodeRegistered(1,CommandDispatcherImpl::OPCODE_CMD_NO_OP_STRING,1,1); ASSERT_EVENTS_OpCodeRegistered(2,CommandDispatcherImpl::OPCODE_CMD_TEST_CMD_1,1,2); ASSERT_EVENTS_OpCodeRegistered(3,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING,1,3); // register our own command FwOpcodeType testOpCode = 0x50; U32 testContext = 13; this->clearEvents(); this->invoke_to_compCmdReg(0,testOpCode); ASSERT_TRUE(this->m_impl.m_entryTable[4].used); ASSERT_EQ(this->m_impl.m_entryTable[4].opcode,testOpCode); ASSERT_EQ(this->m_impl.m_entryTable[4].port,0); // verify registration event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeRegistered_SIZE(1); ASSERT_EVENTS_OpCodeRegistered(0,testOpCode,0,4); // dispatch a test command U32 testCmdArg = 100; this->clearEvents(); Fw::ComBuffer buff; ASSERT_EQ(buff.serialize(FwPacketDescriptorType(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testOpCode),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(testCmdArg),Fw::FW_SERIALIZE_OK); this->invoke_to_seqCmdBuff(0,buff,testContext); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeDispatched_SIZE(1); ASSERT_EVENTS_OpCodeDispatched(0,testOpCode,0); // verify sequence table entry ASSERT_TRUE(this->m_impl.m_sequenceTracker[0].used); ASSERT_EQ(0u,this->m_impl.m_sequenceTracker[0].seq); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].opCode,testOpCode); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].context,testContext); ASSERT_EQ(this->m_impl.m_sequenceTracker[0].callerPort,0); // verify command received ASSERT_TRUE(this->m_cmdSendRcvd); ASSERT_EQ(this->m_cmdSendOpCode,testOpCode); ASSERT_EQ(0u,this->m_cmdSendCmdSeq); // check argument U32 checkVal; ASSERT_EQ(this->m_cmdSendArgs.deserialize(checkVal),Fw::FW_SERIALIZE_OK); ASSERT_EQ(checkVal,testCmdArg); this->clearEvents(); // dispatch command to clear sequence tracker table buff.resetSer(); ASSERT_EQ(buff.serialize(FwPacketDescriptorType(Fw::ComPacket::FW_PACKET_COMMAND)),Fw::FW_SERIALIZE_OK); ASSERT_EQ(buff.serialize(static_cast<FwOpcodeType>(CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING)),Fw::FW_SERIALIZE_OK); this->invoke_to_seqCmdBuff(0,buff,testContext); // send buffer to command dispatcher ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify dispatch event ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_OpCodeDispatched_SIZE(1); ASSERT_EVENTS_OpCodeDispatched(0,CommandDispatcherImpl::OPCODE_CMD_CLEAR_TRACKING,1); // dispatch command from dispatcher to command handler ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify tracking table empty for (NATIVE_UINT_TYPE entry = 0; entry < FW_NUM_ARRAY_ELEMENTS(this->m_impl.m_sequenceTracker); entry++) { ASSERT_TRUE(this->m_impl.m_sequenceTracker[entry].used == false); } clearHistory(); // send command complete this->invoke_to_compCmdStat(0,testOpCode,this->m_cmdSendCmdSeq,Fw::CmdResponse::OK); ASSERT_EQ(Fw::QueuedComponentBase::MSG_DISPATCH_OK,this->m_impl.doDispatch()); // verify no status returned ASSERT_CMD_RESPONSE_SIZE(0); } void CommandDispatcherImplTester::from_pingOut_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 key /*!< Value to return to pinger*/ ) { } } /* namespace SvcTest */
cpp
fprime
data/projects/fprime/Svc/CmdDispatcher/test/ut/CommandDispatcherImplTester.hpp
/* * CommandDispatcherImplTester.hpp * * Created on: Mar 18, 2015 * Author: tcanham */ #ifndef CMDDISP_TEST_UT_TLMCHANIMPLTESTER_HPP_ #define CMDDISP_TEST_UT_TLMCHANIMPLTESTER_HPP_ #include <CommandDispatcherGTestBase.hpp> #include <Svc/CmdDispatcher/CommandDispatcherImpl.hpp> namespace Svc { class CommandDispatcherImplTester: public CommandDispatcherGTestBase { public: CommandDispatcherImplTester(Svc::CommandDispatcherImpl& inst); virtual ~CommandDispatcherImplTester(); void init(NATIVE_INT_TYPE instance = 0); void runNominalDispatch(); void runInvalidOpcodeDispatch(); void runCommandReregister(); void runFailedCommand(); void runInvalidCommand(); void runOverflowCommands(); void runNopCommands(); void runClearCommandTracking(); private: Svc::CommandDispatcherImpl& m_impl; void from_compCmdSend_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, Fw::CmdArgBuffer &args); void from_pingOut_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 key /*!< Value to return to pinger*/ ); // store port call bool m_cmdSendRcvd; FwOpcodeType m_cmdSendOpCode; U32 m_cmdSendCmdSeq; Fw::CmdArgBuffer m_cmdSendArgs; void from_seqCmdStatus_handler(NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdResponse &response); bool m_seqStatusRcvd; FwOpcodeType m_seqStatusOpCode; U32 m_seqStatusCmdSeq; Fw::CmdResponse m_seqStatusCmdResponse; }; } /* namespace Svc */ #endif /* CMDDISP_TEST_UT_TLMCHANIMPLTESTER_HPP_ */
hpp
fprime
data/projects/fprime/Svc/CmdDispatcher/test/ut/CommandDispatcherTester.cpp
/* * CommandDispatcherTester.cpp * * Created on: Mar 18, 2015 * Author: tcanham */ #include <Svc/CmdDispatcher/test/ut/CommandDispatcherImplTester.hpp> #include <Svc/CmdDispatcher/CommandDispatcherImpl.hpp> #include <Fw/Obj/SimpleObjRegistry.hpp> #include <gtest/gtest.h> #include <Fw/Test/UnitTest.hpp> void connectPorts(Svc::CommandDispatcherImpl& impl, Svc::CommandDispatcherImplTester& tester) { //Fw::SimpleObjRegistry simpleReg; // command ports tester.connect_to_compCmdStat(0,impl.get_compCmdStat_InputPort(0)); tester.connect_to_seqCmdBuff(0,impl.get_seqCmdBuff_InputPort(0)); tester.connect_to_compCmdReg(0,impl.get_compCmdReg_InputPort(0)); impl.set_compCmdSend_OutputPort(0,tester.get_from_compCmdSend(0)); impl.set_seqCmdStatus_OutputPort(0,tester.get_from_seqCmdStatus(0)); // local dispatcher command registration impl.set_CmdReg_OutputPort(0,impl.get_compCmdReg_InputPort(1)); impl.set_CmdStatus_OutputPort(0,impl.get_compCmdStat_InputPort(0)); impl.set_compCmdSend_OutputPort(1,impl.get_CmdDisp_InputPort(0)); impl.set_Tlm_OutputPort(0,tester.get_from_Tlm(0)); impl.set_Time_OutputPort(0,tester.get_from_Time(0)); impl.set_Log_OutputPort(0,tester.get_from_Log(0)); impl.set_LogText_OutputPort(0,tester.get_from_LogText(0)); #if FW_PORT_TRACING //Fw::PortBase::setTrace(true); #endif //simpleReg.dump(); } TEST(CmdDispTestNominal,NominalDispatch) { TEST_CASE(102.1.1,"Nominal Dispatch"); COMMENT("Dispatch a series of commands and verify they are dispatched correctly."); Svc::CommandDispatcherImpl impl("CmdDispImpl"); impl.init(10,0); Svc::CommandDispatcherImplTester tester(impl); tester.init(); // connect ports connectPorts(impl,tester); tester.runNominalDispatch(); } TEST(CmdDispTestNominal,NopTest) { TEST_CASE(102.1.2,"NO_OP Command Test"); COMMENT("Verify the test NO_OP commands by dispatching them."); Svc::CommandDispatcherImpl impl("CmdDispImpl"); impl.init(10,0); Svc::CommandDispatcherImplTester tester(impl); tester.init(); // connect ports connectPorts(impl,tester); tester.runNopCommands(); } TEST(CmdDispTestNominal, ReregisterCommand) { TEST_CASE(102.1.3,"Reregister Command"); COMMENT("Verify user can call command registration port with the same opcode multiple times safely."); Svc::CommandDispatcherImpl impl("CmdDispImpl"); impl.init(10,0); Svc::CommandDispatcherImplTester tester(impl); tester.init(); // connect ports connectPorts(impl,tester); tester.runCommandReregister(); } TEST(CmdDispTestOffNominal,InvalidOpcodeDispatch) { TEST_CASE(102.2.1,"Off-nominal Dispatch"); COMMENT("Verify the correct handling of unregistered opcodes."); Svc::CommandDispatcherImpl impl("CmdDispImpl"); impl.init(10,0); Svc::CommandDispatcherImplTester tester(impl); tester.init(); // connect ports connectPorts(impl,tester); tester.runInvalidOpcodeDispatch(); } TEST(CmdDispTestOffNominal,FailedCommand) { TEST_CASE(102.2.2,"Off-nominal Failed command"); COMMENT("Verify that failed commands operate correctly"); Svc::CommandDispatcherImpl impl("CmdDispImpl"); impl.init(10,0); Svc::CommandDispatcherImplTester tester(impl); tester.init(); // connect ports connectPorts(impl,tester); tester.runFailedCommand(); } TEST(CmdDispTestOffNominal,InvalidCommand) { TEST_CASE(102.2.3,"Off-nominal Invalid Command"); COMMENT("Verify that malformed commands are detected."); Svc::CommandDispatcherImpl impl("CmdDispImpl"); impl.init(10,0); Svc::CommandDispatcherImplTester tester(impl); tester.init(); // connect ports connectPorts(impl,tester); tester.runInvalidCommand(); } TEST(CmdDispTestOffNominal,CommandOverflow) { TEST_CASE(102.2.4,"Off-nominal Command Overflow"); COMMENT("Verify error case where there are too many outstanding commands."); Svc::CommandDispatcherImpl impl("CmdDispImpl"); impl.init(10,0); Svc::CommandDispatcherImplTester tester(impl); tester.init(); // connect ports connectPorts(impl,tester); tester.runOverflowCommands(); } TEST(CmdDispTestOffNominal,ClearSequenceTracker) { TEST_CASE(102.1.3,"Clear Command Tracker"); COMMENT("Verify command to clear command tracker."); Svc::CommandDispatcherImpl impl("CmdDispImpl"); impl.init(10,0); Svc::CommandDispatcherImplTester tester(impl); tester.init(); // connect ports connectPorts(impl,tester); tester.runClearCommandTracking(); } #ifndef TGT_OS_TYPE_VXWORKS int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } #endif
cpp
fprime
data/projects/fprime/Svc/ActiveTextLogger/LogFile.cpp
// \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include <Svc/ActiveTextLogger/LogFile.hpp> #include <Fw/Types/Assert.hpp> #include <Os/File.hpp> #include <Os/FileSystem.hpp> #include <limits> #include <cstring> #include <cstdio> #include <Fw/Types/StringUtils.hpp> namespace Svc { // ---------------------------------------------------------------------- // Initialization/Exiting // ---------------------------------------------------------------------- LogFile::LogFile() : m_fileName(), m_file(), m_maxFileSize(0), m_openFile(false), m_currentFileSize(0) { } LogFile::~LogFile() { // Close the file if needed: if (this->m_openFile) { this->m_file.close(); } } // ---------------------------------------------------------------------- // Member Functions // ---------------------------------------------------------------------- bool LogFile::write_to_log(const char *const buf, const U32 size) { FW_ASSERT(buf != nullptr); bool status = true; // Print to file if there is one, and given a valid size: if (this->m_openFile && size > 0) { // Make sure we won't exceed the maximum size: // Note: second condition in if statement is true if there is overflow // in the addition below U32 projectedSize = this->m_currentFileSize + size; if ( projectedSize > this->m_maxFileSize || (this->m_currentFileSize > (std::numeric_limits<U32>::max() - size)) ) { status = false; this->m_openFile = false; this->m_file.close(); } // Won't exceed max size, so write to file: else { FwSignedSizeType writeSize = size; Os::File::Status stat = this->m_file.write(reinterpret_cast<const U8*>(buf),writeSize,Os::File::WAIT); // Assert that we are not trying to write to a file we never opened: FW_ASSERT(stat != Os::File::NOT_OPENED); // Only return a good status if the write was valid status = (writeSize > 0); this->m_currentFileSize += writeSize; } } return status; } bool LogFile::set_log_file(const char* fileName, const U32 maxSize, const U32 maxBackups) { FW_ASSERT(fileName != nullptr); // If there is already a previously open file then close it: if (this->m_openFile) { this->m_openFile = false; this->m_file.close(); } // If file name is too large, return failure: U32 fileNameSize = Fw::StringUtils::string_length(fileName, Fw::String::STRING_SIZE); if (fileNameSize == Fw::String::STRING_SIZE) { return false; } U32 suffix = 0; FwSignedSizeType tmp; char fileNameFinal[Fw::String::STRING_SIZE]; (void) strncpy(fileNameFinal,fileName, Fw::String::STRING_SIZE); fileNameFinal[Fw::String::STRING_SIZE-1] = 0; // Check if file already exists, and if it does try to tack on a suffix. // Quit after 10 suffix addition tries (first try is w/ the original name). bool failedSuffix = false; while (Os::FileSystem::getFileSize(fileNameFinal,tmp) == Os::FileSystem::OP_OK) { // If the file name was the max size, then can't append a suffix, // so just fail: if (fileNameSize == (Fw::String::STRING_SIZE-1)) { return false; } // Not able to create a new non-existing file in maxBackups tries, then mark that it failed: if (suffix >= maxBackups) { failedSuffix = true; break; } NATIVE_INT_TYPE stat = snprintf(fileNameFinal,Fw::String::STRING_SIZE, "%s%" PRIu32,fileName,suffix); // If there was error, then just fail: if (stat <= 0) { return false; } // There should never be truncation: FW_ASSERT(stat < Fw::String::STRING_SIZE); ++suffix; } // If failed trying to make a new file, just use the original file if (failedSuffix) { (void) strncpy(fileNameFinal,fileName, Fw::String::STRING_SIZE); fileNameFinal[Fw::String::STRING_SIZE-1] = 0; } // Open the file (using CREATE so that it truncates an already existing file): Os::File::Status stat = this->m_file.open(fileNameFinal, Os::File::OPEN_CREATE, Os::File::OverwriteType::NO_OVERWRITE); // Bad status when trying to open the file: if (stat != Os::File::OP_OK) { return false; } this->m_currentFileSize = 0; this->m_maxFileSize = maxSize; this->m_fileName = fileNameFinal; this->m_openFile = true; return true; } } // namespace Svc
cpp
fprime
data/projects/fprime/Svc/ActiveTextLogger/ActiveTextLogger.cpp
// \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include <Svc/ActiveTextLogger/ActiveTextLogger.hpp> #include <Fw/Types/Assert.hpp> #include <Fw/Logger/Logger.hpp> #include <ctime> namespace Svc { // ---------------------------------------------------------------------- // Initialization/Exiting // ---------------------------------------------------------------------- ActiveTextLogger::ActiveTextLogger(const char* name) : ActiveTextLoggerComponentBase(name), m_log_file() { } ActiveTextLogger::~ActiveTextLogger() { } void ActiveTextLogger::init(NATIVE_INT_TYPE queueDepth, NATIVE_INT_TYPE instance) { ActiveTextLoggerComponentBase::init(queueDepth,instance); } // ---------------------------------------------------------------------- // Handlers to implement for typed input ports // ---------------------------------------------------------------------- void ActiveTextLogger::TextLogger_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::TextLogString &text) { // Currently not doing any input filtering // TKC - 5/3/2018 - remove diagnostic if (Fw::LogSeverity::DIAGNOSTIC == severity.e) { return; } // Format the string here, so that it is done in the task context // of the caller. Format doc borrowed from PassiveTextLogger. const char *severityString = "UNKNOWN"; switch (severity.e) { case Fw::LogSeverity::FATAL: severityString = "FATAL"; break; case Fw::LogSeverity::WARNING_HI: severityString = "WARNING_HI"; break; case Fw::LogSeverity::WARNING_LO: severityString = "WARNING_LO"; break; case Fw::LogSeverity::COMMAND: severityString = "COMMAND"; break; case Fw::LogSeverity::ACTIVITY_HI: severityString = "ACTIVITY_HI"; break; case Fw::LogSeverity::ACTIVITY_LO: severityString = "ACTIVITY_LO"; break; case Fw::LogSeverity::DIAGNOSTIC: severityString = "DIAGNOSTIC"; break; default: severityString = "SEVERITY ERROR"; break; } // TODO: Add calling task id to format string char textStr[FW_INTERNAL_INTERFACE_STRING_MAX_SIZE]; if (timeTag.getTimeBase() == TB_WORKSTATION_TIME) { time_t t = timeTag.getSeconds(); // Using localtime_r prevents any other calls to localtime (from another thread for example) from // interfering with our time object before we use it. However, the null pointer check is still needed // to ensure a successful call tm tm; if (localtime_r(&t, &tm) == nullptr) { return; } (void) snprintf(textStr, FW_INTERNAL_INTERFACE_STRING_MAX_SIZE, "EVENT: (%" PRI_FwEventIdType ") (%04d-%02d-%02dT%02d:%02d:%02d.%06" PRIu32 ") %s: %s\n", id, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,tm.tm_sec,timeTag.getUSeconds(), severityString,text.toChar()); } else { (void) snprintf(textStr, FW_INTERNAL_INTERFACE_STRING_MAX_SIZE, "EVENT: (%" PRI_FwEventIdType ") (%" PRI_FwTimeBaseStoreType ":%" PRId32 ",%" PRId32 ") %s: %s\n", id, static_cast<FwTimeBaseStoreType>(timeTag.getTimeBase()),timeTag.getSeconds(),timeTag.getUSeconds(),severityString,text.toChar()); } // Call internal interface so that everything else is done on component thread, // this helps ensure consistent ordering of the printed text: Fw::InternalInterfaceString intText(textStr); this->TextQueue_internalInterfaceInvoke(intText); } // ---------------------------------------------------------------------- // Internal interface handlers // ---------------------------------------------------------------------- void ActiveTextLogger::TextQueue_internalInterfaceHandler(const Fw::InternalInterfaceString& text) { // Print to console: Fw::Logger::logMsg(text.toChar(),0,0,0,0,0,0,0,0,0); // Print to file if there is one: (void) this->m_log_file.write_to_log(text.toChar(), text.length()); // Ignoring return status } // ---------------------------------------------------------------------- // Helper Methods // ---------------------------------------------------------------------- bool ActiveTextLogger::set_log_file(const char* fileName, const U32 maxSize, const U32 maxBackups) { FW_ASSERT(fileName != nullptr); return this->m_log_file.set_log_file(fileName, maxSize, maxBackups); } } // namespace Svc
cpp
fprime
data/projects/fprime/Svc/ActiveTextLogger/LogFile.hpp
// \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef SVCLOGFILE_HPP_ #define SVCLOGFILE_HPP_ #include <Fw/Types/String.hpp> #include <Os/File.hpp> #include <Os/FileSystem.hpp> namespace Svc { //! \class LogFile //! \brief LogFile struct //! //! The object is used for writing to a log file. Making it a struct so all //! members are public, for ease of use in object composition. struct LogFile { //! \brief Constructor //! LogFile(); //! \brief Destructor //! ~LogFile(); // ---------------------------------------------------------------------- // Member Functions // ---------------------------------------------------------------------- //! \brief Set log file and max size //! //! \param fileName The name of the file to create. Must be less than 80 characters. //! \param maxSize The max size of the file //! \param maxBackups The max backups for the file. Default: 10 //! //! \return true if creating the file was successful, false otherwise bool set_log_file(const char* fileName, const U32 maxSize, const U32 maxBackups = 10); //! \brief Write the passed buf to the log if possible //! //! \param buf The buffer of data to write //! \param size The size of buf //! //! \return true if writing to the file was successful, false otherwise bool write_to_log(const char *const buf, const U32 size); // ---------------------------------------------------------------------- // Member Variables // ---------------------------------------------------------------------- // The name of the file to text logs to: Fw::String m_fileName; // The file to write text logs to: Os::File m_file; // The max size of the text log file: U32 m_maxFileSize; // True if there is currently an open file to write text logs to: bool m_openFile; // Current size of the file: U32 m_currentFileSize; }; } #endif /* SVCLOGFILEL_HPP_ */
hpp
fprime
data/projects/fprime/Svc/ActiveTextLogger/ActiveTextLogger.hpp
// \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef ACTIVETEXTLOGGERIMPL_HPP_ #define ACTIVETEXTLOGGERIMPL_HPP_ #include <Svc/ActiveTextLogger/ActiveTextLoggerComponentAc.hpp> #include <Svc/ActiveTextLogger/LogFile.hpp> namespace Svc { //! \class ActiveTextLoggerComponent //! \brief Active text logger component class //! //! Similarly to the PassiveTextLogger, this component takes log texts //! and prints them to the console, but does so from a thread to keep //! consistent ordering. It also provides the option to write the text //! to a file as well. class ActiveTextLogger: public ActiveTextLoggerComponentBase { public: //! \brief Component constructor //! //! The constructor initializes the state of the component. //! //! Note: Making constructor explicit to prevent implicit //! type conversion. //! //! \param compName the component instance name explicit ActiveTextLogger(const char* compName); //! \brief Component destructor //! virtual ~ActiveTextLogger(); //!< destructor //! \brief Component initialization routine //! //! The initialization function calls the initialization //! routine for the base class. //! //! \param queueDepth the depth of the message queue for the component //! \param instance: instance identifier. Default: 0. void init(NATIVE_INT_TYPE queueDepth, NATIVE_INT_TYPE instance = 0); //! \brief Set log file and max size //! //! This is to create an optional log file to write all the messages to. //! The file will not be written to once the max size is hit. //! //! \param fileName The name of the file to create. Must be less than 80 characters. //! \param maxSize The max size of the file //! \param maxBackups The maximum backups of the log file. Default: 10 //! //! \return true if creating the file was successful, false otherwise bool set_log_file(const char* fileName, const U32 maxSize, const U32 maxBackups = 10); PRIVATE: // ---------------------------------------------------------------------- // Prohibit Copying // ---------------------------------------------------------------------- /*! \brief Copy constructor * */ ActiveTextLogger(const ActiveTextLogger&); /*! \brief Copy assignment operator * */ ActiveTextLogger& operator=(const ActiveTextLogger&); // ---------------------------------------------------------------------- // Constants/Types // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // Member Functions // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // Handlers to implement for typed input ports // ---------------------------------------------------------------------- //! Handler for input port TextLogger // virtual void TextLogger_handler( NATIVE_INT_TYPE portNum, /*!< The port number*/ FwEventIdType id, /*!< Log ID*/ Fw::Time &timeTag, /*!< Time Tag*/ const Fw::LogSeverity& severity, /*!< The severity argument*/ Fw::TextLogString &text /*!< Text of log message*/ ); // ---------------------------------------------------------------------- // Internal interface handlers // ---------------------------------------------------------------------- //! Internal Interface handler for TextQueue //! virtual void TextQueue_internalInterfaceHandler( const Fw::InternalInterfaceString& text /*!< The text string*/ ); // ---------------------------------------------------------------------- // Member Variables // ---------------------------------------------------------------------- // The optional file to text logs to: LogFile m_log_file; }; } #endif /* ACTIVETEXTLOGGERIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Svc/ActiveTextLogger/test/ut/ActiveTextLoggerTester.hpp
// \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #ifndef TESTER_HPP #define TESTER_HPP #include "ActiveTextLoggerGTestBase.hpp" #include "Svc/ActiveTextLogger/ActiveTextLogger.hpp" namespace Svc { class ActiveTextLoggerTester : public ActiveTextLoggerGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: //! Construct object ActiveTextLoggerTester //! ActiveTextLoggerTester(); //! Destroy object ActiveTextLoggerTester //! ~ActiveTextLoggerTester(); public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void run_nominal_test(); void run_off_nominal_test(); private: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(); //! Initialize components //! void initComponents(); private: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! ActiveTextLogger component; }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/ActiveTextLogger/test/ut/ActiveTextLoggerTester.cpp
// \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. #include "ActiveTextLoggerTester.hpp" #include "Fw/Types/StringUtils.hpp" #include <fstream> #define INSTANCE 0 #define MAX_HISTORY_SIZE 10 #define QUEUE_DEPTH 10 namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- ActiveTextLoggerTester :: ActiveTextLoggerTester() : ActiveTextLoggerGTestBase("Tester", MAX_HISTORY_SIZE), component("ActiveTextLogger") { this->initComponents(); this->connectPorts(); } ActiveTextLoggerTester :: ~ActiveTextLoggerTester() { } // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void ActiveTextLoggerTester :: run_nominal_test() { printf("Testing writing to console\n"); // Verifying initial state: ASSERT_FALSE(this->component.m_log_file.m_openFile); FwEventIdType id = 1; Fw::Time timeTag(TB_NONE,3,6); Fw::LogSeverity severity = Fw::LogSeverity::ACTIVITY_HI; Fw::TextLogString text("This component is the greatest!"); this->invoke_to_TextLogger(0,id,timeTag,severity,text); this->component.doDispatch(); id = 2; timeTag.set(TB_PROC_TIME,4,7); severity = Fw::LogSeverity::ACTIVITY_LO; text = "This component is the probably the greatest!"; this->invoke_to_TextLogger(0,id,timeTag,severity,text); this->component.doDispatch(); // This will output in a different format b/c WORKSTATION_TIME id = 3; timeTag.set(TB_WORKSTATION_TIME,5,876); severity = Fw::LogSeverity::WARNING_LO; text = "This component is maybe the greatest!"; this->invoke_to_TextLogger(0,id,timeTag,severity,text); this->component.doDispatch(); // No way to verify internal interface was called, but // can manually see the print out to the console printf("Testing writing to console and file\n"); // Setup file for writing to: bool stat = this->component.set_log_file("test_file",512); ASSERT_TRUE(stat); ASSERT_TRUE(this->component.m_log_file.m_openFile); EXPECT_STREQ("test_file",this->component.m_log_file.m_fileName.toChar()); ASSERT_EQ(0U, this->component.m_log_file.m_currentFileSize); ASSERT_EQ(512U, this->component.m_log_file.m_maxFileSize); id = 4; timeTag.set(TB_NONE,5,8); severity = Fw::LogSeverity::WARNING_LO; const char* severityString = "WARNING_LO"; text = "This component may be the greatest!"; this->invoke_to_TextLogger(0,id,timeTag,severity,text); this->component.doDispatch(); ASSERT_TRUE(this->component.m_log_file.m_openFile); ASSERT_EQ(strlen(text.toChar())+32, this->component.m_log_file.m_currentFileSize); ASSERT_EQ(512U, this->component.m_log_file.m_maxFileSize); U32 past_size = strlen(text.toChar())+32; // Read file to verify contents: std::ifstream stream1("test_file"); char oldLine[256]; while(stream1) { char buf[256]; stream1.getline(buf,256); if (stream1) { std::cout << "readLine: " << buf << std::endl; char textStr[512]; snprintf(textStr, sizeof(textStr), "EVENT: (%d) (%d:%d,%d) %s: %s", id,timeTag.getTimeBase(),timeTag.getSeconds(),timeTag.getUSeconds(),severityString,text.toChar()); ASSERT_EQ(0,strcmp(textStr,buf)); (void) Fw::StringUtils::string_copy(oldLine, buf, sizeof(oldLine)); } } stream1.close(); id = 5; timeTag.set(TB_PROC_TIME,6,9); severity = Fw::LogSeverity::WARNING_HI; severityString = "WARNING_HI"; text = "This component is probably not the greatest!"; this->invoke_to_TextLogger(0,id,timeTag,severity,text); this->component.doDispatch(); ASSERT_TRUE(this->component.m_log_file.m_openFile); ASSERT_EQ(past_size+strlen(text.toChar())+32, this->component.m_log_file.m_currentFileSize); ASSERT_EQ(512U, this->component.m_log_file.m_maxFileSize); // Test predicted size matches actual: FwSignedSizeType fileSize = 0; Os::FileSystem::getFileSize("test_file",fileSize); ASSERT_EQ(fileSize,this->component.m_log_file.m_currentFileSize); // Read file to verify contents: std::ifstream stream2("test_file"); U32 iter = 0; while(stream2) { char buf[256]; stream2.getline(buf,256); if (stream2) { std::cout << "readLine: " << buf << std::endl; // Verify first printed line is still there if (iter == 0) { ASSERT_EQ(0,strcmp(oldLine,buf)); } // Verify new printed line else { char textStr[512]; snprintf(textStr, sizeof(textStr), "EVENT: (%d) (%d:%d,%d) %s: %s", id,timeTag.getTimeBase(),timeTag.getSeconds(),timeTag.getUSeconds(),severityString,text.toChar()); ASSERT_EQ(0,strcmp(textStr,buf)); } } ++iter; } stream2.close(); // Clean up: remove("test_file"); } void ActiveTextLoggerTester :: run_off_nominal_test() { // TODO file errors- use the Os/Stubs? FwSignedSizeType tmp; printf("Testing writing text that is larger than FW_INTERNAL_INTERFACE_STRING_MAX_SIZE\n"); // Can't test this b/c max size of TextLogString is 256 and // FW_INTERNAL_INTERFACE_STRING_MAX_SIZE is 512 printf("Testing writing more than the max file size\n"); // Setup file for writing to: bool stat = this->component.set_log_file("test_file_max",45); ASSERT_TRUE(stat); ASSERT_TRUE(this->component.m_log_file.m_openFile); ASSERT_STREQ("test_file_max",this->component.m_log_file.m_fileName.toChar()); ASSERT_EQ(0U, this->component.m_log_file.m_currentFileSize); ASSERT_EQ(45U, this->component.m_log_file.m_maxFileSize); ASSERT_EQ(Os::FileSystem::OP_OK, Os::FileSystem::getFileSize("test_file_max",tmp)); // Write once to the file: FwEventIdType id = 1; Fw::Time timeTag(TB_NONE,3,6); Fw::LogSeverity severity = Fw::LogSeverity::ACTIVITY_HI; const char* severityString = "ACTIVITY_HI"; Fw::TextLogString text("abcd"); this->invoke_to_TextLogger(0,id,timeTag,severity,text); this->component.doDispatch(); ASSERT_TRUE(this->component.m_log_file.m_openFile); ASSERT_EQ(strlen(text.toChar())+33, this->component.m_log_file.m_currentFileSize); ASSERT_EQ(45U, this->component.m_log_file.m_maxFileSize); U32 past_size = strlen(text.toChar())+33; // Read file to verify contents: std::ifstream stream1("test_file_max"); char oldLine[256]; while(stream1) { char buf[256]; stream1.getline(buf,256); if (stream1) { std::cout << "readLine: " << buf << std::endl; char textStr[512]; snprintf(textStr, sizeof(textStr), "EVENT: (%d) (%d:%d,%d) %s: %s", id,timeTag.getTimeBase(),timeTag.getSeconds(),timeTag.getUSeconds(),severityString,text.toChar()); ASSERT_EQ(0,strcmp(textStr,buf)); (void) Fw::StringUtils::string_copy(oldLine, buf, sizeof(oldLine)); } } stream1.close(); // Write again to the file going over the max: text = "This will go over max size of the file!"; this->invoke_to_TextLogger(0,id,timeTag,severity,text); this->component.doDispatch(); // Verify file was closed and size didn't increase: ASSERT_FALSE(this->component.m_log_file.m_openFile); ASSERT_EQ(past_size, this->component.m_log_file.m_currentFileSize); ASSERT_EQ(45U, this->component.m_log_file.m_maxFileSize); // Read file to verify contents didn't change: std::ifstream stream2("test_file_max"); while(stream2) { char buf[256]; stream2.getline(buf,256); if (stream2) { std::cout << "readLine: " << buf << std::endl; ASSERT_EQ(0,strcmp(oldLine,buf)); } } stream2.close(); printf("Testing with file name that already exists\n"); // Setup file for writing to that is a duplicate name: stat = this->component.set_log_file("test_file_max",50); // Verify made file with 0 suffix: ASSERT_TRUE(stat); ASSERT_TRUE(this->component.m_log_file.m_openFile); ASSERT_STREQ("test_file_max0",this->component.m_log_file.m_fileName.toChar()); ASSERT_EQ(0U, this->component.m_log_file.m_currentFileSize); ASSERT_EQ(50U, this->component.m_log_file.m_maxFileSize); ASSERT_EQ(Os::FileSystem::OP_OK, Os::FileSystem::getFileSize("test_file_max0",tmp)); printf("Testing file name larger than string size\n"); // Setup filename larger than 80 char: char longFileName[Fw::String::STRING_SIZE + 1]; for (U32 i = 0; i < Fw::String::STRING_SIZE; ++i) { longFileName[i] = 'a'; } longFileName[Fw::String::STRING_SIZE] = 0; stat = this->component.set_log_file(longFileName,50); // Verify file not made: ASSERT_FALSE(stat); ASSERT_FALSE(this->component.m_log_file.m_openFile); ASSERT_NE(Os::FileSystem::OP_OK, Os::FileSystem::getFileSize(longFileName,tmp)); printf("Testing file name of max size and file already exists\n"); char longFileNameDup[Fw::String::STRING_SIZE]; for (U32 i = 0; i < Fw::String::STRING_SIZE; ++i) { longFileNameDup[i] = 'a'; } longFileNameDup[Fw::String::STRING_SIZE-1] = 0; stat = this->component.set_log_file(longFileNameDup,50); // Verify file made successful: ASSERT_TRUE(stat); ASSERT_TRUE(this->component.m_log_file.m_openFile); ASSERT_EQ(Os::FileSystem::OP_OK, Os::FileSystem::getFileSize(longFileNameDup,tmp)); // Try to make the same one again: stat = this->component.set_log_file(longFileNameDup,50); // Verify file not made: ASSERT_FALSE(stat); ASSERT_FALSE(this->component.m_log_file.m_openFile); char longFileNameDupS[81] = "0"; ASSERT_NE(Os::FileSystem::OP_OK, Os::FileSystem::getFileSize(longFileNameDupS,tmp)); printf("Testing with file name that already exists and the next 10 suffixes\n"); // Create 11 files with the same name, and verify 11th fails, and re-uses the original const char* baseName = "test_mult_dup"; // Create first file: stat = this->component.set_log_file(baseName,50); ASSERT_TRUE(stat); ASSERT_TRUE(this->component.m_log_file.m_openFile); ASSERT_EQ(0,strcmp(baseName,this->component.m_log_file.m_fileName.toChar())); ASSERT_EQ(Os::FileSystem::OP_OK, Os::FileSystem::getFileSize(baseName,tmp)); // Create 10 more, which all should succeed: char baseNameWithSuffix[128]; U32 i; for (i = 0; i < 10; ++i) { //printf("<< %i\n",i); stat = this->component.set_log_file(baseName,50); snprintf(baseNameWithSuffix, sizeof(baseNameWithSuffix), "%s%d",baseName,i); ASSERT_TRUE(stat); ASSERT_TRUE(this->component.m_log_file.m_openFile); ASSERT_EQ(0,strcmp(baseNameWithSuffix,this->component.m_log_file.m_fileName.toChar())); ASSERT_EQ(Os::FileSystem::OP_OK, Os::FileSystem::getFileSize(baseNameWithSuffix,tmp)); } // Create 11th which will fail and re-use the original: stat = this->component.set_log_file(baseName,50); snprintf(baseNameWithSuffix, sizeof(baseNameWithSuffix), "%s%d",baseName,i); ASSERT_TRUE(stat); ASSERT_TRUE(this->component.m_log_file.m_openFile); printf("<< %s %s\n",baseName,this->component.m_log_file.m_fileName.toChar()); ASSERT_EQ(0,strcmp(baseName,this->component.m_log_file.m_fileName.toChar())); ASSERT_EQ(Os::FileSystem::OP_OK, Os::FileSystem::getFileSize(baseName,tmp)); // Clean up: remove("test_file_max"); remove("test_file_max0"); remove(longFileNameDup); remove(baseName); for (i = 0; i < 10; ++i) { snprintf(baseNameWithSuffix, sizeof(baseNameWithSuffix), "%s%d",baseName,i); remove(baseNameWithSuffix); } } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void ActiveTextLoggerTester :: connectPorts() { // TextLogger this->connect_to_TextLogger( 0, this->component.get_TextLogger_InputPort(0) ); } void ActiveTextLoggerTester :: initComponents() { this->init(); this->component.init( QUEUE_DEPTH, INSTANCE ); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/BufferAccumulator/BufferAccumulator.hpp
// ====================================================================== // \title BufferAccumulator.hpp // \author bocchino // \brief BufferAccumulator interface // // \copyright // Copyright (C) 2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef Svc_BufferAccumulator_HPP #define Svc_BufferAccumulator_HPP #include <Fw/Types/MemAllocator.hpp> #include "Os/Queue.hpp" #include "Svc/BufferAccumulator/BufferAccumulatorComponentAc.hpp" namespace Svc { class BufferAccumulator : public BufferAccumulatorComponentBase { PRIVATE: // ---------------------------------------------------------------------- // Types // ---------------------------------------------------------------------- //! A BufferLogger file class ArrayFIFOBuffer { public: //! Construct an ArrayFIFOBuffer object ArrayFIFOBuffer(); //! Destroy an ArrayFIFOBuffer File object ~ArrayFIFOBuffer(); void init(Fw::Buffer* const elements, //!< The array elements NATIVE_UINT_TYPE capacity //!< The capacity ); //! Enqueue an index. //! Fails if the queue is full. //! \return Whether the operation succeeded bool enqueue(const Fw::Buffer& e //!< The element to enqueue ); //! Dequeue an index. //! Fails if the queue is empty. bool dequeue(Fw::Buffer& e //!< The dequeued element ); //! Get the size of the queue //! \return The size U32 getSize() const; //! Get the capacity of the queue //! \return The capacity U32 getCapacity() const; PRIVATE: // ---------------------------------------------------------------------- // Private member variables // ---------------------------------------------------------------------- //! The memory for the elements Fw::Buffer* m_elements; //! The capacity of the queue NATIVE_UINT_TYPE m_capacity; //! The enqueue index NATIVE_UINT_TYPE m_enqueueIndex; //! The dequeue index NATIVE_UINT_TYPE m_dequeueIndex; //! The size of the queue NATIVE_UINT_TYPE m_size; }; // class ArrayFIFOBuffer public: // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Construct BufferAccumulator instance //! BufferAccumulator( const char* const compName /*!< The component name*/ ); //! Initialize BufferAccumulator instance //! void init(const NATIVE_INT_TYPE queueDepth, //!< The queue depth const NATIVE_INT_TYPE instance = 0 //!< The instance number ); //! Destroy BufferAccumulator instance //! ~BufferAccumulator(); // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- //! Give the class a memory buffer. Should be called after constructor //! and init, but before task is spawned. void allocateQueue( NATIVE_INT_TYPE identifier, Fw::MemAllocator& allocator, NATIVE_UINT_TYPE maxNumBuffers //!< The maximum number of buffers ); //! Return allocated queue. Should be done during shutdown void deallocateQueue(Fw::MemAllocator& allocator); PRIVATE: // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- //! Handler implementation for bufferSendInFill //! void bufferSendInFill_handler( const NATIVE_INT_TYPE portNum, //!< The port number Fw::Buffer& buffer); //! Handler implementation for bufferSendInReturn //! void bufferSendInReturn_handler( const NATIVE_INT_TYPE portNum, //!< The port number Fw::Buffer& buffer); //! Handler implementation for pingIn //! void pingIn_handler(const NATIVE_INT_TYPE portNum, //!< The port number U32 key //!< Value to return to pinger ); PRIVATE: // ---------------------------------------------------------------------- // Command handler implementations // ---------------------------------------------------------------------- //! Implementation for SetMode command handler //! Set the mode void BA_SetMode_cmdHandler(const FwOpcodeType opCode, //!< The opcode const U32 cmdSeq, //!< The command sequence number BufferAccumulator_OpState mode //!< The mode ); //! Implementation for BA_DrainBuffers command handler //! Drain the commanded number of buffers void BA_DrainBuffers_cmdHandler(const FwOpcodeType opCode, /*!< The opcode*/ const U32 cmdSeq, /*!< The command sequence number*/ U32 numToDrain, BufferAccumulator_BlockMode blockMode ); PRIVATE: // ---------------------------------------------------------------------- // Private helper methods // ---------------------------------------------------------------------- //! Send a stored buffer void sendStoredBuffer(); PRIVATE: // ---------------------------------------------------------------------- // Private member variables // ---------------------------------------------------------------------- //! The mode BufferAccumulator_OpState m_mode; //! Memory for the buffer array Fw::Buffer* m_bufferMemory; //! The FIFO queue of buffers ArrayFIFOBuffer m_bufferQueue; //! Whether to send a buffer to the downstream client bool m_send; //! If we are switched to ACCUMULATE then back to DRAIN, whether we were //! waiting on a buffer bool m_waitForBuffer; //! The number of QueueFull warnings sent since the last successful enqueue //! operation U32 m_numWarnings; //! The number of buffers drained in a partial drain command U32 m_numDrained; //! The number of buffers TO drain in a partial drain command U32 m_numToDrain; //! The DrainBuffers opcode to respond to FwOpcodeType m_opCode; //! The DrainBuffers cmdSeq to respond to U32 m_cmdSeq; //! The allocator ID NATIVE_INT_TYPE m_allocatorId; }; } // namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/BufferAccumulator/ArrayFIFOBuffer.cpp
// ====================================================================== // \title ArrayFIFOBuffer.cpp // \author mereweth // \brief ArrayFIFOBuffer implementation // // \copyright // Copyright (C) 2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Fw/Types/Assert.hpp" #include "Fw/Types/BasicTypes.hpp" #include "Svc/BufferAccumulator/BufferAccumulator.hpp" #include <new> // For placement new namespace Svc { // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- BufferAccumulator::ArrayFIFOBuffer ::ArrayFIFOBuffer() : m_elements(nullptr), m_capacity(0), m_enqueueIndex(0), m_dequeueIndex(0), m_size(0) { } BufferAccumulator::ArrayFIFOBuffer ::~ArrayFIFOBuffer() {} // ---------------------------------------------------------------------- // Public functions // ---------------------------------------------------------------------- void BufferAccumulator::ArrayFIFOBuffer ::init(Fw::Buffer* const elements, NATIVE_UINT_TYPE capacity) { this->m_elements = elements; this->m_capacity = capacity; // Construct all elements for (NATIVE_UINT_TYPE idx = 0; idx < capacity; idx++) { new (&this->m_elements[idx]) Fw::Buffer; } } bool BufferAccumulator::ArrayFIFOBuffer ::enqueue(const Fw::Buffer& e) { if (this->m_elements == nullptr) { return false; } bool status; if (this->m_size < this->m_capacity) { // enqueueIndex is unsigned, no need to compare with 0 FW_ASSERT(m_enqueueIndex < this->m_capacity, m_enqueueIndex); this->m_elements[this->m_enqueueIndex] = e; this->m_enqueueIndex = (this->m_enqueueIndex + 1) % this->m_capacity; status = true; this->m_size++; } else { status = false; } return status; } bool BufferAccumulator::ArrayFIFOBuffer ::dequeue(Fw::Buffer& e) { if (this->m_elements == nullptr) { return false; } FW_ASSERT(this->m_elements); bool status; if (this->m_size > 0) { // dequeueIndex is unsigned, no need to compare with 0 FW_ASSERT(m_dequeueIndex < this->m_capacity, m_dequeueIndex); e = this->m_elements[this->m_dequeueIndex]; this->m_dequeueIndex = (this->m_dequeueIndex + 1) % this->m_capacity; this->m_size--; status = true; } else { status = false; } return status; } U32 BufferAccumulator::ArrayFIFOBuffer ::getSize() const { return this->m_size; } U32 BufferAccumulator::ArrayFIFOBuffer ::getCapacity() const { return this->m_capacity; } } // namespace Svc
cpp
fprime
data/projects/fprime/Svc/BufferAccumulator/BufferAccumulator.cpp
// ====================================================================== // \title BufferAccumulator.cpp // \author bocchino // \brief BufferAccumulator implementation // // \copyright // Copyright (C) 2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Svc/BufferAccumulator/BufferAccumulator.hpp" #include <sys/time.h> #include "Fw/Types/BasicTypes.hpp" namespace Svc { // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- BufferAccumulator :: BufferAccumulator(const char* const compName) : BufferAccumulatorComponentBase(compName), //!< The component name m_mode(BufferAccumulator_OpState::ACCUMULATE), m_bufferMemory(nullptr), m_bufferQueue(), m_send(false), m_waitForBuffer(false), m_numWarnings(0u), m_numDrained(0u), m_numToDrain(0u), m_opCode(), m_cmdSeq(0u), m_allocatorId(0) { } void BufferAccumulator ::init(const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE instance) { BufferAccumulatorComponentBase::init(queueDepth, instance); } BufferAccumulator ::~BufferAccumulator() {} // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- void BufferAccumulator ::allocateQueue( NATIVE_INT_TYPE identifier, Fw::MemAllocator& allocator, NATIVE_UINT_TYPE maxNumBuffers //!< The maximum number of buffers ) { this->m_allocatorId = identifier; NATIVE_UINT_TYPE memSize = sizeof(Fw::Buffer) * maxNumBuffers; bool recoverable = false; this->m_bufferMemory = static_cast<Fw::Buffer*>( allocator.allocate(identifier, memSize, recoverable)); //TODO: Fail gracefully here m_bufferQueue.init(this->m_bufferMemory, maxNumBuffers); } void BufferAccumulator ::deallocateQueue(Fw::MemAllocator& allocator) { allocator.deallocate(this->m_allocatorId, this->m_bufferMemory); } // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- void BufferAccumulator ::bufferSendInFill_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& buffer) { const bool status = this->m_bufferQueue.enqueue(buffer); if (status) { if (this->m_numWarnings > 0) { this->log_ACTIVITY_HI_BA_BufferAccepted(); } this->m_numWarnings = 0; } else { if (this->m_numWarnings == 0) { this->log_WARNING_HI_BA_QueueFull(); } m_numWarnings++; } if (this->m_send) { this->sendStoredBuffer(); } this->tlmWrite_BA_NumQueuedBuffers(this->m_bufferQueue.getSize()); } void BufferAccumulator ::bufferSendInReturn_handler( const NATIVE_INT_TYPE portNum, Fw::Buffer& buffer) { this->bufferSendOutReturn_out(0, buffer); this->m_waitForBuffer = false; if ((this->m_mode == BufferAccumulator_OpState::DRAIN) || // we are draining ALL buffers (this->m_numDrained < this->m_numToDrain)) { // OR we aren't done draining some buffers // in a partial drain this->m_send = true; this->sendStoredBuffer(); } } void BufferAccumulator ::pingIn_handler(const NATIVE_INT_TYPE portNum, U32 key) { this->pingOut_out(0, key); } // ---------------------------------------------------------------------- // Command handler implementations // ---------------------------------------------------------------------- void BufferAccumulator ::BA_SetMode_cmdHandler(const FwOpcodeType opCode, const U32 cmdSeq, BufferAccumulator_OpState mode) { // cancel an in-progress partial drain if (this->m_numToDrain > 0) { // reset counters for partial buffer drain this->m_numToDrain = 0; this->m_numDrained = 0; // respond to the original command this->cmdResponse_out(this->m_opCode, this->m_cmdSeq, Fw::CmdResponse::OK); } this->m_mode = mode; if (mode == BufferAccumulator_OpState::DRAIN) { if (!this->m_waitForBuffer) { this->m_send = true; this->sendStoredBuffer(); } } else { this->m_send = false; } this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } void BufferAccumulator ::BA_DrainBuffers_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq, U32 numToDrain, BufferAccumulator_BlockMode blockMode) { if (this->m_numDrained < this->m_numToDrain) { this->log_WARNING_HI_BA_StillDraining(this->m_numDrained, this->m_numToDrain); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::BUSY); return; } if (this->m_mode == BufferAccumulator_OpState::DRAIN) { this->log_WARNING_HI_BA_AlreadyDraining(); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::VALIDATION_ERROR); return; } if (numToDrain == 0) { this->log_ACTIVITY_HI_BA_PartialDrainDone(0); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); return; } this->m_opCode = opCode; this->m_cmdSeq = cmdSeq; this->m_numDrained = 0; this->m_numToDrain = numToDrain; if (blockMode == BufferAccumulator_BlockMode::NOBLOCK) { U32 numBuffers = this->m_bufferQueue.getSize(); if (numBuffers < numToDrain) { this->m_numToDrain = numBuffers; this->log_WARNING_LO_BA_NonBlockDrain(this->m_numToDrain, numToDrain); } /* OK if there were 0 buffers queued, and we * end up setting numToDrain to 0 */ if (0 == this->m_numToDrain) { this->log_ACTIVITY_HI_BA_PartialDrainDone(0); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); return; } } // We are still waiting for a buffer from last time if (!this->m_waitForBuffer) { this->m_send = true; this->sendStoredBuffer(); // kick off the draining; } } // ---------------------------------------------------------------------- // Private helper methods // ---------------------------------------------------------------------- void BufferAccumulator ::sendStoredBuffer() { FW_ASSERT(this->m_send); Fw::Buffer buffer; if ((this->m_numToDrain == 0) || // we are draining ALL buffers (this->m_numDrained < this->m_numToDrain)) { // OR we aren't done draining some buffers in a // partial drain const bool status = this->m_bufferQueue.dequeue(buffer); if (status) { // a buffer was dequeued this->m_numDrained++; this->bufferSendOutDrain_out(0, buffer); this->m_waitForBuffer = true; this->m_send = false; } else if (this->m_numToDrain > 0) { this->log_WARNING_HI_BA_DrainStalled(this->m_numDrained, this->m_numToDrain); } } /* This used to be "else if", but then you wait for all * drained buffers in a partial drain to be RETURNED before returning OK. * Correct thing is to return OK once they are SENT */ if ((this->m_numToDrain > 0) && // we are doing a partial drain (this->m_numDrained == this->m_numToDrain)) { // AND we just finished draining // this->log_ACTIVITY_HI_BA_PartialDrainDone(this->m_numDrained); // reset counters for partial buffer drain this->m_numToDrain = 0; this->m_numDrained = 0; this->m_send = false; this->cmdResponse_out(this->m_opCode, this->m_cmdSeq, Fw::CmdResponse::OK); } this->tlmWrite_BA_NumQueuedBuffers(this->m_bufferQueue.getSize()); } } // namespace Svc
cpp
fprime
data/projects/fprime/Svc/BufferAccumulator/test/ut/BufferAccumulatorTester.cpp
// ====================================================================== // \title BufferAccumulatorTester.hpp // \author bocchino, mereweth // \brief BufferAccumulator test harness implementation // // \copyright // Copyright 2009-2017, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "BufferAccumulatorTester.hpp" #include "Fw/Types/BasicTypes.hpp" #include "Fw/Types/MallocAllocator.hpp" #define INSTANCE 0 #define MAX_HISTORY_SIZE 30 #define QUEUE_DEPTH 30 namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- BufferAccumulatorTester ::BufferAccumulatorTester(bool doAllocateQueue) : #if FW_OBJECT_NAMES == 1 BufferAccumulatorGTestBase("Tester", MAX_HISTORY_SIZE), component("BufferAccumulator"), #else BufferAccumulatorGTestBase(MAX_HISTORY_SIZE), component(), #endif doAllocateQueue(doAllocateQueue) { this->initComponents(); this->connectPorts(); // Witch to BufferAccumulator_OpState::DRAIN at start so we don't have to // change ut component.mode = BufferAccumulator_OpState::DRAIN; component.send = true; if (this->doAllocateQueue) { Fw::MallocAllocator buffAccumMallocator; this->component.allocateQueue(0, buffAccumMallocator, MAX_NUM_BUFFERS); } } BufferAccumulatorTester ::~BufferAccumulatorTester() { if (this->doAllocateQueue) { Fw::MallocAllocator buffAccumMallocator; this->component.deallocateQueue(buffAccumMallocator); } } // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- void BufferAccumulatorTester ::from_bufferSendOutDrain_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) { this->pushFromPortEntry_bufferSendOutDrain(fwBuffer); } void BufferAccumulatorTester ::from_bufferSendOutReturn_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) { this->pushFromPortEntry_bufferSendOutReturn(fwBuffer); } void BufferAccumulatorTester ::from_pingOut_handler(const NATIVE_INT_TYPE portNum, U32 key) { this->pushFromPortEntry_pingOut(key); } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void BufferAccumulatorTester ::connectPorts() { // bufferSendInFill this->connect_to_bufferSendInFill( 0, this->component.get_bufferSendInFill_InputPort(0)); // bufferSendInReturn this->connect_to_bufferSendInReturn( 0, this->component.get_bufferSendInReturn_InputPort(0)); // cmdIn this->connect_to_cmdIn(0, this->component.get_cmdIn_InputPort(0)); // pingIn this->connect_to_pingIn(0, this->component.get_pingIn_InputPort(0)); // bufferSendOutDrain this->component.set_bufferSendOutDrain_OutputPort( 0, this->get_from_bufferSendOutDrain(0)); // bufferSendOutReturn this->component.set_bufferSendOutReturn_OutputPort( 0, this->get_from_bufferSendOutReturn(0)); // cmdRegOut this->component.set_cmdRegOut_OutputPort(0, this->get_from_cmdRegOut(0)); // cmdResponseOut this->component.set_cmdResponseOut_OutputPort( 0, this->get_from_cmdResponseOut(0)); // eventOut this->component.set_eventOut_OutputPort(0, this->get_from_eventOut(0)); // eventOutText this->component.set_eventOutText_OutputPort(0, this->get_from_eventOutText(0)); // pingOut this->component.set_pingOut_OutputPort(0, this->get_from_pingOut(0)); // timeCaller this->component.set_timeCaller_OutputPort(0, this->get_from_timeCaller(0)); // tlmOut this->component.set_tlmOut_OutputPort(0, this->get_from_tlmOut(0)); } void BufferAccumulatorTester ::initComponents() { this->init(); this->component.init(QUEUE_DEPTH, INSTANCE); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/BufferAccumulator/test/ut/Accumulate.hpp
// ====================================================================== // \title Accumulate.hpp // \author bocchino, mereweth // \brief Test accumulate mode // // \copyright // Copyright (c) 2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef Svc_Accumulate_HPP #define Svc_Accumulate_HPP #include "BufferAccumulatorTester.hpp" namespace Svc { namespace Accumulate { class BufferAccumulatorTester : public Svc::BufferAccumulatorTester { public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! Send some buffers void OK(void); }; } // namespace Accumulate } // namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/BufferAccumulator/test/ut/Health.cpp
// ====================================================================== // \title Health.cpp // \author bocchino, mereweth // \brief Implementation for Buffer Accumulator health tests // // \copyright // Copyright (C) 2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Health.hpp" namespace Svc { namespace Health { void BufferAccumulatorTester ::Ping() { U32 key = 42; this->invoke_to_pingIn(0, key); this->component.doDispatch(); ASSERT_EVENTS_SIZE(0); ASSERT_from_pingOut_SIZE(1); ASSERT_from_pingOut(0, key); } } // namespace Health } // namespace Svc
cpp
fprime
data/projects/fprime/Svc/BufferAccumulator/test/ut/Errors.cpp
// ====================================================================== // \title Errors.hpp // \author bocchino, mereweth // \brief Test errors // // \copyright // Copyright (c) 2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Errors.hpp" namespace Svc { namespace Errors { // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void BufferAccumulatorTester ::PartialDrain() { ASSERT_EQ(BufferAccumulator_OpState::DRAIN, this->component.mode.e); this->sendCmd_BA_DrainBuffers(0, 0, 1, BufferAccumulator_BlockMode::BLOCK); this->component.doDispatch(); // will fail - we are still in // BufferAccumulator_OpState::DRAIN mode ASSERT_EQ(BufferAccumulator_OpState::DRAIN, this->component.mode.e); ASSERT_FROM_PORT_HISTORY_SIZE(0); ASSERT_EVENTS_BA_AlreadyDraining_SIZE(1); ASSERT_EQ(0u, this->component.numDrained); ASSERT_EQ(0u, this->component.numToDrain); this->sendCmd_BA_SetMode(0, 0, BufferAccumulator_OpState::ACCUMULATE); this->component.doDispatch(); ASSERT_EQ(BufferAccumulator_OpState::ACCUMULATE, this->component.mode.e); ASSERT_FROM_PORT_HISTORY_SIZE(0); this->sendCmd_BA_DrainBuffers(0, 0, 10, BufferAccumulator_BlockMode::BLOCK); this->component.doDispatch(); // will succeed - now we are in ACCUMULATE ASSERT_EQ(BufferAccumulator_OpState::ACCUMULATE, this->component.mode.e); ASSERT_FROM_PORT_HISTORY_SIZE( 0); // would be first buffer out, but we are empty ASSERT_EVENTS_BA_DrainStalled_SIZE(1); ASSERT_EVENTS_BA_DrainStalled(0, 0u, 10u); ASSERT_EVENTS_BA_PartialDrainDone_SIZE(0); // partial drain not done ASSERT_EQ(true, this->component.send); ASSERT_EQ(0u, this->component.numDrained); ASSERT_EQ(10u, this->component.numToDrain); this->sendCmd_BA_DrainBuffers(0, 0, 1, BufferAccumulator_BlockMode::BLOCK); this->component .doDispatch(); // will fail - we are still doing a partial drain ASSERT_EVENTS_BA_StillDraining_SIZE(1); ASSERT_EVENTS_BA_StillDraining(0, 0u, 10u); ASSERT_EVENTS_BA_PartialDrainDone_SIZE(0); // partial drain not done ASSERT_EQ(BufferAccumulator_OpState::ACCUMULATE, this->component.mode.e); ASSERT_FROM_PORT_HISTORY_SIZE(0); ASSERT_EQ(true, this->component.send); ASSERT_EQ(0u, this->component.numDrained); ASSERT_EQ(10u, this->component.numToDrain); } void BufferAccumulatorTester ::QueueFull() { U8* data = new U8[10]; const U32 size = 10; Fw::Buffer buffer(data, size); // Go to Accumulate mode ASSERT_EQ(BufferAccumulator_OpState::DRAIN, this->component.mode.e); this->sendCmd_BA_SetMode(0, 0, BufferAccumulator_OpState::ACCUMULATE); this->component.doDispatch(); ASSERT_EQ(BufferAccumulator_OpState::ACCUMULATE, this->component.mode.e); ASSERT_FROM_PORT_HISTORY_SIZE(0); // Fill up the buffer queue for (U32 i = 0; i < MAX_NUM_BUFFERS; ++i) { this->invoke_to_bufferSendInFill(0, buffer); this->component.doDispatch(); ASSERT_FROM_PORT_HISTORY_SIZE(0); } // Send another buffer and expect an event this->invoke_to_bufferSendInFill(0, buffer); this->component.doDispatch(); ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_BA_QueueFull_SIZE(1); // Send another buffer and expect no new event this->invoke_to_bufferSendInFill(0, buffer); this->component.doDispatch(); ASSERT_EVENTS_SIZE(1); // Drain one buffer this->sendCmd_BA_SetMode(0, 0, BufferAccumulator_OpState::DRAIN); this->component.doDispatch(); ASSERT_FROM_PORT_HISTORY_SIZE(1); ASSERT_from_bufferSendOutDrain_SIZE(1); ASSERT_from_bufferSendOutDrain(0, buffer); // Send another buffer and expect an event this->invoke_to_bufferSendInFill(0, buffer); this->component.doDispatch(); ASSERT_EVENTS_SIZE(2); ASSERT_EVENTS_BA_BufferAccepted_SIZE(1); // Return the original buffer in order to drain one buffer this->invoke_to_bufferSendInReturn(0, buffer); this->component.doDispatch(); ASSERT_FROM_PORT_HISTORY_SIZE(3); ASSERT_from_bufferSendOutDrain_SIZE(2); ASSERT_from_bufferSendOutDrain(1, buffer); // Send another buffer and expect no new event this->invoke_to_bufferSendInFill(0, buffer); this->component.doDispatch(); ASSERT_EVENTS_SIZE(2); ASSERT_EVENTS_BA_BufferAccepted_SIZE(1); // Send another buffer and expect an event this->invoke_to_bufferSendInFill(0, buffer); this->component.doDispatch(); ASSERT_EVENTS_SIZE(3); ASSERT_EVENTS_BA_QueueFull_SIZE(2); delete[] data; } } // namespace Errors } // namespace Svc
cpp