1 #include "libpldm/entity.h"
2 
3 #include "platform-mc/numeric_sensor.hpp"
4 #include "platform-mc/terminus.hpp"
5 
6 #include <gtest/gtest.h>
7 
8 TEST(TerminusTest, supportedTypeTest)
9 {
10     auto t1 = pldm::platform_mc::Terminus(1, 1 << PLDM_BASE);
11     auto t2 = pldm::platform_mc::Terminus(2,
12                                           1 << PLDM_BASE | 1 << PLDM_PLATFORM);
13 
14     EXPECT_EQ(true, t1.doesSupportType(PLDM_BASE));
15     EXPECT_EQ(false, t1.doesSupportType(PLDM_PLATFORM));
16     EXPECT_EQ(true, t2.doesSupportType(PLDM_BASE));
17     EXPECT_EQ(true, t2.doesSupportType(PLDM_PLATFORM));
18 }
19 
20 TEST(TerminusTest, getTidTest)
21 {
22     const pldm_tid_t tid = 1;
23     auto t1 = pldm::platform_mc::Terminus(tid, 1 << PLDM_BASE);
24 
25     EXPECT_EQ(tid, t1.getTid());
26 }
27 
28 TEST(TerminusTest, parseSensorAuxiliaryNamesPDRTest)
29 {
30     auto t1 = pldm::platform_mc::Terminus(1,
31                                           1 << PLDM_BASE | 1 << PLDM_PLATFORM);
32     std::vector<uint8_t> pdr1{
33         0x0,
34         0x0,
35         0x0,
36         0x1,                             // record handle
37         0x1,                             // PDRHeaderVersion
38         PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
39         0x0,
40         0x0,                             // recordChangeNumber
41         0x0,
42         21,                              // dataLength
43         0,
44         0x0,                             // PLDMTerminusHandle
45         0x1,
46         0x0,                             // sensorID
47         0x1,                             // sensorCount
48         0x1,                             // nameStringCount
49         'e',
50         'n',
51         0x0, // nameLanguageTag
52         0x0,
53         'T',
54         0x0,
55         'E',
56         0x0,
57         'M',
58         0x0,
59         'P',
60         0x0,
61         '1',
62         0x0,
63         0x0 // sensorName
64     };
65 
66     std::vector<uint8_t> pdr2{
67         0x1, 0x0, 0x0,
68         0x0,                             // record handle
69         0x1,                             // PDRHeaderVersion
70         PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
71         0x1,
72         0x0,                             // recordChangeNumber
73         0x11,
74         0,                               // dataLength
75         /* Entity Auxiliary Names PDR Data*/
76         3,
77         0x80, // entityType system software
78         0x1,
79         0x0,  // Entity instance number =1
80         0,
81         0,    // Overal system
82         0,    // shared Name Count one name only
83         01,   // nameStringCount
84         0x65, 0x6e, 0x00,
85         0x00, // Language Tag "en"
86         0x53, 0x00, 0x30, 0x00,
87         0x00  // Entity Name "S0"
88     };
89 
90     t1.pdrs.emplace_back(pdr1);
91     t1.pdrs.emplace_back(pdr2);
92     t1.parseTerminusPDRs();
93 
94     auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
95     EXPECT_EQ(nullptr, sensorAuxNames);
96 
97     sensorAuxNames = t1.getSensorAuxiliaryNames(1);
98     EXPECT_NE(nullptr, sensorAuxNames);
99 
100     const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
101     EXPECT_EQ(1, sensorId);
102     EXPECT_EQ(1, sensorCnt);
103     EXPECT_EQ(1, names.size());
104     EXPECT_EQ(1, names[0].size());
105     EXPECT_EQ("en", names[0][0].first);
106     EXPECT_EQ("TEMP1", names[0][0].second);
107     EXPECT_EQ(2, t1.pdrs.size());
108     EXPECT_EQ("S0", t1.getTerminusName());
109 }
110 
111 TEST(TerminusTest, parsePDRTestNoSensorPDR)
112 {
113     auto t1 = pldm::platform_mc::Terminus(1,
114                                           1 << PLDM_BASE | 1 << PLDM_PLATFORM);
115     std::vector<uint8_t> pdr1{
116         0x1, 0x0, 0x0,
117         0x0,                             // record handle
118         0x1,                             // PDRHeaderVersion
119         PLDM_ENTITY_AUXILIARY_NAMES_PDR, // PDRType
120         0x1,
121         0x0,                             // recordChangeNumber
122         0x11,
123         0,                               // dataLength
124         /* Entity Auxiliary Names PDR Data*/
125         3,
126         0x80, // entityType system software
127         0x1,
128         0x0,  // Entity instance number =1
129         0,
130         0,    // Overal system
131         0,    // shared Name Count one name only
132         01,   // nameStringCount
133         0x65, 0x6e, 0x00,
134         0x00, // Language Tag "en"
135         0x53, 0x00, 0x30, 0x00,
136         0x00  // Entity Name "S0"
137     };
138 
139     t1.pdrs.emplace_back(pdr1);
140     t1.parseTerminusPDRs();
141 
142     auto sensorAuxNames = t1.getSensorAuxiliaryNames(1);
143     EXPECT_EQ(nullptr, sensorAuxNames);
144 }
145