1de2a132aSGilbert Chen #include "common/instance_id.hpp" 2de2a132aSGilbert Chen #include "mock_terminus_manager.hpp" 3de2a132aSGilbert Chen #include "platform-mc/platform_manager.hpp" 4de2a132aSGilbert Chen #include "test/test_instance_id.hpp" 5de2a132aSGilbert Chen 6de2a132aSGilbert Chen #include <sdeventplus/event.hpp> 7de2a132aSGilbert Chen 8de2a132aSGilbert Chen #include <bitset> 9de2a132aSGilbert Chen 10de2a132aSGilbert Chen #include <gtest/gtest.h> 11de2a132aSGilbert Chen 12de2a132aSGilbert Chen class PlatformManagerTest : public testing::Test 13de2a132aSGilbert Chen { 14de2a132aSGilbert Chen protected: 15de2a132aSGilbert Chen PlatformManagerTest() : 16de2a132aSGilbert Chen bus(pldm::utils::DBusHandler::getBus()), 17de2a132aSGilbert Chen event(sdeventplus::Event::get_default()), instanceIdDb(), 18de2a132aSGilbert Chen reqHandler(pldmTransport, event, instanceIdDb, false, 19de2a132aSGilbert Chen std::chrono::seconds(1), 2, std::chrono::milliseconds(100)), 20de2a132aSGilbert Chen mockTerminusManager(event, reqHandler, instanceIdDb, termini, nullptr), 21de2a132aSGilbert Chen platformManager(mockTerminusManager, termini) 22de2a132aSGilbert Chen {} 23de2a132aSGilbert Chen 24de2a132aSGilbert Chen PldmTransport* pldmTransport = nullptr; 25de2a132aSGilbert Chen sdbusplus::bus_t& bus; 26de2a132aSGilbert Chen sdeventplus::Event event; 27de2a132aSGilbert Chen TestInstanceIdDb instanceIdDb; 28de2a132aSGilbert Chen pldm::requester::Handler<pldm::requester::Request> reqHandler; 29de2a132aSGilbert Chen pldm::platform_mc::MockTerminusManager mockTerminusManager; 30de2a132aSGilbert Chen pldm::platform_mc::PlatformManager platformManager; 31de2a132aSGilbert Chen std::map<pldm_tid_t, std::shared_ptr<pldm::platform_mc::Terminus>> termini; 32de2a132aSGilbert Chen }; 33de2a132aSGilbert Chen 34de2a132aSGilbert Chen TEST_F(PlatformManagerTest, initTerminusTest) 35de2a132aSGilbert Chen { 36de2a132aSGilbert Chen // Add terminus 37de2a132aSGilbert Chen auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1)); 38de2a132aSGilbert Chen auto tid = mappedTid.value(); 39de2a132aSGilbert Chen termini[tid] = std::make_shared<pldm::platform_mc::Terminus>( 40de2a132aSGilbert Chen tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM); 41de2a132aSGilbert Chen auto terminus = termini[tid]; 42de2a132aSGilbert Chen 43de2a132aSGilbert Chen /* Set supported command by terminus */ 44de2a132aSGilbert Chen auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8); 45de2a132aSGilbert Chen std::vector<uint8_t> pldmCmds(size); 46de2a132aSGilbert Chen uint8_t type = PLDM_PLATFORM; 47de2a132aSGilbert Chen uint8_t cmd = PLDM_GET_PDR; 48de2a132aSGilbert Chen auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8); 49de2a132aSGilbert Chen pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8)); 50de2a132aSGilbert Chen cmd = PLDM_GET_PDR_REPOSITORY_INFO; 51de2a132aSGilbert Chen idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8); 52de2a132aSGilbert Chen pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8)); 53de2a132aSGilbert Chen termini[tid]->setSupportedCommands(pldmCmds); 54de2a132aSGilbert Chen 55de2a132aSGilbert Chen // queue getPDRRepositoryInfo response 56de2a132aSGilbert Chen const size_t getPDRRepositoryInfoLen = 57de2a132aSGilbert Chen PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES; 58de2a132aSGilbert Chen std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen> 59de2a132aSGilbert Chen getPDRRepositoryInfoResp{ 60de2a132aSGilbert Chen 0x0, 0x02, 0x50, PLDM_SUCCESS, 61de2a132aSGilbert Chen 0x0, // repositoryState 62de2a132aSGilbert Chen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 63de2a132aSGilbert Chen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // updateTime 64de2a132aSGilbert Chen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 65de2a132aSGilbert Chen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // OEMUpdateTime 66de2a132aSGilbert Chen 1, 0x0, 0x0, 0x0, // recordCount 67de2a132aSGilbert Chen 0x0, 0x1, 0x0, 0x0, // repositorySize 68de2a132aSGilbert Chen 59, 0x0, 0x0, 0x0, // largestRecordSize 69de2a132aSGilbert Chen 0x0 // dataTransferHandleTimeout 70de2a132aSGilbert Chen }; 71de2a132aSGilbert Chen auto rc = mockTerminusManager.enqueueResponse( 72de2a132aSGilbert Chen (pldm_msg*)getPDRRepositoryInfoResp.data(), 73de2a132aSGilbert Chen sizeof(getPDRRepositoryInfoResp)); 74de2a132aSGilbert Chen EXPECT_EQ(rc, PLDM_SUCCESS); 75de2a132aSGilbert Chen 76de2a132aSGilbert Chen // queue getPDR responses 77de2a132aSGilbert Chen const size_t getPdrRespLen = 81; 78de2a132aSGilbert Chen std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{ 79de2a132aSGilbert Chen 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0, 0x0, // nextRecordHandle 80de2a132aSGilbert Chen 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle 81de2a132aSGilbert Chen 0x5, // transferFlag 82de2a132aSGilbert Chen 69, 0x0, // responseCount 83de2a132aSGilbert Chen // numeric Sensor PDR 84de2a132aSGilbert Chen 0x1, 0x0, 0x0, 85de2a132aSGilbert Chen 0x0, // record handle 86de2a132aSGilbert Chen 0x1, // PDRHeaderVersion 87de2a132aSGilbert Chen PLDM_NUMERIC_SENSOR_PDR, // PDRType 88de2a132aSGilbert Chen 0x0, 89de2a132aSGilbert Chen 0x0, // recordChangeNumber 90de2a132aSGilbert Chen PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH + 91de2a132aSGilbert Chen PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH + 92de2a132aSGilbert Chen PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH, 93de2a132aSGilbert Chen 0, // dataLength 94de2a132aSGilbert Chen 0, 95de2a132aSGilbert Chen 0, // PLDMTerminusHandle 96de2a132aSGilbert Chen 0x1, 97de2a132aSGilbert Chen 0x0, // sensorID=1 98de2a132aSGilbert Chen 120, 99de2a132aSGilbert Chen 0, // entityType=Power Supply(120) 100de2a132aSGilbert Chen 1, 101de2a132aSGilbert Chen 0, // entityInstanceNumber 102de2a132aSGilbert Chen 0x1, 103de2a132aSGilbert Chen 0x0, // containerID=1 104de2a132aSGilbert Chen PLDM_NO_INIT, // sensorInit 105de2a132aSGilbert Chen false, // sensorAuxiliaryNamesPDR 106de2a132aSGilbert Chen PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C 107de2a132aSGilbert Chen 1, // unitModifier = 1 108de2a132aSGilbert Chen 0, // rateUnit 109de2a132aSGilbert Chen 0, // baseOEMUnitHandle 110de2a132aSGilbert Chen 0, // auxUnit 111de2a132aSGilbert Chen 0, // auxUnitModifier 112de2a132aSGilbert Chen 0, // auxRateUnit 113de2a132aSGilbert Chen 0, // rel 114de2a132aSGilbert Chen 0, // auxOEMUnitHandle 115de2a132aSGilbert Chen true, // isLinear 116de2a132aSGilbert Chen PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize 117de2a132aSGilbert Chen 0, 0, 0xc0, 118de2a132aSGilbert Chen 0x3f, // resolution=1.5 119de2a132aSGilbert Chen 0, 0, 0x80, 120de2a132aSGilbert Chen 0x3f, // offset=1.0 121de2a132aSGilbert Chen 0, 122de2a132aSGilbert Chen 0, // accuracy 123de2a132aSGilbert Chen 0, // plusTolerance 124de2a132aSGilbert Chen 0, // minusTolerance 125de2a132aSGilbert Chen 2, // hysteresis 126de2a132aSGilbert Chen 0, // supportedThresholds 127de2a132aSGilbert Chen 0, // thresholdAndHysteresisVolatility 128de2a132aSGilbert Chen 0, 0, 0x80, 129de2a132aSGilbert Chen 0x3f, // stateTransistionInterval=1.0 130de2a132aSGilbert Chen 0, 0, 0x80, 131de2a132aSGilbert Chen 0x3f, // updateInverval=1.0 132de2a132aSGilbert Chen 255, // maxReadable 133de2a132aSGilbert Chen 0, // minReadable 134de2a132aSGilbert Chen PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat 135de2a132aSGilbert Chen 0, // rangeFieldsupport 136de2a132aSGilbert Chen 0, // nominalValue 137de2a132aSGilbert Chen 0, // normalMax 138de2a132aSGilbert Chen 0, // normalMin 139de2a132aSGilbert Chen 0, // warningHigh 140de2a132aSGilbert Chen 0, // warningLow 141de2a132aSGilbert Chen 0, // criticalHigh 142de2a132aSGilbert Chen 0, // criticalLow 143de2a132aSGilbert Chen 0, // fatalHigh 144de2a132aSGilbert Chen 0 // fatalLow 145de2a132aSGilbert Chen }; 146de2a132aSGilbert Chen rc = mockTerminusManager.enqueueResponse((pldm_msg*)getPdrResp.data(), 147de2a132aSGilbert Chen sizeof(getPdrResp)); 148de2a132aSGilbert Chen EXPECT_EQ(rc, PLDM_SUCCESS); 149de2a132aSGilbert Chen 150de2a132aSGilbert Chen stdexec::sync_wait(platformManager.initTerminus()); 151de2a132aSGilbert Chen EXPECT_EQ(true, terminus->initialized); 152de2a132aSGilbert Chen EXPECT_EQ(1, terminus->pdrs.size()); 153de2a132aSGilbert Chen } 154de2a132aSGilbert Chen 155*b8cf46b8SThu Nguyen TEST_F(PlatformManagerTest, parseTerminusNameTest) 156*b8cf46b8SThu Nguyen { 157*b8cf46b8SThu Nguyen // Add terminus 158*b8cf46b8SThu Nguyen auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1)); 159*b8cf46b8SThu Nguyen auto tid = mappedTid.value(); 160*b8cf46b8SThu Nguyen termini[tid] = std::make_shared<pldm::platform_mc::Terminus>( 161*b8cf46b8SThu Nguyen tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM); 162*b8cf46b8SThu Nguyen auto terminus = termini[tid]; 163*b8cf46b8SThu Nguyen 164*b8cf46b8SThu Nguyen /* Set supported command by terminus */ 165*b8cf46b8SThu Nguyen auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8); 166*b8cf46b8SThu Nguyen std::vector<uint8_t> pldmCmds(size); 167*b8cf46b8SThu Nguyen uint8_t type = PLDM_PLATFORM; 168*b8cf46b8SThu Nguyen uint8_t cmd = PLDM_GET_PDR; 169*b8cf46b8SThu Nguyen auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8); 170*b8cf46b8SThu Nguyen pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8)); 171*b8cf46b8SThu Nguyen cmd = PLDM_GET_PDR_REPOSITORY_INFO; 172*b8cf46b8SThu Nguyen idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8); 173*b8cf46b8SThu Nguyen pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8)); 174*b8cf46b8SThu Nguyen termini[tid]->setSupportedCommands(pldmCmds); 175*b8cf46b8SThu Nguyen 176*b8cf46b8SThu Nguyen // queue getPDRRepositoryInfo response 177*b8cf46b8SThu Nguyen const size_t getPDRRepositoryInfoLen = 178*b8cf46b8SThu Nguyen PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES; 179*b8cf46b8SThu Nguyen std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen> 180*b8cf46b8SThu Nguyen getPDRRepositoryInfoResp{ 181*b8cf46b8SThu Nguyen 0x0, 0x02, 0x50, PLDM_SUCCESS, 182*b8cf46b8SThu Nguyen 0x0, // repositoryState 183*b8cf46b8SThu Nguyen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 184*b8cf46b8SThu Nguyen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // updateTime 185*b8cf46b8SThu Nguyen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 186*b8cf46b8SThu Nguyen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // OEMUpdateTime 187*b8cf46b8SThu Nguyen 2, 0x0, 0x0, 0x0, // recordCount 188*b8cf46b8SThu Nguyen 0x0, 0x1, 0x0, 0x0, // repositorySize 189*b8cf46b8SThu Nguyen 59, 0x0, 0x0, 0x0, // largestRecordSize 190*b8cf46b8SThu Nguyen 0x0 // dataTransferHandleTimeout 191*b8cf46b8SThu Nguyen }; 192*b8cf46b8SThu Nguyen auto rc = mockTerminusManager.enqueueResponse( 193*b8cf46b8SThu Nguyen reinterpret_cast<pldm_msg*>(getPDRRepositoryInfoResp.data()), 194*b8cf46b8SThu Nguyen sizeof(getPDRRepositoryInfoResp)); 195*b8cf46b8SThu Nguyen EXPECT_EQ(rc, PLDM_SUCCESS); 196*b8cf46b8SThu Nguyen 197*b8cf46b8SThu Nguyen // queue getPDR responses 198*b8cf46b8SThu Nguyen const size_t getPdrRespLen = 81; 199*b8cf46b8SThu Nguyen std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{ 200*b8cf46b8SThu Nguyen 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x1, 0x0, 0x0, 0x0, // nextRecordHandle 201*b8cf46b8SThu Nguyen 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle 202*b8cf46b8SThu Nguyen 0x5, // transferFlag 203*b8cf46b8SThu Nguyen 69, 0x0, // responseCount 204*b8cf46b8SThu Nguyen // numeric Sensor PDR 205*b8cf46b8SThu Nguyen 0x0, 0x0, 0x0, 206*b8cf46b8SThu Nguyen 0x0, // record handle 207*b8cf46b8SThu Nguyen 0x1, // PDRHeaderVersion 208*b8cf46b8SThu Nguyen PLDM_NUMERIC_SENSOR_PDR, // PDRType 209*b8cf46b8SThu Nguyen 0x0, 210*b8cf46b8SThu Nguyen 0x0, // recordChangeNumber 211*b8cf46b8SThu Nguyen PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH + 212*b8cf46b8SThu Nguyen PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH + 213*b8cf46b8SThu Nguyen PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH, 214*b8cf46b8SThu Nguyen 0, // dataLength 215*b8cf46b8SThu Nguyen 0, 216*b8cf46b8SThu Nguyen 0, // PLDMTerminusHandle 217*b8cf46b8SThu Nguyen 0x1, 218*b8cf46b8SThu Nguyen 0x0, // sensorID=1 219*b8cf46b8SThu Nguyen 120, 220*b8cf46b8SThu Nguyen 0, // entityType=Power Supply(120) 221*b8cf46b8SThu Nguyen 1, 222*b8cf46b8SThu Nguyen 0, // entityInstanceNumber 223*b8cf46b8SThu Nguyen 0x1, 224*b8cf46b8SThu Nguyen 0x0, // containerID=1 225*b8cf46b8SThu Nguyen PLDM_NO_INIT, // sensorInit 226*b8cf46b8SThu Nguyen false, // sensorAuxiliaryNamesPDR 227*b8cf46b8SThu Nguyen PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C 228*b8cf46b8SThu Nguyen 1, // unitModifier = 1 229*b8cf46b8SThu Nguyen 0, // rateUnit 230*b8cf46b8SThu Nguyen 0, // baseOEMUnitHandle 231*b8cf46b8SThu Nguyen 0, // auxUnit 232*b8cf46b8SThu Nguyen 0, // auxUnitModifier 233*b8cf46b8SThu Nguyen 0, // auxRateUnit 234*b8cf46b8SThu Nguyen 0, // rel 235*b8cf46b8SThu Nguyen 0, // auxOEMUnitHandle 236*b8cf46b8SThu Nguyen true, // isLinear 237*b8cf46b8SThu Nguyen PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize 238*b8cf46b8SThu Nguyen 0, 0, 0xc0, 239*b8cf46b8SThu Nguyen 0x3f, // resolution=1.5 240*b8cf46b8SThu Nguyen 0, 0, 0x80, 241*b8cf46b8SThu Nguyen 0x3f, // offset=1.0 242*b8cf46b8SThu Nguyen 0, 243*b8cf46b8SThu Nguyen 0, // accuracy 244*b8cf46b8SThu Nguyen 0, // plusTolerance 245*b8cf46b8SThu Nguyen 0, // minusTolerance 246*b8cf46b8SThu Nguyen 2, // hysteresis 247*b8cf46b8SThu Nguyen 0, // supportedThresholds 248*b8cf46b8SThu Nguyen 0, // thresholdAndHysteresisVolatility 249*b8cf46b8SThu Nguyen 0, 0, 0x80, 250*b8cf46b8SThu Nguyen 0x3f, // stateTransistionInterval=1.0 251*b8cf46b8SThu Nguyen 0, 0, 0x80, 252*b8cf46b8SThu Nguyen 0x3f, // updateInverval=1.0 253*b8cf46b8SThu Nguyen 255, // maxReadable 254*b8cf46b8SThu Nguyen 0, // minReadable 255*b8cf46b8SThu Nguyen PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat 256*b8cf46b8SThu Nguyen 0, // rangeFieldsupport 257*b8cf46b8SThu Nguyen 0, // nominalValue 258*b8cf46b8SThu Nguyen 0, // normalMax 259*b8cf46b8SThu Nguyen 0, // normalMin 260*b8cf46b8SThu Nguyen 0, // warningHigh 261*b8cf46b8SThu Nguyen 0, // warningLow 262*b8cf46b8SThu Nguyen 0, // criticalHigh 263*b8cf46b8SThu Nguyen 0, // criticalLow 264*b8cf46b8SThu Nguyen 0, // fatalHigh 265*b8cf46b8SThu Nguyen 0 // fatalLow 266*b8cf46b8SThu Nguyen }; 267*b8cf46b8SThu Nguyen rc = mockTerminusManager.enqueueResponse( 268*b8cf46b8SThu Nguyen reinterpret_cast<pldm_msg*>(getPdrResp.data()), sizeof(getPdrResp)); 269*b8cf46b8SThu Nguyen EXPECT_EQ(rc, PLDM_SUCCESS); 270*b8cf46b8SThu Nguyen 271*b8cf46b8SThu Nguyen const size_t getPdrAuxNameRespLen = 39; 272*b8cf46b8SThu Nguyen std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrAuxNameRespLen> 273*b8cf46b8SThu Nguyen getPdrAuxNameResp{ 274*b8cf46b8SThu Nguyen 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0, 275*b8cf46b8SThu Nguyen 0x0, // nextRecordHandle 276*b8cf46b8SThu Nguyen 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle 277*b8cf46b8SThu Nguyen 0x5, // transferFlag 278*b8cf46b8SThu Nguyen 0x1b, 0x0, // responseCount 279*b8cf46b8SThu Nguyen // Common PDR Header 280*b8cf46b8SThu Nguyen 0x1, 0x0, 0x0, 281*b8cf46b8SThu Nguyen 0x0, // record handle 282*b8cf46b8SThu Nguyen 0x1, // PDRHeaderVersion 283*b8cf46b8SThu Nguyen PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType 284*b8cf46b8SThu Nguyen 0x1, 285*b8cf46b8SThu Nguyen 0x0, // recordChangeNumber 286*b8cf46b8SThu Nguyen 0x11, 287*b8cf46b8SThu Nguyen 0, // dataLength 288*b8cf46b8SThu Nguyen /* Entity Auxiliary Names PDR Data*/ 289*b8cf46b8SThu Nguyen 3, 290*b8cf46b8SThu Nguyen 0x80, // entityType system software 291*b8cf46b8SThu Nguyen 0x1, 292*b8cf46b8SThu Nguyen 0x0, // Entity instance number =1 293*b8cf46b8SThu Nguyen 0, 294*b8cf46b8SThu Nguyen 0, // Overal system 295*b8cf46b8SThu Nguyen 0, // shared Name Count one name only 296*b8cf46b8SThu Nguyen 01, // nameStringCount 297*b8cf46b8SThu Nguyen 0x65, 0x6e, 0x00, 298*b8cf46b8SThu Nguyen 0x00, // Language Tag "en" 299*b8cf46b8SThu Nguyen 0x53, 0x00, 0x30, 0x00, 300*b8cf46b8SThu Nguyen 0x00 // Entity Name "S0" 301*b8cf46b8SThu Nguyen }; 302*b8cf46b8SThu Nguyen rc = mockTerminusManager.enqueueResponse( 303*b8cf46b8SThu Nguyen reinterpret_cast<pldm_msg*>(getPdrAuxNameResp.data()), 304*b8cf46b8SThu Nguyen sizeof(getPdrAuxNameResp)); 305*b8cf46b8SThu Nguyen EXPECT_EQ(rc, PLDM_SUCCESS); 306*b8cf46b8SThu Nguyen 307*b8cf46b8SThu Nguyen stdexec::sync_wait(platformManager.initTerminus()); 308*b8cf46b8SThu Nguyen EXPECT_EQ(true, terminus->initialized); 309*b8cf46b8SThu Nguyen EXPECT_EQ(2, terminus->pdrs.size()); 310*b8cf46b8SThu Nguyen EXPECT_EQ("S0", terminus->getTerminusName()); 311*b8cf46b8SThu Nguyen } 312*b8cf46b8SThu Nguyen 313de2a132aSGilbert Chen TEST_F(PlatformManagerTest, initTerminusDontSupportGetPDRTest) 314de2a132aSGilbert Chen { 315de2a132aSGilbert Chen // Add terminus 316de2a132aSGilbert Chen auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1)); 317de2a132aSGilbert Chen auto tid = mappedTid.value(); 318de2a132aSGilbert Chen termini[tid] = std::make_shared<pldm::platform_mc::Terminus>( 319de2a132aSGilbert Chen tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM); 320de2a132aSGilbert Chen auto terminus = termini[tid]; 321de2a132aSGilbert Chen 322de2a132aSGilbert Chen /* Set supported command by terminus */ 323de2a132aSGilbert Chen auto size = PLDM_MAX_TYPES * (PLDM_MAX_CMDS_PER_TYPE / 8); 324de2a132aSGilbert Chen std::vector<uint8_t> pldmCmds(size); 325de2a132aSGilbert Chen uint8_t type = PLDM_PLATFORM; 326de2a132aSGilbert Chen uint8_t cmd = PLDM_GET_PDR_REPOSITORY_INFO; 327de2a132aSGilbert Chen auto idx = type * (PLDM_MAX_CMDS_PER_TYPE / 8) + (cmd / 8); 328de2a132aSGilbert Chen pldmCmds[idx] = pldmCmds[idx] | (1 << (cmd % 8)); 329de2a132aSGilbert Chen termini[tid]->setSupportedCommands(pldmCmds); 330de2a132aSGilbert Chen 331de2a132aSGilbert Chen // queue getPDRRepositoryInfo response 332de2a132aSGilbert Chen const size_t getPDRRepositoryInfoLen = 333de2a132aSGilbert Chen PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES; 334de2a132aSGilbert Chen std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen> 335de2a132aSGilbert Chen getPDRRepositoryInfoResp{ 336de2a132aSGilbert Chen 0x0, 0x02, 0x50, PLDM_SUCCESS, 337de2a132aSGilbert Chen 0x0, // repositoryState 338de2a132aSGilbert Chen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 339de2a132aSGilbert Chen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // updateTime 340de2a132aSGilbert Chen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 341de2a132aSGilbert Chen 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // OEMUpdateTime 342de2a132aSGilbert Chen 1, 0x0, 0x0, 0x0, // recordCount 343de2a132aSGilbert Chen 0x0, 0x1, 0x0, 0x0, // repositorySize 344de2a132aSGilbert Chen 59, 0x0, 0x0, 0x0, // largestRecordSize 345de2a132aSGilbert Chen 0x0 // dataTransferHandleTimeout 346de2a132aSGilbert Chen }; 347de2a132aSGilbert Chen auto rc = mockTerminusManager.enqueueResponse( 348de2a132aSGilbert Chen (pldm_msg*)getPDRRepositoryInfoResp.data(), 349de2a132aSGilbert Chen sizeof(getPDRRepositoryInfoResp)); 350de2a132aSGilbert Chen EXPECT_EQ(rc, PLDM_SUCCESS); 351de2a132aSGilbert Chen 352de2a132aSGilbert Chen // queue getPDR responses 353de2a132aSGilbert Chen const size_t getPdrRespLen = 81; 354de2a132aSGilbert Chen std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{ 355de2a132aSGilbert Chen 0x0, 0x02, 0x51, PLDM_SUCCESS, 0x0, 0x0, 0x0, 0x0, // nextRecordHandle 356de2a132aSGilbert Chen 0x0, 0x0, 0x0, 0x0, // nextDataTransferHandle 357de2a132aSGilbert Chen 0x5, // transferFlag 358de2a132aSGilbert Chen 69, 0x0, // responseCount 359de2a132aSGilbert Chen // numeric Sensor PDR 360de2a132aSGilbert Chen 0x1, 0x0, 0x0, 361de2a132aSGilbert Chen 0x0, // record handle 362de2a132aSGilbert Chen 0x1, // PDRHeaderVersion 363de2a132aSGilbert Chen PLDM_NUMERIC_SENSOR_PDR, // PDRType 364de2a132aSGilbert Chen 0x0, 365de2a132aSGilbert Chen 0x0, // recordChangeNumber 366de2a132aSGilbert Chen PLDM_PDR_NUMERIC_SENSOR_PDR_FIXED_LENGTH + 367de2a132aSGilbert Chen PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_SENSOR_DATA_SIZE_MIN_LENGTH + 368de2a132aSGilbert Chen PLDM_PDR_NUMERIC_SENSOR_PDR_VARIED_RANGE_FIELD_MIN_LENGTH, 369de2a132aSGilbert Chen 0, // dataLength 370de2a132aSGilbert Chen 0, 371de2a132aSGilbert Chen 0, // PLDMTerminusHandle 372de2a132aSGilbert Chen 0x1, 373de2a132aSGilbert Chen 0x0, // sensorID=1 374de2a132aSGilbert Chen 120, 375de2a132aSGilbert Chen 0, // entityType=Power Supply(120) 376de2a132aSGilbert Chen 1, 377de2a132aSGilbert Chen 0, // entityInstanceNumber 378de2a132aSGilbert Chen 0x1, 379de2a132aSGilbert Chen 0x0, // containerID=1 380de2a132aSGilbert Chen PLDM_NO_INIT, // sensorInit 381de2a132aSGilbert Chen false, // sensorAuxiliaryNamesPDR 382de2a132aSGilbert Chen PLDM_SENSOR_UNIT_DEGRESS_C, // baseUint(2)=degrees C 383de2a132aSGilbert Chen 1, // unitModifier = 1 384de2a132aSGilbert Chen 0, // rateUnit 385de2a132aSGilbert Chen 0, // baseOEMUnitHandle 386de2a132aSGilbert Chen 0, // auxUnit 387de2a132aSGilbert Chen 0, // auxUnitModifier 388de2a132aSGilbert Chen 0, // auxRateUnit 389de2a132aSGilbert Chen 0, // rel 390de2a132aSGilbert Chen 0, // auxOEMUnitHandle 391de2a132aSGilbert Chen true, // isLinear 392de2a132aSGilbert Chen PLDM_SENSOR_DATA_SIZE_UINT8, // sensorDataSize 393de2a132aSGilbert Chen 0, 0, 0xc0, 394de2a132aSGilbert Chen 0x3f, // resolution=1.5 395de2a132aSGilbert Chen 0, 0, 0x80, 396de2a132aSGilbert Chen 0x3f, // offset=1.0 397de2a132aSGilbert Chen 0, 398de2a132aSGilbert Chen 0, // accuracy 399de2a132aSGilbert Chen 0, // plusTolerance 400de2a132aSGilbert Chen 0, // minusTolerance 401de2a132aSGilbert Chen 2, // hysteresis 402de2a132aSGilbert Chen 0, // supportedThresholds 403de2a132aSGilbert Chen 0, // thresholdAndHysteresisVolatility 404de2a132aSGilbert Chen 0, 0, 0x80, 405de2a132aSGilbert Chen 0x3f, // stateTransistionInterval=1.0 406de2a132aSGilbert Chen 0, 0, 0x80, 407de2a132aSGilbert Chen 0x3f, // updateInverval=1.0 408de2a132aSGilbert Chen 255, // maxReadable 409de2a132aSGilbert Chen 0, // minReadable 410de2a132aSGilbert Chen PLDM_RANGE_FIELD_FORMAT_UINT8, // rangeFieldFormat 411de2a132aSGilbert Chen 0, // rangeFieldsupport 412de2a132aSGilbert Chen 0, // nominalValue 413de2a132aSGilbert Chen 0, // normalMax 414de2a132aSGilbert Chen 0, // normalMin 415de2a132aSGilbert Chen 0, // warningHigh 416de2a132aSGilbert Chen 0, // warningLow 417de2a132aSGilbert Chen 0, // criticalHigh 418de2a132aSGilbert Chen 0, // criticalLow 419de2a132aSGilbert Chen 0, // fatalHigh 420de2a132aSGilbert Chen 0 // fatalLow 421de2a132aSGilbert Chen }; 422de2a132aSGilbert Chen rc = mockTerminusManager.enqueueResponse((pldm_msg*)getPdrResp.data(), 423de2a132aSGilbert Chen sizeof(getPdrResp)); 424de2a132aSGilbert Chen EXPECT_EQ(rc, PLDM_SUCCESS); 425de2a132aSGilbert Chen 426de2a132aSGilbert Chen stdexec::sync_wait(platformManager.initTerminus()); 427de2a132aSGilbert Chen EXPECT_EQ(true, terminus->initialized); 428de2a132aSGilbert Chen EXPECT_EQ(0, terminus->pdrs.size()); 429de2a132aSGilbert Chen } 430de2a132aSGilbert Chen 431de2a132aSGilbert Chen TEST_F(PlatformManagerTest, negativeInitTerminusTest1) 432de2a132aSGilbert Chen { 433de2a132aSGilbert Chen // terminus doesn't Type2 support 434de2a132aSGilbert Chen auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1)); 435de2a132aSGilbert Chen auto tid = mappedTid.value(); 436de2a132aSGilbert Chen termini[tid] = 437de2a132aSGilbert Chen std::make_shared<pldm::platform_mc::Terminus>(tid, 1 << PLDM_BASE); 438de2a132aSGilbert Chen auto terminus = termini[tid]; 439de2a132aSGilbert Chen 440de2a132aSGilbert Chen stdexec::sync_wait(platformManager.initTerminus()); 441de2a132aSGilbert Chen EXPECT_EQ(true, terminus->initialized); 442de2a132aSGilbert Chen EXPECT_EQ(0, terminus->pdrs.size()); 443de2a132aSGilbert Chen } 444de2a132aSGilbert Chen 445de2a132aSGilbert Chen TEST_F(PlatformManagerTest, negativeInitTerminusTest2) 446de2a132aSGilbert Chen { 447de2a132aSGilbert Chen // terminus responses error 448de2a132aSGilbert Chen auto mappedTid = mockTerminusManager.mapTid(pldm::MctpInfo(10, "", "", 1)); 449de2a132aSGilbert Chen auto tid = mappedTid.value(); 450de2a132aSGilbert Chen termini[tid] = std::make_shared<pldm::platform_mc::Terminus>( 451de2a132aSGilbert Chen tid, 1 << PLDM_BASE | 1 << PLDM_PLATFORM); 452de2a132aSGilbert Chen auto terminus = termini[tid]; 453de2a132aSGilbert Chen 454de2a132aSGilbert Chen // queue getPDRRepositoryInfo response cc=PLDM_ERROR 455de2a132aSGilbert Chen const size_t getPDRRepositoryInfoLen = 1; 456de2a132aSGilbert Chen std::array<uint8_t, sizeof(pldm_msg_hdr) + getPDRRepositoryInfoLen> 457de2a132aSGilbert Chen getPDRRepositoryInfoResp{0x0, 0x02, 0x50, PLDM_ERROR}; 458de2a132aSGilbert Chen auto rc = mockTerminusManager.enqueueResponse( 459de2a132aSGilbert Chen (pldm_msg*)getPDRRepositoryInfoResp.data(), 460de2a132aSGilbert Chen sizeof(getPDRRepositoryInfoResp)); 461de2a132aSGilbert Chen EXPECT_EQ(rc, PLDM_SUCCESS); 462de2a132aSGilbert Chen 463de2a132aSGilbert Chen // queue getPDR responses cc=PLDM_ERROR 464de2a132aSGilbert Chen const size_t getPdrRespLen = 1; 465de2a132aSGilbert Chen std::array<uint8_t, sizeof(pldm_msg_hdr) + getPdrRespLen> getPdrResp{ 466de2a132aSGilbert Chen 0x0, 0x02, 0x51, PLDM_ERROR}; 467de2a132aSGilbert Chen rc = mockTerminusManager.enqueueResponse((pldm_msg*)getPdrResp.data(), 468de2a132aSGilbert Chen sizeof(getPdrResp)); 469de2a132aSGilbert Chen EXPECT_EQ(rc, PLDM_SUCCESS); 470de2a132aSGilbert Chen 471de2a132aSGilbert Chen stdexec::sync_wait(platformManager.initTerminus()); 472de2a132aSGilbert Chen EXPECT_EQ(true, terminus->initialized); 473de2a132aSGilbert Chen EXPECT_EQ(0, terminus->pdrs.size()); 474de2a132aSGilbert Chen } 475