13f1242f3SBrandon Wyman #include "../power_supply.hpp" 23f1242f3SBrandon Wyman #include "mock.hpp" 33f1242f3SBrandon Wyman 43f1242f3SBrandon Wyman #include <xyz/openbmc_project/Common/Device/error.hpp> 53f1242f3SBrandon Wyman #include <xyz/openbmc_project/Common/error.hpp> 63f1242f3SBrandon Wyman 73f1242f3SBrandon Wyman #include <gmock/gmock.h> 83f1242f3SBrandon Wyman #include <gtest/gtest.h> 93f1242f3SBrandon Wyman 103f1242f3SBrandon Wyman using namespace phosphor::power::psu; 113f1242f3SBrandon Wyman using namespace phosphor::pmbus; 123f1242f3SBrandon Wyman 133f1242f3SBrandon Wyman using ::testing::_; 1459a35793SBrandon Wyman using ::testing::Args; 153f1242f3SBrandon Wyman using ::testing::Assign; 163f1242f3SBrandon Wyman using ::testing::DoAll; 1759a35793SBrandon Wyman using ::testing::ElementsAre; 1859a35793SBrandon Wyman using ::testing::NotNull; 193f1242f3SBrandon Wyman using ::testing::Return; 203f1242f3SBrandon Wyman using ::testing::StrEq; 213f1242f3SBrandon Wyman 223f1242f3SBrandon Wyman static auto PSUInventoryPath = "/xyz/bmc/inv/sys/chassis/board/powersupply0"; 233f1242f3SBrandon Wyman 243f1242f3SBrandon Wyman class PowerSupplyTests : public ::testing::Test 253f1242f3SBrandon Wyman { 263f1242f3SBrandon Wyman public: 273f1242f3SBrandon Wyman PowerSupplyTests() : 283f1242f3SBrandon Wyman mockedUtil(reinterpret_cast<const MockedUtil&>(getUtils())) 293f1242f3SBrandon Wyman { 303f1242f3SBrandon Wyman ON_CALL(mockedUtil, getPresence(_, _)).WillByDefault(Return(false)); 313f1242f3SBrandon Wyman } 323f1242f3SBrandon Wyman 333f1242f3SBrandon Wyman ~PowerSupplyTests() override 343f1242f3SBrandon Wyman { 353f1242f3SBrandon Wyman freeUtils(); 363f1242f3SBrandon Wyman } 373f1242f3SBrandon Wyman 383f1242f3SBrandon Wyman const MockedUtil& mockedUtil; 393f1242f3SBrandon Wyman }; 403f1242f3SBrandon Wyman 413f1242f3SBrandon Wyman TEST_F(PowerSupplyTests, Constructor) 423f1242f3SBrandon Wyman { 433f1242f3SBrandon Wyman /** 443f1242f3SBrandon Wyman * @param[in] invpath - String for inventory path to use 453f1242f3SBrandon Wyman * @param[in] i2cbus - The bus number this power supply is on 463f1242f3SBrandon Wyman * @param[in] i2caddr - The 16-bit I2C address of the power supply 473f1242f3SBrandon Wyman */ 483f1242f3SBrandon Wyman auto bus = sdbusplus::bus::new_default(); 491d7a7df8SBrandon Wyman 501d7a7df8SBrandon Wyman // Try where inventory path is empty, constructor should fail. 511d7a7df8SBrandon Wyman try 521d7a7df8SBrandon Wyman { 531d7a7df8SBrandon Wyman auto psu = std::make_unique<PowerSupply>(bus, "", 3, "0068"); 541d7a7df8SBrandon Wyman ADD_FAILURE() << "Should not have reached this line."; 551d7a7df8SBrandon Wyman } 561d7a7df8SBrandon Wyman catch (const std::invalid_argument& e) 571d7a7df8SBrandon Wyman { 581d7a7df8SBrandon Wyman EXPECT_STREQ(e.what(), "Invalid empty inventoryPath"); 591d7a7df8SBrandon Wyman } 601d7a7df8SBrandon Wyman catch (...) 611d7a7df8SBrandon Wyman { 621d7a7df8SBrandon Wyman ADD_FAILURE() << "Should not have caught exception."; 631d7a7df8SBrandon Wyman } 641d7a7df8SBrandon Wyman 651d7a7df8SBrandon Wyman // Test with valid arguments 661d7a7df8SBrandon Wyman try 671d7a7df8SBrandon Wyman { 681d7a7df8SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath))) 691d7a7df8SBrandon Wyman .Times(1); 701d7a7df8SBrandon Wyman auto psu = 711d7a7df8SBrandon Wyman std::make_unique<PowerSupply>(bus, PSUInventoryPath, 3, "0068"); 723f1242f3SBrandon Wyman 733f1242f3SBrandon Wyman EXPECT_EQ(psu->isPresent(), false); 743f1242f3SBrandon Wyman EXPECT_EQ(psu->isFaulted(), false); 753f1242f3SBrandon Wyman EXPECT_EQ(psu->hasInputFault(), false); 763f1242f3SBrandon Wyman EXPECT_EQ(psu->hasMFRFault(), false); 773f1242f3SBrandon Wyman EXPECT_EQ(psu->hasVINUVFault(), false); 783f1242f3SBrandon Wyman } 791d7a7df8SBrandon Wyman catch (...) 801d7a7df8SBrandon Wyman { 811d7a7df8SBrandon Wyman ADD_FAILURE() << "Should not have caught exception."; 821d7a7df8SBrandon Wyman } 831d7a7df8SBrandon Wyman } 843f1242f3SBrandon Wyman 853f1242f3SBrandon Wyman TEST_F(PowerSupplyTests, Analyze) 863f1242f3SBrandon Wyman { 873f1242f3SBrandon Wyman auto bus = sdbusplus::bus::new_default(); 883f1242f3SBrandon Wyman 893f1242f3SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath))).Times(1); 903f1242f3SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 4, "0069"}; 913f1242f3SBrandon Wyman psu.analyze(); 923f1242f3SBrandon Wyman // By default, nothing should change. 933f1242f3SBrandon Wyman EXPECT_EQ(psu.isPresent(), false); 943f1242f3SBrandon Wyman EXPECT_EQ(psu.isFaulted(), false); 953f1242f3SBrandon Wyman EXPECT_EQ(psu.hasInputFault(), false); 963f1242f3SBrandon Wyman EXPECT_EQ(psu.hasMFRFault(), false); 973f1242f3SBrandon Wyman EXPECT_EQ(psu.hasVINUVFault(), false); 983f1242f3SBrandon Wyman 993f1242f3SBrandon Wyman // In order to get the various faults tested, the power supply needs to be 1003f1242f3SBrandon Wyman // present in order to read from the PMBus device(s). 1013f1242f3SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath))) 1023f1242f3SBrandon Wyman .Times(1) 1033f1242f3SBrandon Wyman .WillOnce(Return(true)); // present 1043f1242f3SBrandon Wyman PowerSupply psu2{bus, PSUInventoryPath, 5, "006a"}; 1053f1242f3SBrandon Wyman EXPECT_EQ(psu2.isPresent(), true); 1063f1242f3SBrandon Wyman 1073f1242f3SBrandon Wyman // STATUS_WORD 0x0000 is powered on, no faults. 1083f1242f3SBrandon Wyman MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu2.getPMBus()); 1093f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)).Times(1).WillOnce(Return(0x0000)); 1103f1242f3SBrandon Wyman psu2.analyze(); 1113f1242f3SBrandon Wyman EXPECT_EQ(psu2.isPresent(), true); 1123f1242f3SBrandon Wyman EXPECT_EQ(psu2.isFaulted(), false); 1133f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasInputFault(), false); 1143f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasMFRFault(), false); 1153f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasVINUVFault(), false); 1163f1242f3SBrandon Wyman 1173f1242f3SBrandon Wyman // STATUS_WORD input fault/warn 1183f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)) 119*10d94055SJay Meyer .Times(2) 120*10d94055SJay Meyer .WillOnce(Return(status_word::INPUT_FAULT_WARN)) 121*10d94055SJay Meyer .WillOnce(Return(0x0000)); 1223f1242f3SBrandon Wyman psu2.analyze(); 1233f1242f3SBrandon Wyman EXPECT_EQ(psu2.isPresent(), true); 1243f1242f3SBrandon Wyman EXPECT_EQ(psu2.isFaulted(), true); 1253f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasInputFault(), true); 1263f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasMFRFault(), false); 1273f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasVINUVFault(), false); 1283f1242f3SBrandon Wyman 1293f1242f3SBrandon Wyman // STATUS_WORD INPUT/UV fault. 1303f1242f3SBrandon Wyman // First need it to return good status, then the fault 1313f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)) 1323f1242f3SBrandon Wyman .WillOnce(Return(0x0000)) 133*10d94055SJay Meyer .WillOnce(Return(status_word::VIN_UV_FAULT)) 134*10d94055SJay Meyer .WillOnce(Return(0x0000)); 1353f1242f3SBrandon Wyman psu2.analyze(); 1363f1242f3SBrandon Wyman psu2.analyze(); 1373f1242f3SBrandon Wyman EXPECT_EQ(psu2.isPresent(), true); 1383f1242f3SBrandon Wyman EXPECT_EQ(psu2.isFaulted(), true); 1393f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasInputFault(), false); 1403f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasMFRFault(), false); 1413f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasVINUVFault(), true); 1423f1242f3SBrandon Wyman 1433f1242f3SBrandon Wyman // STATUS_WORD MFR fault. 1443f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)) 1453f1242f3SBrandon Wyman .WillOnce(Return(0x0000)) 146*10d94055SJay Meyer .WillOnce(Return(status_word::MFR_SPECIFIC_FAULT)) 147*10d94055SJay Meyer .WillOnce(Return(1)); // mock return for read(STATUS_MFR... ) 1483f1242f3SBrandon Wyman psu2.analyze(); 1493f1242f3SBrandon Wyman psu2.analyze(); 1503f1242f3SBrandon Wyman EXPECT_EQ(psu2.isPresent(), true); 1513f1242f3SBrandon Wyman EXPECT_EQ(psu2.isFaulted(), true); 1523f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasInputFault(), false); 1533f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasMFRFault(), true); 1543f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasVINUVFault(), false); 1553f1242f3SBrandon Wyman 1563f1242f3SBrandon Wyman // Ignore Temperature fault. 1573f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)) 1583f1242f3SBrandon Wyman .WillOnce(Return(0x0000)) 159*10d94055SJay Meyer .WillOnce(Return(status_word::TEMPERATURE_FAULT_WARN)) 160*10d94055SJay Meyer .WillOnce(Return(0x0000)); 1613f1242f3SBrandon Wyman psu2.analyze(); 1623f1242f3SBrandon Wyman psu2.analyze(); 1633f1242f3SBrandon Wyman EXPECT_EQ(psu2.isPresent(), true); 1643f1242f3SBrandon Wyman EXPECT_EQ(psu2.isFaulted(), false); 1653f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasInputFault(), false); 1663f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasMFRFault(), false); 1673f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasVINUVFault(), false); 1683f1242f3SBrandon Wyman 1693f1242f3SBrandon Wyman // Ignore fan fault 1703f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)) 1713f1242f3SBrandon Wyman .WillOnce(Return(0x0000)) 172*10d94055SJay Meyer .WillOnce(Return(status_word::FAN_FAULT)) 173*10d94055SJay Meyer .WillOnce(Return(0x0000)); 1743f1242f3SBrandon Wyman psu2.analyze(); 1753f1242f3SBrandon Wyman psu2.analyze(); 1763f1242f3SBrandon Wyman EXPECT_EQ(psu2.isPresent(), true); 1773f1242f3SBrandon Wyman EXPECT_EQ(psu2.isFaulted(), false); 1783f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasInputFault(), false); 1793f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasMFRFault(), false); 1803f1242f3SBrandon Wyman EXPECT_EQ(psu2.hasVINUVFault(), false); 1813f1242f3SBrandon Wyman 1823f1242f3SBrandon Wyman // TODO: ReadFailure 1833f1242f3SBrandon Wyman } 1843f1242f3SBrandon Wyman 18559a35793SBrandon Wyman TEST_F(PowerSupplyTests, OnOffConfig) 18659a35793SBrandon Wyman { 18759a35793SBrandon Wyman auto bus = sdbusplus::bus::new_default(); 18859a35793SBrandon Wyman uint8_t data = 0x15; 18959a35793SBrandon Wyman 19059a35793SBrandon Wyman // Test where PSU is NOT present 19159a35793SBrandon Wyman try 19259a35793SBrandon Wyman { 19359a35793SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath))) 19459a35793SBrandon Wyman .Times(1) 19559a35793SBrandon Wyman .WillOnce(Return(false)); 19659a35793SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 4, "0069"}; 19759a35793SBrandon Wyman MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); 19859a35793SBrandon Wyman // If it is not present, I should not be trying to write to it. 19959a35793SBrandon Wyman EXPECT_CALL(mockPMBus, writeBinary(_, _, _)).Times(0); 20059a35793SBrandon Wyman psu.onOffConfig(data); 20159a35793SBrandon Wyman } 20259a35793SBrandon Wyman catch (...) 20359a35793SBrandon Wyman { 20459a35793SBrandon Wyman } 20559a35793SBrandon Wyman 20659a35793SBrandon Wyman // Test where PSU is present 20759a35793SBrandon Wyman try 20859a35793SBrandon Wyman { 20959a35793SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath))) 21059a35793SBrandon Wyman .Times(1) 21159a35793SBrandon Wyman .WillOnce(Return(true)); // present 21259a35793SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 5, "006a"}; 21359a35793SBrandon Wyman MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); 21459a35793SBrandon Wyman // TODO: ???should I check the filename? 21559a35793SBrandon Wyman EXPECT_CALL(mockPMBus, 21659a35793SBrandon Wyman writeBinary(_, ElementsAre(0x15), Type::HwmonDeviceDebug)) 21759a35793SBrandon Wyman .Times(1); 21859a35793SBrandon Wyman psu.onOffConfig(data); 21959a35793SBrandon Wyman } 22059a35793SBrandon Wyman catch (...) 22159a35793SBrandon Wyman { 22259a35793SBrandon Wyman } 22359a35793SBrandon Wyman } 22459a35793SBrandon Wyman 2253f1242f3SBrandon Wyman TEST_F(PowerSupplyTests, ClearFaults) 2263f1242f3SBrandon Wyman { 2273f1242f3SBrandon Wyman auto bus = sdbusplus::bus::new_default(); 2283f1242f3SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath))) 2293f1242f3SBrandon Wyman .Times(1) 2303f1242f3SBrandon Wyman .WillOnce(Return(true)); // present 2313f1242f3SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 13, "0068"}; 2323f1242f3SBrandon Wyman EXPECT_EQ(psu.isPresent(), true); 2333f1242f3SBrandon Wyman EXPECT_EQ(psu.isFaulted(), false); 2343f1242f3SBrandon Wyman EXPECT_EQ(psu.hasInputFault(), false); 2353f1242f3SBrandon Wyman EXPECT_EQ(psu.hasMFRFault(), false); 2363f1242f3SBrandon Wyman EXPECT_EQ(psu.hasVINUVFault(), false); 2373f1242f3SBrandon Wyman MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); 238*10d94055SJay Meyer EXPECT_CALL(mockPMBus, read(_, _)) 239*10d94055SJay Meyer .Times(2) 240*10d94055SJay Meyer .WillOnce(Return(0xFFFF)) 241*10d94055SJay Meyer .WillOnce(Return(1)); // mock return for read(STATUS_MFR... ) 2423f1242f3SBrandon Wyman psu.analyze(); 2433f1242f3SBrandon Wyman EXPECT_EQ(psu.isPresent(), true); 2443f1242f3SBrandon Wyman EXPECT_EQ(psu.isFaulted(), true); 2453f1242f3SBrandon Wyman EXPECT_EQ(psu.hasInputFault(), true); 2463f1242f3SBrandon Wyman EXPECT_EQ(psu.hasMFRFault(), true); 2473f1242f3SBrandon Wyman EXPECT_EQ(psu.hasVINUVFault(), true); 2483c208464SBrandon Wyman EXPECT_CALL(mockPMBus, read("in1_input", _)) 2493c208464SBrandon Wyman .Times(1) 2503c208464SBrandon Wyman .WillOnce(Return(209000)); 2513f1242f3SBrandon Wyman psu.clearFaults(); 2523f1242f3SBrandon Wyman EXPECT_EQ(psu.isPresent(), true); 2533f1242f3SBrandon Wyman EXPECT_EQ(psu.isFaulted(), false); 2543f1242f3SBrandon Wyman EXPECT_EQ(psu.hasInputFault(), false); 2553f1242f3SBrandon Wyman EXPECT_EQ(psu.hasMFRFault(), false); 2563f1242f3SBrandon Wyman EXPECT_EQ(psu.hasVINUVFault(), false); 2573f1242f3SBrandon Wyman } 2583f1242f3SBrandon Wyman 2593f1242f3SBrandon Wyman TEST_F(PowerSupplyTests, UpdateInventory) 2603f1242f3SBrandon Wyman { 2613f1242f3SBrandon Wyman auto bus = sdbusplus::bus::new_default(); 2621d7a7df8SBrandon Wyman 2631d7a7df8SBrandon Wyman try 2641d7a7df8SBrandon Wyman { 2651d7a7df8SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath))) 2661d7a7df8SBrandon Wyman .Times(1) 2671d7a7df8SBrandon Wyman .WillOnce(Return(false)); // missing 2681d7a7df8SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 3, "0068"}; 2691d7a7df8SBrandon Wyman MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); 2701d7a7df8SBrandon Wyman // If it is not present, I should not be trying to read a string 2711d7a7df8SBrandon Wyman EXPECT_CALL(mockPMBus, readString(_, _)).Times(0); 2721d7a7df8SBrandon Wyman psu.updateInventory(); 2731d7a7df8SBrandon Wyman } 2741d7a7df8SBrandon Wyman catch (...) 2751d7a7df8SBrandon Wyman { 2761d7a7df8SBrandon Wyman ADD_FAILURE() << "Should not have caught exception."; 2771d7a7df8SBrandon Wyman } 2781d7a7df8SBrandon Wyman 2791d7a7df8SBrandon Wyman try 2801d7a7df8SBrandon Wyman { 2813f1242f3SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath))) 2823f1242f3SBrandon Wyman .Times(1) 2833f1242f3SBrandon Wyman .WillOnce(Return(true)); // present 2841d7a7df8SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 13, "0069"}; 2851d7a7df8SBrandon Wyman MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); 2861d7a7df8SBrandon Wyman EXPECT_CALL(mockPMBus, readString(_, _)).WillRepeatedly(Return("")); 2873f1242f3SBrandon Wyman psu.updateInventory(); 2881d7a7df8SBrandon Wyman 2891d7a7df8SBrandon Wyman EXPECT_CALL(mockPMBus, readString(_, _)) 2901d7a7df8SBrandon Wyman .WillOnce(Return("CCIN")) 2911d7a7df8SBrandon Wyman .WillOnce(Return("PN3456")) 2921d7a7df8SBrandon Wyman .WillOnce(Return("FN3456")) 2931d7a7df8SBrandon Wyman .WillOnce(Return("HEADER")) 2941d7a7df8SBrandon Wyman .WillOnce(Return("SN3456")) 2951d7a7df8SBrandon Wyman .WillOnce(Return("FW3456")); 2961d7a7df8SBrandon Wyman psu.updateInventory(); 2971d7a7df8SBrandon Wyman // TODO: D-Bus mocking to verify values stored on D-Bus (???) 2981d7a7df8SBrandon Wyman } 2991d7a7df8SBrandon Wyman catch (...) 3001d7a7df8SBrandon Wyman { 3011d7a7df8SBrandon Wyman ADD_FAILURE() << "Should not have caught exception."; 3021d7a7df8SBrandon Wyman } 3033f1242f3SBrandon Wyman } 3043f1242f3SBrandon Wyman 3053f1242f3SBrandon Wyman TEST_F(PowerSupplyTests, IsPresent) 3063f1242f3SBrandon Wyman { 3073f1242f3SBrandon Wyman auto bus = sdbusplus::bus::new_default(); 3083f1242f3SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath))).Times(1); 3093f1242f3SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 3, "0068"}; 3103f1242f3SBrandon Wyman EXPECT_EQ(psu.isPresent(), false); 3113f1242f3SBrandon Wyman 3123f1242f3SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, _)) 3133f1242f3SBrandon Wyman .WillOnce(Return(true)); // present 3143f1242f3SBrandon Wyman PowerSupply psu2{bus, PSUInventoryPath, 10, "006b"}; 3153f1242f3SBrandon Wyman EXPECT_EQ(psu2.isPresent(), true); 3163f1242f3SBrandon Wyman } 3173f1242f3SBrandon Wyman 3183f1242f3SBrandon Wyman TEST_F(PowerSupplyTests, IsFaulted) 3193f1242f3SBrandon Wyman { 3203f1242f3SBrandon Wyman auto bus = sdbusplus::bus::new_default(); 3213f1242f3SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, _)) 3223f1242f3SBrandon Wyman .WillOnce(Return(true)); // present 3233f1242f3SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 11, "006f"}; 3243f1242f3SBrandon Wyman EXPECT_EQ(psu.isFaulted(), false); 3253f1242f3SBrandon Wyman MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); 326*10d94055SJay Meyer EXPECT_CALL(mockPMBus, read(_, _)) 327*10d94055SJay Meyer .Times(2) 328*10d94055SJay Meyer .WillOnce(Return(0xFFFF)) 329*10d94055SJay Meyer .WillOnce(Return(1)); // mock return for read(STATUS_MFR... ) 3303f1242f3SBrandon Wyman psu.analyze(); 3313f1242f3SBrandon Wyman EXPECT_EQ(psu.isFaulted(), true); 3323f1242f3SBrandon Wyman } 3333f1242f3SBrandon Wyman 3343f1242f3SBrandon Wyman TEST_F(PowerSupplyTests, HasInputFault) 3353f1242f3SBrandon Wyman { 3363f1242f3SBrandon Wyman auto bus = sdbusplus::bus::new_default(); 3373f1242f3SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, _)) 3383f1242f3SBrandon Wyman .WillOnce(Return(true)); // present 3393f1242f3SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 3, "0068"}; 3403f1242f3SBrandon Wyman MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); 3413f1242f3SBrandon Wyman EXPECT_EQ(psu.hasInputFault(), false); 3423f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)).Times(1).WillOnce(Return(0x0000)); 3433f1242f3SBrandon Wyman psu.analyze(); 3443f1242f3SBrandon Wyman EXPECT_EQ(psu.hasInputFault(), false); 3453f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)) 346*10d94055SJay Meyer .Times(2) 347*10d94055SJay Meyer .WillOnce(Return(status_word::INPUT_FAULT_WARN)) 348*10d94055SJay Meyer .WillOnce(Return(0)); 3493f1242f3SBrandon Wyman psu.analyze(); 3503f1242f3SBrandon Wyman EXPECT_EQ(psu.hasInputFault(), true); 3513f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)).Times(1).WillOnce(Return(0x0000)); 3523f1242f3SBrandon Wyman psu.analyze(); 3533f1242f3SBrandon Wyman EXPECT_EQ(psu.hasInputFault(), false); 3543f1242f3SBrandon Wyman } 3553f1242f3SBrandon Wyman 3563f1242f3SBrandon Wyman TEST_F(PowerSupplyTests, HasMFRFault) 3573f1242f3SBrandon Wyman { 3583f1242f3SBrandon Wyman auto bus = sdbusplus::bus::new_default(); 3593f1242f3SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, _)) 3603f1242f3SBrandon Wyman .WillOnce(Return(true)); // present 3613f1242f3SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 3, "0068"}; 3623f1242f3SBrandon Wyman MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); 3633f1242f3SBrandon Wyman EXPECT_EQ(psu.hasMFRFault(), false); 3643f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)).Times(1).WillOnce(Return(0x0000)); 3653f1242f3SBrandon Wyman psu.analyze(); 3663f1242f3SBrandon Wyman EXPECT_EQ(psu.hasMFRFault(), false); 3673f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)) 368*10d94055SJay Meyer .Times(2) 369*10d94055SJay Meyer .WillOnce(Return(status_word::MFR_SPECIFIC_FAULT)) 370*10d94055SJay Meyer .WillOnce(Return(1)); // mock return for read(STATUS_MFR... ) 3713f1242f3SBrandon Wyman psu.analyze(); 3723f1242f3SBrandon Wyman EXPECT_EQ(psu.hasMFRFault(), true); 3733f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)).Times(1).WillOnce(Return(0x0000)); 3743f1242f3SBrandon Wyman psu.analyze(); 3753f1242f3SBrandon Wyman EXPECT_EQ(psu.hasMFRFault(), false); 3763f1242f3SBrandon Wyman } 3773f1242f3SBrandon Wyman 3783f1242f3SBrandon Wyman TEST_F(PowerSupplyTests, HasVINUVFault) 3793f1242f3SBrandon Wyman { 3803f1242f3SBrandon Wyman auto bus = sdbusplus::bus::new_default(); 3813f1242f3SBrandon Wyman EXPECT_CALL(mockedUtil, getPresence(_, _)) 3823f1242f3SBrandon Wyman .WillOnce(Return(true)); // present 3833f1242f3SBrandon Wyman PowerSupply psu{bus, PSUInventoryPath, 3, "0068"}; 3843f1242f3SBrandon Wyman MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); 3853f1242f3SBrandon Wyman EXPECT_EQ(psu.hasVINUVFault(), false); 3863f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)).Times(1).WillOnce(Return(0x0000)); 3873f1242f3SBrandon Wyman psu.analyze(); 3883f1242f3SBrandon Wyman EXPECT_EQ(psu.hasVINUVFault(), false); 3893f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)) 390*10d94055SJay Meyer .Times(2) 391*10d94055SJay Meyer .WillOnce(Return(status_word::VIN_UV_FAULT)) 392*10d94055SJay Meyer .WillOnce(Return(0)); 3933f1242f3SBrandon Wyman psu.analyze(); 3943f1242f3SBrandon Wyman EXPECT_EQ(psu.hasVINUVFault(), true); 3953f1242f3SBrandon Wyman EXPECT_CALL(mockPMBus, read(_, _)).Times(1).WillOnce(Return(0x0000)); 3963f1242f3SBrandon Wyman psu.analyze(); 3973f1242f3SBrandon Wyman EXPECT_EQ(psu.hasVINUVFault(), false); 3983f1242f3SBrandon Wyman } 399