blob: d0f1398a29307414ff6ac37c6a0a2d766c74aa30 [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");
Shawn McCarney5b819f42021-03-16 14:41:15 -0500302 EXPECT_EQ(pe.getDeviceID(), "reg1");
303 EXPECT_EQ(pe.getInventoryPath(), "/xyz/openbmc_project/inventory/"
304 "system/chassis/motherboard/reg1");
Bob King717d2da2020-06-02 11:11:15 +0800305 }
306 catch (...)
307 {
308 ADD_FAILURE() << "Should not have caught exception.";
309 }
310 }
311 catch (...)
312 {
313 ADD_FAILURE() << "Should not have caught exception.";
314 }
315
316 // Test where fails: Reading VOUT_MODE fails
317 try
318 {
319 // Create mock I2CInterface. Expect action to do the following:
320 // * will try to read VOUT_MODE; exception will be thrown
321 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
322 std::make_unique<i2c::MockedI2CInterface>();
323 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
Bob Kingab7d6cb2020-07-17 10:24:07 +0800324 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0xC6), A<uint16_t&>()))
325 .Times(1);
Bob King717d2da2020-06-02 11:11:15 +0800326 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x20), A<uint8_t&>()))
327 .Times(1)
328 .WillOnce(Throw(
329 i2c::I2CException{"Failed to read byte", "/dev/i2c-1", 0x70}));
330
Bob King73eacee2020-10-23 13:58:02 +0800331 // Create Device, IDMap, MockServices, and ActionEnvironment
Bob Kinga76898f2020-10-13 15:08:33 +0800332 Device device{
333 "reg1", true,
334 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
335 std::move(i2cInterface)};
Bob King717d2da2020-06-02 11:11:15 +0800336 IDMap idMap{};
337 idMap.addDevice(device);
Bob King73eacee2020-10-23 13:58:02 +0800338 MockServices services{};
339 ActionEnvironment env{idMap, "reg1", services};
Bob King717d2da2020-06-02 11:11:15 +0800340
341 // Create and execute action
342 pmbus_utils::SensorValueType type{
343 pmbus_utils::SensorValueType::vout_peak};
344 uint8_t command = 0xC6;
345 pmbus_utils::SensorDataFormat format{
346 pmbus_utils::SensorDataFormat::linear_16};
347 std::optional<int8_t> exponent{};
348 PMBusReadSensorAction action{type, command, format, exponent};
349 action.execute(env);
350 ADD_FAILURE() << "Should not have reached this line.";
351 }
352 catch (const ActionError& e)
353 {
354 EXPECT_STREQ(e.what(),
355 "ActionError: pmbus_read_sensor: { type: vout_peak, "
356 "command: 0xC6, format: linear_16 }");
357 try
358 {
359 // Re-throw inner I2CException
360 std::rethrow_if_nested(e);
361 ADD_FAILURE() << "Should not have reached this line.";
362 }
363 catch (const i2c::I2CException& ie)
364 {
365 EXPECT_STREQ(
366 ie.what(),
367 "I2CException: Failed to read byte: bus /dev/i2c-1, addr 0x70");
368 }
369 catch (...)
370 {
371 ADD_FAILURE() << "Should not have caught exception.";
372 }
373 }
374 catch (...)
375 {
376 ADD_FAILURE() << "Should not have caught exception.";
377 }
378
379 // Test where fails: Reading PMBus command code with sensor value fails
380 try
381 {
382 // Create mock I2CInterface. Expect action to do the following:
383 // * will try to read PMBus command(0x96); exception will be thrown
384 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
385 std::make_unique<i2c::MockedI2CInterface>();
386 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
387 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x96), A<uint16_t&>()))
388 .Times(1)
389 .WillOnce(Throw(
390 i2c::I2CException{"Failed to read word", "/dev/i2c-1", 0x70}));
391
Bob King73eacee2020-10-23 13:58:02 +0800392 // Create Device, IDMap, MockServices, and ActionEnvironment
Bob Kinga76898f2020-10-13 15:08:33 +0800393 Device device{
394 "reg1", true,
395 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
396 std::move(i2cInterface)};
Bob King717d2da2020-06-02 11:11:15 +0800397 IDMap idMap{};
398 idMap.addDevice(device);
Bob King73eacee2020-10-23 13:58:02 +0800399 MockServices services{};
400 ActionEnvironment env{idMap, "reg1", services};
Bob King717d2da2020-06-02 11:11:15 +0800401
402 // Create and execute action
403 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::pout};
404 uint8_t command = 0x96;
405 pmbus_utils::SensorDataFormat format{
406 pmbus_utils::SensorDataFormat::linear_11};
407 std::optional<int8_t> exponent{};
408 PMBusReadSensorAction action{type, command, format, exponent};
409 action.execute(env);
410 ADD_FAILURE() << "Should not have reached this line.";
411 }
412 catch (const ActionError& e)
413 {
414 EXPECT_STREQ(e.what(), "ActionError: pmbus_read_sensor: { type: pout, "
415 "command: 0x96, format: linear_11 }");
416 try
417 {
418 // Re-throw inner I2CException
419 std::rethrow_if_nested(e);
420 ADD_FAILURE() << "Should not have reached this line.";
421 }
422 catch (const i2c::I2CException& ie)
423 {
424 EXPECT_STREQ(
425 ie.what(),
426 "I2CException: Failed to read word: bus /dev/i2c-1, addr 0x70");
427 }
428 catch (...)
429 {
430 ADD_FAILURE() << "Should not have caught exception.";
431 }
432 }
433 catch (...)
434 {
435 ADD_FAILURE() << "Should not have caught exception.";
436 }
Bob Kingd6820bb2020-04-28 15:37:02 +0800437}
438
439TEST(PMBusReadSensorActionTests, GetCommand)
440{
441 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
442 uint8_t command = 0x8C;
443 pmbus_utils::SensorDataFormat format{
444 pmbus_utils::SensorDataFormat::linear_16};
445 std::optional<int8_t> exponent{-8};
446 PMBusReadSensorAction action{type, command, format, exponent};
447 EXPECT_EQ(action.getCommand(), 0x8C);
448}
449
450TEST(PMBusReadSensorActionTests, GetExponent)
451{
452 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
453 uint8_t command = 0x8C;
454 pmbus_utils::SensorDataFormat format{
455 pmbus_utils::SensorDataFormat::linear_16};
456
457 // Exponent value is specified
458 {
459 std::optional<int8_t> exponent{-9};
460 PMBusReadSensorAction action{type, command, format, exponent};
461 EXPECT_EQ(action.getExponent().has_value(), true);
462 EXPECT_EQ(action.getExponent().value(), -9);
463 }
464
465 // Exponent value is not specified
466 {
467 std::optional<int8_t> exponent{};
468 PMBusReadSensorAction action{type, command, format, exponent};
469 EXPECT_EQ(action.getExponent().has_value(), false);
470 }
471}
472
473TEST(PMBusReadSensorActionTests, GetFormat)
474{
475 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
476 uint8_t command = 0x8C;
477 pmbus_utils::SensorDataFormat format{
478 pmbus_utils::SensorDataFormat::linear_16};
479 std::optional<int8_t> exponent{-8};
480 PMBusReadSensorAction action{type, command, format, exponent};
481 EXPECT_EQ(action.getFormat(), pmbus_utils::SensorDataFormat::linear_16);
482}
483
484TEST(PMBusReadSensorActionTests, GetType)
485{
486 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::pout};
487 uint8_t command = 0x8C;
488 pmbus_utils::SensorDataFormat format{
489 pmbus_utils::SensorDataFormat::linear_16};
490 std::optional<int8_t> exponent{-8};
491 PMBusReadSensorAction action{type, command, format, exponent};
492 EXPECT_EQ(action.getType(), pmbus_utils::SensorValueType::pout);
493}
494
495TEST(PMBusReadSensorActionTests, ToString)
496{
497 // Test where exponent value is specified
498 {
Bob King717d2da2020-06-02 11:11:15 +0800499 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::vout};
500 uint8_t command = 0x8B;
Bob Kingd6820bb2020-04-28 15:37:02 +0800501 pmbus_utils::SensorDataFormat format{
502 pmbus_utils::SensorDataFormat::linear_16};
503 std::optional<int8_t> exponent{-8};
504 PMBusReadSensorAction action{type, command, format, exponent};
505 EXPECT_EQ(action.toString(), "pmbus_read_sensor: { type: "
Bob King717d2da2020-06-02 11:11:15 +0800506 "vout, command: 0x8B, format: "
Bob Kingd6820bb2020-04-28 15:37:02 +0800507 "linear_16, exponent: -8 }");
508 }
509
510 // Test where exponent value is not specified
511 {
Bob King717d2da2020-06-02 11:11:15 +0800512 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
Bob Kingd6820bb2020-04-28 15:37:02 +0800513 uint8_t command = 0x8C;
514 pmbus_utils::SensorDataFormat format{
515 pmbus_utils::SensorDataFormat::linear_11};
516 std::optional<int8_t> exponent{};
517 PMBusReadSensorAction action{type, command, format, exponent};
Bob King717d2da2020-06-02 11:11:15 +0800518 EXPECT_EQ(action.toString(), "pmbus_read_sensor: { type: iout, "
Bob Kingd6820bb2020-04-28 15:37:02 +0800519 "command: 0x8C, format: linear_11 }");
520 }
521}