1*d7be555eSGeorge Liu #include "ipmb/IpmbSensor.hpp"
2*d7be555eSGeorge Liu
3*d7be555eSGeorge Liu #include <cstddef>
4*d7be555eSGeorge Liu #include <cstdint>
5*d7be555eSGeorge Liu #include <vector>
6*d7be555eSGeorge Liu
7*d7be555eSGeorge Liu #include <gtest/gtest.h>
8*d7be555eSGeorge Liu
9*d7be555eSGeorge Liu namespace
10*d7be555eSGeorge Liu {
11*d7be555eSGeorge Liu
TEST(IPMBSensor,Byte0)12*d7be555eSGeorge Liu TEST(IPMBSensor, Byte0)
13*d7be555eSGeorge Liu {
14*d7be555eSGeorge Liu std::vector<uint8_t> data;
15*d7be555eSGeorge Liu data.push_back(42);
16*d7be555eSGeorge Liu
17*d7be555eSGeorge Liu double responseValue = 0.0;
18*d7be555eSGeorge Liu size_t errCount = 0;
19*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::byte0, 0, data,
20*d7be555eSGeorge Liu responseValue, errCount));
21*d7be555eSGeorge Liu EXPECT_EQ(responseValue, 42.0);
22*d7be555eSGeorge Liu }
23*d7be555eSGeorge Liu
TEST(IPMBSensor,NineBitValidPositive)24*d7be555eSGeorge Liu TEST(IPMBSensor, NineBitValidPositive)
25*d7be555eSGeorge Liu {
26*d7be555eSGeorge Liu std::vector<uint8_t> data;
27*d7be555eSGeorge Liu data.push_back(0x2a);
28*d7be555eSGeorge Liu data.push_back(0x00);
29*d7be555eSGeorge Liu
30*d7be555eSGeorge Liu double responseValue = 0.0;
31*d7be555eSGeorge Liu size_t errCount = 0;
32*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::nineBit, 0, data,
33*d7be555eSGeorge Liu responseValue, errCount));
34*d7be555eSGeorge Liu EXPECT_EQ(responseValue, 42.0);
35*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
36*d7be555eSGeorge Liu }
37*d7be555eSGeorge Liu
TEST(IPMBSensor,NineBitValidNegative)38*d7be555eSGeorge Liu TEST(IPMBSensor, NineBitValidNegative)
39*d7be555eSGeorge Liu {
40*d7be555eSGeorge Liu std::vector<uint8_t> data;
41*d7be555eSGeorge Liu data.push_back(0x9c);
42*d7be555eSGeorge Liu data.push_back(0x01);
43*d7be555eSGeorge Liu
44*d7be555eSGeorge Liu double responseValue = 0.0;
45*d7be555eSGeorge Liu size_t errCount = 0;
46*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::nineBit, 0, data,
47*d7be555eSGeorge Liu responseValue, errCount));
48*d7be555eSGeorge Liu EXPECT_EQ(responseValue, -100.0);
49*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
50*d7be555eSGeorge Liu }
51*d7be555eSGeorge Liu
TEST(IPMBSensor,NineBitMin)52*d7be555eSGeorge Liu TEST(IPMBSensor, NineBitMin)
53*d7be555eSGeorge Liu {
54*d7be555eSGeorge Liu std::vector<uint8_t> data;
55*d7be555eSGeorge Liu data.push_back(0x01);
56*d7be555eSGeorge Liu data.push_back(0x01);
57*d7be555eSGeorge Liu
58*d7be555eSGeorge Liu double responseValue = 0.0;
59*d7be555eSGeorge Liu size_t errCount = 0;
60*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::nineBit, 0, data,
61*d7be555eSGeorge Liu responseValue, errCount));
62*d7be555eSGeorge Liu EXPECT_EQ(responseValue, -255.0);
63*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
64*d7be555eSGeorge Liu }
65*d7be555eSGeorge Liu
66*d7be555eSGeorge Liu // The Altra Family SoC BMC Interface Specification says the maximum 9-bit value
67*d7be555eSGeorge Liu // is 256, but that can't be represented in 9 bits, so test the max as 255.
TEST(IPMBSensor,NineBitMax)68*d7be555eSGeorge Liu TEST(IPMBSensor, NineBitMax)
69*d7be555eSGeorge Liu {
70*d7be555eSGeorge Liu std::vector<uint8_t> data;
71*d7be555eSGeorge Liu data.push_back(0xff);
72*d7be555eSGeorge Liu data.push_back(0x00);
73*d7be555eSGeorge Liu
74*d7be555eSGeorge Liu double responseValue = 0.0;
75*d7be555eSGeorge Liu size_t errCount = 0;
76*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::nineBit, 0, data,
77*d7be555eSGeorge Liu responseValue, errCount));
78*d7be555eSGeorge Liu EXPECT_EQ(responseValue, 255.0);
79*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
80*d7be555eSGeorge Liu }
81*d7be555eSGeorge Liu
TEST(IPMBSensor,NineBitTooShort)82*d7be555eSGeorge Liu TEST(IPMBSensor, NineBitTooShort)
83*d7be555eSGeorge Liu {
84*d7be555eSGeorge Liu std::vector<uint8_t> data;
85*d7be555eSGeorge Liu data.push_back(0x00);
86*d7be555eSGeorge Liu
87*d7be555eSGeorge Liu double responseValue = 0.0;
88*d7be555eSGeorge Liu size_t errCount = 0;
89*d7be555eSGeorge Liu EXPECT_FALSE(IpmbSensor::processReading(ReadingFormat::nineBit, 0, data,
90*d7be555eSGeorge Liu responseValue, errCount));
91*d7be555eSGeorge Liu }
92*d7be555eSGeorge Liu
TEST(IPMBSensor,NineBitTooLong)93*d7be555eSGeorge Liu TEST(IPMBSensor, NineBitTooLong)
94*d7be555eSGeorge Liu {
95*d7be555eSGeorge Liu std::vector<uint8_t> data;
96*d7be555eSGeorge Liu data.push_back(0x00);
97*d7be555eSGeorge Liu data.push_back(0x00);
98*d7be555eSGeorge Liu data.push_back(0x00);
99*d7be555eSGeorge Liu
100*d7be555eSGeorge Liu double responseValue = 0.0;
101*d7be555eSGeorge Liu size_t errCount = 0;
102*d7be555eSGeorge Liu EXPECT_FALSE(IpmbSensor::processReading(ReadingFormat::nineBit, 0, data,
103*d7be555eSGeorge Liu responseValue, errCount));
104*d7be555eSGeorge Liu }
105*d7be555eSGeorge Liu
TEST(IPMBSensor,NineBitInvalid)106*d7be555eSGeorge Liu TEST(IPMBSensor, NineBitInvalid)
107*d7be555eSGeorge Liu {
108*d7be555eSGeorge Liu std::vector<uint8_t> data;
109*d7be555eSGeorge Liu data.push_back(0xff);
110*d7be555eSGeorge Liu data.push_back(0xff);
111*d7be555eSGeorge Liu
112*d7be555eSGeorge Liu double responseValue = 0.0;
113*d7be555eSGeorge Liu size_t errCount = 0;
114*d7be555eSGeorge Liu EXPECT_FALSE(IpmbSensor::processReading(ReadingFormat::nineBit, 0, data,
115*d7be555eSGeorge Liu responseValue, errCount));
116*d7be555eSGeorge Liu }
117*d7be555eSGeorge Liu
TEST(IPMBSensor,TenBitValid1)118*d7be555eSGeorge Liu TEST(IPMBSensor, TenBitValid1)
119*d7be555eSGeorge Liu {
120*d7be555eSGeorge Liu std::vector<uint8_t> data;
121*d7be555eSGeorge Liu data.push_back(0x08);
122*d7be555eSGeorge Liu data.push_back(0x00);
123*d7be555eSGeorge Liu
124*d7be555eSGeorge Liu double responseValue = 0.0;
125*d7be555eSGeorge Liu size_t errCount = 0;
126*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::tenBit, 0, data,
127*d7be555eSGeorge Liu responseValue, errCount));
128*d7be555eSGeorge Liu EXPECT_EQ(responseValue, 8.0);
129*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
130*d7be555eSGeorge Liu }
131*d7be555eSGeorge Liu
TEST(IPMBSensor,TenBitValid2)132*d7be555eSGeorge Liu TEST(IPMBSensor, TenBitValid2)
133*d7be555eSGeorge Liu {
134*d7be555eSGeorge Liu std::vector<uint8_t> data;
135*d7be555eSGeorge Liu data.push_back(0x30);
136*d7be555eSGeorge Liu data.push_back(0x02);
137*d7be555eSGeorge Liu
138*d7be555eSGeorge Liu double responseValue = 0.0;
139*d7be555eSGeorge Liu size_t errCount = 0;
140*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::tenBit, 0, data,
141*d7be555eSGeorge Liu responseValue, errCount));
142*d7be555eSGeorge Liu
143*d7be555eSGeorge Liu EXPECT_EQ(responseValue, 560.0);
144*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
145*d7be555eSGeorge Liu }
146*d7be555eSGeorge Liu
TEST(IPMBSensor,TenBitMin)147*d7be555eSGeorge Liu TEST(IPMBSensor, TenBitMin)
148*d7be555eSGeorge Liu {
149*d7be555eSGeorge Liu std::vector<uint8_t> data;
150*d7be555eSGeorge Liu data.push_back(0x00);
151*d7be555eSGeorge Liu data.push_back(0x00);
152*d7be555eSGeorge Liu
153*d7be555eSGeorge Liu double responseValue = 0.0;
154*d7be555eSGeorge Liu size_t errCount = 0;
155*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::tenBit, 0, data,
156*d7be555eSGeorge Liu responseValue, errCount));
157*d7be555eSGeorge Liu
158*d7be555eSGeorge Liu EXPECT_EQ(responseValue, 0.0);
159*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
160*d7be555eSGeorge Liu }
161*d7be555eSGeorge Liu
TEST(IPMBSensor,TenBitValidMax)162*d7be555eSGeorge Liu TEST(IPMBSensor, TenBitValidMax)
163*d7be555eSGeorge Liu {
164*d7be555eSGeorge Liu std::vector<uint8_t> data;
165*d7be555eSGeorge Liu data.push_back(0xff);
166*d7be555eSGeorge Liu data.push_back(0x03);
167*d7be555eSGeorge Liu
168*d7be555eSGeorge Liu double responseValue = 0.0;
169*d7be555eSGeorge Liu size_t errCount = 0;
170*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::tenBit, 0, data,
171*d7be555eSGeorge Liu responseValue, errCount));
172*d7be555eSGeorge Liu
173*d7be555eSGeorge Liu EXPECT_EQ(responseValue, 1023.0);
174*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
175*d7be555eSGeorge Liu }
176*d7be555eSGeorge Liu
TEST(IPMBSensor,TenBitTooShort)177*d7be555eSGeorge Liu TEST(IPMBSensor, TenBitTooShort)
178*d7be555eSGeorge Liu {
179*d7be555eSGeorge Liu std::vector<uint8_t> data;
180*d7be555eSGeorge Liu data.push_back(0xff);
181*d7be555eSGeorge Liu
182*d7be555eSGeorge Liu double responseValue = 0.0;
183*d7be555eSGeorge Liu size_t errCount = 0;
184*d7be555eSGeorge Liu EXPECT_FALSE(IpmbSensor::processReading(ReadingFormat::tenBit, 0, data,
185*d7be555eSGeorge Liu responseValue, errCount));
186*d7be555eSGeorge Liu }
187*d7be555eSGeorge Liu
TEST(IPMBSensor,TenBitTooLong)188*d7be555eSGeorge Liu TEST(IPMBSensor, TenBitTooLong)
189*d7be555eSGeorge Liu {
190*d7be555eSGeorge Liu std::vector<uint8_t> data;
191*d7be555eSGeorge Liu data.push_back(0x00);
192*d7be555eSGeorge Liu data.push_back(0x00);
193*d7be555eSGeorge Liu data.push_back(0x00);
194*d7be555eSGeorge Liu
195*d7be555eSGeorge Liu double responseValue = 0.0;
196*d7be555eSGeorge Liu size_t errCount = 0;
197*d7be555eSGeorge Liu EXPECT_FALSE(IpmbSensor::processReading(ReadingFormat::tenBit, 0, data,
198*d7be555eSGeorge Liu responseValue, errCount));
199*d7be555eSGeorge Liu }
200*d7be555eSGeorge Liu
TEST(IPMBSensor,TenBitInvalid)201*d7be555eSGeorge Liu TEST(IPMBSensor, TenBitInvalid)
202*d7be555eSGeorge Liu {
203*d7be555eSGeorge Liu std::vector<uint8_t> data;
204*d7be555eSGeorge Liu data.push_back(0xff);
205*d7be555eSGeorge Liu data.push_back(0xff);
206*d7be555eSGeorge Liu
207*d7be555eSGeorge Liu double responseValue = 0.0;
208*d7be555eSGeorge Liu size_t errCount = 0;
209*d7be555eSGeorge Liu EXPECT_FALSE(IpmbSensor::processReading(ReadingFormat::tenBit, 0, data,
210*d7be555eSGeorge Liu responseValue, errCount));
211*d7be555eSGeorge Liu }
212*d7be555eSGeorge Liu
TEST(IPMBSensor,FifteenBitValid1)213*d7be555eSGeorge Liu TEST(IPMBSensor, FifteenBitValid1)
214*d7be555eSGeorge Liu {
215*d7be555eSGeorge Liu std::vector<uint8_t> data;
216*d7be555eSGeorge Liu data.push_back(0xda);
217*d7be555eSGeorge Liu data.push_back(0x02);
218*d7be555eSGeorge Liu
219*d7be555eSGeorge Liu double responseValue = 0.0;
220*d7be555eSGeorge Liu size_t errCount = 0;
221*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::fifteenBit, 0, data,
222*d7be555eSGeorge Liu responseValue, errCount));
223*d7be555eSGeorge Liu EXPECT_EQ(responseValue, 0.730);
224*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
225*d7be555eSGeorge Liu }
226*d7be555eSGeorge Liu
TEST(IPMBSensor,FifteenBitMin)227*d7be555eSGeorge Liu TEST(IPMBSensor, FifteenBitMin)
228*d7be555eSGeorge Liu {
229*d7be555eSGeorge Liu std::vector<uint8_t> data;
230*d7be555eSGeorge Liu data.push_back(0x00);
231*d7be555eSGeorge Liu data.push_back(0x00);
232*d7be555eSGeorge Liu
233*d7be555eSGeorge Liu double responseValue = 0.0;
234*d7be555eSGeorge Liu size_t errCount = 0;
235*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::fifteenBit, 0, data,
236*d7be555eSGeorge Liu responseValue, errCount));
237*d7be555eSGeorge Liu EXPECT_EQ(responseValue, 0.0);
238*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
239*d7be555eSGeorge Liu }
240*d7be555eSGeorge Liu
TEST(IPMBSensor,FifteenBitMax)241*d7be555eSGeorge Liu TEST(IPMBSensor, FifteenBitMax)
242*d7be555eSGeorge Liu {
243*d7be555eSGeorge Liu std::vector<uint8_t> data;
244*d7be555eSGeorge Liu data.push_back(0xff);
245*d7be555eSGeorge Liu data.push_back(0x7f);
246*d7be555eSGeorge Liu
247*d7be555eSGeorge Liu double responseValue = 0.0;
248*d7be555eSGeorge Liu size_t errCount = 0;
249*d7be555eSGeorge Liu EXPECT_TRUE(IpmbSensor::processReading(ReadingFormat::fifteenBit, 0, data,
250*d7be555eSGeorge Liu responseValue, errCount));
251*d7be555eSGeorge Liu EXPECT_EQ(responseValue, 32.767);
252*d7be555eSGeorge Liu EXPECT_EQ(errCount, 0);
253*d7be555eSGeorge Liu }
254*d7be555eSGeorge Liu
TEST(IPMBSensor,FifteenBitTooShort)255*d7be555eSGeorge Liu TEST(IPMBSensor, FifteenBitTooShort)
256*d7be555eSGeorge Liu {
257*d7be555eSGeorge Liu std::vector<uint8_t> data;
258*d7be555eSGeorge Liu data.push_back(0xff);
259*d7be555eSGeorge Liu
260*d7be555eSGeorge Liu double responseValue = 0.0;
261*d7be555eSGeorge Liu size_t errCount = 0;
262*d7be555eSGeorge Liu EXPECT_FALSE(IpmbSensor::processReading(ReadingFormat::fifteenBit, 0, data,
263*d7be555eSGeorge Liu responseValue, errCount));
264*d7be555eSGeorge Liu }
265*d7be555eSGeorge Liu
TEST(IPMBSensor,FifteenBitTooLong)266*d7be555eSGeorge Liu TEST(IPMBSensor, FifteenBitTooLong)
267*d7be555eSGeorge Liu {
268*d7be555eSGeorge Liu std::vector<uint8_t> data;
269*d7be555eSGeorge Liu data.push_back(0x00);
270*d7be555eSGeorge Liu data.push_back(0x00);
271*d7be555eSGeorge Liu data.push_back(0x00);
272*d7be555eSGeorge Liu
273*d7be555eSGeorge Liu double responseValue = 0.0;
274*d7be555eSGeorge Liu size_t errCount = 0;
275*d7be555eSGeorge Liu EXPECT_FALSE(IpmbSensor::processReading(ReadingFormat::fifteenBit, 0, data,
276*d7be555eSGeorge Liu responseValue, errCount));
277*d7be555eSGeorge Liu }
278*d7be555eSGeorge Liu
TEST(IPMBSensor,FifteenBitInvalid)279*d7be555eSGeorge Liu TEST(IPMBSensor, FifteenBitInvalid)
280*d7be555eSGeorge Liu {
281*d7be555eSGeorge Liu std::vector<uint8_t> data;
282*d7be555eSGeorge Liu data.push_back(0xff);
283*d7be555eSGeorge Liu data.push_back(0xff);
284*d7be555eSGeorge Liu
285*d7be555eSGeorge Liu double responseValue = 0.0;
286*d7be555eSGeorge Liu size_t errCount = 0;
287*d7be555eSGeorge Liu EXPECT_FALSE(IpmbSensor::processReading(ReadingFormat::fifteenBit, 0, data,
288*d7be555eSGeorge Liu responseValue, errCount));
289*d7be555eSGeorge Liu }
290*d7be555eSGeorge Liu
291*d7be555eSGeorge Liu } // namespace
292