1 #include "libpldm/entity.h"
2 
3 #include "platform-mc/terminus.hpp"
4 
5 #include <gtest/gtest.h>
6 
7 TEST(TerminusTest, supportedTypeTest)
8 {
9     auto t1 = pldm::platform_mc::Terminus(1, 1 << PLDM_BASE);
10     auto t2 = pldm::platform_mc::Terminus(2,
11                                           1 << PLDM_BASE | 1 << PLDM_PLATFORM);
12 
13     EXPECT_EQ(true, t1.doesSupportType(PLDM_BASE));
14     EXPECT_EQ(false, t1.doesSupportType(PLDM_PLATFORM));
15     EXPECT_EQ(true, t2.doesSupportType(PLDM_BASE));
16     EXPECT_EQ(true, t2.doesSupportType(PLDM_PLATFORM));
17 }
18 
19 TEST(TerminusTest, getTidTest)
20 {
21     const pldm_tid_t tid = 1;
22     auto t1 = pldm::platform_mc::Terminus(tid, 1 << PLDM_BASE);
23 
24     EXPECT_EQ(tid, t1.getTid());
25 }
26 
27 TEST(TerminusTest, parseSensorAuxiliaryNamesPDRTest)
28 {
29     auto t1 = pldm::platform_mc::Terminus(1,
30                                           1 << PLDM_BASE | 1 << PLDM_PLATFORM);
31     std::vector<uint8_t> pdr1{
32         0x0,
33         0x0,
34         0x0,
35         0x1,                             // record handle
36         0x1,                             // PDRHeaderVersion
37         PLDM_SENSOR_AUXILIARY_NAMES_PDR, // PDRType
38         0x0,
39         0x0,                             // recordChangeNumber
40         0x0,
41         21,                              // dataLength
42         0,
43         0x0,                             // PLDMTerminusHandle
44         0x1,
45         0x0,                             // sensorID
46         0x1,                             // sensorCount
47         0x1,                             // nameStringCount
48         'e',
49         'n',
50         0x0, // nameLanguageTag
51         0x0,
52         'T',
53         0x0,
54         'E',
55         0x0,
56         'M',
57         0x0,
58         'P',
59         0x0,
60         '1',
61         0x0,
62         0x0 // sensorName
63     };
64 
65     t1.pdrs.emplace_back(pdr1);
66     t1.parseTerminusPDRs();
67 
68     auto sensorAuxNames = t1.getSensorAuxiliaryNames(0);
69     EXPECT_EQ(nullptr, sensorAuxNames);
70 
71     sensorAuxNames = t1.getSensorAuxiliaryNames(1);
72     EXPECT_NE(nullptr, sensorAuxNames);
73 
74     const auto& [sensorId, sensorCnt, names] = *sensorAuxNames;
75     EXPECT_EQ(1, sensorId);
76     EXPECT_EQ(1, sensorCnt);
77     EXPECT_EQ(1, names.size());
78     EXPECT_EQ(1, names[0].size());
79     EXPECT_EQ("en", names[0][0].first);
80     EXPECT_EQ("TEMP1", names[0][0].second);
81 }
82