xref: /openbmc/pldm/platform-mc/test/terminus_test.cpp (revision de2a132aee45d077e83f59ede182a6fb73613aeb)
1*de2a132aSGilbert Chen #include "libpldm/entity.h"
2*de2a132aSGilbert Chen 
36c7fed4cSGilbert Chen #include "platform-mc/terminus.hpp"
46c7fed4cSGilbert Chen 
56c7fed4cSGilbert Chen #include <gtest/gtest.h>
66c7fed4cSGilbert Chen 
76c7fed4cSGilbert Chen TEST(TerminusTest, supportedTypeTest)
86c7fed4cSGilbert Chen {
96c7fed4cSGilbert Chen     auto t1 = pldm::platform_mc::Terminus(1, 1 << PLDM_BASE);
106c7fed4cSGilbert Chen     auto t2 = pldm::platform_mc::Terminus(2,
116c7fed4cSGilbert Chen                                           1 << PLDM_BASE | 1 << PLDM_PLATFORM);
126c7fed4cSGilbert Chen 
136c7fed4cSGilbert Chen     EXPECT_EQ(true, t1.doesSupportType(PLDM_BASE));
146c7fed4cSGilbert Chen     EXPECT_EQ(false, t1.doesSupportType(PLDM_PLATFORM));
156c7fed4cSGilbert Chen     EXPECT_EQ(true, t2.doesSupportType(PLDM_BASE));
166c7fed4cSGilbert Chen     EXPECT_EQ(true, t2.doesSupportType(PLDM_PLATFORM));
176c7fed4cSGilbert Chen }
186c7fed4cSGilbert Chen 
196c7fed4cSGilbert Chen TEST(TerminusTest, getTidTest)
206c7fed4cSGilbert Chen {
216c7fed4cSGilbert Chen     const pldm_tid_t tid = 1;
226c7fed4cSGilbert Chen     auto t1 = pldm::platform_mc::Terminus(tid, 1 << PLDM_BASE);
236c7fed4cSGilbert Chen 
246c7fed4cSGilbert Chen     EXPECT_EQ(tid, t1.getTid());
256c7fed4cSGilbert Chen }
26*de2a132aSGilbert Chen 
27*de2a132aSGilbert Chen TEST(TerminusTest, parseSensorAuxiliaryNamesPDRTest)
28*de2a132aSGilbert Chen {
29*de2a132aSGilbert Chen     auto t1 = pldm::platform_mc::Terminus(1,
30*de2a132aSGilbert Chen                                           1 << PLDM_BASE | 1 << PLDM_PLATFORM);
31*de2a132aSGilbert Chen     std::vector<uint8_t> pdr1{
32*de2a132aSGilbert Chen         0x0,
33*de2a132aSGilbert Chen         0x0,
34*de2a132aSGilbert Chen         0x0,
35*de2a132aSGilbert Chen         0x1,                             // record handle
36*de2a132aSGilbert Chen         0x1,                             // PDRHeaderVersion
37*de2a132aSGilbert Chen         PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
38*de2a132aSGilbert Chen         0x0,
39*de2a132aSGilbert Chen         0x0,                             // recordChangeNumber
40*de2a132aSGilbert Chen         0x0,
41*de2a132aSGilbert Chen         21,                              // dataLength
42*de2a132aSGilbert Chen         0,
43*de2a132aSGilbert Chen         0x0,                             // PLDMTerminusHandle
44*de2a132aSGilbert Chen         0x1,
45*de2a132aSGilbert Chen         0x0,                             // sensorID
46*de2a132aSGilbert Chen         0x1,                             // sensorCount
47*de2a132aSGilbert Chen         0x1,                             // nameStringCount
48*de2a132aSGilbert Chen         'e',
49*de2a132aSGilbert Chen         'n',
50*de2a132aSGilbert Chen         0x0, // nameLanguageTag
51*de2a132aSGilbert Chen         0x0,
52*de2a132aSGilbert Chen         'T',
53*de2a132aSGilbert Chen         0x0,
54*de2a132aSGilbert Chen         'E',
55*de2a132aSGilbert Chen         0x0,
56*de2a132aSGilbert Chen         'M',
57*de2a132aSGilbert Chen         0x0,
58*de2a132aSGilbert Chen         'P',
59*de2a132aSGilbert Chen         0x0,
60*de2a132aSGilbert Chen         '1',
61*de2a132aSGilbert Chen         0x0,
62*de2a132aSGilbert Chen         0x0 // sensorName
63*de2a132aSGilbert Chen     };
64*de2a132aSGilbert Chen 
65*de2a132aSGilbert Chen     t1.pdrs.emplace_back(pdr1);
66*de2a132aSGilbert Chen     t1.parseTerminusPDRs();
67*de2a132aSGilbert Chen 
68*de2a132aSGilbert Chen     auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
69*de2a132aSGilbert Chen     EXPECT_EQ(nullptr, sensorAuxNames);
70*de2a132aSGilbert Chen 
71*de2a132aSGilbert Chen     sensorAuxNames = t1.getSensorAuxiliaryNames(1);
72*de2a132aSGilbert Chen     EXPECT_NE(nullptr, sensorAuxNames);
73*de2a132aSGilbert Chen 
74*de2a132aSGilbert Chen     const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
75*de2a132aSGilbert Chen     EXPECT_EQ(1, sensorId);
76*de2a132aSGilbert Chen     EXPECT_EQ(1, sensorCnt);
77*de2a132aSGilbert Chen     EXPECT_EQ(1, names.size());
78*de2a132aSGilbert Chen     EXPECT_EQ(1, names[0].size());
79*de2a132aSGilbert Chen     EXPECT_EQ("en", names[0][0].first);
80*de2a132aSGilbert Chen     EXPECT_EQ("TEMP1", names[0][0].second);
81*de2a132aSGilbert Chen }
82