xref: /openbmc/pldm/platform-mc/test/mock_terminus_manager.hpp (revision 51d66b59c6f0bdad9c6a79f39f1c192bafc00c1f)
16c7fed4cSGilbert Chen #pragma once
26c7fed4cSGilbert Chen 
36c7fed4cSGilbert Chen #include "platform-mc/terminus_manager.hpp"
46c7fed4cSGilbert Chen 
56c7fed4cSGilbert Chen #include <queue>
66c7fed4cSGilbert Chen 
76c7fed4cSGilbert Chen #include <gmock/gmock.h>
86c7fed4cSGilbert Chen 
96c7fed4cSGilbert Chen namespace pldm
106c7fed4cSGilbert Chen {
116c7fed4cSGilbert Chen namespace platform_mc
126c7fed4cSGilbert Chen {
136c7fed4cSGilbert Chen 
146c7fed4cSGilbert Chen class MockTerminusManager : public TerminusManager
156c7fed4cSGilbert Chen {
166c7fed4cSGilbert Chen   public:
MockTerminusManager(sdeventplus::Event & event,RequesterHandler & handler,pldm::InstanceIdDb & instanceIdDb,TerminiMapper & termini,Manager * manager)176c7fed4cSGilbert Chen     MockTerminusManager(sdeventplus::Event& event, RequesterHandler& handler,
186c7fed4cSGilbert Chen                         pldm::InstanceIdDb& instanceIdDb,
196c7fed4cSGilbert Chen                         TerminiMapper& termini, Manager* manager) :
20*51d66b59SThu Nguyen         TerminusManager(event, handler, instanceIdDb, termini, manager,
21*51d66b59SThu Nguyen                         pldm::BmcMctpEid)
226c7fed4cSGilbert Chen     {}
236c7fed4cSGilbert Chen 
sendRecvPldmMsgOverMctp(mctp_eid_t,Request &,const pldm_msg ** responseMsg,size_t * responseLen)2416c2a0a0SPatrick Williams     exec::task<int> sendRecvPldmMsgOverMctp(
2516c2a0a0SPatrick Williams         mctp_eid_t /*eid*/, Request& /*request*/, const pldm_msg** responseMsg,
266c7fed4cSGilbert Chen         size_t* responseLen) override
276c7fed4cSGilbert Chen     {
286c7fed4cSGilbert Chen         if (responseMsgs.empty() || responseMsg == nullptr ||
296c7fed4cSGilbert Chen             responseLen == nullptr)
306c7fed4cSGilbert Chen         {
316c7fed4cSGilbert Chen             co_return PLDM_ERROR;
326c7fed4cSGilbert Chen         }
336c7fed4cSGilbert Chen 
346c7fed4cSGilbert Chen         *responseMsg = responseMsgs.front();
356c7fed4cSGilbert Chen         *responseLen = responseLens.front() - sizeof(pldm_msg_hdr);
366c7fed4cSGilbert Chen 
376c7fed4cSGilbert Chen         responseMsgs.pop();
386c7fed4cSGilbert Chen         responseLens.pop();
396c7fed4cSGilbert Chen         co_return PLDM_SUCCESS;
406c7fed4cSGilbert Chen     }
416c7fed4cSGilbert Chen 
enqueueResponse(pldm_msg * responseMsg,size_t responseLen)426c7fed4cSGilbert Chen     int enqueueResponse(pldm_msg* responseMsg, size_t responseLen)
436c7fed4cSGilbert Chen     {
446c7fed4cSGilbert Chen         if (responseMsg == nullptr)
456c7fed4cSGilbert Chen         {
466c7fed4cSGilbert Chen             return PLDM_ERROR_INVALID_DATA;
476c7fed4cSGilbert Chen         }
486c7fed4cSGilbert Chen 
496c7fed4cSGilbert Chen         if (responseLen <= sizeof(pldm_msg_hdr))
506c7fed4cSGilbert Chen         {
516c7fed4cSGilbert Chen             return PLDM_ERROR_INVALID_LENGTH;
526c7fed4cSGilbert Chen         }
536c7fed4cSGilbert Chen 
546c7fed4cSGilbert Chen         responseMsgs.push(responseMsg);
556c7fed4cSGilbert Chen         responseLens.push(responseLen);
566c7fed4cSGilbert Chen         return PLDM_SUCCESS;
576c7fed4cSGilbert Chen     }
586c7fed4cSGilbert Chen 
clearQueuedResponses()596c7fed4cSGilbert Chen     int clearQueuedResponses()
606c7fed4cSGilbert Chen     {
616c7fed4cSGilbert Chen         while (!responseMsgs.empty())
626c7fed4cSGilbert Chen         {
636c7fed4cSGilbert Chen             responseMsgs.pop();
646c7fed4cSGilbert Chen             responseLens.pop();
656c7fed4cSGilbert Chen         }
666c7fed4cSGilbert Chen         return PLDM_SUCCESS;
676c7fed4cSGilbert Chen     }
686c7fed4cSGilbert Chen 
696c7fed4cSGilbert Chen     std::queue<pldm_msg*> responseMsgs;
706c7fed4cSGilbert Chen     std::queue<size_t> responseLens;
716c7fed4cSGilbert Chen };
726c7fed4cSGilbert Chen 
736c7fed4cSGilbert Chen } // namespace platform_mc
746c7fed4cSGilbert Chen } // namespace pldm
75