blob: f907e7992758114db1e159814d6dcbb750e6c129 [file] [log] [blame]
Bob Kingd6820bb2020-04-28 15:37:02 +08001/**
2 * Copyright © 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "action_environment.hpp"
Bob King717d2da2020-06-02 11:11:15 +080017#include "action_error.hpp"
18#include "device.hpp"
Bob Kingd6820bb2020-04-28 15:37:02 +080019#include "i2c_action.hpp"
20#include "i2c_interface.hpp"
Bob King717d2da2020-06-02 11:11:15 +080021#include "id_map.hpp"
Bob King73eacee2020-10-23 13:58:02 +080022#include "mock_services.hpp"
Bob King717d2da2020-06-02 11:11:15 +080023#include "mocked_i2c_interface.hpp"
24#include "pmbus_error.hpp"
Bob Kingd6820bb2020-04-28 15:37:02 +080025#include "pmbus_read_sensor_action.hpp"
26#include "pmbus_utils.hpp"
27
28#include <cstdint>
Bob King717d2da2020-06-02 11:11:15 +080029#include <memory>
Bob Kingd6820bb2020-04-28 15:37:02 +080030#include <optional>
31#include <stdexcept>
32#include <string>
Bob King717d2da2020-06-02 11:11:15 +080033#include <utility>
Bob Kingd6820bb2020-04-28 15:37:02 +080034
Bob King717d2da2020-06-02 11:11:15 +080035#include <gmock/gmock.h>
Bob Kingd6820bb2020-04-28 15:37:02 +080036#include <gtest/gtest.h>
37
38using namespace phosphor::power::regulators;
39
Bob King717d2da2020-06-02 11:11:15 +080040using ::testing::A;
41using ::testing::Return;
42using ::testing::SetArgReferee;
43using ::testing::Throw;
44using ::testing::TypedEq;
45
Bob Kingd6820bb2020-04-28 15:37:02 +080046TEST(PMBusReadSensorActionTests, Constructor)
47{
48 // Test where works: exponent value is specified
49 try
50 {
51 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
52 uint8_t command = 0x8C;
53 pmbus_utils::SensorDataFormat format{
54 pmbus_utils::SensorDataFormat::linear_16};
55 std::optional<int8_t> exponent{-8};
56 PMBusReadSensorAction action{type, command, format, exponent};
57 EXPECT_EQ(action.getType(), pmbus_utils::SensorValueType::iout);
58 EXPECT_EQ(action.getCommand(), 0x8C);
59 EXPECT_EQ(action.getFormat(), pmbus_utils::SensorDataFormat::linear_16);
60 EXPECT_EQ(action.getExponent().has_value(), true);
61 EXPECT_EQ(action.getExponent().value(), -8);
62 }
63 catch (...)
64 {
65 ADD_FAILURE() << "Should not have caught exception.";
66 }
67
68 // Test where works: exponent value is not specified
69 try
70 {
71 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
72 uint8_t command = 0x8C;
73 pmbus_utils::SensorDataFormat format{
74 pmbus_utils::SensorDataFormat::linear_11};
75 std::optional<int8_t> exponent{};
76 PMBusReadSensorAction action{type, command, format, exponent};
77 EXPECT_EQ(action.getType(), pmbus_utils::SensorValueType::iout);
78 EXPECT_EQ(action.getCommand(), 0x8C);
79 EXPECT_EQ(action.getFormat(), pmbus_utils::SensorDataFormat::linear_11);
80 EXPECT_EQ(action.getExponent().has_value(), false);
81 }
82 catch (...)
83 {
84 ADD_FAILURE() << "Should not have caught exception.";
85 }
86}
87
88TEST(PMBusReadSensorActionTests, Execute)
89{
Bob King717d2da2020-06-02 11:11:15 +080090 // Test where works: linear_11 defined in action
91 try
92 {
93 // Create mock I2CInterface.
94 // * will read 0xD2E0 from READ_IOUT (command/register 0x8C)
95 // * will not read from VOUT_MODE (command/register 0x20)
96 // assume output current is 11.5 amps,
97 // exponent = -6 = 11010, mantissa = 736 = 010 1110 0000
98 // linear data format = 1101 0010 1110 0000 = 0xD2E0
99 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
100 std::make_unique<i2c::MockedI2CInterface>();
101 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
102 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x8C), A<uint16_t&>()))
103 .Times(1)
104 .WillOnce(SetArgReferee<1>(0xD2E0));
105 EXPECT_CALL(*i2cInterface, read(A<uint8_t>(), A<uint8_t&>())).Times(0);
106
Bob King73eacee2020-10-23 13:58:02 +0800107 // Create Device, IDMap, MockServices, and ActionEnvironment
Bob Kinga76898f2020-10-13 15:08:33 +0800108 Device device{
109 "reg1", true,
110 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
111 std::move(i2cInterface)};
Bob King717d2da2020-06-02 11:11:15 +0800112 IDMap idMap{};
113 idMap.addDevice(device);
Bob King73eacee2020-10-23 13:58:02 +0800114 MockServices services{};
115 ActionEnvironment env{idMap, "reg1", services};
Bob King717d2da2020-06-02 11:11:15 +0800116
117 // Create and execute action
118 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
119 uint8_t command = 0x8C;
120 pmbus_utils::SensorDataFormat format{
121 pmbus_utils::SensorDataFormat::linear_11};
122 std::optional<int8_t> exponent{};
123 PMBusReadSensorAction action{type, command, format, exponent};
124 EXPECT_EQ(action.execute(env), true);
125 EXPECT_EQ(env.getSensorReadings().size(), 1);
126 EXPECT_EQ(env.getSensorReadings()[0].type,
127 pmbus_utils::SensorValueType::iout);
128 EXPECT_DOUBLE_EQ(env.getSensorReadings()[0].value, 11.5);
129 }
130 catch (...)
131 {
132 ADD_FAILURE() << "Should not have caught exception.";
133 }
134
135 // Test where works: linear_16 with exponent defined in action
136 try
137 {
138 // Create mock I2CInterface.
139 // * will read 0x0002 from READ_VOUT (command/register 0x8B)
140 // * will not read from VOUT_MODE (command/register 0x20)
141 // assume output voltage is 16 volts,
142 // exponent = 3
143 // linear data format = 0000 0000 0000 0010 = 0x0002 = 2
144 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
145 std::make_unique<i2c::MockedI2CInterface>();
146 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
147 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x8B), A<uint16_t&>()))
148 .Times(1)
149 .WillOnce(SetArgReferee<1>(0x0002));
150 EXPECT_CALL(*i2cInterface, read(A<uint8_t>(), A<uint8_t&>())).Times(0);
151
Bob King73eacee2020-10-23 13:58:02 +0800152 // Create Device, IDMap, MockServices, and ActionEnvironment
Bob Kinga76898f2020-10-13 15:08:33 +0800153 Device device{
154 "reg1", true,
155 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
156 std::move(i2cInterface)};
Bob King717d2da2020-06-02 11:11:15 +0800157 IDMap idMap{};
158 idMap.addDevice(device);
Bob King73eacee2020-10-23 13:58:02 +0800159 MockServices services{};
160 ActionEnvironment env{idMap, "reg1", services};
Bob King717d2da2020-06-02 11:11:15 +0800161
162 // Create and execute action
163 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::vout};
164 uint8_t command = 0x8B;
165 pmbus_utils::SensorDataFormat format{
166 pmbus_utils::SensorDataFormat::linear_16};
167 std::optional<int8_t> exponent{3};
168 PMBusReadSensorAction action{type, command, format, exponent};
169 EXPECT_EQ(action.execute(env), true);
170 EXPECT_EQ(env.getSensorReadings().size(), 1);
171 EXPECT_EQ(env.getSensorReadings()[0].type,
172 pmbus_utils::SensorValueType::vout);
173 EXPECT_DOUBLE_EQ(env.getSensorReadings()[0].value, 16);
174 }
175 catch (...)
176 {
177 ADD_FAILURE() << "Should not have caught exception.";
178 }
179
180 // Test where works: linear_16 with no exponent defined in action
181 try
182 {
183 // Create mock I2CInterface.
184 // * will read 0xB877 from vout_peak (command/register 0xC6)
185 // * will read 0b0001'0111 (linear format, -9 exponent) from VOUT_MODE
186 // assume output voltage is 0.232421875 volts,
187 // linear data format = 0000 0000 0111 0111 = 0x0077
188 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
189 std::make_unique<i2c::MockedI2CInterface>();
190 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
191 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0xC6), A<uint16_t&>()))
192 .Times(1)
193 .WillOnce(SetArgReferee<1>(0x0077));
194 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x20), A<uint8_t&>()))
195 .Times(1)
196 .WillOnce(SetArgReferee<1>(0b0001'0111));
Bob King73eacee2020-10-23 13:58:02 +0800197 // Create Device, IDMap, MockServices, and ActionEnvironment
Bob Kinga76898f2020-10-13 15:08:33 +0800198 Device device{
199 "reg1", true,
200 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
201 std::move(i2cInterface)};
Bob King717d2da2020-06-02 11:11:15 +0800202 IDMap idMap{};
203 idMap.addDevice(device);
Bob King73eacee2020-10-23 13:58:02 +0800204 MockServices services{};
205 ActionEnvironment env{idMap, "reg1", services};
Bob King717d2da2020-06-02 11:11:15 +0800206
207 // Create and execute action
208 pmbus_utils::SensorValueType type{
209 pmbus_utils::SensorValueType::vout_peak};
210 uint8_t command = 0xC6;
211 pmbus_utils::SensorDataFormat format{
212 pmbus_utils::SensorDataFormat::linear_16};
213 std::optional<int8_t> exponent{};
214 PMBusReadSensorAction action{type, command, format, exponent};
215 EXPECT_EQ(action.execute(env), true);
216 EXPECT_EQ(env.getSensorReadings().size(), 1);
217 EXPECT_EQ(env.getSensorReadings()[0].type,
218 pmbus_utils::SensorValueType::vout_peak);
219 EXPECT_DOUBLE_EQ(env.getSensorReadings()[0].value, 0.232421875);
220 }
221 catch (...)
222 {
223 ADD_FAILURE() << "Should not have caught exception.";
224 }
225
226 // Test where fails: Unable to get I2C interface to current device
227 try
228 {
Bob King73eacee2020-10-23 13:58:02 +0800229 // Create IDMap, MockServices, and ActionEnvironment
Bob King717d2da2020-06-02 11:11:15 +0800230 IDMap idMap{};
Bob King73eacee2020-10-23 13:58:02 +0800231 MockServices services{};
232 ActionEnvironment env{idMap, "reg1", services};
Bob King717d2da2020-06-02 11:11:15 +0800233
234 // Create and execute action
235 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::pout};
236 uint8_t command = 0x96;
237 pmbus_utils::SensorDataFormat format{
238 pmbus_utils::SensorDataFormat::linear_11};
239 std::optional<int8_t> exponent{};
240 PMBusReadSensorAction action{type, command, format, exponent};
241 action.execute(env);
242 ADD_FAILURE() << "Should not have reached this line.";
243 }
244 catch (const std::invalid_argument& e)
245 {
246 EXPECT_STREQ(e.what(), "Unable to find device with ID \"reg1\"");
247 }
248 catch (...)
249 {
250 ADD_FAILURE() << "Should not have caught exception.";
251 }
252
253 // Test where fails: VOUT_MODE data format is not linear
254 try
255 {
256 // Create mock I2CInterface. Expect action to do the following:
257 // * will read 0b0010'0000 (vid data format) from VOUT_MODE
258 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
259 std::make_unique<i2c::MockedI2CInterface>();
260 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
Bob Kingab7d6cb2020-07-17 10:24:07 +0800261 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x8B), A<uint16_t&>()))
262 .Times(1);
Bob King717d2da2020-06-02 11:11:15 +0800263 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x20), A<uint8_t&>()))
264 .Times(1)
265 .WillOnce(SetArgReferee<1>(0b0010'0000));
266
Bob King73eacee2020-10-23 13:58:02 +0800267 // Create Device, IDMap, MockServices, and ActionEnvironment
Bob Kinga76898f2020-10-13 15:08:33 +0800268 Device device{
269 "reg1", true,
270 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
271 std::move(i2cInterface)};
Bob King717d2da2020-06-02 11:11:15 +0800272 IDMap idMap{};
273 idMap.addDevice(device);
Bob King73eacee2020-10-23 13:58:02 +0800274 MockServices services{};
275 ActionEnvironment env{idMap, "reg1", services};
Bob King717d2da2020-06-02 11:11:15 +0800276
277 // Create and execute action
278 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::vout};
279 uint8_t command = 0x8B;
280 pmbus_utils::SensorDataFormat format{
281 pmbus_utils::SensorDataFormat::linear_16};
282 std::optional<int8_t> exponent{};
283 PMBusReadSensorAction action{type, command, format, exponent};
284 action.execute(env);
285 ADD_FAILURE() << "Should not have reached this line.";
286 }
287 catch (const ActionError& e)
288 {
289 EXPECT_STREQ(e.what(), "ActionError: pmbus_read_sensor: { type: vout, "
290 "command: 0x8B, format: linear_16 }");
291 try
292 {
293 // Re-throw inner PMBusError
294 std::rethrow_if_nested(e);
295 ADD_FAILURE() << "Should not have reached this line.";
296 }
297 catch (const PMBusError& pe)
298 {
299 EXPECT_STREQ(
300 pe.what(),
301 "PMBusError: VOUT_MODE contains unsupported data format");
302 }
303 catch (...)
304 {
305 ADD_FAILURE() << "Should not have caught exception.";
306 }
307 }
308 catch (...)
309 {
310 ADD_FAILURE() << "Should not have caught exception.";
311 }
312
313 // Test where fails: Reading VOUT_MODE fails
314 try
315 {
316 // Create mock I2CInterface. Expect action to do the following:
317 // * will try to read VOUT_MODE; exception will be thrown
318 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
319 std::make_unique<i2c::MockedI2CInterface>();
320 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
Bob Kingab7d6cb2020-07-17 10:24:07 +0800321 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0xC6), A<uint16_t&>()))
322 .Times(1);
Bob King717d2da2020-06-02 11:11:15 +0800323 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x20), A<uint8_t&>()))
324 .Times(1)
325 .WillOnce(Throw(
326 i2c::I2CException{"Failed to read byte", "/dev/i2c-1", 0x70}));
327
Bob King73eacee2020-10-23 13:58:02 +0800328 // Create Device, IDMap, MockServices, and ActionEnvironment
Bob Kinga76898f2020-10-13 15:08:33 +0800329 Device device{
330 "reg1", true,
331 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
332 std::move(i2cInterface)};
Bob King717d2da2020-06-02 11:11:15 +0800333 IDMap idMap{};
334 idMap.addDevice(device);
Bob King73eacee2020-10-23 13:58:02 +0800335 MockServices services{};
336 ActionEnvironment env{idMap, "reg1", services};
Bob King717d2da2020-06-02 11:11:15 +0800337
338 // Create and execute action
339 pmbus_utils::SensorValueType type{
340 pmbus_utils::SensorValueType::vout_peak};
341 uint8_t command = 0xC6;
342 pmbus_utils::SensorDataFormat format{
343 pmbus_utils::SensorDataFormat::linear_16};
344 std::optional<int8_t> exponent{};
345 PMBusReadSensorAction action{type, command, format, exponent};
346 action.execute(env);
347 ADD_FAILURE() << "Should not have reached this line.";
348 }
349 catch (const ActionError& e)
350 {
351 EXPECT_STREQ(e.what(),
352 "ActionError: pmbus_read_sensor: { type: vout_peak, "
353 "command: 0xC6, format: linear_16 }");
354 try
355 {
356 // Re-throw inner I2CException
357 std::rethrow_if_nested(e);
358 ADD_FAILURE() << "Should not have reached this line.";
359 }
360 catch (const i2c::I2CException& ie)
361 {
362 EXPECT_STREQ(
363 ie.what(),
364 "I2CException: Failed to read byte: bus /dev/i2c-1, addr 0x70");
365 }
366 catch (...)
367 {
368 ADD_FAILURE() << "Should not have caught exception.";
369 }
370 }
371 catch (...)
372 {
373 ADD_FAILURE() << "Should not have caught exception.";
374 }
375
376 // Test where fails: Reading PMBus command code with sensor value fails
377 try
378 {
379 // Create mock I2CInterface. Expect action to do the following:
380 // * will try to read PMBus command(0x96); exception will be thrown
381 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
382 std::make_unique<i2c::MockedI2CInterface>();
383 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
384 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x96), A<uint16_t&>()))
385 .Times(1)
386 .WillOnce(Throw(
387 i2c::I2CException{"Failed to read word", "/dev/i2c-1", 0x70}));
388
Bob King73eacee2020-10-23 13:58:02 +0800389 // Create Device, IDMap, MockServices, and ActionEnvironment
Bob Kinga76898f2020-10-13 15:08:33 +0800390 Device device{
391 "reg1", true,
392 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
393 std::move(i2cInterface)};
Bob King717d2da2020-06-02 11:11:15 +0800394 IDMap idMap{};
395 idMap.addDevice(device);
Bob King73eacee2020-10-23 13:58:02 +0800396 MockServices services{};
397 ActionEnvironment env{idMap, "reg1", services};
Bob King717d2da2020-06-02 11:11:15 +0800398
399 // Create and execute action
400 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::pout};
401 uint8_t command = 0x96;
402 pmbus_utils::SensorDataFormat format{
403 pmbus_utils::SensorDataFormat::linear_11};
404 std::optional<int8_t> exponent{};
405 PMBusReadSensorAction action{type, command, format, exponent};
406 action.execute(env);
407 ADD_FAILURE() << "Should not have reached this line.";
408 }
409 catch (const ActionError& e)
410 {
411 EXPECT_STREQ(e.what(), "ActionError: pmbus_read_sensor: { type: pout, "
412 "command: 0x96, format: linear_11 }");
413 try
414 {
415 // Re-throw inner I2CException
416 std::rethrow_if_nested(e);
417 ADD_FAILURE() << "Should not have reached this line.";
418 }
419 catch (const i2c::I2CException& ie)
420 {
421 EXPECT_STREQ(
422 ie.what(),
423 "I2CException: Failed to read word: bus /dev/i2c-1, addr 0x70");
424 }
425 catch (...)
426 {
427 ADD_FAILURE() << "Should not have caught exception.";
428 }
429 }
430 catch (...)
431 {
432 ADD_FAILURE() << "Should not have caught exception.";
433 }
Bob Kingd6820bb2020-04-28 15:37:02 +0800434}
435
436TEST(PMBusReadSensorActionTests, GetCommand)
437{
438 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
439 uint8_t command = 0x8C;
440 pmbus_utils::SensorDataFormat format{
441 pmbus_utils::SensorDataFormat::linear_16};
442 std::optional<int8_t> exponent{-8};
443 PMBusReadSensorAction action{type, command, format, exponent};
444 EXPECT_EQ(action.getCommand(), 0x8C);
445}
446
447TEST(PMBusReadSensorActionTests, GetExponent)
448{
449 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
450 uint8_t command = 0x8C;
451 pmbus_utils::SensorDataFormat format{
452 pmbus_utils::SensorDataFormat::linear_16};
453
454 // Exponent value is specified
455 {
456 std::optional<int8_t> exponent{-9};
457 PMBusReadSensorAction action{type, command, format, exponent};
458 EXPECT_EQ(action.getExponent().has_value(), true);
459 EXPECT_EQ(action.getExponent().value(), -9);
460 }
461
462 // Exponent value is not specified
463 {
464 std::optional<int8_t> exponent{};
465 PMBusReadSensorAction action{type, command, format, exponent};
466 EXPECT_EQ(action.getExponent().has_value(), false);
467 }
468}
469
470TEST(PMBusReadSensorActionTests, GetFormat)
471{
472 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
473 uint8_t command = 0x8C;
474 pmbus_utils::SensorDataFormat format{
475 pmbus_utils::SensorDataFormat::linear_16};
476 std::optional<int8_t> exponent{-8};
477 PMBusReadSensorAction action{type, command, format, exponent};
478 EXPECT_EQ(action.getFormat(), pmbus_utils::SensorDataFormat::linear_16);
479}
480
481TEST(PMBusReadSensorActionTests, GetType)
482{
483 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::pout};
484 uint8_t command = 0x8C;
485 pmbus_utils::SensorDataFormat format{
486 pmbus_utils::SensorDataFormat::linear_16};
487 std::optional<int8_t> exponent{-8};
488 PMBusReadSensorAction action{type, command, format, exponent};
489 EXPECT_EQ(action.getType(), pmbus_utils::SensorValueType::pout);
490}
491
492TEST(PMBusReadSensorActionTests, ToString)
493{
494 // Test where exponent value is specified
495 {
Bob King717d2da2020-06-02 11:11:15 +0800496 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::vout};
497 uint8_t command = 0x8B;
Bob Kingd6820bb2020-04-28 15:37:02 +0800498 pmbus_utils::SensorDataFormat format{
499 pmbus_utils::SensorDataFormat::linear_16};
500 std::optional<int8_t> exponent{-8};
501 PMBusReadSensorAction action{type, command, format, exponent};
502 EXPECT_EQ(action.toString(), "pmbus_read_sensor: { type: "
Bob King717d2da2020-06-02 11:11:15 +0800503 "vout, command: 0x8B, format: "
Bob Kingd6820bb2020-04-28 15:37:02 +0800504 "linear_16, exponent: -8 }");
505 }
506
507 // Test where exponent value is not specified
508 {
Bob King717d2da2020-06-02 11:11:15 +0800509 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
Bob Kingd6820bb2020-04-28 15:37:02 +0800510 uint8_t command = 0x8C;
511 pmbus_utils::SensorDataFormat format{
512 pmbus_utils::SensorDataFormat::linear_11};
513 std::optional<int8_t> exponent{};
514 PMBusReadSensorAction action{type, command, format, exponent};
Bob King717d2da2020-06-02 11:11:15 +0800515 EXPECT_EQ(action.toString(), "pmbus_read_sensor: { type: iout, "
Bob Kingd6820bb2020-04-28 15:37:02 +0800516 "command: 0x8C, format: linear_11 }");
517 }
518}