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