repo_name
stringclasses
10 values
file_path
stringlengths
29
222
content
stringlengths
24
926k
extention
stringclasses
5 values
fprime
data/projects/fprime/Autocoders/Python/test/event_enum/main.cpp
#include <Autocoders/Python/test/event_enum/TestLogImpl.hpp> #include <Autocoders/Python/test/event_enum/TestLogRecvImpl.hpp> #include <Autocoders/Python/test/time_tester/TestTimeImpl.hpp> #include <Fw/Obj/SimpleObjRegistry.hpp> int main(int argc, char* argv[]) { #if FW_PORT_TRACING Fw::PortBase::setTrace(true); #endif #if FW_OBJECT_REGISTRATION == 1 Fw::SimpleObjRegistry objReg; #endif TestLogImpl testImpl("TestLogImpl"); testImpl.init(); TestLogRecvImpl logRecv("TestLogRecv"); logRecv.init(); TestTimeImpl timeSource("TimeComp"); timeSource.init(); testImpl.set_Log_OutputPort(0,logRecv.get_logRecvPort_InputPort(0)); testImpl.set_Time_OutputPort(0,timeSource.get_timeGetPort_InputPort(0)); testImpl.set_LogText_OutputPort(0,logRecv.get_textLogRecvPort_InputPort(0)); timeSource.setTime(Fw::Time(TB_NONE,2,3)); #if FW_OBJECT_REGISTRATION == 1 objReg.dump(); #endif testImpl.sendEvent(20,7,40); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_enum/TestLogRecvImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/event_enum/TestLogRecvImpl.hpp> #include <cstdio> TestLogRecvImpl::TestLogRecvImpl(const char* name) : LogTextImpl(name) { } TestLogRecvImpl::~TestLogRecvImpl() { } void TestLogRecvImpl::logRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer &args) { printf("Received log %d, Time (%d,%d:%d) severity %d\n",id,timeTag.getTimeBase(),timeTag.getSeconds(),timeTag.getUSeconds(),severity.e); I32 arg1; I32 arg2; U8 arg3; // deserialize them in reverse order args.deserialize(arg3); args.deserialize(arg2); args.deserialize(arg1); printf("Args: %d %d %c\n",arg1,arg2,arg3); } void TestLogRecvImpl::init() { LogTextImpl::init(); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_enum/TestLogRecvImpl.hpp
/* * TestTelemRecvImpl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTTELEMRECVIMPL_HPP_ #define TESTTELEMRECVIMPL_HPP_ #include <Autocoders/Python/test/log_tester/TestTextLogImpl.hpp> class TestLogRecvImpl: public LogTextImpl { public: TestLogRecvImpl(const char* compName); virtual ~TestLogRecvImpl(); void init(); protected: void logRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer &args); private: }; #endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/event_enum/TestLogImpl.hpp
/* * TestCommand1Impl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTCOMMAND1IMPL_HPP_ #define TESTCOMMAND1IMPL_HPP_ #include <Autocoders/Python/test/event_enum/TestComponentAc.hpp> class TestLogImpl: public Somewhere::TestLogComponentBase { public: TestLogImpl(const char* compName); virtual ~TestLogImpl(); void init(); void sendEvent(I32 arg1, I32 arg2, U8 arg3); protected: void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6); }; #endif /* TESTCOMMAND1IMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/event_enum/TestLogImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/event_enum/TestLogImpl.hpp> #include <cstdio> TestLogImpl::TestLogImpl(const char* name) : Somewhere::TestLogComponentBase(name) { } TestLogImpl::~TestLogImpl() { } void TestLogImpl::init() { Somewhere::TestLogComponentBase::init(); } void TestLogImpl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) { } void TestLogImpl::sendEvent(I32 arg1, I32 arg2, U8 arg3) { printf("Sending event args %d, %d, %d\n",arg1, arg2, arg3); this->log_ACTIVITY_LO_SomeEvent(arg1,static_cast<SomeEnum>(arg2),arg3); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_enum/test/ut/main.cpp
#ifdef FPRIME_CMAKE #include "Autocoder/GTestBase.hpp" #else #include <event_enumGTestBase.hpp> #endif // Very minimal to test autocoder. Some day they'll be actual unit test code class ATester : public Somewhere::TestLogGTestBase { public: ATester() : Somewhere::TestLogGTestBase("comp",10) { } }; int main(int argc, char* argv[]) { ATester testBase; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/tlm2/main.cpp
#include <Autocoders/Python/test/tlm2/TestTelemImpl.hpp> #include <Autocoders/Python/test/tlm2/TestTelemRecvImpl.hpp> #include <Autocoders/Python/test/time_tester/TestTimeImpl.hpp> #include <Fw/Obj/SimpleObjRegistry.hpp> int main(int argc, char* argv[]) { #if FW_PORT_TRACING Fw::PortBase::setTrace(true); #endif #if FW_OBJECT_REGISTRATION == 1 Fw::SimpleObjRegistry objReg; #endif TestTlmImpl testImpl("TestTlmImpl"); testImpl.init(); TestTelemRecvImpl tlmRecv("TestTlmRecv"); tlmRecv.init(); TestTimeImpl timeSource("TimeComp"); timeSource.init(); testImpl.set_Tlm_OutputPort(0,tlmRecv.get_tlmRecvPort_InputPort(0)); testImpl.set_Time_OutputPort(0,timeSource.get_timeGetPort_InputPort(0)); timeSource.setTime(Fw::Time(TB_NONE,2,3)); #if FW_OBJECT_REGISTRATION == 1 objReg.dump(); #endif testImpl.genTlm(Ref::Gnc::Quaternion(0.1,0.2,0.3,0.4)); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/tlm2/TestTelemRecvImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/tlm2/TestTelemRecvImpl.hpp> #include <Fw/Types/String.hpp> #include <Autocoders/Python/test/tlm2/QuaternionSerializableAc.hpp> #include <cstdio> TestTelemRecvImpl::TestTelemRecvImpl(const char* name) : Tlm::TelemTesterComponentBase(name) { } TestTelemRecvImpl::~TestTelemRecvImpl() { } void TestTelemRecvImpl::tlmRecvPort_handler(NATIVE_INT_TYPE portNum, FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val) { Ref::Gnc::Quaternion tlmVal; val.deserialize(tlmVal); Fw::String str; tlmVal.toString(str); printf("ID: %d TLM value is %s. Time is %d:%d base: %d\n",id,str.toChar(),timeTag.getSeconds(),timeTag.getUSeconds(),timeTag.getTimeBase()); } void TestTelemRecvImpl::init() { Tlm::TelemTesterComponentBase::init(); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/tlm2/TestTelemImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/tlm2/TestTelemImpl.hpp> #include <cstdio> TestTlmImpl::TestTlmImpl(const char* name) : Tlm::TestTlmComponentBase(name) { } TestTlmImpl::~TestTlmImpl() { } void TestTlmImpl::init() { Tlm::TestTlmComponentBase::init(); } void TestTlmImpl::genTlm(Ref::Gnc::Quaternion val) { this->tlmWrite_AQuat(val); } void TestTlmImpl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) { }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/tlm2/TestTelemRecvImpl.hpp
/* * TestTelemRecvImpl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTTELEMRECVIMPL_HPP_ #define TESTTELEMRECVIMPL_HPP_ #include <Autocoders/Python/test/telem_tester/TelemTestComponentAc.hpp> class TestTelemRecvImpl: public Tlm::TelemTesterComponentBase { public: TestTelemRecvImpl(const char* compName); virtual ~TestTelemRecvImpl(); void init(); protected: void tlmRecvPort_handler(NATIVE_INT_TYPE portNum, FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val); private: }; #endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/tlm2/TestTelemImpl.hpp
/* * TestCommand1Impl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTCOMMAND1IMPL_HPP_ #define TESTCOMMAND1IMPL_HPP_ #include <Autocoders/Python/test/tlm2/TestComponentAc.hpp> class TestTlmImpl: public Tlm::TestTlmComponentBase { public: TestTlmImpl(const char* compName); void genTlm(Ref::Gnc::Quaternion val); virtual ~TestTlmImpl(); void init(); protected: void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6); }; #endif /* TESTCOMMAND1IMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/tlm2/test/ut/main.cpp
#ifdef FPRIME_CMAKE #include "Autocoder/GTestBase.hpp" #else #include <tlm2GTestBase.hpp> #endif // Very minimal to test autocoder. Some day they'll be actual unit test code class ATester : public Tlm::TestTlmGTestBase { public: ATester() : Tlm::TestTlmGTestBase("comp",10) { } }; int main(int argc, char* argv[]) { ATester testBase; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/command_tester/test/ut/main.cpp
#ifdef FPRIME_CMAKE #include "Autocoder/GTestBase.hpp" #else #include <command_testerGTestBase.hpp> #endif #include "TesterBase.hpp" #include <FpConfig.hpp> // Very minimal to test autocoder. Some day they'll be actual unit test code class ATester : public Cmd::CommandTesterGTestBase { public: ATester() : Cmd::CommandTesterGTestBase("comp",10) { } void from_cmdSendPort_handler( const NATIVE_INT_TYPE portNum, //!< The port number FwOpcodeType opCode, //!< Command Op Code U32 cmdSeq, //!< Command Sequence Fw::CmdArgBuffer &args //!< Buffer containing arguments ) {} }; int main(int argc, char* argv[]) { ATester testBase; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/log_tester/TestTextLogImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/log_tester/TestTextLogImpl.hpp> #include <cstdio> LogTextImpl::LogTextImpl(const char* name) : Log::LogTesterComponentBase(name) { } LogTextImpl::~LogTextImpl() { } void LogTextImpl::init() { Log::LogTesterComponentBase::init(); } void LogTextImpl::textLogRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::TextLogString &text) { printf("Log id %d, time (%d,%d:%d), severity %d, text \"%s\"",id,timeTag.getTimeBase(),timeTag.getSeconds(),timeTag.getUSeconds(),severity.e,text.toChar()); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/log_tester/TestTextLogImpl.hpp
/* * TestTelemRecvImpl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTTEXTLOGIMPL_HPP_ #define TESTTEXTLOGIMPL_HPP_ #include <Autocoders/Python/test/log_tester/LogTestComponentAc.hpp> class LogTextImpl: public Log::LogTesterComponentBase { public: LogTextImpl(const char* compName); virtual ~LogTextImpl(); void init(); void setTime(Fw::Time time); protected: void textLogRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::TextLogString &text); private: }; #endif /* TESTTIMEIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/log_tester/test/ut/main.cpp
#ifdef FPRIME_CMAKE #include "Autocoder/GTestBase.hpp" #else #include <log_testerGTestBase.hpp> #endif #include "TesterBase.hpp" #include <FpConfig.hpp> // Very minimal to test autocoder. Some day they'll be actual unit test code class ATester : public Log::LogTesterGTestBase { public: ATester() : Log::LogTesterGTestBase("comp",10) { } void from_Time_handler( const NATIVE_INT_TYPE portNum, Fw::Time &time ) { this->pushFromPortEntry_Time(time); } }; int main(int argc, char* argv[]) { ATester testBase; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_multi_inst/main.cpp
#include <Autocoders/Python/test/event_multi_inst/TestLogImpl.hpp> #include <Autocoders/Python/test/event_multi_inst/TestLogRecvImpl.hpp> #include <Autocoders/Python/test/time_tester/TestTimeImpl.hpp> #include <Fw/Obj/SimpleObjRegistry.hpp> int main(int argc, char* argv[]) { #if FW_PORT_TRACING Fw::PortBase::setTrace(true); #endif #if FW_OBJECT_REGISTRATION == 1 Fw::SimpleObjRegistry objReg; #endif TestLogImpl testImpl("TestLogImpl"); testImpl.init(); TestLogRecvImpl logRecv("TestLogRecv"); logRecv.init(); TestTimeImpl timeSource("TimeComp"); timeSource.init(); testImpl.set_Log_OutputPort(0,logRecv.get_logRecvPort_InputPort(0)); testImpl.set_Time_OutputPort(0,timeSource.get_timeGetPort_InputPort(0)); testImpl.set_LogText_OutputPort(0,logRecv.get_textLogRecvPort_InputPort(0)); timeSource.setTime(Fw::Time(TB_NONE,2,3)); #if FW_OBJECT_REGISTRATION == 1 objReg.dump(); #endif testImpl.sendEvent(20,30.0,40); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_multi_inst/TestLogRecvImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/event1/TestLogRecvImpl.hpp> #include <cstdio> TestLogRecvImpl::TestLogRecvImpl(const char* name) : LogTextImpl(name) { } TestLogRecvImpl::~TestLogRecvImpl() { } void TestLogRecvImpl::logRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer &args) { printf("Received log %d, Time (%d,%d:%d) severity %d\n",id,timeTag.getTimeBase(),timeTag.getSeconds(),timeTag.getUSeconds(),severity.e); I32 arg1; F32 arg2; U8 arg3; // deserialize them in reverse order args.deserialize(arg3); args.deserialize(arg2); args.deserialize(arg1); printf("Args: %d %f %c\n",arg1,arg2,arg3); } void TestLogRecvImpl::init() { LogTextImpl::init(); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_multi_inst/TestLogRecvImpl.hpp
/* * TestTelemRecvImpl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTTELEMRECVIMPL_HPP_ #define TESTTELEMRECVIMPL_HPP_ #include <Autocoders/Python/test/log_tester/TestTextLogImpl.hpp> class TestLogRecvImpl: public LogTextImpl { public: TestLogRecvImpl(const char* compName); virtual ~TestLogRecvImpl(); void init(); protected: void logRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer &args); private: }; #endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/event_multi_inst/TestLogImpl.hpp
/* * TestCommand1Impl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTCOMMAND1IMPL_HPP_ #define TESTCOMMAND1IMPL_HPP_ #include <Autocoders/Python/test/event_multi_inst/TestComponentAc.hpp> class TestLogImpl: public Somewhere::TestLogComponentBase { public: TestLogImpl(const char* compName); virtual ~TestLogImpl(); void init(); void sendEvent(I32 arg1, F32 arg2, U8 arg3); protected: void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6); }; #endif /* TESTCOMMAND1IMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/event_multi_inst/TestLogImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/event_multi_inst/TestLogImpl.hpp> #include <cstdio> TestLogImpl::TestLogImpl(const char* name) : Somewhere::TestLogComponentBase(name) { } TestLogImpl::~TestLogImpl() { } void TestLogImpl::init() { Somewhere::TestLogComponentBase::init(); } void TestLogImpl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) { } void TestLogImpl::sendEvent(I32 arg1, F32 arg2, U8 arg3) { printf("Sending event args %d, %f, %d\n",arg1, arg2, arg3); this->log_DIAGNOSTIC_SomeEvent(arg1,arg2,arg3); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_multi_inst/test/ut/main.cpp
#ifdef FPRIME_CMAKE #include "Autocoder/GTestBase.hpp" #else #include <event_multi_instGTestBase.hpp> #endif // Very minimal to test autocoder. Some day they'll be actual unit test code class ATester : public Somewhere::TestLogGTestBase { public: ATester() : Somewhere::TestLogGTestBase("comp",10) { } }; int main(int argc, char* argv[]) { ATester testBase; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/enum1port/DrvTimingSignalPort.hpp
#ifndef DRV_BIU_RB_INT_SIG_RECEIVE_PORT_HPP #define DRV_BIU_RB_INT_SIG_RECEIVE_PORT_HPP #include <Fw/Port/FwInputPortBase.hpp> #include <Fw/Port/FwOutputPortBase.hpp> #include <Fw/Comp/FwCompBase.hpp> #include <FpConfig.hpp> namespace Drv { typedef enum { REAL_TIME_INTERRUPT } TimingSignal ; class InputTimingSignalPort : public Fw::InputPortBase { public: typedef void (*CompFuncPtr)(Fw::ComponentBase* callComp, NATIVE_INT_TYPE portNum, TimingSignal signal); InputTimingSignalPort(); void init(); void addCallComp(Fw::ComponentBase* callComp, CompFuncPtr funcPtr); void invoke(TimingSignal signal); protected: private: CompFuncPtr m_func; #if FW_PORT_SERIALIZATION void invokeSerial(Fw::SerializeBufferBase &buffer); #endif }; class OutputTimingSignalPort : public Fw::OutputPortBase { public: OutputTimingSignalPort(); void init(); void addCallPort(Drv::InputTimingSignalPort* callPort); void invoke(TimingSignal signal); protected: private: Drv::InputTimingSignalPort* m_port; }; } #endif
hpp
fprime
data/projects/fprime/Autocoders/Python/test/enum1port/DrvTimingSignalPort.cpp
#include <Fw/Types/FwAssert.hpp> #include <Drv/BlockDriver/DrvTimingSignalPort.hpp> #include <cstdio> extern I32 debug_flag; namespace Drv { namespace { class TimingSignalPortBuffer : public Fw::SerializeBufferBase { public: NATIVE_INT_TYPE getBuffCapacity() const { return sizeof(m_buff); } U8* getBuffAddr() { return m_buff; } const U8* getBuffAddr() const { return m_buff; } private: U8 m_buff[sizeof(I32)]; }; } InputTimingSignalPort::InputTimingSignalPort() : m_func(0) { } void InputTimingSignalPort::init() { Fw::InputPortBase::init(); } void InputTimingSignalPort::addCallComp(Fw::ComponentBase* callComp, CompFuncPtr funcPtr) { FW_ASSERT(callComp); FW_ASSERT(funcPtr); this->m_comp = callComp; this->m_func = funcPtr; this->m_connObj = callComp; } void InputTimingSignalPort::invoke(TimingSignal signal) { #if FW_PORT_TRACING this->trace(); #endif FW_ASSERT(this->m_comp); FW_ASSERT(this->m_func); this->m_func(this->m_comp, this->m_portNum, signal); } #if FW_PORT_SERIALIZATION void InputTimingSignalPort::invokeSerial(Fw::SerializeBufferBase &buffer) { #if FW_PORT_TRACING this->trace(); #endif I32 val; Fw::SerializeStatus status = buffer.deserialize(val); FW_ASSERT(Fw::FW_SERIALIZE_OK == status); TimingSignal signal = static_cast<TimingSignal>(val); FW_ASSERT(this->m_comp); FW_ASSERT(this->m_func); this->m_func(this->m_comp, this->m_portNum, signal); } #endif OutputTimingSignalPort::OutputTimingSignalPort() : m_port(0) { } void OutputTimingSignalPort::init() { Fw::OutputPortBase::init(); } void OutputTimingSignalPort::addCallPort(InputTimingSignalPort* callPort) { FW_ASSERT(callPort); this->m_port = callPort; this->m_connObj = callPort; } void OutputTimingSignalPort::invoke(TimingSignal signal) { #if FW_PORT_TRACING == 1 this->trace(); #endif if (this->m_port) { this->m_port->invoke(signal); #if FW_PORT_SERIALIZATION } else if (this->m_serPort) { TimingSignalPortBuffer buffer; Fw::SerializeStatus status = buffer.serialize(static_cast<I32>(signal)); FW_ASSERT(Fw::FW_SERIALIZE_OK == status); this->m_serPort->invokeSerial(buffer); #endif } else { FW_ASSERT(0); } } }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/pass_by_attrib/Msg1Port.cpp
#include <Fw/Cfg/FwConfig.hpp> #include <Fw/Types/FwAssert.hpp> #include <Fw/Types/FwSerializable.hpp> #include <Ports/Msg1PortAc.hpp> namespace Ports { namespace { class Msg1PortBuffer : public Fw::SerializeBufferBase { public: I32 getBuffCapacity() const { return sizeof(m_buff); } U8* getBuffAddr() { return m_buff; } const U8* getBuffAddr() const { return m_buff; } private: U8 m_buff[InputMsg1Port::SERIALIZED_SIZE]; }; } InputMsg1Port::InputMsg1Port() : Fw::InputPortBase(), m_func(0) { } void InputMsg1Port::init() { Fw::InputPortBase::init(); } void InputMsg1Port::addCallComp(Fw::ComponentBase* callComp, CompFuncPtr funcPtr) { FW_ASSERT(callComp); FW_ASSERT(funcPtr); this->m_comp = callComp; this->m_func = funcPtr; this->m_connObj = callComp; } // call virtual logging function for component void InputMsg1Port::invoke(U32 arg1, U32 *arg2, U32 &arg3) { #if FW_PORT_TRACING == 1 this->trace(); #endif FW_ASSERT(this->m_comp); FW_ASSERT(this->m_func); this->m_func(this->m_comp, this->m_portNum, arg1, arg2, arg3); } #if FW_PORT_SERIALIZATION == 1 void InputMsg1Port::invokeSerial(Fw::SerializeBufferBase &buffer) { Fw::SerializeStatus status; #if FW_PORT_TRACING == 1 this->trace(); #endif FW_ASSERT(this->m_comp); FW_ASSERT(this->m_func); U32 arg3; status = buffer.deserialize(arg3); FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<NATIVE_INT_TYPE>(status)); U32 *arg2; status = buffer.deserialize(static_cast<void *>(arg2)); FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<NATIVE_INT_TYPE>(status)); U32 arg1; status = buffer.deserialize(arg1); FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<NATIVE_INT_TYPE>(status)); this->m_func(this->m_comp, this->m_portNum, arg1, arg2, arg3); } #endif OutputMsg1Port::OutputMsg1Port() : Fw::OutputPortBase(), m_port(0) { } void OutputMsg1Port::init() { Fw::OutputPortBase::init(); } void OutputMsg1Port::addCallPort(InputMsg1Port* callPort) { FW_ASSERT(callPort); this->m_port = callPort; this->m_connObj = callPort; #if FW_PORT_SERIALIZATION == 1 this->m_serPort = 0; #endif } void OutputMsg1Port::invoke(U32 arg1, U32 *arg2, U32 &arg3) { #if FW_PORT_TRACING == 1 this->trace(); #endif if (this->m_port) { this->m_port->invoke(arg1, arg2, arg3); #if FW_PORT_SERIALIZATION } else if (this->m_serPort) { Fw::SerializeStatus status; Msg1PortBuffer _buffer; status = _buffer.serialize(arg1); FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<NATIVE_INT_TYPE>(status)); status = _buffer.serialize(static_cast<void *>(arg2)); FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<NATIVE_INT_TYPE>(status)); status = _buffer.serialize(arg3); FW_ASSERT(Fw::FW_SERIALIZE_OK == status,static_cast<NATIVE_INT_TYPE>(status)); this->m_serPort->invokeSerial(_buffer); #endif } else { FW_ASSERT(0); } } };
cpp
fprime
data/projects/fprime/Autocoders/Python/test/pass_by_attrib/Msg1Port.hpp
/* * Msg1Port.hpp * * Created on: Monday, 09 September 2013 * Author: reder * */ #ifndef MSG1PORT_HPP_ #define MSG1PORT_HPP_ #include <Fw/Cfg/FwConfig.hpp> #include <Fw/Port/FwInputPortBase.hpp> #include <Fw/Port/FwOutputPortBase.hpp> #include <Fw/Comp/FwCompBase.hpp> #include <FpConfig.hpp> #include <Fw/Types/FwSerializable.hpp> #include <Fw/Types/FwStringType.hpp> namespace Ports { class InputMsg1Port : public Fw::InputPortBase { public: enum { SERIALIZED_SIZE = sizeof(U32) + sizeof(U32 *) + sizeof(U32) }; typedef void (*CompFuncPtr)(Fw::ComponentBase* callComp, NATIVE_INT_TYPE portNum, U32 arg1, U32 *arg2, U32 &arg3); InputMsg1Port(); void init(); void addCallComp(Fw::ComponentBase* callComp, CompFuncPtr funcPtr); void invoke(U32 arg1, U32 *arg2, U32 &arg3); protected: private: CompFuncPtr m_func; #if FW_PORT_SERIALIZATION == 1 void invokeSerial(Fw::SerializeBufferBase &buffer); #endif }; class OutputMsg1Port : public Fw::OutputPortBase { public: OutputMsg1Port(); void init(); void addCallPort(InputMsg1Port* callPort); void invoke(U32 arg1, U32 *arg2, U32 &arg3); protected: private: InputMsg1Port* m_port; }; }; #endif /* MSG1_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/pass_by_attrib/test/ut/main.cpp
#ifdef FPRIME_CMAKE #include "Autocoder/GTestBase.hpp" #else #include <pass_by_attribGTestBase.hpp> #endif // Very minimal to test autocoder. Some day they'll be actual unit test code class ATester : public App::PassByGTestBase { public: ATester() : App::PassByGTestBase("comp",10) { } }; int main(int argc, char* argv[]) { ATester testBase; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/partition/DuckDuckImpl.hpp
#ifndef DUCK_DUCK_IMPL_HPP #define DUCK_DUCK_IMPL_HPP #include <Autocoders/Python/test/partition/DuckDuckComponentAc.hpp> namespace Duck { class DuckImpl : public DuckBase { public: // Only called by derived class DuckImpl(const char* compName); ~DuckImpl(); private: // downcall for input ports I32 externInputPort1_Msg1_handler(U32 cmd, Fw::String str); I32 externInputPort3_Msg3_handler(U32 cmd); I32 inputPort1_Msg1_handler(U32 cmd, Fw::String str); I32 inputPort2_Msg1_handler(U32 cmd, Fw::String str); I32 inputPort3_Msg3_handler(U32 cmd); }; }; #endif
hpp
fprime
data/projects/fprime/Autocoders/Python/test/partition/DuckDuckImpl.cpp
#include <Autocoders/Python/test/partition/DuckDuckImpl.hpp> #include <FpConfig.hpp> #include <iostream> #include <cstdio> using namespace std; namespace Duck { DuckImpl::DuckImpl(const char* compName) : DuckBase(compName) { } DuckImpl::~DuckImpl() { } // Internal call - implemented by hand. // downcall for input port externInputPort1 I32 DuckImpl::externInputPort1_Msg1_handler(U32 cmd, Fw::String str) { // User code is written here. printf("\n\t*** %s: externInputPort1_Msg1_handler down-call\n", this->m_objName); this->outputPort1_Msg1_out(cmd, str); return 0; } // downcall for input port externInputPort3 I32 DuckImpl::externInputPort3_Msg3_handler(U32 cmd) { // User code is written here. printf("\n\t*** %s: externInputPort3_Msg3_handler down-call\n", this->m_objName); outputPort2_Msg3_out(cmd); return 0; } // downcall for input port inputPort1 I32 DuckImpl::inputPort1_Msg1_handler(U32 cmd, Fw::String str) { // User code is written here. return 0; } // downcall for input port inputPort2 I32 DuckImpl::inputPort2_Msg1_handler(U32 cmd, Fw::String str) { // User code is written here. printf("\n\t*** %s: inputPort2_Msg1_handler(%d, %s) down-call\n", this->m_objName, cmd, str.toChar()); return 0; } // downcall for input port inputPort3 I32 DuckImpl::inputPort3_Msg3_handler(U32 cmd) { // User code is written here. printf("\n\t*** %s: inputPort3_Msg3_handler(%d) down-call\n", this->m_objName, cmd); return 0; } };
cpp
fprime
data/projects/fprime/Autocoders/Python/test/partition/PartitionImpl.hpp
#ifndef PARTITION_PARTITION_IMPL_HPP #define PARTITION_PARTITION_IMPL_HPP #include <Autocoders/Python/test/partition/PartitionPartitionComponentAc.hpp> namespace Partition { class PartitionImpl : public PartitionBase { public: PartitionImpl(const char* compName); ~PartitionImpl(); private: // downcall for input port I32 inputPort1_Serialize_handler(Fw::SerializeBufferBase &Buffer); I32 inputPort2_Serialize_handler(Fw::SerializeBufferBase &Buffer); }; }; #endif
hpp
fprime
data/projects/fprime/Autocoders/Python/test/partition/PartitionImpl.cpp
#include <Autocoders/Python/test/partition/PartitionImpl.hpp> #include <FpConfig.hpp> #include <iostream> #include <cstdio> using namespace std; namespace Partition { PartitionImpl::PartitionImpl(const char* compName) : PartitionBase(compName) { } PartitionImpl::~PartitionImpl() { } // downcall for input port I32 PartitionImpl::inputPort1_Serialize_handler(Fw::SerializeBufferBase &Buffer) { printf("\n\t\t*** %s: inputPort1_Serialize_handler down-call\n", this->m_objName); outputPort1_Serialize_out(Buffer); return 0; } I32 PartitionImpl::inputPort2_Serialize_handler(Fw::SerializeBufferBase &Buffer) { printf("\n\t\t*** %s: inputPort2_Serialize_handler down-call\n", this->m_objName); outputPort2_Serialize_out(Buffer); return 0; } };
cpp
fprime
data/projects/fprime/Autocoders/Python/test/partition/Top.cpp
//-------------------------------------------------------------------------------------- // Top1.cpp // // This application contains a Duck and Partition component only // This is a simple passive test case based on the Partition component // that only contains serializable port types and is passive. // //-------------------------------------------------------------------------------------- #include <Autocoders/Python/test/partition/Top.hpp> #include <Fw/Obj/SimpleObjRegistry.hpp> #include <iostream> #include <cstring> #include <Autocoders/Python/test/partition/DuckDuckImpl.hpp> #include <Autocoders/Python/test/partition/PartitionImpl.hpp> #include <unistd.h> using namespace std; // Registry static Fw::SimpleObjRegistry* simpleRegPtr = 0; // Component instance pointers Duck::DuckImpl* hueyComp_ptr = 0; Partition::PartitionImpl *partitionComp_ptr = 0; extern "C" { void dumparch(); void dumpobj(const char* objName); } void dumparch() { simpleRegPtr->dump(); } void dumpobj(const char* objName) { simpleRegPtr->dump(objName); } void constructArchitecture() { Fw::PortBase::setTrace(true); simpleRegPtr = new Fw::SimpleObjRegistry(); // Instantiate the Huey hueyComp_ptr = new Duck::DuckImpl("Huey"); //printf("*** Instantiated Huey\n"); // Instantiate the Partition Base component partitionComp_ptr = new Partition::PartitionImpl("HueyPartition"); //printf("*** Instantiated HueyPartition\n"); // Connect Huey output port to Partition Comp input port. hueyComp_ptr->getoutputPort1Msg1OutputPort()->registerSerialPort(partitionComp_ptr->getinputPort1SerializeInputPort()); hueyComp_ptr->getoutputPort2Msg3OutputPort()->registerSerialPort(partitionComp_ptr->getinputPort2SerializeInputPort()); // Connect Partition Comp output port to Huey input port. partitionComp_ptr->getoutputPort1SerializeOutputPort()->registerSerialPort(hueyComp_ptr->getinputPort2Msg1InputPort()); partitionComp_ptr->getoutputPort2SerializeOutputPort()->registerSerialPort(hueyComp_ptr->getinputPort3Msg3InputPort()); // Active component startup // start() hueyComp_ptr->start(); dumparch(); } #ifdef TGT_OS_TYPE_LINUX extern "C" { int main(int argc, char* argv[]); }; #endif int main(int argc, char* argv[]) { // Construct the topology here. constructArchitecture(); // Ask for input to huey or duey here. char in[80] = {}; U32 cmd; Fw::String *str; char str2[80]; // while ( strcmp(in,"quit") != 0) { // cout << "\nEnter interface number (1 or 3 or quit): "; cin >> in; // if (in[0]=='1') { // cout << "Enter cmd number: "; cin >> cmd; // cout << "Enter short string: "; cin >> str2; cout << "The string 2 is: " << str2 << endl; str = new Fw::String(str2); cout << "hueyComp_ptr->getexternInputPort1InputPort()->msg_in(" << cmd << "," << str2 << ")" << endl; hueyComp_ptr->getexternInputPort1Msg1InputPort()->msg_in(cmd,*str); } else if (in[0] == '3') { // cout << "Enter cmd number: "; cin >> cmd; cout << "hueyComp_ptr->getexternInputPort1InputPort()->msg_in(" << cmd << ")" << endl; hueyComp_ptr->getexternInputPort3Msg3InputPort()->msg_in(cmd); } else if (strcmp(in,"quit")==0) { cout << "quit demo!" << endl; } else { cout << "Unrecognized component." << endl; }; } cout << "Deleting components..." << endl; delete hueyComp_ptr; delete partitionComp_ptr; cout << "Delete registration objects..." << endl; delete simpleRegPtr; cout << "Completed..." << endl; return 0; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/partition/Top.hpp
#ifndef TOP_TARGET_INIT_HPP #define TOP_TARGET_INIT_HPP extern "C" { void localTargetInit(); } #endif
hpp
fprime
data/projects/fprime/Autocoders/Python/test/serialize2/Top.cpp
#include <Fw/Obj/SimpleObjRegistry.hpp> #include <iostream> #include <cstring> #include <Autocoders/Python/test/serialize2/GncMeasurementSerializableAc.hpp> #include <unistd.h> using namespace std; // Serializable instance pointers Ref::Gnc::Quaternion* q_ptr = 0; Ref::Gnc::GncMeasurement* S1_ptr = 0; Ref::Gnc::GncMeasurement* S2_ptr = 0; Ref::Gnc::GncMeasurement* S3_ptr = 0; // Test buffer class SerializeTestBuffer : public Fw::SerializeBufferBase { public: I32 getBuffCapacity() const { // !< returns capacity, not current size, of buffer return sizeof(m_testBuff); } U8* getBuffAddr() { // !< gets buffer address for data filling return m_testBuff; } const U8* getBuffAddr() const { // !< gets buffer address for data reading return m_testBuff; } private: U8 m_testBuff[255]; }; #ifdef TGT_OS_TYPE_LINUX extern "C" { int main(int argc, char* argv[]); }; #endif void show(int n, Ref::Gnc::GncMeasurement *p) { cout << "S" << n << ": timeStamp = " << p->gettimeStamp() << ", Q1 = " << p->getquaternion().getQ1() << ", Q2 = " << p->getquaternion().getQ2() << ", Q3 = " << p->getquaternion().getQ3() << ", Q4 = " << p->getquaternion().getQ4() << endl; } int main(int argc, char* argv[]) { SerializeTestBuffer buffer; // Default construction S1_ptr = new Ref::Gnc::GncMeasurement(); cout << "Default construction of S1." << endl; show(1,S1_ptr); // Constructor with arguments q_ptr = new Ref::Gnc::Quaternion(1.2, 3.4, 5.6, 7.8); S2_ptr = new Ref::Gnc::GncMeasurement(12345678, *q_ptr); cout << "Constructor with arguments of S2.." << endl; show(2,S2_ptr); // copy constructor with pointer argument S3_ptr = new Ref::Gnc::GncMeasurement(S2_ptr); cout << "Copy constructor with pointer argument of S2 copied to S3..." << endl; show(3,S3_ptr); // setting S1 to non-zero values q_ptr->setQ1(9.10); q_ptr->setQ2(11.12); q_ptr->setQ3(13.14); q_ptr->setQ4(15.16); S1_ptr->settimeStamp(87654321); S1_ptr->setquaternion(*q_ptr); cout << "Setting S1 to non-zero values...." << endl; show(1,S1_ptr); // copy constructor with reference argument S1_ptr = new Ref::Gnc::GncMeasurement(S2_ptr); cout << "Copy constructor with reference argument of S2 copied to S1....." << endl; show(1,S1_ptr); // setting S3 to new values q_ptr->setQ1(17.18); q_ptr->setQ2(19.20); q_ptr->setQ3(21.22); q_ptr->setQ4(23.24); S3_ptr->settimeStamp(91011121314); S3_ptr->setquaternion(*q_ptr); cout << "Setting S3 to new values......" << endl; show(3,S3_ptr); // = constructor S1_ptr = S3_ptr; cout << "Setting S1 = S3......." << endl; show(1,S1_ptr); // Testing serialization here cout << "Testing serialization here (S2 -> S1)........" << endl; S2_ptr->serialize(buffer); S1_ptr->deserialize(buffer); show(1,S1_ptr); cout << "End of testing serializable." << endl; return 0; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/port_return_type/test/ut/main.cpp
#ifdef FPRIME_CMAKE #include "Autocoder/GTestBase.hpp" #else #include <port_return_typeGTestBase.hpp> #endif // Very minimal to test autocoder. Some day they'll be actual unit test code class ATester : public Tlm::TestEventGTestBase { public: ATester() : Tlm::TestEventGTestBase("comp",10) { } }; int main(int argc, char* argv[]) { ATester testBase; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/string_port/test/ut/main.cpp
#ifdef FPRIME_CMAKE #include "Autocoder/GTestBase.hpp" #else #include <string_portGTestBase.hpp> #endif // Very minimal to test autocoder. Some day they'll be actual unit test code class ATester : public ExampleComponents::TestComponentGTestBase { public: ATester() : ExampleComponents::TestComponentGTestBase("comp",10) { } void from_testOut_handler( const NATIVE_INT_TYPE portNum, //!< The port number I32 arg1, //!< A built-in type argument AnotherExample::arg2String &arg2, //!< A string argument const AnotherExample::arg3Buffer &arg3 //!< A buffer argument ); }; void ATester::from_testOut_handler( const NATIVE_INT_TYPE portNum, //!< The port number I32 arg1, //!< A built-in type argument AnotherExample::arg2String &arg2, //!< A string argument const AnotherExample::arg3Buffer &arg3 //!< A buffer argument ) { } int main(int argc, char* argv[]) { ATester testBase; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_throttle/main.cpp
#include <Autocoders/Python/test/event_throttle/TestLogImpl.hpp> #include <Autocoders/Python/test/event_throttle/TestLogRecvImpl.hpp> #include <Autocoders/Python/test/time_tester/TestTimeImpl.hpp> #include <Fw/Obj/SimpleObjRegistry.hpp> int main(int argc, char* argv[]) { #if FW_PORT_TRACING Fw::PortBase::setTrace(true); #endif #if FW_OBJECT_REGISTRATION == 1 Fw::SimpleObjRegistry objReg; #endif TestLogImpl testImpl("TestLogImpl"); testImpl.init(0); TestLogRecvImpl logRecv("TestLogRecv"); logRecv.init(); TestTimeImpl timeSource("TimeComp"); timeSource.init(); testImpl.set_Log_OutputPort(0,logRecv.get_logRecvPort_InputPort(0)); testImpl.set_Time_OutputPort(0,timeSource.get_timeGetPort_InputPort(0)); testImpl.set_LogText_OutputPort(0,logRecv.get_textLogRecvPort_InputPort(0)); timeSource.setTime(Fw::Time(TB_NONE,2,3)); #if FW_OBJECT_REGISTRATION == 1 objReg.dump(); #endif testImpl.sendEvent(20,30.0,40); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_throttle/TestLogRecvImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/event_throttle/TestLogRecvImpl.hpp> #include <cstdio> TestLogRecvImpl::TestLogRecvImpl(const char* name) : LogTextImpl(name) { } TestLogRecvImpl::~TestLogRecvImpl() { } void TestLogRecvImpl::logRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, Fw::LogSeverity severity, Fw::LogBuffer &args) { printf("Received log %d, Time (%d,%d:%d) severity %d\n",id,timeTag.getTimeBase(),timeTag.getSeconds(),timeTag.getUSeconds(),severity); I32 arg1; F32 arg2; U8 arg3; // deserialize them in reverse order args.deserialize(arg3); args.deserialize(arg2); args.deserialize(arg1); printf("Args: %d %f %c\n",arg1,arg2,arg3); } void TestLogRecvImpl::init() { LogTextImpl::init(); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_throttle/TestLogRecvImpl.hpp
/* * TestTelemRecvImpl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTTELEMRECVIMPL_HPP_ #define TESTTELEMRECVIMPL_HPP_ #include <Autocoders/Python/test/log_tester/TestTextLogImpl.hpp> class TestLogRecvImpl: public LogTextImpl { public: TestLogRecvImpl(const char* compName); virtual ~TestLogRecvImpl(); void init(); protected: void logRecvPort_handler(NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time &timeTag, Fw::LogSeverity severity, Fw::LogBuffer &args); private: }; #endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/event_throttle/TestLogImpl.hpp
/* * TestCommand1Impl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTCOMMAND1IMPL_HPP_ #define TESTCOMMAND1IMPL_HPP_ #include <Autocoders/Python/test/event_throttle/TestComponentAc.hpp> class TestLogImpl: public Somewhere::TestLogComponentBase { public: TestLogImpl(const char* compName); virtual ~TestLogImpl(); void init(NATIVE_INT_TYPE instance); void sendEvent(I32 arg1, F32 arg2, U8 arg3); void resetEvent(); protected: void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6); }; #endif /* TESTCOMMAND1IMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/event_throttle/TestLogImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/event_throttle/TestLogImpl.hpp> #include <cstdio> TestLogImpl::TestLogImpl(const char* name) : Somewhere::TestLogComponentBase(name) { } TestLogImpl::~TestLogImpl() { } void TestLogImpl::init(NATIVE_INT_TYPE instance) { Somewhere::TestLogComponentBase::init(instance); } void TestLogImpl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) { } void TestLogImpl::sendEvent(I32 arg1, F32 arg2, U8 arg3) { printf("Sending event args %d, %f, %d\n",arg1, arg2, arg3); this->log_DIAGNOSTIC_SomeEvent(arg1,arg2,arg3); } void TestLogImpl::resetEvent() { this->log_DIAGNOSTIC_SomeEvent_ThrottleClear(); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_throttle/test/ut/event_throttleTester.hpp
// ====================================================================== // \title TestLog/test/ut/Tester.hpp // \author tcanham // \brief hpp file for TestLog 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 "event_throttleGTestBase.hpp" #include "Autocoders/Python/test/event_throttle/TestLogImpl.hpp" namespace Somewhere { class event_throttleTester : public TestLogGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: //! Construct object event_throttleTester //! event_throttleTester(); //! Destroy object event_throttleTester //! ~event_throttleTester(); public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! test event throttling void doEventThrottleTest(); private: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(); //! Initialize components //! void initComponents(); private: void 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 ); // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! TestLogImpl component; }; } // end namespace Somewhere #endif
hpp
fprime
data/projects/fprime/Autocoders/Python/test/event_throttle/test/ut/main.cpp
#include "event_throttleTester.hpp" TEST(EventThrottleTest,ThrottleTest) { Somewhere::event_throttleTester tester; tester.doEventThrottleTest(); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/event_throttle/test/ut/event_throttleTester.cpp
// ====================================================================== // \title TestLog.hpp // \author tcanham // \brief cpp file for TestLog test harness implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "event_throttleTester.hpp" #define INSTANCE 0 #define MAX_HISTORY_SIZE 10 namespace Somewhere { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- event_throttleTester :: event_throttleTester() : TestLogGTestBase("Tester", MAX_HISTORY_SIZE), component("TestLog") { this->initComponents(); this->connectPorts(); } event_throttleTester :: ~event_throttleTester() { } // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void event_throttleTester::doEventThrottleTest() { // should send up to EVENTID_SOMEEVENT_THROTTLE events for (NATIVE_UINT_TYPE call = 0; call < TestLogComponentBase::EVENTID_SOMEEVENT_THROTTLE; call++) { this->component.sendEvent(1, 2.0, 3); ASSERT_EVENTS_SIZE(call+1); ASSERT_EVENTS_SomeEvent_SIZE(call+1); } // should be throttled this->clearHistory(); this->component.sendEvent(1, 2.0, 3); ASSERT_EVENTS_SIZE(0); ASSERT_EVENTS_SomeEvent_SIZE(0); this->component.resetEvent(); // should start sending again for (NATIVE_UINT_TYPE call = 0; call < TestLogComponentBase::EVENTID_SOMEEVENT_THROTTLE; call++) { this->component.sendEvent(1, 2.0, 3); ASSERT_EVENTS_SIZE(call+1); ASSERT_EVENTS_SomeEvent_SIZE(call+1); } // should be throttled this->clearHistory(); this->component.sendEvent(1, 2.0, 3); ASSERT_EVENTS_SIZE(0); ASSERT_EVENTS_SomeEvent_SIZE(0); } void event_throttleTester::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); } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void event_throttleTester :: connectPorts() { // aport this->connect_to_aport( 0, this->component.get_aport_InputPort(0) ); // Time this->component.set_Time_OutputPort( 0, this->get_from_Time(0) ); // Log this->component.set_Log_OutputPort( 0, this->get_from_Log(0) ); // LogText this->component.set_LogText_OutputPort( 0, this->get_from_LogText(0) ); } void event_throttleTester :: initComponents() { this->init(); this->component.init( INSTANCE ); } } // end namespace Somewhere
cpp
fprime
data/projects/fprime/Autocoders/Python/test/serialize_user/main.cpp
#include <Fw/Obj/SimpleObjRegistry.hpp> #include <Autocoders/Python/test/serialize_user/ExampleComponentImpl.hpp> int main(int argc, char* argv[]) { #if FW_PORT_TRACING Fw::PortBase::setTrace(true); #endif #if FW_OBJECT_REGISTRATION == 1 Fw::SimpleObjRegistry objReg; #endif #if FW_OBJECT_REGISTRATION == 1 objReg.dump(); #endif ExampleComponentImpl comp("ExComp"); comp.init(10); comp.start(); AnotherExample::InputExamplePort* port = comp.get_exampleInput_InputPort(0); ANameSpace::UserSerializer arg; SomeUserStruct val = {12,29.6,2}; arg.setVal(val); port->invoke(-10,arg); Os::Task::delay(1000); comp.exit(); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/serialize_user/ExampleComponentImpl.hpp
/* * TestCommand1Impl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTCOMMAND2IMPL_HPP_ #define TESTCOMMAND2IMPL_HPP_ #include <Autocoders/Python/test/serialize_user/ExampleComponentAc.hpp> class ExampleComponentImpl: public ExampleComponents::ExampleComponentComponentBase { public: ExampleComponentImpl(const char* compName); void init(NATIVE_INT_TYPE queueDepth); virtual ~ExampleComponentImpl(); private: void exampleInput_handler(NATIVE_INT_TYPE portNum, I32 arg1, const ANameSpace::UserSerializer& arg2); }; #endif /* TESTCOMMAND1IMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/serialize_user/ExampleComponentImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/serialize_user/ExampleComponentImpl.hpp> #include <Fw/Types/String.hpp> #include <cstdio> ExampleComponentImpl::ExampleComponentImpl(const char* name) : ExampleComponents::ExampleComponentComponentBase(name) { } void ExampleComponentImpl::init(NATIVE_INT_TYPE queueDepth) { ExampleComponents::ExampleComponentComponentBase::init(queueDepth); } ExampleComponentImpl::~ExampleComponentImpl() { } void ExampleComponentImpl::exampleInput_handler(NATIVE_INT_TYPE portNum, I32 arg1, const ANameSpace::UserSerializer& arg2) { Fw::String str; arg2.toString(str); printf("ARG: %s\n",str.toChar()); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/serialize_user/UserSerializer.cpp
#include <Autocoders/Python/test/serialize_user/UserSerializer.hpp> #include <Fw/Types/Assert.hpp> #include <cstdio> namespace ANameSpace { UserSerializer::UserSerializer(): Serializable() { } UserSerializer::UserSerializer(const SomeUserStruct& src) : Serializable() { this->setVal(src); } UserSerializer::UserSerializer(const SomeUserStruct* src) : Serializable() { FW_ASSERT(src); this->setVal(*src); } UserSerializer::UserSerializer(SomeUserStruct val) : Serializable() { this->setVal(val); } SomeUserStruct& UserSerializer::operator=(const SomeUserStruct& src) { this->setVal(src); return this->m_struct; } void UserSerializer::getVal(SomeUserStruct& arg) { arg = this->m_struct; } void UserSerializer::setVal(const SomeUserStruct& val) { this->m_struct = val; } Fw::SerializeStatus UserSerializer::serialize(Fw::SerializeBufferBase& buffer) const { return buffer.serialize(reinterpret_cast<const U8*>(&m_struct),sizeof(m_struct)); } Fw::SerializeStatus UserSerializer::deserialize(Fw::SerializeBufferBase& buffer) { NATIVE_UINT_TYPE serSize = sizeof(m_struct); Fw::SerializeStatus stat = buffer.deserialize(reinterpret_cast<U8*>(&m_struct),serSize); FW_ASSERT(serSize == sizeof(m_struct)); return stat; } #if FW_SERIALIZABLE_TO_STRING void UserSerializer::toString(Fw::StringBase& text) const { // declare strings to hold any serializable toString() arguments char outputString[FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE]; snprintf(outputString,FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE, "SomeUserStruct: %d %f %d", this->m_struct.mem1,this->m_struct.mem2,this->m_struct.mem3); outputString[FW_SERIALIZABLE_TO_STRING_BUFFER_SIZE-1] = 0; // NULL terminate text = outputString; } #endif }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/serialize_user/UserSerializer.hpp
#ifndef EXAMPLE_TYPE_HPP #define EXAMPLE_TYPE_HPP // A hand-coded serializable #include <FpConfig.hpp> #include <Fw/Types/Serializable.hpp> #include <Autocoders/Python/test/serialize_user/SomeStruct.hpp> #if FW_SERIALIZABLE_TO_STRING #include <Fw/Types/StringType.hpp> #endif namespace ANameSpace { class UserSerializer : public Fw::Serializable { public: enum { SERIALIZED_SIZE = sizeof(SomeUserStruct) + sizeof(I32) }; UserSerializer(); // Default constructor UserSerializer(const SomeUserStruct* src); // copy constructor UserSerializer(const SomeUserStruct& src); // copy constructor UserSerializer(SomeUserStruct arg); // constructor with arguments SomeUserStruct& operator=(const SomeUserStruct& src); // Equal operator void setVal(const SomeUserStruct& arg); // set values void getVal(SomeUserStruct& arg); Fw::SerializeStatus serialize(Fw::SerializeBufferBase& buffer) const; Fw::SerializeStatus deserialize(Fw::SerializeBufferBase& buffer); #if FW_SERIALIZABLE_TO_STRING void toString(Fw::StringBase& text) const; //!< generate text from serializable #endif protected: private: SomeUserStruct m_struct; // stored value }; } #endif
hpp
fprime
data/projects/fprime/Autocoders/Python/test/serialize_user/SomeStruct.hpp
#ifndef SOME_STRUCT_HPP #define SOME_STRUCT_HPP #include <FpConfig.hpp> extern "C" { typedef struct { U32 mem1; F64 mem2; U8 mem3; } SomeUserStruct; } #endif
hpp
fprime
data/projects/fprime/Autocoders/Python/test/serialize_user/test/ut/main.cpp
#ifdef FPRIME_CMAKE #include "Autocoder/GTestBase.hpp" #else #include <serialize_userGTestBase.hpp> #endif // Very minimal to test autocoder. Some day they'll be actual unit test code class ATester : public ExampleComponents::ExampleComponentGTestBase { public: ATester() : ExampleComponents::ExampleComponentGTestBase("comp",10) { } void from_exampleOutput_handler( const NATIVE_INT_TYPE portNum, //!< The port number I32 arg1, //!< A built-in type argument const ANameSpace::UserSerializer& arg2 //!< A user-defined type argument ); }; void ATester::from_exampleOutput_handler( const NATIVE_INT_TYPE portNum, //!< The port number I32 arg1, //!< A built-in type argument const ANameSpace::UserSerializer& arg2 //!< A user-defined type argument ) { } int main(int argc, char* argv[]) { ATester testBase; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/param_enum/TestPrmImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/param_enum/TestPrmImpl.hpp> #include <cstdio> TestPrmImpl::TestPrmImpl(const char* name) : Prm::TestPrmComponentBase(name) { } TestPrmImpl::~TestPrmImpl() { } void TestPrmImpl::init() { Prm::TestPrmComponentBase::init(); } void TestPrmImpl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) { } void TestPrmImpl::printParam() { Fw::ParamValid valid = Fw::ParamValid::INVALID; SomeEnum val = this->paramGet_enumparam(valid); printf("Parameter is: %d %s\n",val,valid==Fw::ParamValid::VALID?"VALID":"INVALID"); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/param_enum/main.cpp
#include <Autocoders/Python/test/param_enum/TestPrmImpl.hpp> #include <Autocoders/Python/test/param_enum/TestPrmSourceImpl.hpp> #include <Fw/Obj/SimpleObjRegistry.hpp> int main(int argc, char* argv[]) { #if FW_PORT_TRACING Fw::PortBase::setTrace(true); #endif #if FW_OBJECT_REGISTRATION == 1 Fw::SimpleObjRegistry objReg; #endif TestPrmImpl testImpl("TestPrmImpl"); testImpl.init(); TestParamSourceImpl prmSrc("TestPrmSrc"); prmSrc.init(); testImpl.set_ParamGet_OutputPort(0,prmSrc.get_paramGetPort_InputPort(0)); testImpl.set_ParamSet_OutputPort(0,prmSrc.get_paramSetPort_InputPort(0)); #if FW_OBJECT_REGISTRATION == 1 objReg.dump(); #endif prmSrc.setPrm(7); testImpl.loadParameters(); testImpl.printParam(); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/param_enum/TestPrmSourceImpl.hpp
/* * TestTelemRecvImpl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTPARAMRECVIMPL_HPP_ #define TESTPARAMRECVIMPL_HPP_ #include <Autocoders/Python/test/param_tester/ParamTestComponentAc.hpp> class TestParamSourceImpl: public Prm::ParamTesterComponentBase { public: TestParamSourceImpl(const char* compName); virtual ~TestParamSourceImpl(); void init(); void setPrm(I32 val); protected: Fw::ParamValid paramGetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val); void paramSetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val); private: Fw::ParamBuffer m_prm; }; #endif /* TESTCOMMANDSOURCEIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/param_enum/TestPrmSourceImpl.cpp
/* * TestCommand1Impl.cpp * * Created on: Mar 28, 2014 * Author: tcanham */ #include <Autocoders/Python/test/param_enum/TestPrmSourceImpl.hpp> #include <cstdio> TestParamSourceImpl::TestParamSourceImpl(const char* name) : Prm::ParamTesterComponentBase(name) { } TestParamSourceImpl::~TestParamSourceImpl() { } Fw::ParamValid TestParamSourceImpl::paramGetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val) { val = this->m_prm; return Fw::ParamValid::VALID; } void TestParamSourceImpl::paramSetPort_handler(NATIVE_INT_TYPE portNum, FwPrmIdType id, Fw::ParamBuffer &val) { } void TestParamSourceImpl::init() { Prm::ParamTesterComponentBase::init(); } void TestParamSourceImpl::setPrm(I32 val) { printf("Setting parameter to %d\n",val); this->m_prm.resetSer(); this->m_prm.serialize(val); }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/param_enum/TestPrmImpl.hpp
/* * TestPrmImpl.hpp * * Created on: Mar 28, 2014 * Author: tcanham */ #ifndef TESTPARAMIMPL_HPP_ #define TESTPARAMIMPL_HPP_ #include <Autocoders/Python/test/param_enum/TestComponentAc.hpp> class TestPrmImpl: public Prm::TestPrmComponentBase { public: TestPrmImpl(const char* compName); void genTlm(U32 val); virtual ~TestPrmImpl(); void init(); void printParam(); protected: void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6); }; #endif /* TESTPARAMIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/param_enum/test/ut/main.cpp
#ifdef FPRIME_CMAKE #include "Autocoder/GTestBase.hpp" #else #include <param_enumGTestBase.hpp> #endif // Very minimal to test autocoder. Some day they'll be actual unit test code class ATester : public Prm::TestPrmGTestBase { public: ATester() : Prm::TestPrmGTestBase("comp",10) { } }; int main(int argc, char* argv[]) { ATester testBase; }
cpp
fprime
data/projects/fprime/Autocoders/Python/test/queued1/TestComponentImpl.hpp
/* * TestComponentImpl.hpp * * Created on: Jul 1, 2015 * Author: tcanham */ #ifndef TEST_QUEUED1_TESTCOMPONENTIMPL_HPP_ #define TEST_QUEUED1_TESTCOMPONENTIMPL_HPP_ #include <Autocoders/Python/test/queued1/TestComponentAc.hpp> namespace SvcTest { class TestComponentImpl: public AQueuedTest::TestComponentBase { public: TestComponentImpl(const char* compName); virtual ~TestComponentImpl(); private: void aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6); void aport2_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, bool arg6); }; } /* namespace SvcTest */ #endif /* TEST_QUEUED1_TESTCOMPONENTIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/queued1/TestComponentImpl.cpp
/* * TestComponentImpl.cpp * * Created on: Jul 1, 2015 * Author: tcanham */ #include <Autocoders/Python/test/queued1/TestComponentImpl.hpp> #include <cstdio> namespace SvcTest { TestComponentImpl::TestComponentImpl(const char* compName) : TestComponentBase(compName) { } TestComponentImpl::~TestComponentImpl() { } void TestComponentImpl::aport_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, U8 arg6) { printf("aport_handler called with %d, %f, %d,\n",arg4,arg5,arg6); // call dispatcher MsgDispatchStatus stat = this->doDispatch(); printf("Dispatch status: %d\n",stat); } void TestComponentImpl::aport2_handler(NATIVE_INT_TYPE portNum, I32 arg4, F32 arg5, bool arg6) { printf("aport2_handler called with %d, %f, %s.\n",arg4,arg5,arg6?"TRUE":"FALSE"); } } /* namespace SvcTest */
cpp
fprime
data/projects/fprime/Autocoders/Python/test/queued1/test/ut/ComponentTesterImpl.hpp
/* * ComponentTesterImpl.hpp * * Created on: Jul 1, 2015 * Author: tcanham */ #ifndef TEST_QUEUED1_TEST_UT_COMPONENTTESTERIMPL_HPP_ #define TEST_QUEUED1_TEST_UT_COMPONENTTESTERIMPL_HPP_ #include <Autocoders/Python/test/queued1/TestComponentTestAc.hpp> #include <Autocoders/Python/test/queued1/TestComponentImpl.hpp> namespace SvcTest { class ComponentTesterImpl: public AQueuedTest::TestTesterComponentBase { public: ComponentTesterImpl(const char* compName); virtual ~ComponentTesterImpl(); void init(); void runTest(); private: }; } /* namespace SvcTest */ #endif /* TEST_QUEUED1_TEST_UT_COMPONENTTESTERIMPL_HPP_ */
hpp
fprime
data/projects/fprime/Autocoders/Python/test/queued1/test/ut/ComponentTesterImpl.cpp
/* * ComponentTesterImpl.cpp * * Created on: Jul 1, 2015 * Author: tcanham */ #include "ComponentTesterImpl.hpp" namespace SvcTest { ComponentTesterImpl::ComponentTesterImpl(const char* compName) : TestTesterComponentBase(compName) { } ComponentTesterImpl::~ComponentTesterImpl() { } void ComponentTesterImpl::init() { TestTesterComponentBase::init(); } void ComponentTesterImpl::runTest() { printf("Invoking aport2\n"); this->aport2_out(0, 1, 2.3, true); printf("Invoking aport\n"); this->aport_out(0,4, 5.0, 6); printf("Invoking aport again.\n"); this->aport_out(0,7, 8.9, 10); } } /* namespace SvcTest */
cpp
fprime
data/projects/fprime/Autocoders/Python/test/queued1/test/ut/ComponentTester.cpp
#include <Autocoders/Python/test/queued1/test/ut/ComponentTesterImpl.hpp> #include <Autocoders/Python/test/queued1/TestComponentImpl.hpp> int main(int argc, char* argv[]) { SvcTest::TestComponentImpl impl("impl"); SvcTest::ComponentTesterImpl tester("tester"); impl.init(10); tester.init(); tester.set_aport_OutputPort(0,impl.get_aport_InputPort(0)); tester.set_aport2_OutputPort(0,impl.get_aport2_InputPort(0)); tester.runTest(); return 0; }
cpp
fprime
data/projects/fprime/Svc/UdpReceiver/UdpReceiverComponentImpl.hpp
// ====================================================================== // \title UdpReceiverImpl.hpp // \author tcanham // \brief hpp file for UdpReceiver component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef UdpReceiver_HPP #define UdpReceiver_HPP #include "Svc/UdpReceiver/UdpReceiverComponentAc.hpp" #include "UdpReceiverComponentImplCfg.hpp" namespace Svc { class UdpReceiverComponentImpl : public UdpReceiverComponentBase { public: // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Construct object UdpReceiver //! UdpReceiverComponentImpl( const char *const compName /*!< The component name*/ ); //! Initialize object UdpReceiver //! void init( const NATIVE_INT_TYPE instance = 0 /*!< The instance number*/ ); //! Destroy object UdpReceiver //! ~UdpReceiverComponentImpl(); //! Open the connection void open( const char* port ); //! start worker thread void startThread( NATIVE_UINT_TYPE priority, /*!< read task priority */ NATIVE_UINT_TYPE stackSize, /*!< stack size */ NATIVE_UINT_TYPE affinity /*!< cpu affinity */ ); PRIVATE: // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- //! Handler implementation for Sched //! void Sched_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 context /*!< The call order*/ ); static void workerTask(void* ptr); //!< worker task entry point void doRecv(); //!< receives a single packet (helps unit testing) Os::Task m_socketTask; NATIVE_INT_TYPE m_fd; //!< socket file descriptor class UdpSerialBuffer : public Fw::SerializeBufferBase { public: #ifdef BUILD_UT UdpSerialBuffer& operator=(const UdpSerialBuffer& other); UdpSerialBuffer(const Fw::SerializeBufferBase& other); UdpSerialBuffer(const UdpSerialBuffer& other); UdpSerialBuffer(); #endif NATIVE_UINT_TYPE getBuffCapacity() const { return sizeof(m_buff); } // Get the max number of bytes that can be serialized NATIVE_UINT_TYPE getBuffSerLeft() const { const NATIVE_UINT_TYPE size = getBuffCapacity(); const NATIVE_UINT_TYPE loc = getBuffLength(); if (loc >= (size-1) ) { return 0; } else { return (size - loc - 1); } } U8* getBuffAddr() { return m_buff; } const U8* getBuffAddr() const { return m_buff; } private: // Should be the max of all the input ports serialized sizes... U8 m_buff[UDP_RECEIVER_MSG_SIZE]; } m_recvBuff; UdpSerialBuffer m_portBuff; //!< working buffer for decoding packets U32 m_packetsReceived; //!< number of packets received U32 m_bytesReceived; //!< number of bytes received U32 m_packetsDropped; //!< number of detected packets dropped U32 m_decodeErrors; //!< deserialization errors bool m_firstSeq; //!< first sequence number detected U8 m_currSeq; //!< current tracked sequence number }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/UdpReceiver/UdpReceiverComponentImpl.cpp
// ====================================================================== // \title UdpReceiverImpl.cpp // \author tcanham // \brief cpp file for UdpReceiver component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include <Svc/UdpReceiver/UdpReceiverComponentImpl.hpp> #include <FpConfig.hpp> #include <sys/types.h> #include <cstring> #include <cerrno> #include <cstdlib> #include <unistd.h> #include <sys/socket.h> #include <arpa/inet.h> #include <Os/TaskString.hpp> //#define DEBUG_PRINT(...) printf(##__VA_ARGS__) #define DEBUG_PRINT(...) namespace Svc { // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- UdpReceiverComponentImpl :: UdpReceiverComponentImpl( const char *const compName ) : UdpReceiverComponentBase(compName), m_fd(-1), m_packetsReceived(0), m_bytesReceived(0), m_packetsDropped(0), m_decodeErrors(0), m_firstSeq(true), m_currSeq(0) { } void UdpReceiverComponentImpl :: init( const NATIVE_INT_TYPE instance ) { UdpReceiverComponentBase::init(instance); } UdpReceiverComponentImpl :: ~UdpReceiverComponentImpl() { if (this->m_fd != -1) { close(this->m_fd); } } void UdpReceiverComponentImpl::open( const char* port ) { //create a UDP socket this->m_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (-1 == this->m_fd) { Fw::LogStringArg arg(strerror(errno)); this->log_WARNING_HI_UR_SocketError(arg); } sockaddr_in saddr; // zero out the structure memset(&saddr, 0, sizeof(saddr)); saddr.sin_family = AF_INET; saddr.sin_port = htons(atoi(port)); saddr.sin_addr.s_addr = htonl(INADDR_ANY); //bind socket to port NATIVE_INT_TYPE status = bind(this->m_fd , (struct sockaddr*)&saddr, sizeof(saddr)); if (-1 == status) { Fw::LogStringArg arg(strerror(errno)); this->log_WARNING_HI_UR_BindError(arg); close(this->m_fd); this->m_fd = -1; } else { this->log_ACTIVITY_HI_UR_PortOpened(atoi(port)); } } void UdpReceiverComponentImpl::startThread( NATIVE_UINT_TYPE priority, /*!< read task priority */ NATIVE_UINT_TYPE stackSize, /*!< stack size */ NATIVE_UINT_TYPE affinity /*!< cpu affinity */ ) { Os::TaskString name(this->getObjName()); Os::Task::TaskStatus stat = this->m_socketTask.start( name, 0, priority, stackSize, UdpReceiverComponentImpl::workerTask, this, affinity); FW_ASSERT(Os::Task::TASK_OK == stat,stat); } // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- void UdpReceiverComponentImpl :: Sched_handler( const NATIVE_INT_TYPE portNum, U32 context ) { this->tlmWrite_UR_BytesReceived(this->m_bytesReceived); this->tlmWrite_UR_PacketsReceived(this->m_packetsReceived); this->tlmWrite_UR_PacketsDropped(this->m_packetsDropped); } void UdpReceiverComponentImpl::workerTask(void* ptr) { UdpReceiverComponentImpl *compPtr = static_cast<UdpReceiverComponentImpl*>(ptr); while (true) { compPtr->doRecv(); } } void UdpReceiverComponentImpl::doRecv() { // wait for data from the socket NATIVE_INT_TYPE psize = recvfrom( this->m_fd, this->m_recvBuff.getBuffAddr(), this->m_recvBuff.getBuffCapacity(), MSG_WAITALL, 0, 0); if (-1 == psize) { if (errno != EINTR) { Fw::LogStringArg arg(strerror(errno)); this->log_WARNING_HI_UR_RecvError(arg); } return; } // reset buffer for deserialization Fw::SerializeStatus stat = this->m_recvBuff.setBuffLen(psize); FW_ASSERT(Fw::FW_SERIALIZE_OK == stat, stat); // get sequence number U8 seqNum; stat = this->m_recvBuff.deserialize(seqNum); // check for deserialization error or port number too high if (stat != Fw::FW_SERIALIZE_OK) { this->log_WARNING_HI_UR_DecodeError(DECODE_SEQ,stat); this->m_decodeErrors++; return; } // track sequence number if (this->m_firstSeq) { // first time, set tracked sequence number equal to the one received this->m_currSeq = seqNum; this->m_firstSeq = false; } else { // make sure sequence number has gone up by one if (seqNum != ++this->m_currSeq) { // will only be right if it rolls over only once, but better than nothing U8 diff = seqNum - this->m_currSeq; this->m_packetsDropped += diff; // send EVR this->log_WARNING_HI_UR_DroppedPacket(diff); // reset to current sequence this->m_currSeq = seqNum; } } // get port number U8 portNum; stat = this->m_recvBuff.deserialize(portNum); // check for deserialization error or port number too high if (stat != Fw::FW_SERIALIZE_OK or portNum > this->getNum_PortsOut_OutputPorts()) { this->log_WARNING_HI_UR_DecodeError(DECODE_PORT,stat); this->m_decodeErrors++; return; } // get buffer for port stat = this->m_recvBuff.deserialize(this->m_portBuff); if (stat != Fw::FW_SERIALIZE_OK) { this->log_WARNING_HI_UR_DecodeError(DECODE_BUFFER,stat); this->m_decodeErrors++; return; } // call output port DEBUG_PRINT("Calling port %d with %d bytes.\n",portNum,this->m_portBuff.getBuffLength()); if (this->isConnected_PortsOut_OutputPort(portNum)) { Fw::SerializeStatus stat = this->PortsOut_out(portNum,this->m_portBuff); // If had issues deserializing the data, then report it: if (stat != Fw::FW_SERIALIZE_OK) { this->log_WARNING_HI_UR_DecodeError(PORT_SEND,stat); this->m_decodeErrors++; } this->m_packetsReceived++; this->m_bytesReceived += psize; } } #ifdef BUILD_UT UdpReceiverComponentImpl::UdpSerialBuffer& UdpReceiverComponentImpl::UdpSerialBuffer::operator=(const UdpReceiverComponentImpl::UdpSerialBuffer& other) { this->resetSer(); this->serialize(other.getBuffAddr(),other.getBuffLength(),true); return *this; } UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer( const Fw::SerializeBufferBase& other) : Fw::SerializeBufferBase() { FW_ASSERT(sizeof(this->m_buff)>= other.getBuffLength(),sizeof(this->m_buff),other.getBuffLength()); memcpy(this->m_buff,other.getBuffAddr(),other.getBuffLength()); this->setBuffLen(other.getBuffLength()); } UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer( const UdpReceiverComponentImpl::UdpSerialBuffer& other) : Fw::SerializeBufferBase() { FW_ASSERT(sizeof(this->m_buff)>= other.getBuffLength(),sizeof(this->m_buff),other.getBuffLength()); memcpy(this->m_buff,other.m_buff,other.getBuffLength()); this->setBuffLen(other.getBuffLength()); } UdpReceiverComponentImpl::UdpSerialBuffer::UdpSerialBuffer(): Fw::SerializeBufferBase() { } #endif } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/UdpReceiver/test/ut/main.cpp
#include <Svc/UdpReceiver/test/ut/Tester.hpp> #include <Fw/Test/UnitTest.hpp> TEST(Nominal,OpenConnection) { COMMENT("Open the connections"); Svc::Tester tester; tester.openTest("50000"); } TEST(Nominal,RecvPacket) { COMMENT("Receive a packet"); Svc::Tester tester; tester.recvTest("50000"); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
cpp
fprime
data/projects/fprime/Svc/UdpReceiver/test/ut/Tester.cpp
// ====================================================================== // \title UdpReceiver.hpp // \author tcanham // \brief cpp file for UdpReceiver test harness implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Tester.hpp" #include <sys/types.h> #include <cstring> #include <cerrno> #include <cstdlib> #include <unistd.h> #include <sys/socket.h> #include <arpa/inet.h> #define INSTANCE 0 #define MAX_HISTORY_SIZE 10 namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- Tester :: Tester() : UdpReceiverGTestBase("Tester", MAX_HISTORY_SIZE), component("UdpReceiver") { this->initComponents(); this->connectPorts(); } Tester :: ~Tester() { } // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void Tester::openTest(const char* port) { this->component.open("50000"); } void Tester::recvTest(const char* port) { this->component.open("50000"); // send a packet this->sendPacket(20,"127.0.0.1","50000",26,3); // retrieve the packet this->m_sentVal = 0; this->m_sentPort = 0; this->component.doRecv(); // verify the port call EXPECT_EQ(20u,this->m_sentVal); EXPECT_EQ(3,this->m_sentPort); } // ---------------------------------------------------------------------- // Handlers for serial from ports // ---------------------------------------------------------------------- void Tester :: from_PortsOut_handler( NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::SerializeBufferBase &Buffer /*!< The serialization buffer*/ ) { this->m_sentPort = portNum; EXPECT_EQ(Fw::FW_SERIALIZE_OK,Buffer.deserialize(this->m_sentVal)); } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void Tester :: connectPorts() { // Sched this->connect_to_Sched( 0, this->component.get_Sched_InputPort(0) ); // Tlm this->component.set_Tlm_OutputPort( 0, this->get_from_Tlm(0) ); // Time this->component.set_Time_OutputPort( 0, this->get_from_Time(0) ); // Log this->component.set_Log_OutputPort( 0, this->get_from_Log(0) ); // LogText this->component.set_LogText_OutputPort( 0, this->get_from_LogText(0) ); // Output serial ports for (NATIVE_UINT_TYPE port = 0; port < UdpReceiverComponentImpl::NUM_PORTSOUT_OUTPUT_PORTS; port++) { this->component.set_PortsOut_OutputPort(port,this->get_from_PortsOut(port)); } // ---------------------------------------------------------------------- // Connect serial output ports // ---------------------------------------------------------------------- for (NATIVE_INT_TYPE i = 0; i < 10; ++i) { this->component.set_PortsOut_OutputPort( i, this->get_from_PortsOut(i) ); } } void Tester :: initComponents() { this->init(); this->component.init( INSTANCE ); } void Tester::sendPacket(U32 val, const char* addr, const char* port, NATIVE_UINT_TYPE seq, NATIVE_UINT_TYPE portNum) { // open UDP connection NATIVE_INT_TYPE fd = socket(AF_INET, SOCK_DGRAM, 0); EXPECT_NE(fd,-1); /* fill in the server's address and data */ struct sockaddr_in sockAddr; memset(&sockAddr, 0, sizeof(sockAddr)); sockAddr.sin_family = AF_INET; sockAddr.sin_port = htons(atoi(port)); inet_aton(addr , &sockAddr.sin_addr); UdpReceiverComponentImpl::UdpSerialBuffer buff; // serialize sequence number EXPECT_EQ(Fw::FW_SERIALIZE_OK,buff.serialize(static_cast<U8>(seq))); // serialize port call EXPECT_EQ(Fw::FW_SERIALIZE_OK,buff.serialize(static_cast<U8>(portNum))); UdpReceiverComponentImpl::UdpSerialBuffer portBuff; EXPECT_EQ(Fw::FW_SERIALIZE_OK,portBuff.serialize(val)); EXPECT_EQ(Fw::FW_SERIALIZE_OK,buff.serialize(portBuff)); // send on UDP socket ssize_t sendStat = sendto(fd, buff.getBuffAddr(), buff.getBuffLength(), 0, reinterpret_cast<struct sockaddr *>(&sockAddr), sizeof(sockAddr)); EXPECT_NE(-1,sendStat); EXPECT_EQ(buff.getBuffLength(),sendStat); close(fd); } void Tester::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); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/UdpReceiver/test/ut/Tester.hpp
// ====================================================================== // \title UdpReceiver/test/ut/Tester.hpp // \author tcanham // \brief hpp file for UdpReceiver 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 "UdpReceiverGTestBase.hpp" #include "Svc/UdpReceiver/UdpReceiverComponentImpl.hpp" namespace Svc { class Tester : public UdpReceiverGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: //! Construct object Tester //! Tester(); //! Destroy object Tester //! ~Tester(); public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! Open the connection //! void openTest(const char* port); //! Receive a packet //! void recvTest(const char* port); private: // ---------------------------------------------------------------------- // Handlers for serial from ports // ---------------------------------------------------------------------- //! Handler for from_PortsOut //! void from_PortsOut_handler( NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::SerializeBufferBase &Buffer /*!< The serialization buffer*/ ); private: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(); //! Initialize components //! void initComponents(); private: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! UdpReceiverComponentImpl component; // helper to send a packet void sendPacket(U32 val, const char* addr, const char* port, NATIVE_UINT_TYPE seq, NATIVE_UINT_TYPE portNum); // stored port call arguments U32 m_sentVal; NATIVE_INT_TYPE m_sentPort; void 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 ); }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/CmdSplitter/CmdSplitter.cpp
// ====================================================================== // \title CmdSplitter.cpp // \author watney // \brief cpp file for CmdSplitter component implementation class // ====================================================================== #include <FpConfig.hpp> #include <Fw/Cmd/CmdPacket.hpp> #include <Svc/CmdSplitter/CmdSplitter.hpp> #include <Fw/Types/Assert.hpp> #include <FppConstantsAc.hpp> namespace Svc { // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- CmdSplitter ::CmdSplitter(const char* const compName) : CmdSplitterComponentBase(compName) {} CmdSplitter ::~CmdSplitter() {} void CmdSplitter ::configure(const FwOpcodeType remoteBaseOpcode) { this->m_remoteBase = remoteBaseOpcode; } // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- void CmdSplitter ::CmdBuff_handler(const NATIVE_INT_TYPE portNum, Fw::ComBuffer& data, U32 context) { Fw::CmdPacket cmdPkt; Fw::SerializeStatus stat = cmdPkt.deserialize(data); FW_ASSERT(portNum < CmdSplitterPorts); if (stat != Fw::FW_SERIALIZE_OK) { // Let the local command dispatcher deal with it this->LocalCmd_out(portNum, data, context); } else { // Check if local or remote if (cmdPkt.getOpCode() < this->m_remoteBase) { this->LocalCmd_out(portNum, data, context); } else { this->RemoteCmd_out(portNum, data, context); } } } void CmdSplitter ::seqCmdStatus_handler(const NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdResponse& response) { FW_ASSERT(portNum < CmdSplitterPorts); // Forward the command status this->forwardSeqCmdStatus_out(portNum, opCode, cmdSeq, response); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/CmdSplitter/CmdSplitter.hpp
// ====================================================================== // \title CmdSplitter.hpp // \author watney // \brief hpp file for CmdSplitter component implementation class // ====================================================================== #ifndef CmdSplitter_HPP #define CmdSplitter_HPP #include <Fw/Cmd/CmdResponsePortAc.hpp> #include "Svc/CmdSplitter/CmdSplitterComponentAc.hpp" namespace Svc { class CmdSplitter : public CmdSplitterComponentBase { public: // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Construct object CmdSplitter //! CmdSplitter(const char* const compName /*!< The component name*/ ); //! Destroy object CmdSplitter //! ~CmdSplitter(); //! Configure this splitter //! void configure(const FwOpcodeType remoteBaseOpcode /*!< Base remote opcode*/); PRIVATE: // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- //! Handler implementation for CmdBuff //! void CmdBuff_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 */ ); //! Handler implementation for seqCmdStatus //! void seqCmdStatus_handler(const NATIVE_INT_TYPE portNum, /*!< The port number */ FwOpcodeType opCode, /*!< Command Op Code */ U32 cmdSeq, /*!< Command Sequence */ const Fw::CmdResponse& response /*!< The command response argument */ ); FwOpcodeType m_remoteBase; // Opcodes greater than or equal than this value will route remotely }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/CmdSplitter/test/ut/CmdSplitterTestMain.cpp
// ---------------------------------------------------------------------- // TestMain.cpp // ---------------------------------------------------------------------- #include "CmdSplitterTester.hpp" TEST(Nominal, Local) { Svc::CmdSplitterTester tester; tester.test_local_routing(); } TEST(Nominal, Remote) { Svc::CmdSplitterTester tester; tester.test_remote_routing(); } TEST(Nominal, Forwarding) { Svc::CmdSplitterTester tester; tester.test_response_forwarding(); } TEST(Error, BadCommands) { Svc::CmdSplitterTester tester; tester.test_error_routing(); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
cpp
fprime
data/projects/fprime/Svc/CmdSplitter/test/ut/CmdSplitterTester.hpp
// ====================================================================== // \title CmdSplitter/test/ut/Tester.hpp // \author mstarch // \brief hpp file for CmdSplitter test harness implementation class // ====================================================================== #ifndef TESTER_HPP #define TESTER_HPP #include "CmdSplitterGTestBase.hpp" #include "Svc/CmdSplitter/CmdSplitter.hpp" namespace Svc { class CmdSplitterTester : public CmdSplitterGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: // Maximum size of histories storing events, telemetry, and port outputs static const NATIVE_INT_TYPE MAX_HISTORY_SIZE = 10; // Instance ID supplied to the component instance under test static const NATIVE_INT_TYPE TEST_INSTANCE_ID = 0; //! Construct object CmdSplitterTester //! CmdSplitterTester(); //! Destroy object CmdSplitterTester //! ~CmdSplitterTester(); public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! Test that commands under a limit route locally //! void test_local_routing(); //! Test the commands above the limit route remotely //! void test_remote_routing(); //! Test that errored command route locally //! void test_error_routing(); //! Test that command response forwarding works //! void test_response_forwarding(); private: //! Helper to build a com buffer given an opcode //! Fw::ComBuffer build_command_around_opcode(FwOpcodeType opcode); //! Helper to set opcode base and select a valid opcode //! FwOpcodeType setup_and_pick_valid_opcode(bool for_local /*!< Local command testing*/); // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- //! Handler for from_LocalCmd //! void from_LocalCmd_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 */ ); //! Handler for from_RemoteCmd //! void from_RemoteCmd_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 */ ); //! Handler for from_forwardSeqCmdStatus //! void from_forwardSeqCmdStatus_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ FwOpcodeType opCode, /*!< Command Op Code */ U32 cmdSeq, /*!< Command Sequence */ const Fw::CmdResponse& response /*!< The command response argument */ ); private: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(); //! Initialize components //! void initComponents(); private: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! CmdSplitter component; NATIVE_INT_TYPE active_command_source; }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/CmdSplitter/test/ut/CmdSplitterTester.cpp
// ====================================================================== // \title CmdSplitter.hpp // \author mstarch // \brief cpp file for CmdSplitter test harness implementation class // ====================================================================== #include "CmdSplitterTester.hpp" #include <Fw/Cmd/CmdPacket.hpp> #include <Fw/Test/UnitTest.hpp> #include <STest/Pick/Pick.hpp> #include "FppConstantsAc.hpp" namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- CmdSplitterTester ::CmdSplitterTester() : CmdSplitterGTestBase("Tester", CmdSplitterTester::MAX_HISTORY_SIZE), component("CmdSplitter") { this->initComponents(); this->connectPorts(); } CmdSplitterTester ::~CmdSplitterTester() {} // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- Fw::ComBuffer CmdSplitterTester ::build_command_around_opcode(FwOpcodeType opcode) { Fw::ComBuffer comBuffer; EXPECT_EQ(comBuffer.serialize(static_cast<FwPacketDescriptorType>(Fw::ComPacket::FW_PACKET_COMMAND)), Fw::FW_SERIALIZE_OK); EXPECT_EQ(comBuffer.serialize(opcode), Fw::FW_SERIALIZE_OK); Fw::CmdArgBuffer args; U32 random_size = STest::Pick::lowerUpper(0, args.getBuffCapacity()); args.resetSer(); for (FwSizeType i = 0; i < random_size; i++) { args.serialize(static_cast<U8>(STest::Pick::any())); } EXPECT_EQ(comBuffer.serialize(args), Fw::FW_SERIALIZE_OK); return comBuffer; } FwOpcodeType CmdSplitterTester ::setup_and_pick_valid_opcode(bool for_local) { const FwOpcodeType MAX_OPCODE = std::numeric_limits<FwOpcodeType>::max(); if (for_local) { FwOpcodeType base = STest::Pick::lowerUpper(1, MAX_OPCODE); component.configure(base); EXPECT_GT(base, 0); // Must leave some room for local commands return static_cast<FwOpcodeType>( STest::Pick::lowerUpper(0, FW_MIN(base - 1, MAX_OPCODE)) ); } FwOpcodeType base = STest::Pick::lowerUpper(0, MAX_OPCODE); component.configure(base); return static_cast<FwOpcodeType>(STest::Pick::lowerUpper(base, MAX_OPCODE)); } void CmdSplitterTester ::test_local_routing() { REQUIREMENT("SVC-CMD-SPLITTER-000"); REQUIREMENT("SVC-CMD-SPLITTER-001"); REQUIREMENT("SVC-CMD-SPLITTER-002"); FwOpcodeType local_opcode = this->setup_and_pick_valid_opcode(true); Fw::ComBuffer testBuffer = this->build_command_around_opcode(local_opcode); U32 context = static_cast<U32>(STest::Pick::any()); this->active_command_source = static_cast<NATIVE_INT_TYPE>(STest::Pick::lowerUpper( 0, CmdSplitterPorts)); this->invoke_to_CmdBuff(this->active_command_source, testBuffer, context); ASSERT_from_RemoteCmd_SIZE(0); ASSERT_from_LocalCmd_SIZE(1); ASSERT_from_LocalCmd(0, testBuffer, context); } void CmdSplitterTester ::test_remote_routing() { REQUIREMENT("SVC-CMD-SPLITTER-000"); REQUIREMENT("SVC-CMD-SPLITTER-001"); REQUIREMENT("SVC-CMD-SPLITTER-003"); FwOpcodeType remote_opcode = this->setup_and_pick_valid_opcode(false); Fw::ComBuffer testBuffer = this->build_command_around_opcode(remote_opcode); U32 context = static_cast<U32>(STest::Pick::any()); this->active_command_source = static_cast<NATIVE_INT_TYPE>(STest::Pick::lowerUpper( 0, CmdSplitterPorts)); this->invoke_to_CmdBuff(this->active_command_source, testBuffer, context); ASSERT_from_LocalCmd_SIZE(0); ASSERT_from_RemoteCmd_SIZE(1); ASSERT_from_RemoteCmd(0, testBuffer, context); } void CmdSplitterTester ::test_error_routing() { REQUIREMENT("SVC-CMD-SPLITTER-000"); REQUIREMENT("SVC-CMD-SPLITTER-001"); REQUIREMENT("SVC-CMD-SPLITTER-004"); Fw::ComBuffer testBuffer; // Intentionally left empty U32 context = static_cast<U32>(STest::Pick::any()); this->active_command_source = static_cast<NATIVE_INT_TYPE>(STest::Pick::lowerUpper( 0, CmdDispatcherSequencePorts)); this->invoke_to_CmdBuff(this->active_command_source, testBuffer, context); ASSERT_from_RemoteCmd_SIZE(0); ASSERT_from_LocalCmd_SIZE(1); ASSERT_from_LocalCmd(0, testBuffer, context); } void CmdSplitterTester ::test_response_forwarding() { REQUIREMENT("SVC-CMD-SPLITTER-000"); REQUIREMENT("SVC-CMD-SPLITTER-001"); REQUIREMENT("SVC-CMD-SPLITTER-005"); FwOpcodeType opcode = static_cast<FwOpcodeType>(STest::Pick::lowerUpper(0, std::numeric_limits<FwOpcodeType>::max())); Fw::CmdResponse response; response.e = static_cast<Fw::CmdResponse::T>(STest::Pick::lowerUpper(0, Fw::CmdResponse::NUM_CONSTANTS)); U32 cmdSeq = static_cast<U32>(STest::Pick::any()); this->active_command_source = static_cast<NATIVE_INT_TYPE>(STest::Pick::lowerUpper( 0, CmdDispatcherSequencePorts)); this->invoke_to_seqCmdStatus(this->active_command_source, opcode, cmdSeq, response); ASSERT_from_forwardSeqCmdStatus_SIZE(1); ASSERT_from_forwardSeqCmdStatus(0, opcode, cmdSeq, response); } // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- void CmdSplitterTester ::from_LocalCmd_handler(const NATIVE_INT_TYPE portNum, Fw::ComBuffer& data, U32 context) { EXPECT_EQ(this->active_command_source, portNum) << "Command source not respected"; this->pushFromPortEntry_LocalCmd(data, context); } void CmdSplitterTester ::from_RemoteCmd_handler(const NATIVE_INT_TYPE portNum, Fw::ComBuffer& data, U32 context) { EXPECT_EQ(this->active_command_source, portNum) << "Command source not respected"; this->pushFromPortEntry_RemoteCmd(data, context); } void CmdSplitterTester ::from_forwardSeqCmdStatus_handler(const NATIVE_INT_TYPE portNum, FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdResponse& response) { EXPECT_EQ(this->active_command_source, portNum) << "Command source not respected"; this->pushFromPortEntry_forwardSeqCmdStatus(opCode, cmdSeq, response); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/GenericHub/GenericHubComponentImpl.hpp
// ====================================================================== // \title GenericHubComponentImpl.hpp // \author mstarch // \brief hpp file for GenericHub component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef GenericHub_HPP #define GenericHub_HPP #include "Svc/GenericHub/GenericHubComponentAc.hpp" namespace Svc { class GenericHubComponentImpl : public GenericHubComponentBase { public: /** * HubType: * * Type of serialized data on the wire. Allows for expanding them on the opposing end. */ enum HubType { HUB_TYPE_PORT, //!< Port type transmission HUB_TYPE_BUFFER, //!< Buffer type transmission HUB_TYPE_EVENT, //!< Event transmission HUB_TYPE_CHANNEL, //!< Telemetry channel type HUB_TYPE_MAX }; const static U32 GENERIC_HUB_DATA_SIZE = 1024; // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Construct object GenericHub //! GenericHubComponentImpl(const char* const compName /*!< The component name*/ ); //! Initialize object GenericHub //! void init(const NATIVE_INT_TYPE instance = 0 /*!< The instance number*/ ); //! Destroy object GenericHub //! ~GenericHubComponentImpl(); PRIVATE: // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- //! Handler implementation for buffersIn //! void buffersIn_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::Buffer& fwBuffer); //! Handler implementation for dataIn //! void dataIn_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::Buffer& fwBuffer); //! Handler implementation for LogRecv //! void LogRecv_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ FwEventIdType id, /*!< Log ID */ Fw::Time& timeTag, /*!< Time Tag */ const Fw::LogSeverity& severity, /*!< The severity argument */ Fw::LogBuffer& args /*!< Buffer containing serialized log entry */ ); //! 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 implementations for user-defined serial input ports // ---------------------------------------------------------------------- //! Handler implementation for portIn //! void portIn_handler(NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::SerializeBufferBase& Buffer /*!< The serialization buffer*/ ); // Helpers and members void send_data(const HubType type, const NATIVE_INT_TYPE port, const U8* data, const U32 size); }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/GenericHub/GenericHubComponentImpl.cpp
// ====================================================================== // \title GenericHubComponentImpl.cpp // \author mstarch // \brief cpp file for GenericHub 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 <Svc/GenericHub/GenericHubComponentImpl.hpp> #include "Fw/Logger/Logger.hpp" #include "Fw/Types/Assert.hpp" // Required port serialization or the hub cannot work static_assert(FW_PORT_SERIALIZATION, "FW_PORT_SERIALIZATION must be enabled to use GenericHub"); namespace Svc { // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- GenericHubComponentImpl ::GenericHubComponentImpl(const char* const compName) : GenericHubComponentBase(compName) {} void GenericHubComponentImpl ::init(const NATIVE_INT_TYPE instance) { GenericHubComponentBase::init(instance); } GenericHubComponentImpl ::~GenericHubComponentImpl() {} void GenericHubComponentImpl ::send_data(const HubType type, const NATIVE_INT_TYPE port, const U8* data, const U32 size) { FW_ASSERT(data != nullptr); Fw::SerializeStatus status; // Buffer to send and a buffer used to write to it Fw::Buffer outgoing = dataOutAllocate_out(0, size + sizeof(U32) + sizeof(U32) + sizeof(FwBuffSizeType)); Fw::SerializeBufferBase& serialize = outgoing.getSerializeRepr(); // Write data to our buffer status = serialize.serialize(static_cast<U32>(type)); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); status = serialize.serialize(static_cast<U32>(port)); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); status = serialize.serialize(data, size); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); outgoing.setSize(serialize.getBuffLength()); dataOut_out(0, outgoing); } // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- void GenericHubComponentImpl ::buffersIn_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) { send_data(HUB_TYPE_BUFFER, portNum, fwBuffer.getData(), fwBuffer.getSize()); bufferDeallocate_out(0, fwBuffer); } void GenericHubComponentImpl ::dataIn_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) { HubType type = HUB_TYPE_MAX; U32 type_in = 0; U32 port = 0; FwBuffSizeType size = 0; Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK; // Representation of incoming data prepped for serialization Fw::SerializeBufferBase& incoming = fwBuffer.getSerializeRepr(); FW_ASSERT(incoming.setBuffLen(fwBuffer.getSize()) == Fw::FW_SERIALIZE_OK); // Must inform buffer that there is *real* data in the buffer status = incoming.setBuffLen(fwBuffer.getSize()); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); status = incoming.deserialize(type_in); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); type = static_cast<HubType>(type_in); FW_ASSERT(type < HUB_TYPE_MAX, type); status = incoming.deserialize(port); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); status = incoming.deserialize(size); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); // invokeSerial deserializes arguments before calling a normal invoke, this will return ownership immediately U8* rawData = fwBuffer.getData() + sizeof(U32) + sizeof(U32) + sizeof(FwBuffSizeType); U32 rawSize = fwBuffer.getSize() - sizeof(U32) - sizeof(U32) - sizeof(FwBuffSizeType); FW_ASSERT(rawSize == static_cast<U32>(size)); if (type == HUB_TYPE_PORT) { // Com buffer representations should be copied before the call returns, so we need not "allocate" new data Fw::ExternalSerializeBuffer wrapper(rawData, rawSize); status = wrapper.setBuffLen(rawSize); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); portOut_out(port, wrapper); // Deallocate the existing buffer dataInDeallocate_out(0, fwBuffer); } else if (type == HUB_TYPE_BUFFER) { // Fw::Buffers can reuse the existing data buffer as the storage type! No deallocation done. fwBuffer.set(rawData, rawSize, fwBuffer.getContext()); buffersOut_out(port, fwBuffer); } else if (type == HUB_TYPE_EVENT) { FwEventIdType id; Fw::Time timeTag; Fw::LogSeverity severity; Fw::LogBuffer args; // Deserialize tokens for events status = incoming.deserialize(id); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); status = incoming.deserialize(timeTag); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); status = incoming.deserialize(severity); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); status = incoming.deserialize(args); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); // Send it! this->LogSend_out(port, id, timeTag, severity, args); // Deallocate the existing buffer dataInDeallocate_out(0, fwBuffer); } else if (type == HUB_TYPE_CHANNEL) { FwChanIdType id; Fw::Time timeTag; Fw::TlmBuffer val; // Deserialize tokens for channels status = incoming.deserialize(id); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); status = incoming.deserialize(timeTag); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); status = incoming.deserialize(val); FW_ASSERT(status == Fw::FW_SERIALIZE_OK, static_cast<NATIVE_INT_TYPE>(status)); // Send it! this->TlmSend_out(port, id, timeTag, val); // Deallocate the existing buffer dataInDeallocate_out(0, fwBuffer); } } void GenericHubComponentImpl ::LogRecv_handler(const NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time& timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer& args) { Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK; U8 buffer[sizeof(FwEventIdType) + Fw::Time::SERIALIZED_SIZE + Fw::LogSeverity::SERIALIZED_SIZE + FW_LOG_BUFFER_MAX_SIZE]; Fw::ExternalSerializeBuffer serializer(buffer, sizeof(buffer)); serializer.resetSer(); status = serializer.serialize(id); FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); status = serializer.serialize(timeTag); FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); status = serializer.serialize(severity); FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); status = serializer.serialize(args); FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); U32 size = serializer.getBuffLength(); this->send_data(HubType::HUB_TYPE_EVENT, portNum, buffer, size); } void GenericHubComponentImpl ::TlmRecv_handler(const NATIVE_INT_TYPE portNum, FwChanIdType id, Fw::Time& timeTag, Fw::TlmBuffer& val) { Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK; U8 buffer[sizeof(FwChanIdType) + Fw::Time::SERIALIZED_SIZE + FW_TLM_BUFFER_MAX_SIZE]; Fw::ExternalSerializeBuffer serializer(buffer, sizeof(buffer)); serializer.resetSer(); status = serializer.serialize(id); FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); status = serializer.serialize(timeTag); FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); status = serializer.serialize(val); FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); U32 size = serializer.getBuffLength(); this->send_data(HubType::HUB_TYPE_CHANNEL, portNum, buffer, size); } // ---------------------------------------------------------------------- // Handler implementations for user-defined serial input ports // ---------------------------------------------------------------------- void GenericHubComponentImpl ::portIn_handler(NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::SerializeBufferBase& Buffer /*!< The serialization buffer*/ ) { send_data(HUB_TYPE_PORT, portNum, Buffer.getBuffAddr(), Buffer.getBuffLength()); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/GenericHub/GenericHub.hpp
// ====================================================================== // GenericHub.hpp // Standardization header for GenericHub // ====================================================================== #ifndef Svc_GenericHub_HPP #define Svc_GenericHub_HPP #include "Svc/GenericHub/GenericHubComponentImpl.hpp" namespace Svc { using GenericHub = GenericHubComponentImpl; } #endif
hpp
fprime
data/projects/fprime/Svc/GenericHub/test/ut/GenericHubTester.cpp
// ====================================================================== // \title GenericHub.hpp // \author mstarch // \brief cpp file for GenericHub test harness implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "GenericHubTester.hpp" #include <STest/Pick/Pick.hpp> #define INSTANCE 0 #define MAX_HISTORY_SIZE 10000 namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- GenericHubTester ::GenericHubTester() : GenericHubGTestBase("Tester", MAX_HISTORY_SIZE), componentIn("GenericHubIn"), componentOut("GenericHubOut"), m_buffer(m_data_store, DATA_SIZE), m_comm_in(0), m_buffer_in(0), m_comm_out(0), m_buffer_out(0), m_current_port(0) { this->initComponents(); this->connectPorts(); } GenericHubTester ::~GenericHubTester() {} // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void GenericHubTester ::test_in_out() { U32 max = std::min(this->componentIn.getNum_portIn_InputPorts(), this->componentOut.getNum_portOut_OutputPorts()); for (U32 i = 0; i < max; i++) { send_random_comm(i); ASSERT_from_dataInDeallocate_SIZE(1); fromPortHistory_dataInDeallocate->clear(); } } void GenericHubTester ::test_buffer_io() { U32 max = std::min(this->componentIn.getNum_buffersIn_InputPorts(), this->componentOut.getNum_buffersOut_OutputPorts()); for (U32 i = 0; i < max; i++) { send_random_buffer(i); ASSERT_from_dataInDeallocate_SIZE(1); fromPortHistory_dataInDeallocate->clear(); } } void GenericHubTester ::test_random_io() { for (U32 i = 0; i < 10000; i++) { U32 choice = STest::Pick::lowerUpper(0, 1); if (choice) { U32 port = STest::Pick::lowerUpper(0, std::min(this->componentIn.getNum_portIn_InputPorts(), this->componentOut.getNum_portOut_OutputPorts()) - 1); send_random_comm(port); } else { U32 port = STest::Pick::lowerUpper(0, std::min(this->componentIn.getNum_buffersIn_InputPorts(), this->componentOut.getNum_buffersOut_OutputPorts()) - 1); send_random_buffer(port); } ASSERT_from_dataInDeallocate_SIZE(1); fromPortHistory_dataInDeallocate->clear(); } } void GenericHubTester ::random_fill(Fw::SerializeBufferBase& buffer, U32 max_size) { U32 random_size = STest::Pick::lowerUpper(0, max_size); buffer.resetSer(); for (U32 i = 0; i < random_size; i++) { buffer.serialize(static_cast<U8>(STest::Pick::any())); } } void GenericHubTester ::test_telemetry() { Fw::TlmBuffer buffer; random_fill(buffer, FW_TLM_BUFFER_MAX_SIZE); Fw::Time time(100, 200); invoke_to_TlmRecv(0, 123, time, buffer); // **must** deallocate buffer ASSERT_from_dataInDeallocate_SIZE(1); ASSERT_from_TlmSend_SIZE(1); ASSERT_from_TlmSend(0, 123, time, buffer); clearFromPortHistory(); } void GenericHubTester ::test_events() { Fw::LogSeverity severity = Fw::LogSeverity::WARNING_HI; Fw::LogBuffer buffer; random_fill(buffer, FW_LOG_BUFFER_MAX_SIZE); Fw::Time time(100, 200); invoke_to_LogRecv(0, 123, time, severity, buffer); // **must** deallocate buffer ASSERT_from_dataInDeallocate_SIZE(1); ASSERT_from_LogSend_SIZE(1); ASSERT_from_LogSend(0, 123, time, severity, buffer); clearFromPortHistory(); } // Helpers void GenericHubTester ::send_random_comm(U32 port) { random_fill(m_comm, FW_COM_BUFFER_MAX_SIZE); m_current_port = port; invoke_to_portIn(m_current_port, m_comm); // Ensure that the data out was called, and that the portOut unwrapped properly ASSERT_from_dataOut_SIZE(m_comm_in + m_buffer_out + 1); ASSERT_EQ(m_comm_in + 1, m_comm_out); m_comm_in++; } void GenericHubTester ::send_random_buffer(U32 port) { U32 max_random_size = STest::Pick::lowerUpper(0, DATA_SIZE - (sizeof(U32) + sizeof(U32) + sizeof(FwBuffSizeType))); m_buffer.set(m_data_store, sizeof(m_data_store)); ASSERT_GE(m_buffer.getSize(), max_random_size); random_fill(m_buffer.getSerializeRepr(), max_random_size); m_buffer.setSize(max_random_size); m_current_port = port; invoke_to_buffersIn(m_current_port, m_buffer); ASSERT_from_bufferDeallocate_SIZE(1); ASSERT_from_bufferDeallocate(0, m_buffer); fromPortHistory_bufferDeallocate->clear(); // Ensure that the data out was called, and that the portOut unwrapped properly ASSERT_from_dataOut_SIZE(m_buffer_in + m_comm_out + 1); ASSERT_EQ(m_buffer_in + 1, m_buffer_out); m_buffer_in++; } // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- void GenericHubTester ::from_LogSend_handler(const NATIVE_INT_TYPE portNum, FwEventIdType id, Fw::Time& timeTag, const Fw::LogSeverity& severity, Fw::LogBuffer& args) { this->pushFromPortEntry_LogSend(id, timeTag, severity, args); } void GenericHubTester ::from_TlmSend_handler(const NATIVE_INT_TYPE portNum, FwChanIdType id, Fw::Time& timeTag, Fw::TlmBuffer& val) { this->pushFromPortEntry_TlmSend(id, timeTag, val); } void GenericHubTester ::from_dataOut_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) { ASSERT_NE(fwBuffer.getData(), nullptr) << "Empty buffer to deallocate"; ASSERT_GE(fwBuffer.getData(), m_data_for_allocation) << "Incorrect data pointer deallocated"; ASSERT_LT(fwBuffer.getData(), m_data_for_allocation + sizeof(m_data_for_allocation)) << "Incorrect data pointer deallocated"; // Reuse m_allocate to pass into the otherside of the hub this->pushFromPortEntry_dataOut(fwBuffer); invoke_to_dataIn(0, fwBuffer); } // ---------------------------------------------------------------------- // Handlers for serial from ports // ---------------------------------------------------------------------- void GenericHubTester ::from_buffersOut_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) { m_buffer_out++; // Assert the buffer came through exactly on the right port ASSERT_EQ(portNum, m_current_port); ASSERT_EQ(fwBuffer.getSize(), m_buffer.getSize()); for (U32 i = 0; i < fwBuffer.getSize(); i++) { U8 byte1 = reinterpret_cast<U8*>(fwBuffer.getData())[i]; U8 byte2 = reinterpret_cast<U8*>(m_buffer.getData())[i]; ASSERT_EQ(byte1, byte2); } // Pretend to deallocate like file uplink would this->from_dataInDeallocate_handler(0, fwBuffer); } void GenericHubTester ::from_portOut_handler(NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::SerializeBufferBase& Buffer /*!< The serialization buffer*/ ) { m_comm_out++; // Assert the buffer came through exactly on the right port ASSERT_EQ(portNum, m_current_port); ASSERT_EQ(Buffer.getBuffLength(), m_comm.getBuffLength()); for (U32 i = 0; i < Buffer.getBuffLength(); i++) { ASSERT_EQ(Buffer.getBuffAddr()[i], m_comm.getBuffAddr()[i]); } ASSERT_from_buffersOut_SIZE(0); } Fw::Buffer GenericHubTester ::from_dataOutAllocate_handler(const NATIVE_INT_TYPE portNum, const U32 size) { EXPECT_EQ(m_allocate.getData(), nullptr) << "Allocation buffer is still in use"; EXPECT_LE(size, sizeof(m_data_for_allocation)) << "Allocation buffer is still in use"; m_allocate.set(m_data_for_allocation, size); return m_allocate; } void GenericHubTester ::from_bufferDeallocate_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) { // Check buffer deallocations here ASSERT_EQ(fwBuffer.getData(), m_buffer.getData()) << "Ensure that the buffer was deallocated"; ASSERT_EQ(fwBuffer.getSize(), m_buffer.getSize()) << "Ensure that the buffer was deallocated"; this->pushFromPortEntry_bufferDeallocate(fwBuffer); } void GenericHubTester ::from_dataInDeallocate_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) { ASSERT_NE(fwBuffer.getData(), nullptr) << "Empty buffer to deallocate"; ASSERT_GE(fwBuffer.getData(), m_data_for_allocation) << "Incorrect data pointer deallocated"; ASSERT_LT(fwBuffer.getData(), m_data_for_allocation + sizeof(m_data_for_allocation)) << "Incorrect data pointer deallocated"; m_allocate.set(nullptr, 0); this->pushFromPortEntry_dataInDeallocate(fwBuffer); } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void GenericHubTester ::connectPorts() { // buffersIn U32 max = std::min(this->componentIn.getNum_buffersIn_InputPorts(), this->componentOut.getNum_buffersOut_OutputPorts()); for (U32 i = 0; i < max; ++i) { this->connect_to_buffersIn(i, this->componentIn.get_buffersIn_InputPort(i)); } // LogRecv this->connect_to_LogRecv(0, this->componentIn.get_LogRecv_InputPort(0)); // TlmRecv this->connect_to_TlmRecv(0, this->componentIn.get_TlmRecv_InputPort(0)); // dataIn this->connect_to_dataIn(0, this->componentOut.get_dataIn_InputPort(0)); // buffersOut for (U32 i = 0; i < max; ++i) { this->componentOut.set_buffersOut_OutputPort(i, this->get_from_buffersOut(i)); } // LogSend this->componentOut.set_LogSend_OutputPort(0, this->get_from_LogSend(0)); // TlmSend this->componentOut.set_TlmSend_OutputPort(0, this->get_from_TlmSend(0)); // dataOut this->componentIn.set_dataOut_OutputPort(0, this->get_from_dataOut(0)); // bufferAllocate this->componentIn.set_dataOutAllocate_OutputPort(0, this->get_from_dataOutAllocate(0)); // dataDeallocate this->componentOut.set_dataInDeallocate_OutputPort(0, this->get_from_dataInDeallocate(0)); // bufferDeallocate this->componentIn.set_bufferDeallocate_OutputPort(0, this->get_from_bufferDeallocate(0)); // ---------------------------------------------------------------------- // Connect serial output ports // ---------------------------------------------------------------------- max = std::min(this->componentIn.getNum_portIn_InputPorts(), this->componentOut.getNum_portOut_OutputPorts()); for (U32 i = 0; i < max; ++i) { this->componentOut.set_portOut_OutputPort(i, this->get_from_portOut(i)); } // ---------------------------------------------------------------------- // Connect serial input ports // ---------------------------------------------------------------------- // portIn for (U32 i = 0; i < max; ++i) { this->connect_to_portIn(i, this->componentIn.get_portIn_InputPort(i)); } } void GenericHubTester ::initComponents() { this->init(); this->componentIn.init(INSTANCE); this->componentOut.init(INSTANCE + 1); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/GenericHub/test/ut/GenericHubTestMain.cpp
// ---------------------------------------------------------------------- // TestMain.cpp // ---------------------------------------------------------------------- #include "GenericHubTester.hpp" TEST(Nominal, TestIo) { Svc::GenericHubTester tester; tester.test_in_out(); } TEST(Nominal, TestBufferIo) { Svc::GenericHubTester tester; tester.test_buffer_io(); } TEST(Nominal, TestRandomIo) { Svc::GenericHubTester tester; tester.test_random_io(); } TEST(Nominal, TestEvents) { Svc::GenericHubTester tester; tester.test_events(); } TEST(Nominal, TestTelemetry) { Svc::GenericHubTester tester; tester.test_telemetry(); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
cpp
fprime
data/projects/fprime/Svc/GenericHub/test/ut/GenericHubTester.hpp
// ====================================================================== // \title GenericHub/test/ut/Tester.hpp // \author mstarch // \brief hpp file for GenericHub 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 <Fw/Com/ComBuffer.hpp> #include "GenericHubGTestBase.hpp" #include "Svc/GenericHub/GenericHubComponentImpl.hpp" // Larger than com buffer size #define DATA_SIZE (FW_COM_BUFFER_MAX_SIZE*10 + sizeof(U32) + sizeof(U32) + sizeof(FwBuffSizeType)) namespace Svc { class GenericHubTester : public GenericHubGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: //! Construct object GenericHubTester //! GenericHubTester(); //! Destroy object GenericHubTester //! ~GenericHubTester(); public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! Test of basic in/out of a set of serialized ports //! void test_in_out(); //! Test of buffer in/out of a set of buffer ports //! void test_buffer_io(); //! Test of random in/out of a set of file and normal ports //! void test_random_io(); //! Test of telemetry in-out //! void test_telemetry(); //! Test of event in-out //! void test_events(); private: // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- //! Handler for from_LogSend //! void from_LogSend_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ FwEventIdType id, /*!< Log ID */ Fw::Time& timeTag, /*!< Time Tag */ const Fw::LogSeverity& severity, /*!< The severity argument */ Fw::LogBuffer& args /*!< Buffer containing serialized log entry */ ); //! Handler for from_TlmSend //! void from_TlmSend_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 for from_buffersOut //! void from_buffersOut_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::Buffer& fwBuffer); //! Handler for from_bufferDeallocate //! void from_bufferDeallocate_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::Buffer& fwBuffer); //! Handler for from_dataOutAllocate //! Fw::Buffer from_dataOutAllocate_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 size); //! Handler for from_dataOut //! void from_dataOut_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::Buffer& fwBuffer); //! Handler for from_dataDeallocate //! void from_dataInDeallocate_handler(const NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::Buffer& fwBuffer); private: // ---------------------------------------------------------------------- // Handlers for serial from ports // ---------------------------------------------------------------------- //! Handler for from_portOut //! void from_portOut_handler(NATIVE_INT_TYPE portNum, /*!< The port number*/ Fw::SerializeBufferBase& Buffer /*!< The serialization buffer*/ ); private: void send_random_comm(U32 port); void send_random_buffer(U32 port); void random_fill(Fw::SerializeBufferBase& buffer, U32 max_size); // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(); //! Initialize components //! void initComponents(); private: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! GenericHubComponentImpl componentIn; GenericHubComponentImpl componentOut; Fw::ComBuffer m_comm; Fw::Buffer m_buffer; Fw::Buffer m_allocate; U32 m_comm_in; U32 m_buffer_in; U32 m_comm_out; U32 m_buffer_out; U32 m_current_port; U8 m_data_store[DATA_SIZE]; U8 m_data_for_allocation[DATA_SIZE]; }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/ComSplitter/ComSplitter.cpp
// ---------------------------------------------------------------------- // // ComSplitter.cpp // // ---------------------------------------------------------------------- #include <Svc/ComSplitter/ComSplitter.hpp> #include <FpConfig.hpp> namespace Svc { // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- ComSplitter :: ComSplitter(const char* compName) : ComSplitterComponentBase(compName) { } ComSplitter :: ~ComSplitter() { } void ComSplitter :: init(NATIVE_INT_TYPE instance) { ComSplitterComponentBase::init(instance); } // ---------------------------------------------------------------------- // Handler implementations // ---------------------------------------------------------------------- void ComSplitter :: comIn_handler( NATIVE_INT_TYPE portNum, Fw::ComBuffer &data, U32 context ) { FW_ASSERT(portNum == 0); NATIVE_INT_TYPE numPorts = getNum_comOut_OutputPorts(); FW_ASSERT(numPorts > 0); for(NATIVE_INT_TYPE i = 0; i < numPorts; i++) { if( isConnected_comOut_OutputPort(i) ) { // Need to make a copy because we are passing by reference!: Fw::ComBuffer dataToSend = data; comOut_out(i, dataToSend, 0); } } } }
cpp
fprime
data/projects/fprime/Svc/ComSplitter/ComSplitter.hpp
// ---------------------------------------------------------------------- // // ComSplitter.hpp // // ---------------------------------------------------------------------- #ifndef COMSPLITTER_HPP #define COMSPLITTER_HPP #include <Svc/ComSplitter/ComSplitterComponentAc.hpp> #include <Fw/Types/Assert.hpp> namespace Svc { class ComSplitter : public ComSplitterComponentBase { // ---------------------------------------------------------------------- // Friend class for whitebox testing // ---------------------------------------------------------------------- friend class ComSplitterComponentBaseFriend; // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- public: ComSplitter(const char* compName); ~ComSplitter(); void init(NATIVE_INT_TYPE instance); // ---------------------------------------------------------------------- // Handler implementations // ---------------------------------------------------------------------- private: void comIn_handler( NATIVE_INT_TYPE portNum, Fw::ComBuffer &data, U32 context ); }; } #endif
hpp
fprime
data/projects/fprime/Svc/ComSplitter/test/ut/ComSplitterMain.cpp
/* * Main.cpp * * Created on: March 9, 2017 * Author: Gorang Gandhi */ #include "ComSplitterTester.hpp" #include <Svc/ComSplitter/ComSplitter.hpp> #include <Fw/Obj/SimpleObjRegistry.hpp> #include <gtest/gtest.h> #include <Fw/Test/UnitTest.hpp> TEST(TestNominal,Nominal) { Svc::ComSplitterTester tester; tester.test_nominal(); } #ifndef TGT_OS_TYPE_VXWORKS int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); return 0; } #endif
cpp
fprime
data/projects/fprime/Svc/ComSplitter/test/ut/ComSplitterTester.hpp
// ====================================================================== // \title ComSplitter/test/ut/Tester.hpp // \author gcgandhi // \brief hpp file for ComSplitter 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 "ComSplitterGTestBase.hpp" #include "Svc/ComSplitter/ComSplitter.hpp" namespace Svc { class ComSplitterTester : public ComSplitterGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: //! Construct object ComSplitterTester //! ComSplitterTester(); //! Destroy object ComSplitterTester //! ~ComSplitterTester(); public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void test_nominal(); private: // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- //! Handler for from_comOut //! void from_comOut_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*/ ); void assert_comOut( const U32 index, const Fw::ComBuffer &data ) const; private: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(); //! Initialize components //! void initComponents(); private: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! ComSplitter component; }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/ComSplitter/test/ut/ComSplitterTester.cpp
// ====================================================================== // \title ComSplitter.hpp // \author gcgandhi // \brief cpp file for ComSplitter test harness implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // ====================================================================== #include "ComSplitterTester.hpp" #define INSTANCE 0 #define MAX_HISTORY_SIZE 100 namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- ComSplitterTester :: ComSplitterTester() : ComSplitterGTestBase("Tester", MAX_HISTORY_SIZE), component("ComSplitter") { this->initComponents(); this->connectPorts(); } ComSplitterTester :: ~ComSplitterTester() { } // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void ComSplitterTester :: test_nominal() { U8 d[4] = {0xde,0xad,0xbe,0xef}; for(U8 i = 0; i < 3; i++){ d[0] = i; Fw::ComBuffer buffer(d, sizeof(d)); invoke_to_comIn(0, buffer, 0); } ASSERT_from_comOut_SIZE(9); for(int i = 0; i < 3; i++){ d[0] = i; Fw::ComBuffer data(d, sizeof(d)); for(int j = 0; j < 3; j++){ assert_comOut(i*3 + j, data); } } } void ComSplitterTester :: assert_comOut( const U32 index, const Fw::ComBuffer &data ) const { ASSERT_GT(fromPortHistory_comOut->size(), index); const FromPortEntry_comOut& e = fromPortHistory_comOut->at(index); ASSERT_EQ(data.getBuffLength(), e.data.getBuffLength()); ASSERT_EQ(memcmp(data.getBuffAddr(), e.data.getBuffAddr(), data.getBuffLength()), 0); // for(int k=0; k < e.data.getBuffLength(); k++) // printf("0x%02x ", e.data.getBuffAddr()[k]); // printf("\n"); } // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- void ComSplitterTester :: from_comOut_handler( const NATIVE_INT_TYPE portNum, Fw::ComBuffer &data, U32 context ) { this->pushFromPortEntry_comOut(data, context); } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void ComSplitterTester :: connectPorts() { // comIn this->connect_to_comIn( 0, this->component.get_comIn_InputPort(0) ); // Just connect 3 of 5: // comOut for (NATIVE_INT_TYPE i = 0; i < 3; ++i) { this->component.set_comOut_OutputPort( i, this->get_from_comOut(i) ); } } void ComSplitterTester :: initComponents() { this->init(); this->component.init( INSTANCE ); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/LinuxTimer/LinuxTimerComponentImplTimerFd.cpp
// ====================================================================== // \title LinuxTimerImpl.cpp // \author tim // \brief cpp file for LinuxTimer component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include <Fw/Logger/Logger.hpp> #include <Svc/LinuxTimer/LinuxTimerComponentImpl.hpp> #include <FpConfig.hpp> #include <sys/timerfd.h> #include <unistd.h> #include <cerrno> #include <cstring> namespace Svc { void LinuxTimerComponentImpl::startTimer(NATIVE_INT_TYPE interval) { int fd; struct itimerspec itval; /* Create the timer */ fd = timerfd_create (CLOCK_MONOTONIC, 0); itval.it_interval.tv_sec = interval/1000; itval.it_interval.tv_nsec = (interval*1000000)%1000000000; itval.it_value.tv_sec = interval/1000; itval.it_value.tv_nsec = (interval*1000000)%1000000000; timerfd_settime (fd, 0, &itval, nullptr); while (true) { unsigned long long missed; int ret = read (fd, &missed, sizeof (missed)); if (-1 == ret) { Fw::Logger::logMsg("timer read error: %s\n", reinterpret_cast<POINTER_CAST>(strerror(errno))); } this->m_mutex.lock(); bool quit = this->m_quit; this->m_mutex.unLock(); if (quit) { itval.it_interval.tv_sec = 0; itval.it_interval.tv_nsec = 0; itval.it_value.tv_sec = 0; itval.it_value.tv_nsec = 0; timerfd_settime (fd, 0, &itval, nullptr); return; } this->m_timer.take(); this->CycleOut_out(0,this->m_timer); } } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/LinuxTimer/LinuxTimerComponentImplCommon.cpp
// ====================================================================== // \title LinuxTimerImpl.cpp // \author tim // \brief cpp file for LinuxTimer component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include <Svc/LinuxTimer/LinuxTimerComponentImpl.hpp> #include <FpConfig.hpp> namespace Svc { // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- LinuxTimerComponentImpl :: LinuxTimerComponentImpl( const char *const compName ) : LinuxTimerComponentBase(compName), m_quit(false) { } void LinuxTimerComponentImpl :: init( const NATIVE_INT_TYPE instance ) { LinuxTimerComponentBase::init(instance); } LinuxTimerComponentImpl :: ~LinuxTimerComponentImpl() { } void LinuxTimerComponentImpl::quit() { this->m_mutex.lock(); this->m_quit = true; this->m_mutex.unLock(); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/LinuxTimer/LinuxTimerComponentImplTaskDelay.cpp
// ====================================================================== // \title LinuxTimerImpl.cpp // \author tim // \brief cpp file for LinuxTimer component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include <Svc/LinuxTimer/LinuxTimerComponentImpl.hpp> #include <FpConfig.hpp> #include <Os/Task.hpp> namespace Svc { void LinuxTimerComponentImpl::startTimer(NATIVE_INT_TYPE interval) { while (true) { Os::Task::delay(interval); this->m_mutex.lock(); bool quit = this->m_quit; this->m_mutex.unLock(); if (quit) { return; } this->m_timer.take(); this->CycleOut_out(0,this->m_timer); } } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/LinuxTimer/LinuxTimerComponentImpl.hpp
// ====================================================================== // \title LinuxTimerImpl.hpp // \author tim // \brief hpp file for LinuxTimer component implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef LinuxTimer_HPP #define LinuxTimer_HPP #include "Os/Mutex.hpp" #include "Svc/LinuxTimer/LinuxTimerComponentAc.hpp" namespace Svc { class LinuxTimerComponentImpl : public LinuxTimerComponentBase { public: // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Construct object LinuxTimer //! LinuxTimerComponentImpl( const char *const compName /*!< The component name*/ ); //! Initialize object LinuxTimer //! void init( const NATIVE_INT_TYPE instance = 0 /*!< The instance number*/ ); //! Destroy object LinuxTimer //! ~LinuxTimerComponentImpl(); //! Start timer void startTimer(NATIVE_INT_TYPE interval); //!< interval in milliseconds //! Quit timer void quit(); PRIVATE: Os::Mutex m_mutex; //!< mutex for quit flag volatile bool m_quit; //!< flag to quit Svc::TimerVal m_timer; }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/LinuxTimer/LinuxTimer.hpp
// ====================================================================== // LinuxTimer.hpp // Standardization header for LinuxTimer // ====================================================================== #ifndef Svc_LinuxTimer_HPP #define Svc_LinuxTimer_HPP #include "Svc/LinuxTimer/LinuxTimerComponentImpl.hpp" namespace Svc { using LinuxTimer = LinuxTimerComponentImpl; } #endif
hpp
fprime
data/projects/fprime/Svc/LinuxTimer/test/ut/main.cpp
// ---------------------------------------------------------------------- // Main.cpp // ---------------------------------------------------------------------- #include "LinuxTimerTester.hpp" #include <Fw/Test/UnitTest.hpp> TEST(Nominal, InitTest) { TEST_CASE(103.1.1,"Cycle Test"); Svc::LinuxTimerTester tester; tester.runCycles(); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
cpp
fprime
data/projects/fprime/Svc/LinuxTimer/test/ut/LinuxTimerTester.hpp
// ====================================================================== // \title LinuxTimer/test/ut/Tester.hpp // \author tim // \brief hpp file for LinuxTimer 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 "LinuxTimerGTestBase.hpp" #include "Svc/LinuxTimer/LinuxTimerComponentImpl.hpp" namespace Svc { class LinuxTimerTester : public LinuxTimerGTestBase { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- public: //! Construct object LinuxTimerTester //! LinuxTimerTester(); //! Destroy object LinuxTimerTester //! ~LinuxTimerTester(); public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! To do //! void runCycles(); private: // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- //! Handler for from_CycleOut //! void from_CycleOut_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ Svc::TimerVal &cycleStart /*!< Cycle start timer value*/ ); private: // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- //! Connect ports //! void connectPorts(); //! Initialize components //! void initComponents(); private: // ---------------------------------------------------------------------- // Variables // ---------------------------------------------------------------------- //! The component under test //! LinuxTimerComponentImpl component; NATIVE_INT_TYPE m_numCalls; }; } // end namespace Svc #endif
hpp
fprime
data/projects/fprime/Svc/LinuxTimer/test/ut/LinuxTimerTester.cpp
// ====================================================================== // \title LinuxTimer.hpp // \author tim // \brief cpp file for LinuxTimer test harness implementation class // // \copyright // Copyright 2009-2015, by the California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "LinuxTimerTester.hpp" #define INSTANCE 0 #define MAX_HISTORY_SIZE 10 namespace Svc { // ---------------------------------------------------------------------- // Construction and destruction // ---------------------------------------------------------------------- LinuxTimerTester :: LinuxTimerTester() : LinuxTimerGTestBase("Tester", MAX_HISTORY_SIZE), component("LinuxTimer") ,m_numCalls(0) { this->initComponents(); this->connectPorts(); } LinuxTimerTester :: ~LinuxTimerTester() { } // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- void LinuxTimerTester :: runCycles() { this->m_numCalls = 5; this->component.startTimer(1000); } // ---------------------------------------------------------------------- // Handlers for typed from ports // ---------------------------------------------------------------------- void LinuxTimerTester :: from_CycleOut_handler( const NATIVE_INT_TYPE portNum, Svc::TimerVal &cycleStart ) { printf("TICK\n"); if (--this->m_numCalls == 0) { this->component.quit(); } } // ---------------------------------------------------------------------- // Helper methods // ---------------------------------------------------------------------- void LinuxTimerTester :: connectPorts() { // CycleOut this->component.set_CycleOut_OutputPort( 0, this->get_from_CycleOut(0) ); } void LinuxTimerTester :: initComponents() { this->init(); this->component.init( INSTANCE ); } } // end namespace Svc
cpp
fprime
data/projects/fprime/Svc/BufferLogger/BufferLogger.cpp
// ====================================================================== // \title BufferLogger.cpp // \author bocchino, dinkel, mereweth // \brief Svc BufferLogger implementation // // \copyright // Copyright (C) 2015-2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Svc/BufferLogger/BufferLogger.hpp" namespace Svc { typedef BufferLogger_LogState LogState; // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- BufferLogger :: BufferLogger(const char *const compName) : BufferLoggerComponentBase(compName), m_state(LogState::LOGGING_ON), m_file(*this) { } void BufferLogger :: init( const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE instance ) { BufferLoggerComponentBase::init(queueDepth, instance); } // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- //TODO(mereweth) - only allow calling this once? void BufferLogger :: initLog( const char *const logFilePrefix, const char *const logFileSuffix, const U32 maxFileSize, const U8 sizeOfSize ) { m_file.init(logFilePrefix, logFileSuffix, maxFileSize, sizeOfSize); } // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- void BufferLogger :: bufferSendIn_handler( const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer ) { if (m_state == LogState::LOGGING_ON) { const U8 *const addr = fwBuffer.getData(); const U32 size = fwBuffer.getSize(); m_file.logBuffer(addr, size); } this->bufferSendOut_out(0, fwBuffer); } void BufferLogger :: comIn_handler( NATIVE_INT_TYPE portNum, Fw::ComBuffer &data, U32 context ) { if (m_state == LogState::LOGGING_ON) { const U8 *const addr = data.getBuffAddr(); const U32 size = data.getBuffLength(); m_file.logBuffer(addr, size); } } void BufferLogger :: pingIn_handler(NATIVE_INT_TYPE portNum, U32 key) { this->pingOut_out(0, key); } void BufferLogger :: schedIn_handler( const NATIVE_INT_TYPE portNum, U32 context ) { // TODO } // ---------------------------------------------------------------------- // Command handler implementations // ---------------------------------------------------------------------- // TODO(mereweth) - should this command only set the base name? void BufferLogger :: BL_OpenFile_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq, const Fw::CmdStringArg& file ) { m_file.setBaseName(file); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } void BufferLogger :: BL_CloseFile_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq ) { m_file.closeAndEmitEvent(); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } void BufferLogger :: BL_SetLogging_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq, LogState state ) { m_state = state; if (state == LogState::LOGGING_OFF) { m_file.closeAndEmitEvent(); } this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } void BufferLogger :: BL_FlushFile_cmdHandler( const FwOpcodeType opCode, const U32 cmdSeq ) { const bool status = m_file.flush(); if(status) { this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } else { this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); } } }
cpp
fprime
data/projects/fprime/Svc/BufferLogger/BufferLoggerFile.cpp
// ====================================================================== // \title BufferLoggerFile.cpp // \author bocchino, dinkel, mereweth // \brief Implementation for Svc::BufferLogger::BufferLoggerFile // // \copyright // Copyright (C) 2015-2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Svc/BufferLogger/BufferLogger.hpp" #include "Os/ValidateFile.hpp" #include "Os/ValidatedFile.hpp" namespace Svc { // ---------------------------------------------------------------------- // Constructors and destructors // ---------------------------------------------------------------------- BufferLogger::File :: File( BufferLogger& bufferLogger ) : m_bufferLogger(bufferLogger), m_prefix(""), m_suffix(""), m_baseName(""), m_fileCounter(0), m_maxSize(0), m_sizeOfSize(0), m_mode(Mode::CLOSED), m_bytesWritten(0) { } BufferLogger::File :: ~File() { this->close(); } // ---------------------------------------------------------------------- // Public functions // ---------------------------------------------------------------------- void BufferLogger::File :: init( const char *const logFilePrefix, const char *const logFileSuffix, const U32 maxFileSize, const U8 sizeOfSize ) { //NOTE(mereweth) - only call this before opening the file FW_ASSERT(this->m_mode == File::Mode::CLOSED); this->m_prefix = logFilePrefix; this->m_suffix = logFileSuffix; this->m_maxSize = maxFileSize; this->m_sizeOfSize = sizeOfSize; FW_ASSERT(sizeOfSize <= sizeof(U32), sizeOfSize); FW_ASSERT(m_maxSize > sizeOfSize, m_maxSize); } void BufferLogger::File :: setBaseName( const Fw::StringBase& baseName ) { if (this->m_mode == File::Mode::OPEN) { this->closeAndEmitEvent(); } this->m_baseName = baseName; this->m_fileCounter = 0; this->open(); } void BufferLogger::File :: logBuffer( const U8 *const data, const U32 size ) { // Close the file if it will be too big if (this->m_mode == File::Mode::OPEN) { const U32 projectedByteCount = this->m_bytesWritten + this->m_sizeOfSize + size; if (projectedByteCount > this->m_maxSize) { this->closeAndEmitEvent(); } } // Open a file if necessary if (this->m_mode == File::Mode::CLOSED) { this->open(); } // Write to the file if it is open if (this->m_mode == File::Mode::OPEN) { (void) this->writeBuffer(data, size); } } void BufferLogger::File :: closeAndEmitEvent() { if (this->m_mode == File::Mode::OPEN) { this->close(); Fw::LogStringArg logStringArg(this->m_name.toChar()); this->m_bufferLogger.log_DIAGNOSTIC_BL_LogFileClosed(logStringArg); } } // ---------------------------------------------------------------------- // Private functions // ---------------------------------------------------------------------- void BufferLogger::File :: open() { FW_ASSERT(this->m_mode == File::Mode::CLOSED); // NOTE(mereweth) - check that file path has been set and that initLog has been called if ((this->m_baseName.toChar()[0] == '\0') || (this->m_sizeOfSize > sizeof(U32)) || (this->m_maxSize <= this->m_sizeOfSize)) { this->m_bufferLogger.log_WARNING_HI_BL_NoLogFileOpenInitError(); return; } if (this->m_fileCounter == 0) { this->m_name.format( "%s%s%s", this->m_prefix.toChar(), this->m_baseName.toChar(), this->m_suffix.toChar() ); } else { this->m_name.format( "%s%s%d%s", this->m_prefix.toChar(), this->m_baseName.toChar(), this->m_fileCounter, this->m_suffix.toChar() ); } const Os::File::Status status = this->m_osFile.open( this->m_name.toChar(), Os::File::OPEN_WRITE ); if (status == Os::File::OP_OK) { this->m_fileCounter++; // Reset bytes written this->m_bytesWritten = 0; // Set mode this->m_mode = File::Mode::OPEN; } else { Fw::LogStringArg string(this->m_name.toChar()); this->m_bufferLogger.log_WARNING_HI_BL_LogFileOpenError(status, string); } } bool BufferLogger::File :: writeBuffer( const U8 *const data, const U32 size ) { bool status = this->writeSize(size); if (status) { status = this->writeBytes(data, size); } return status; } bool BufferLogger::File :: writeSize(const U32 size) { FW_ASSERT(this->m_sizeOfSize <= sizeof(U32)); U8 sizeBuffer[sizeof(U32)]; U32 sizeRegister = size; for (U8 i = 0; i < this->m_sizeOfSize; ++i) { sizeBuffer[this->m_sizeOfSize - i - 1] = sizeRegister & 0xFF; sizeRegister >>= 8; } const bool status = this->writeBytes( sizeBuffer, this->m_sizeOfSize ); return status; } bool BufferLogger::File :: writeBytes( const void *const data, const U32 length ) { FW_ASSERT(length > 0, length); FwSignedSizeType size = length; const Os::File::Status fileStatus = this->m_osFile.write(reinterpret_cast<const U8*>(data), size); bool status; if (fileStatus == Os::File::OP_OK && size == static_cast<NATIVE_INT_TYPE>(length)) { this->m_bytesWritten += length; status = true; } else { Fw::LogStringArg string(this->m_name.toChar()); this->m_bufferLogger.log_WARNING_HI_BL_LogFileWriteError(fileStatus, size, length, string); status = false; } return status; } void BufferLogger::File :: writeHashFile() { Os::ValidatedFile validatedFile(this->m_name.toChar()); const Os::ValidateFile::Status status = validatedFile.createHashFile(); if (status != Os::ValidateFile::VALIDATION_OK) { const Fw::String &hashFileName = validatedFile.getHashFileName(); Fw::LogStringArg logStringArg(hashFileName.toChar()); this->m_bufferLogger.log_WARNING_HI_BL_LogFileValidationError( logStringArg, status ); } } bool BufferLogger::File :: flush() { return true; // NOTE(if your fprime uses buffered file I/O, re-enable this) /*bool status = true; if(this->mode == File::Mode::OPEN) { const Os::File::Status fileStatus = this->osFile.flush(); if(fileStatus == Os::File::OP_OK) { status = true; } else { status = false; } } return status;*/ } void BufferLogger::File :: close() { if (this->m_mode == File::Mode::OPEN) { // Close file this->m_osFile.close(); // Write out the hash file to disk this->writeHashFile(); // Update mode this->m_mode = File::Mode::CLOSED; } } }
cpp
fprime
data/projects/fprime/Svc/BufferLogger/BufferLogger.hpp
// ====================================================================== // \title BufferLogger.hpp // \author bocchino, dinkel, mereweth // \brief Svc Buffer Logger interface // // \copyright // Copyright (C) 2015-2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef Svc_BufferLogger_HPP #define Svc_BufferLogger_HPP #include "Svc/BufferLogger/BufferLoggerComponentAc.hpp" #include "Os/File.hpp" #include "Fw/Types/String.hpp" #include "Fw/Types/Assert.hpp" #include "Os/Mutex.hpp" #include "Utils/Hash/Hash.hpp" namespace Svc { class BufferLogger : public BufferLoggerComponentBase { PRIVATE: // ---------------------------------------------------------------------- // Types // ---------------------------------------------------------------------- //! A BufferLogger file class File { public: //! The file mode struct Mode { typedef enum { CLOSED = 0, OPEN = 1 } t; }; public: //! Construct a File object File( BufferLogger& bufferLogger //!< The enclosing BufferLogger instance ); //! Destroy a File object ~File(); public: //! Set File object parameters void init( const char *const prefix, //!< The file name prefix const char *const suffix, //!< The file name suffix const U32 maxSize, //!< The maximum file size const U8 sizeOfSize //!< The number of bytes to use when storing the size field and the start of each buffer) ); //! Set base file name void setBaseName( const Fw::StringBase& baseName //!< The base file name; used with prefix, unique counter value, and suffix ); //! Log a buffer void logBuffer( const U8 *const data, //!< The buffer data const U32 size //!< The size ); //! Close the file and emit an event void closeAndEmitEvent(); //! Flush the file bool flush(); PRIVATE: //! Open the file void open(); //! Write a buffer to a file //! \return Success or failure bool writeBuffer( const U8 *const data, //!< The buffer data const U32 size //!< The number of bytes to write ); //! Write the size field of a buffer //! \return Success or failure bool writeSize( const U32 size //!< The size ); //! Write bytes to a file //! \return Success or failure bool writeBytes( const void *const data, //!< The data const U32 length //!< The number of bytes to write ); //! Write a hash file void writeHashFile(); //! Close the file void close(); PRIVATE: //! The enclosing BufferLogger instance BufferLogger& m_bufferLogger; //! The prefix to use for file names Fw::String m_prefix; //! The suffix to use for file names Fw::String m_suffix; //! The file name base Fw::String m_baseName; //! The counter to use for the same file name NATIVE_UINT_TYPE m_fileCounter; //! The maximum file size U32 m_maxSize; //! The number of bytes to use when storing the size field at the start of each buffer U8 m_sizeOfSize; //! The name of the currently open file Fw::String m_name; // The current mode Mode::t m_mode; //! The underlying Os::File representation Os::File m_osFile; //! The number of bytes written to the current file U32 m_bytesWritten; }; // class File public: // ---------------------------------------------------------------------- // Construction, initialization, and destruction // ---------------------------------------------------------------------- //! Create a BufferLogger object BufferLogger( const char *const compName /*!< The component name*/ ); //! Initialize a BufferLogger object void init( const NATIVE_INT_TYPE queueDepth, //!< The queue depth const NATIVE_INT_TYPE instance //!< The instance number ); // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- //! Set up log file parameters void initLog( const char *const logFilePrefix, //!< The log file name prefix const char *const logFileSuffix, //!< The log file name suffix const U32 maxFileSize, //!< The maximum file size const U8 sizeOfSize //!< The number of bytes to use when storing the size field at the start of each buffer ); PRIVATE: // ---------------------------------------------------------------------- // Handler implementations for user-defined typed input ports // ---------------------------------------------------------------------- //! Handler implementation for bufferSendIn //! void bufferSendIn_handler( const NATIVE_INT_TYPE portNum, //!< The port number Fw::Buffer& fwBuffer ); //! Handler implementation for comIn //! void comIn_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 ); //! Handler implementation for pingIn //! void pingIn_handler( const NATIVE_INT_TYPE portNum, //!< The port number U32 key //!< Value to return to pinger ); //! Handler implementation for schedIn //! void schedIn_handler( const NATIVE_INT_TYPE portNum, /*!< The port number*/ U32 context /*!< The call order*/ ); PRIVATE: // ---------------------------------------------------------------------- // Command handler implementations // ---------------------------------------------------------------------- //! Implementation for BL_OpenFile command handler //! Open a new log file with specified name; required before activating logging void BL_OpenFile_cmdHandler( const FwOpcodeType opCode, /*!< The opcode*/ const U32 cmdSeq, /*!< The command sequence number*/ const Fw::CmdStringArg& file ); //! Implementation for BL_CloseFile command handler //! Close the currently open log file, if any void BL_CloseFile_cmdHandler( const FwOpcodeType opCode, /*!< The opcode*/ const U32 cmdSeq /*!< The command sequence number*/ ); //! Implementation for BL_SetLogging command handler //! Sets the volatile logging state void BL_SetLogging_cmdHandler( const FwOpcodeType opCode, /*!< The opcode*/ const U32 cmdSeq, /*!< The command sequence number*/ BufferLogger_LogState state ); //! Implementation for BL_FlushFile command handler //! Flushes the current open log file to disk void BL_FlushFile_cmdHandler( const FwOpcodeType opCode, /*!< The opcode*/ const U32 cmdSeq /*!< The command sequence number*/ ); PRIVATE: // ---------------------------------------------------------------------- // Private instance variables // ---------------------------------------------------------------------- //! The logging state BufferLogger_LogState m_state; //! The file File m_file; }; } #endif
hpp
fprime
data/projects/fprime/Svc/BufferLogger/test/ut/Logging.hpp
// ====================================================================== // \title Logging.hpp // \author bocchino, mereweth // \brief Interface for BufferLogger logging tests // // \copyright // Copyright (C) 2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef Svc_Logging_HPP #define Svc_Logging_HPP #include "BufferLoggerTester.hpp" namespace Svc { namespace Logging { class BufferLoggerTester : public Svc::BufferLoggerTester { public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! Test logging of data from bufferSendIn void BufferSendIn(); //! Test close file command void CloseFile(); //! Test logging of data from comIn void ComIn(); //! Test logging on/off capability void OnOff(); }; } } #endif
hpp
fprime
data/projects/fprime/Svc/BufferLogger/test/ut/Health.cpp
// ====================================================================== // \title Health.cpp // \author bocchino, mereweth // \brief Implementation for Buffer Logger 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 BufferLoggerTester :: Ping() { U32 key = 42; this->invoke_to_pingIn(0, key); this->dispatchAll(); ASSERT_EVENTS_SIZE(0); ASSERT_from_pingOut_SIZE(1); ASSERT_from_pingOut(0, key); } } }
cpp
fprime
data/projects/fprime/Svc/BufferLogger/test/ut/BufferLoggerMain.cpp
// ---------------------------------------------------------------------- // Main.cpp // ---------------------------------------------------------------------- #include "BufferLoggerTester.hpp" #include "Errors.hpp" #include "Logging.hpp" #include "Health.hpp" TEST(Test, LogNoInit) { Svc::BufferLoggerTester tester(false); // don't call initLog for the user tester.LogNoInit(); } // ---------------------------------------------------------------------- // Test Errors // ---------------------------------------------------------------------- TEST(TestErrors, LogFileOpen) { Svc::Errors::BufferLoggerTester tester; tester.LogFileOpen(); } TEST(TestErrors, LogFileWrite) { Svc::Errors::BufferLoggerTester tester; tester.LogFileWrite(); } TEST(TestErrors, LogFileValidation) { Svc::Errors::BufferLoggerTester tester; tester.LogFileValidation(); } // ---------------------------------------------------------------------- // Test Logging // ---------------------------------------------------------------------- TEST(TestLogging, BufferSendIn) { Svc::Logging::BufferLoggerTester tester; tester.BufferSendIn(); } TEST(TestLogging, CloseFile) { Svc::Logging::BufferLoggerTester tester; tester.CloseFile(); } TEST(TestLogging, ComIn) { Svc::Logging::BufferLoggerTester tester; tester.ComIn(); } TEST(TestLogging, OnOff) { Svc::Logging::BufferLoggerTester tester; tester.OnOff(); } // ---------------------------------------------------------------------- // Test Health // ---------------------------------------------------------------------- TEST(TestHealth, Ping) { Svc::Health::BufferLoggerTester tester; tester.Ping(); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
cpp
fprime
data/projects/fprime/Svc/BufferLogger/test/ut/Errors.cpp
// ====================================================================== // \title Errors.cpp // \author bocchino, mereweth // \brief Implementation for Buffer Logger error tests // // \copyright // Copyright (C) 2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include <cstdlib> #include "Errors.hpp" #include "Os/ValidatedFile.hpp" namespace Svc { namespace Errors { void BufferLoggerTester :: LogFileOpen() { // Remove buf directory (void) system("rm -rf buf"); this->component.m_file.m_baseName = Fw::String("LogFileOpen"); // Check initial state ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.m_mode); ASSERT_EVENTS_SIZE(0); // Send data this->sendComBuffers(3); // Check events // NOTE(mereweth) - not throttled ASSERT_EVENTS_SIZE(3); ASSERT_EVENTS_BL_LogFileOpenError_SIZE(3); for (int i = 0; i < 3; i++) { ASSERT_EVENTS_BL_LogFileOpenError( i, Os::File::DOESNT_EXIST, this->component.m_file.m_name.toChar() ); } // Create buf directory and try again (void) system("mkdir buf"); ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.m_mode); // Send data this->sendComBuffers(3); // Check events // NOTE(mereweth) - should have no more events than we did before ASSERT_EVENTS_SIZE(3); ASSERT_EVENTS_BL_LogFileOpenError_SIZE(3); this->component.m_file.close(); // Remove buf directory and try again (void) system("rm -rf buf"); ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.m_mode); // Send data this->sendComBuffers(3); // Check events // We expect 3 more; not throttled ASSERT_EVENTS_SIZE(6); ASSERT_EVENTS_BL_LogFileOpenError_SIZE(6); for (int i = 3; i < 6; i++) { ASSERT_EVENTS_BL_LogFileOpenError( i, Os::File::DOESNT_EXIST, this->component.m_file.m_name.toChar() ); } } void BufferLoggerTester :: LogFileWrite() { ASSERT_EQ(BufferLogger::File::Mode::CLOSED, this->component.m_file.m_mode); ASSERT_EVENTS_SIZE(0); this->component.m_file.m_baseName = Fw::String("LogFileWrite"); // Send data this->sendComBuffers(1); // Force close the file this->component.m_file.m_osFile.close(); // Send data this->sendComBuffers(1); // Construct file name Fw::String fileName; fileName.format( "%s%s%s", this->component.m_file.m_prefix.toChar(), this->component.m_file.m_baseName.toChar(), this->component.m_file.m_suffix.toChar() ); // Check events // NOTE(mereweth) - not throttled ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_BL_LogFileWriteError_SIZE(1); ASSERT_EVENTS_BL_LogFileWriteError( 0, Os::File::NOT_OPENED, // errornum 0, // bytesWritten sizeof(SIZE_TYPE), // bytesAttempted fileName.toChar() // file ); // Make comlogger open a new file: this->component.m_file.m_mode = BufferLogger::File::Mode::CLOSED; this->component.m_file.open(); // NOTE(mereweth) - new file; counter has incremented fileName.format( "%s%s%d%s", this->component.m_file.m_prefix.toChar(), this->component.m_file.m_baseName.toChar(), 1, this->component.m_file.m_suffix.toChar() ); // Try to write and make sure it succeeds // Send data this->sendComBuffers(3); // Expect no new errors ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_BL_LogFileWriteError_SIZE(1); // Force close the file from underneath the component component.m_file.m_osFile.close(); // Send data this->sendComBuffers(3); // Check events // NOTE(mereweth) - not throttled; 3 more events ASSERT_EVENTS_SIZE(4); ASSERT_EVENTS_BL_LogFileWriteError_SIZE(4); for (int i = 1; i < 4; i++) { ASSERT_EVENTS_BL_LogFileWriteError( i, Os::File::NOT_OPENED, 0, sizeof(SIZE_TYPE), fileName.toChar() ); } } void BufferLoggerTester :: LogFileValidation() { this->component.m_file.m_baseName = Fw::String("LogFileValidation"); // Send data this->sendComBuffers(1); // Remove permission to buf directory (void) system("chmod -w buf"); // Send close file command this->sendCmd_BL_CloseFile(0, 0); this->dispatchOne(); // Check events ASSERT_EVENTS_SIZE(2); Fw::String fileName; fileName.format( "%s%s%s", this->component.m_file.m_prefix.toChar(), this->component.m_file.m_baseName.toChar(), this->component.m_file.m_suffix.toChar() ); ASSERT_EVENTS_BL_LogFileClosed( 0, fileName.toChar() ); Os::ValidatedFile validatedFile(fileName.toChar()); const Fw::String& hashFileName = validatedFile.getHashFileName(); ASSERT_EVENTS_BL_LogFileValidationError( 0, hashFileName.toChar(), Os::ValidateFile::VALIDATION_FILE_NO_PERMISSION ); // Restore permission (void) system("chmod +w buf"); } } }
cpp
fprime
data/projects/fprime/Svc/BufferLogger/test/ut/Errors.hpp
// ====================================================================== // \title Errors.hpp // \author bocchino, mereweth // \brief Interface for BufferLogger error tests // // \copyright // Copyright (C) 2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #ifndef Svc_Errors_HPP #define Svc_Errors_HPP #include "BufferLoggerTester.hpp" namespace Svc { namespace Errors { class BufferLoggerTester : public Svc::BufferLoggerTester { public: // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- //! Log file open error void LogFileOpen(); //! Log file write error void LogFileWrite(); //! Log file validation error void LogFileValidation(); }; } } #endif
hpp
fprime
data/projects/fprime/Svc/BufferLogger/test/ut/Logging.cpp
// ====================================================================== // \title Logging.cpp // \author bocchino, mereweth // \brief Implementation for Buffer Logger logging tests // // \copyright // Copyright (C) 2017 California Institute of Technology. // ALL RIGHTS RESERVED. United States Government Sponsorship // acknowledged. // // ====================================================================== #include "Logging.hpp" #include "Os/FileSystem.hpp" namespace Svc { namespace Logging { class CloseFileTester : public Logging::BufferLoggerTester { public: CloseFileTester() { Fw::Time testTime = this->generateTestTime(0); this->setTestTime(testTime); } private: //! Send close file commands void sendCloseFileCommands(const U32 n) { this->clearHistory(); for (U32 i = 0; i < n; ++i) { this->sendCmd_BL_CloseFile(0, i); this->dispatchOne(); ASSERT_CMD_RESPONSE( i, BufferLogger::OPCODE_BL_CLOSEFILE, i, Fw::CmdResponse::OK ); } ASSERT_CMD_RESPONSE_SIZE(n); } //! Check that files exist void checkFilesExist() { const Fw::String& fileName = this->component.m_file.m_name; this->checkFileExists(fileName); this->checkHashFileExists(fileName); } public: void test() { this->component.m_file.m_baseName = Fw::String("CloseFileTester"); ASSERT_EVENTS_SIZE(0); this->sendCloseFileCommands(3); this->sendComBuffers(3); this->sendCloseFileCommands(3); ASSERT_EVENTS_SIZE(1); ASSERT_EVENTS_BL_LogFileClosed_SIZE(1); ASSERT_EVENTS_BL_LogFileClosed(0, component.m_file.m_name.toChar()); this->checkFilesExist(); } }; void BufferLoggerTester :: CloseFile() { CloseFileTester tester; tester.test(); } class SendBuffersTester : public Logging::BufferLoggerTester { protected: //! Send buffers virtual void sendBuffers( const U32 n //!< The number of buffers to send ) = 0; public: //! Run a test void test( const U32 numFiles, //!< The number of files to create const char *const baseName //!< The baseName to use ) { this->sendCmd_BL_OpenFile(0, 0, baseName); this->dispatchOne(); // Create file name Fw::String currentFileName; currentFileName.format( "%s%s%s", this->component.m_file.m_prefix.toChar(), baseName, this->component.m_file.m_suffix.toChar() ); this->sendBuffers(1); // 0th event has already happened (file open) for (U32 i = 1; i < numFiles+1; ++i) { // File was just created and name set ASSERT_EQ(currentFileName, this->component.m_file.m_name); // Write data to the file this->sendBuffers(MAX_ENTRIES_PER_FILE-1); // File still should have same name ASSERT_EQ(currentFileName, this->component.m_file.m_name); // Send more data // This should open a new file with the updated counter this->sendBuffers(1); currentFileName.format( "%s%s%d%s", this->component.m_file.m_prefix.toChar(), baseName, i, this->component.m_file.m_suffix.toChar() ); // Assert file state ASSERT_EQ(BufferLogger::File::Mode::OPEN, component.m_file.m_mode); ASSERT_EQ(currentFileName, this->component.m_file.m_name); // Assert events ASSERT_EVENTS_SIZE(i); ASSERT_EVENTS_BL_LogFileClosed_SIZE(i); } // Close the last file this->sendCmd_BL_CloseFile(0, 0); this->dispatchOne(); // Check files for (U32 i = 0; i < numFiles; ++i) { // Create file name Fw::String fileName; if (i == 0) { fileName.format( "%s%s%s", this->component.m_file.m_prefix.toChar(), baseName, this->component.m_file.m_suffix.toChar() ); } else { fileName.format( "%s%s%d%s", this->component.m_file.m_prefix.toChar(), baseName, i, this->component.m_file.m_suffix.toChar() ); } // Check events ASSERT_EVENTS_BL_LogFileClosed(i, fileName.toChar()); // Check file integrity this->checkLogFileIntegrity( fileName.toChar(), MAX_BYTES_PER_FILE, MAX_ENTRIES_PER_FILE ); // Check validation this->checkFileValidation(fileName.toChar()); } } }; class ComInTester : public SendBuffersTester { void sendBuffers(const U32 n) { this->sendComBuffers(n); } }; void BufferLoggerTester :: ComIn() { ComInTester tester; tester.test(3, "ComIn"); } class BufferSendInTester : public SendBuffersTester { void sendBuffers(const U32 n) { this->sendManagedBuffers(n); } }; void BufferLoggerTester :: BufferSendIn() { BufferSendInTester tester; tester.test(3, "BufferSendIn"); } class OnOffTester : Logging::BufferLoggerTester { private: //! Send data void sendData() { this->sendComBuffers(MAX_ENTRIES_PER_FILE); } public: //! Set the state void setState( const BufferLogger_LogState state //!< The state ) { this->clearHistory(); this->sendCmd_BL_SetLogging(0, 0, state); this->dispatchOne(); ASSERT_CMD_RESPONSE_SIZE(1); ASSERT_CMD_RESPONSE( 0, BufferLogger::OPCODE_BL_SETLOGGING, 0, Fw::CmdResponse::OK ); } //! Test logging on void testLoggingOn() { this->component.m_file.m_baseName = Fw::String("OnOffTester"); this->sendData(); this->setState(BufferLogger_LogState::LOGGING_OFF); this->checkLogFileIntegrity( this->component.m_file.m_name.toChar(), MAX_BYTES_PER_FILE, MAX_ENTRIES_PER_FILE ); } //! Test logging off void testLoggingOff() { this->setState(BufferLogger_LogState::LOGGING_OFF); this->sendData(); ASSERT_EVENTS_SIZE(0); this->setState(BufferLogger_LogState::LOGGING_ON); } }; void BufferLoggerTester :: OnOff() { { OnOffTester tester; tester.testLoggingOn(); } { OnOffTester tester; tester.testLoggingOff(); } } } }
cpp