blob: 0baa8b7fa19af54cff21027743505f3338542920 [file] [log] [blame]
#include "libpldm/entity.h"
#include "platform-mc/numeric_sensor.hpp"
#include "platform-mc/terminus.hpp"
#include <gtest/gtest.h>
TEST(TerminusTest, supportedTypeTest)
{
auto t1 = pldm::platform_mc::Terminus(1, 1 << PLDM_BASE);
auto t2 =
pldm::platform_mc::Terminus(2, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
EXPECT_EQ(true, t1.doesSupportType(PLDM_BASE));
EXPECT_EQ(false, t1.doesSupportType(PLDM_PLATFORM));
EXPECT_EQ(true, t2.doesSupportType(PLDM_BASE));
EXPECT_EQ(true, t2.doesSupportType(PLDM_PLATFORM));
}
TEST(TerminusTest, getTidTest)
{
const pldm_tid_t tid = 1;
auto t1 = pldm::platform_mc::Terminus(tid, 1 << PLDM_BASE);
EXPECT_EQ(tid, t1.getTid());
}
TEST(TerminusTest, parseSensorAuxiliaryNamesPDRTest)
{
auto t1 =
pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
std::vector<uint8_t> pdr1{
0x0,
0x0,
0x0,
0x1, // record handle
0x1, // PDRHeaderVersion
PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
0x0,
0x0, // recordChangeNumber
0x0,
21, // dataLength
0,
0x0, // PLDMTerminusHandle
0x1,
0x0, // sensorID
0x1, // sensorCount
0x1, // nameStringCount
'e',
'n',
0x0, // nameLanguageTag
0x0,
'T',
0x0,
'E',
0x0,
'M',
0x0,
'P',
0x0,
'1',
0x0,
0x0 // sensorName
};
std::vector<uint8_t> pdr2{
0x1, 0x0, 0x0,
0x0, // record handle
0x1, // PDRHeaderVersion
PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
0x1,
0x0, // recordChangeNumber
0x11,
0, // dataLength
/* Entity Auxiliary Names PDR Data*/
3,
0x80, // entityType system software
0x1,
0x0, // Entity instance number =1
0,
0, // Overal system
0, // shared Name Count one name only
01, // nameStringCount
0x65, 0x6e, 0x00,
0x00, // Language Tag "en"
0x53, 0x00, 0x30, 0x00,
0x00 // Entity Name "S0"
};
t1.pdrs.emplace_back(pdr1);
t1.pdrs.emplace_back(pdr2);
t1.parseTerminusPDRs();
auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
EXPECT_EQ(nullptr, sensorAuxNames);
sensorAuxNames = t1.getSensorAuxiliaryNames(1);
EXPECT_NE(nullptr, sensorAuxNames);
const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
EXPECT_EQ(1, sensorId);
EXPECT_EQ(1, sensorCnt);
EXPECT_EQ(1, names.size());
EXPECT_EQ(1, names[0].size());
EXPECT_EQ("en", names[0][0].first);
EXPECT_EQ("TEMP1", names[0][0].second);
EXPECT_EQ(2, t1.pdrs.size());
EXPECT_EQ("S0", t1.getTerminusName());
}
TEST(TerminusTest, parseSensorAuxiliaryMultiNamesPDRTest)
{
auto t1 =
pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
std::vector<uint8_t> pdr1{
0x0,
0x0,
0x0,
0x1, // record handle
0x1, // PDRHeaderVersion
PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
0x0,
0x0, // recordChangeNumber
0x0,
53, // dataLength
0,
0x0, // PLDMTerminusHandle
0x1,
0x0, // sensorID
0x1, // sensorCount
0x3, // nameStringCount
'e',
'n',
0x0, // nameLanguageTag
0x0,
'T',
0x0,
'E',
0x0,
'M',
0x0,
'P',
0x0,
'1',
0x0,
0x0, // sensorName Temp1
'f',
'r',
0x0, // nameLanguageTag
0x0,
'T',
0x0,
'E',
0x0,
'M',
0x0,
'P',
0x0,
'2',
0x0,
0x0, // sensorName Temp2
'f',
'r',
0x0, // nameLanguageTag
0x0,
'T',
0x0,
'E',
0x0,
'M',
0x0,
'P',
0x0,
'1',
0x0,
'2',
0x0,
0x0 // sensorName Temp12
};
std::vector<uint8_t> pdr2{
0x1, 0x0, 0x0,
0x0, // record handle
0x1, // PDRHeaderVersion
PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
0x1,
0x0, // recordChangeNumber
0x11,
0, // dataLength
/* Entity Auxiliary Names PDR Data*/
3,
0x80, // entityType system software
0x1,
0x0, // Entity instance number =1
0,
0, // Overal system
0, // shared Name Count one name only
01, // nameStringCount
0x65, 0x6e, 0x00,
0x00, // Language Tag "en"
0x53, 0x00, 0x30, 0x00,
0x00 // Entity Name "S0"
};
t1.pdrs.emplace_back(pdr1);
t1.pdrs.emplace_back(pdr2);
t1.parseTerminusPDRs();
auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
EXPECT_EQ(nullptr, sensorAuxNames);
sensorAuxNames = t1.getSensorAuxiliaryNames(1);
EXPECT_NE(nullptr, sensorAuxNames);
const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
EXPECT_EQ(1, sensorId);
EXPECT_EQ(1, sensorCnt);
EXPECT_EQ(1, names.size());
EXPECT_EQ(3, names[0].size());
EXPECT_EQ("en", names[0][0].first);
EXPECT_EQ("TEMP1", names[0][0].second);
EXPECT_EQ("fr", names[0][1].first);
EXPECT_EQ("TEMP2", names[0][1].second);
EXPECT_EQ("fr", names[0][2].first);
EXPECT_EQ("TEMP12", names[0][2].second);
EXPECT_EQ(2, t1.pdrs.size());
EXPECT_EQ("S0", t1.getTerminusName());
}
TEST(TerminusTest, parseSensorAuxiliaryNamesMultiSensorsPDRTest)
{
auto t1 =
pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
std::vector<uint8_t> pdr1{
0x0,
0x0,
0x0,
0x1, // record handle
0x1, // PDRHeaderVersion
PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
0x0,
0x0, // recordChangeNumber
0x0,
54, // dataLength
0,
0x0, // PLDMTerminusHandle
0x1,
0x0, // sensorID
0x2, // sensorCount
0x1, // nameStringCount
'e',
'n',
0x0, // nameLanguageTag
0x0,
'T',
0x0,
'E',
0x0,
'M',
0x0,
'P',
0x0,
'1',
0x0,
0x0, // sensorName Temp1
0x2, // nameStringCount
'f',
'r',
0x0, // nameLanguageTag
0x0,
'T',
0x0,
'E',
0x0,
'M',
0x0,
'P',
0x0,
'2',
0x0,
0x0, // sensorName Temp2
'f',
'r',
0x0, // nameLanguageTag
0x0,
'T',
0x0,
'E',
0x0,
'M',
0x0,
'P',
0x0,
'1',
0x0,
'2',
0x0,
0x0 // sensorName Temp12
};
std::vector<uint8_t> pdr2{
0x1, 0x0, 0x0,
0x0, // record handle
0x1, // PDRHeaderVersion
PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
0x1,
0x0, // recordChangeNumber
0x11,
0, // dataLength
/* Entity Auxiliary Names PDR Data*/
3,
0x80, // entityType system software
0x1,
0x0, // Entity instance number =1
0,
0, // Overal system
0, // shared Name Count one name only
01, // nameStringCount
0x65, 0x6e, 0x00,
0x00, // Language Tag "en"
0x53, 0x00, 0x30, 0x00,
0x00 // Entity Name "S0"
};
t1.pdrs.emplace_back(pdr1);
t1.pdrs.emplace_back(pdr2);
t1.parseTerminusPDRs();
auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
EXPECT_EQ(nullptr, sensorAuxNames);
sensorAuxNames = t1.getSensorAuxiliaryNames(1);
EXPECT_NE(nullptr, sensorAuxNames);
const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
EXPECT_EQ(1, sensorId);
EXPECT_EQ(2, sensorCnt);
EXPECT_EQ(2, names.size());
EXPECT_EQ(1, names[0].size());
EXPECT_EQ("en", names[0][0].first);
EXPECT_EQ("TEMP1", names[0][0].second);
EXPECT_EQ(2, names[1].size());
EXPECT_EQ("fr", names[1][0].first);
EXPECT_EQ("TEMP2", names[1][0].second);
EXPECT_EQ("fr", names[1][1].first);
EXPECT_EQ("TEMP12", names[1][1].second);
EXPECT_EQ(2, t1.pdrs.size());
EXPECT_EQ("S0", t1.getTerminusName());
}
TEST(TerminusTest, parsePDRTestNoSensorPDR)
{
auto t1 =
pldm::platform_mc::Terminus(1, 1 << PLDM_BASE | 1 << PLDM_PLATFORM);
std::vector<uint8_t> pdr1{
0x1, 0x0, 0x0,
0x0, // record handle
0x1, // PDRHeaderVersion
PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
0x1,
0x0, // recordChangeNumber
0x11,
0, // dataLength
/* Entity Auxiliary Names PDR Data*/
3,
0x80, // entityType system software
0x1,
0x0, // Entity instance number =1
0,
0, // Overal system
0, // shared Name Count one name only
01, // nameStringCount
0x65, 0x6e, 0x00,
0x00, // Language Tag "en"
0x53, 0x00, 0x30, 0x00,
0x00 // Entity Name "S0"
};
t1.pdrs.emplace_back(pdr1);
t1.parseTerminusPDRs();
auto sensorAuxNames = t1.getSensorAuxiliaryNames(1);
EXPECT_EQ(nullptr, sensorAuxNames);
}