Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1 | #include "../power_supply.hpp" |
| 2 | #include "mock.hpp" |
| 3 | |
| 4 | #include <xyz/openbmc_project/Common/Device/error.hpp> |
| 5 | #include <xyz/openbmc_project/Common/error.hpp> |
| 6 | |
| 7 | #include <gmock/gmock.h> |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | using namespace phosphor::power::psu; |
| 11 | using namespace phosphor::pmbus; |
| 12 | |
| 13 | using ::testing::_; |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 14 | using ::testing::Args; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 15 | using ::testing::Assign; |
| 16 | using ::testing::DoAll; |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 17 | using ::testing::ElementsAre; |
| 18 | using ::testing::NotNull; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 19 | using ::testing::Return; |
| 20 | using ::testing::StrEq; |
| 21 | |
| 22 | static auto PSUInventoryPath = "/xyz/bmc/inv/sys/chassis/board/powersupply0"; |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 23 | static auto PSUGPIOLineName = "presence-ps0"; |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 24 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 25 | struct PMBusExpectations |
| 26 | { |
| 27 | uint16_t statusWordValue{0x0000}; |
| 28 | uint8_t statusInputValue{0x00}; |
| 29 | uint8_t statusMFRValue{0x00}; |
| 30 | uint8_t statusCMLValue{0x00}; |
| 31 | uint8_t statusVOUTValue{0x00}; |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 32 | uint8_t statusIOUTValue{0x00}; |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 33 | uint8_t statusFans12Value{0x00}; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 34 | uint8_t statusTempValue{0x00}; |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 37 | // Helper function to setup expectations for various STATUS_* commands |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 38 | void setPMBusExpectations(MockedPMBus& mockPMBus, |
| 39 | const PMBusExpectations& expectations) |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 40 | { |
| 41 | EXPECT_CALL(mockPMBus, read(STATUS_WORD, _)) |
| 42 | .Times(1) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 43 | .WillOnce(Return(expectations.statusWordValue)); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 44 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 45 | if (expectations.statusWordValue != 0) |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 46 | { |
| 47 | // If fault bits are on in STATUS_WORD, there will also be a read of |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 48 | // STATUS_INPUT, STATUS_MFR, STATUS_CML, STATUS_VOUT (page 0), and |
| 49 | // STATUS_TEMPERATURE. |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 50 | EXPECT_CALL(mockPMBus, read(STATUS_INPUT, _)) |
| 51 | .Times(1) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 52 | .WillOnce(Return(expectations.statusInputValue)); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 53 | EXPECT_CALL(mockPMBus, read(STATUS_MFR, _)) |
| 54 | .Times(1) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 55 | .WillOnce(Return(expectations.statusMFRValue)); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 56 | EXPECT_CALL(mockPMBus, read(STATUS_CML, _)) |
| 57 | .Times(1) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 58 | .WillOnce(Return(expectations.statusCMLValue)); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 59 | // Page will need to be set to 0 to read STATUS_VOUT. |
| 60 | EXPECT_CALL(mockPMBus, insertPageNum(STATUS_VOUT, 0)) |
| 61 | .Times(1) |
| 62 | .WillOnce(Return("status0_vout")); |
| 63 | EXPECT_CALL(mockPMBus, read("status0_vout", _)) |
| 64 | .Times(1) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 65 | .WillOnce(Return(expectations.statusVOUTValue)); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 66 | EXPECT_CALL(mockPMBus, read(STATUS_IOUT, _)) |
| 67 | .Times(1) |
| 68 | .WillOnce(Return(expectations.statusIOUTValue)); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 69 | EXPECT_CALL(mockPMBus, read(STATUS_FANS_1_2, _)) |
| 70 | .Times(1) |
| 71 | .WillOnce(Return(expectations.statusFans12Value)); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 72 | EXPECT_CALL(mockPMBus, read(STATUS_TEMPERATURE, _)) |
| 73 | .Times(1) |
| 74 | .WillOnce(Return(expectations.statusTempValue)); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 78 | class PowerSupplyTests : public ::testing::Test |
| 79 | { |
| 80 | public: |
| 81 | PowerSupplyTests() : |
| 82 | mockedUtil(reinterpret_cast<const MockedUtil&>(getUtils())) |
| 83 | { |
| 84 | ON_CALL(mockedUtil, getPresence(_, _)).WillByDefault(Return(false)); |
| 85 | } |
| 86 | |
| 87 | ~PowerSupplyTests() override |
| 88 | { |
| 89 | freeUtils(); |
| 90 | } |
| 91 | |
| 92 | const MockedUtil& mockedUtil; |
| 93 | }; |
| 94 | |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 95 | // Helper function for when a power supply goes from missing to present. |
| 96 | void setMissingToPresentExpects(MockedPMBus& pmbus, const MockedUtil& util) |
| 97 | { |
| 98 | // Call to analyze() will update to present, that will trigger updating |
| 99 | // to the correct/latest HWMON directory, in case it changes. |
| 100 | EXPECT_CALL(pmbus, findHwmonDir()); |
| 101 | // Presence change from missing to present will trigger write to |
| 102 | // ON_OFF_CONFIG. |
| 103 | EXPECT_CALL(pmbus, writeBinary(ON_OFF_CONFIG, _, _)); |
| 104 | // Presence change from missing to present will trigger in1_input read |
| 105 | // in an attempt to get CLEAR_FAULTS called. |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 106 | // The voltage defaults to 0, the first call to analyze should update the |
| 107 | // voltage to the current reading, triggering another clearing of faults |
| 108 | // due to below minimum to within range voltage. |
| 109 | // This READ_VIN for CLEAR_FAULTS does not check the returned value. |
| 110 | EXPECT_CALL(pmbus, read(READ_VIN, _)) |
| 111 | .Times(2) |
| 112 | .WillOnce(Return(1)) |
| 113 | .WillOnce(Return(2)); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 114 | // Missing/present call will update Presence in inventory. |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 115 | EXPECT_CALL(util, setPresence(_, _, true, _)); |
| 116 | } |
| 117 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 118 | TEST_F(PowerSupplyTests, Constructor) |
| 119 | { |
| 120 | /** |
| 121 | * @param[in] invpath - String for inventory path to use |
| 122 | * @param[in] i2cbus - The bus number this power supply is on |
| 123 | * @param[in] i2caddr - The 16-bit I2C address of the power supply |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 124 | * @param[in] gpioLineName - The string for the gpio-line-name to read for |
| 125 | * presence. |
| 126 | * @param[in] bindDelay - Time in milliseconds to delay binding the device |
| 127 | * driver after seeing the presence line go active. |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 128 | */ |
| 129 | auto bus = sdbusplus::bus::new_default(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 130 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 131 | // Try where inventory path is empty, constructor should fail. |
| 132 | try |
| 133 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 134 | auto psu = |
| 135 | std::make_unique<PowerSupply>(bus, "", 3, 0x68, PSUGPIOLineName); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 136 | ADD_FAILURE() << "Should not have reached this line."; |
| 137 | } |
| 138 | catch (const std::invalid_argument& e) |
| 139 | { |
| 140 | EXPECT_STREQ(e.what(), "Invalid empty inventoryPath"); |
| 141 | } |
| 142 | catch (...) |
| 143 | { |
| 144 | ADD_FAILURE() << "Should not have caught exception."; |
| 145 | } |
| 146 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 147 | // TODO: Try invalid i2c address? |
| 148 | |
| 149 | // Try where gpioLineName is empty. |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 150 | try |
| 151 | { |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 152 | auto psu = |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 153 | std::make_unique<PowerSupply>(bus, PSUInventoryPath, 3, 0x68, ""); |
| 154 | ADD_FAILURE() |
| 155 | << "Should not have reached this line. Invalid gpioLineName."; |
| 156 | } |
| 157 | catch (const std::invalid_argument& e) |
| 158 | { |
| 159 | EXPECT_STREQ(e.what(), "Invalid empty gpioLineName"); |
| 160 | } |
| 161 | catch (...) |
| 162 | { |
| 163 | ADD_FAILURE() << "Should not have caught exception."; |
| 164 | } |
| 165 | |
| 166 | // Test with valid arguments |
| 167 | // NOT using D-Bus inventory path for presence. |
| 168 | try |
| 169 | { |
| 170 | auto psu = std::make_unique<PowerSupply>(bus, PSUInventoryPath, 3, 0x68, |
| 171 | PSUGPIOLineName); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 172 | |
| 173 | EXPECT_EQ(psu->isPresent(), false); |
| 174 | EXPECT_EQ(psu->isFaulted(), false); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 175 | EXPECT_EQ(psu->hasCommFault(), false); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 176 | EXPECT_EQ(psu->hasInputFault(), false); |
| 177 | EXPECT_EQ(psu->hasMFRFault(), false); |
| 178 | EXPECT_EQ(psu->hasVINUVFault(), false); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 179 | EXPECT_EQ(psu->hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 180 | EXPECT_EQ(psu->hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 181 | EXPECT_EQ(psu->hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 182 | EXPECT_EQ(psu->hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 183 | EXPECT_EQ(psu->hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 184 | EXPECT_EQ(psu->hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 185 | EXPECT_EQ(psu->hasPSKillFault(), false); |
| 186 | EXPECT_EQ(psu->hasPS12VcsFault(), false); |
| 187 | EXPECT_EQ(psu->hasPSCS12VFault(), false); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 188 | } |
| 189 | catch (...) |
| 190 | { |
| 191 | ADD_FAILURE() << "Should not have caught exception."; |
| 192 | } |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 193 | |
| 194 | // Test with valid arguments |
| 195 | // TODO: Using D-Bus inventory path for presence. |
| 196 | try |
| 197 | { |
| 198 | // FIXME: How do I get that presenceGPIO.read() in the startup to throw |
| 199 | // an exception? |
| 200 | |
| 201 | // EXPECT_CALL(mockedUtil, getPresence(_, |
| 202 | // StrEq(PSUInventoryPath))) |
| 203 | // .Times(1); |
| 204 | } |
| 205 | catch (...) |
| 206 | { |
| 207 | ADD_FAILURE() << "Should not have caught exception."; |
| 208 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | TEST_F(PowerSupplyTests, Analyze) |
| 212 | { |
| 213 | auto bus = sdbusplus::bus::new_default(); |
| 214 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 215 | { |
| 216 | // If I default to reading the GPIO, I will NOT expect a call to |
| 217 | // getPresence(). |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 218 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 219 | PowerSupply psu{bus, PSUInventoryPath, 4, 0x69, PSUGPIOLineName}; |
| 220 | MockedGPIOInterface* mockPresenceGPIO = |
| 221 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 222 | EXPECT_CALL(*mockPresenceGPIO, read()).Times(1).WillOnce(Return(0)); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 223 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 224 | psu.analyze(); |
| 225 | // By default, nothing should change. |
| 226 | EXPECT_EQ(psu.isPresent(), false); |
| 227 | EXPECT_EQ(psu.isFaulted(), false); |
| 228 | EXPECT_EQ(psu.hasInputFault(), false); |
| 229 | EXPECT_EQ(psu.hasMFRFault(), false); |
| 230 | EXPECT_EQ(psu.hasVINUVFault(), false); |
| 231 | EXPECT_EQ(psu.hasCommFault(), false); |
| 232 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 233 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 234 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 235 | EXPECT_EQ(psu.hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 236 | EXPECT_EQ(psu.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 237 | EXPECT_EQ(psu.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 238 | EXPECT_EQ(psu.hasPSKillFault(), false); |
| 239 | EXPECT_EQ(psu.hasPS12VcsFault(), false); |
| 240 | EXPECT_EQ(psu.hasPSCS12VFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 241 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 242 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 243 | PowerSupply psu2{bus, PSUInventoryPath, 5, 0x6a, PSUGPIOLineName}; |
| 244 | // In order to get the various faults tested, the power supply needs to |
| 245 | // be present in order to read from the PMBus device(s). |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 246 | MockedGPIOInterface* mockPresenceGPIO2 = |
| 247 | static_cast<MockedGPIOInterface*>(psu2.getPresenceGPIO()); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 248 | // Always return 1 to indicate present. |
| 249 | // Each analyze() call will trigger a read of the presence GPIO. |
| 250 | EXPECT_CALL(*mockPresenceGPIO2, read()).WillRepeatedly(Return(1)); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 251 | EXPECT_EQ(psu2.isPresent(), false); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 252 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 253 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu2.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 254 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 255 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 256 | // STATUS_WORD INPUT fault. |
| 257 | { |
| 258 | // Start with STATUS_WORD 0x0000. Powered on, no faults. |
| 259 | // Set expectations for a no fault |
| 260 | PMBusExpectations expectations; |
| 261 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 262 | // After reading STATUS_WORD, etc., there will be a READ_VIN check. |
| 263 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 264 | .Times(1) |
| 265 | .WillOnce(Return("206000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 266 | psu2.analyze(); |
| 267 | EXPECT_EQ(psu2.isPresent(), true); |
| 268 | EXPECT_EQ(psu2.isFaulted(), false); |
| 269 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 270 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 271 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 272 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 273 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 274 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 275 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 276 | EXPECT_EQ(psu2.hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 277 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 278 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 279 | EXPECT_EQ(psu2.hasPSKillFault(), false); |
| 280 | EXPECT_EQ(psu2.hasPS12VcsFault(), false); |
| 281 | EXPECT_EQ(psu2.hasPSCS12VFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 282 | |
| 283 | // Update expectations for STATUS_WORD input fault/warn |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 284 | // STATUS_INPUT fault bits ... on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 285 | expectations.statusWordValue = (status_word::INPUT_FAULT_WARN); |
| 286 | expectations.statusInputValue = 0x38; |
| 287 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 288 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 289 | .Times(1) |
| 290 | .WillOnce(Return("207000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 291 | psu2.analyze(); |
| 292 | EXPECT_EQ(psu2.isPresent(), true); |
| 293 | EXPECT_EQ(psu2.isFaulted(), true); |
| 294 | EXPECT_EQ(psu2.hasInputFault(), true); |
| 295 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 296 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 297 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 298 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 299 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 300 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 301 | EXPECT_EQ(psu2.hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 302 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 303 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 304 | EXPECT_EQ(psu2.hasPSKillFault(), false); |
| 305 | EXPECT_EQ(psu2.hasPS12VcsFault(), false); |
| 306 | EXPECT_EQ(psu2.hasPSCS12VFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 307 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 308 | |
| 309 | // STATUS_WORD INPUT/UV fault. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 310 | { |
| 311 | // First need it to return good status, then the fault |
| 312 | PMBusExpectations expectations; |
| 313 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 314 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 315 | .Times(1) |
| 316 | .WillOnce(Return("208000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 317 | psu2.analyze(); |
| 318 | // Now set fault bits in STATUS_WORD |
| 319 | expectations.statusWordValue = |
| 320 | (status_word::INPUT_FAULT_WARN | status_word::VIN_UV_FAULT); |
| 321 | // STATUS_INPUT fault bits ... on. |
| 322 | expectations.statusInputValue = 0x38; |
| 323 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 324 | // Input/UV fault, so voltage should read back low. |
| 325 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 326 | .Times(1) |
| 327 | .WillOnce(Return("19123")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 328 | psu2.analyze(); |
| 329 | EXPECT_EQ(psu2.isPresent(), true); |
| 330 | EXPECT_EQ(psu2.isFaulted(), true); |
| 331 | EXPECT_EQ(psu2.hasInputFault(), true); |
| 332 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 333 | EXPECT_EQ(psu2.hasVINUVFault(), true); |
| 334 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 335 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 336 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 337 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 338 | EXPECT_EQ(psu2.hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 339 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 340 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 341 | EXPECT_EQ(psu2.hasPSKillFault(), false); |
| 342 | EXPECT_EQ(psu2.hasPS12VcsFault(), false); |
| 343 | EXPECT_EQ(psu2.hasPSCS12VFault(), false); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 344 | |
| 345 | // Turning VIN_UV fault off causes clearing of faults, causing read of |
| 346 | // in1_input as an attempt to get CLEAR_FAULTS called. |
| 347 | expectations.statusWordValue = 0; |
| 348 | setPMBusExpectations(mockPMBus, expectations); |
| 349 | // The call to read the voltage |
| 350 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 351 | .Times(1) |
| 352 | .WillOnce(Return("209000")); |
| 353 | // The call for CLEAR_FAULTS command |
| 354 | EXPECT_CALL(mockPMBus, read(READ_VIN, _)).Times(1).WillOnce(Return(3)); |
| 355 | psu2.analyze(); |
| 356 | // Should remain present, no longer be faulted, no input fault, no |
| 357 | // VIN_UV fault. Nothing else should change. |
| 358 | EXPECT_EQ(psu2.isPresent(), true); |
| 359 | EXPECT_EQ(psu2.isFaulted(), false); |
| 360 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 361 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 362 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 363 | |
| 364 | // STATUS_WORD MFR fault. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 365 | { |
| 366 | // First need it to return good status, then the fault |
| 367 | PMBusExpectations expectations; |
| 368 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 369 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 370 | .Times(1) |
| 371 | .WillOnce(Return("210000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 372 | psu2.analyze(); |
| 373 | // Now STATUS_WORD with MFR fault bit on. |
| 374 | expectations.statusWordValue = (status_word::MFR_SPECIFIC_FAULT); |
| 375 | // STATUS_MFR bits on. |
| 376 | expectations.statusMFRValue = 0xFF; |
| 377 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 378 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 379 | .Times(1) |
| 380 | .WillOnce(Return("211000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 381 | psu2.analyze(); |
| 382 | EXPECT_EQ(psu2.isPresent(), true); |
| 383 | EXPECT_EQ(psu2.isFaulted(), true); |
| 384 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 385 | EXPECT_EQ(psu2.hasMFRFault(), true); |
| 386 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 387 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 388 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 389 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 390 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 391 | EXPECT_EQ(psu2.hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 392 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 393 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 394 | EXPECT_EQ(psu2.hasPSKillFault(), true); |
| 395 | EXPECT_EQ(psu2.hasPS12VcsFault(), true); |
| 396 | EXPECT_EQ(psu2.hasPSCS12VFault(), true); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 397 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 398 | |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 399 | // Temperature fault. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 400 | { |
| 401 | // First STATUS_WORD with no bits set, then with temperature fault. |
| 402 | PMBusExpectations expectations; |
| 403 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 404 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 405 | .Times(1) |
| 406 | .WillOnce(Return("212000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 407 | psu2.analyze(); |
| 408 | // STATUS_WORD with temperature fault bit on. |
| 409 | expectations.statusWordValue = (status_word::TEMPERATURE_FAULT_WARN); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 410 | // STATUS_TEMPERATURE with fault bit(s) on. |
| 411 | expectations.statusTempValue = 0x10; |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 412 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 413 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 414 | .Times(1) |
| 415 | .WillOnce(Return("213000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 416 | psu2.analyze(); |
| 417 | EXPECT_EQ(psu2.isPresent(), true); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 418 | EXPECT_EQ(psu2.isFaulted(), true); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 419 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 420 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 421 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 422 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 423 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 424 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 425 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 426 | EXPECT_EQ(psu2.hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 427 | EXPECT_EQ(psu2.hasTempFault(), true); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 428 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 429 | EXPECT_EQ(psu2.hasPSKillFault(), false); |
| 430 | EXPECT_EQ(psu2.hasPS12VcsFault(), false); |
| 431 | EXPECT_EQ(psu2.hasPSCS12VFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 432 | } |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 433 | |
| 434 | // CML fault |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 435 | { |
| 436 | // First STATUS_WORD wit no bits set, then with CML fault. |
| 437 | PMBusExpectations expectations; |
| 438 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 439 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 440 | .Times(1) |
| 441 | .WillOnce(Return("214000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 442 | psu2.analyze(); |
| 443 | // STATUS_WORD with CML fault bit on. |
| 444 | expectations.statusWordValue = (status_word::CML_FAULT); |
| 445 | // Turn on STATUS_CML fault bit(s) |
| 446 | expectations.statusCMLValue = 0xFF; |
| 447 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 448 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 449 | .Times(1) |
| 450 | .WillOnce(Return("215000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 451 | psu2.analyze(); |
| 452 | EXPECT_EQ(psu2.isPresent(), true); |
| 453 | EXPECT_EQ(psu2.isFaulted(), true); |
| 454 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 455 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 456 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 457 | EXPECT_EQ(psu2.hasCommFault(), true); |
| 458 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 459 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 460 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 461 | EXPECT_EQ(psu2.hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 462 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 463 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 464 | EXPECT_EQ(psu2.hasPSKillFault(), false); |
| 465 | EXPECT_EQ(psu2.hasPS12VcsFault(), false); |
| 466 | EXPECT_EQ(psu2.hasPSCS12VFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 467 | } |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 468 | |
| 469 | // VOUT_OV_FAULT fault |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 470 | { |
| 471 | // First STATUS_WORD with no bits set, then with VOUT/VOUT_OV fault. |
| 472 | PMBusExpectations expectations; |
| 473 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 474 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 475 | .Times(1) |
| 476 | .WillOnce(Return("216000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 477 | psu2.analyze(); |
| 478 | // STATUS_WORD with VOUT/VOUT_OV fault. |
| 479 | expectations.statusWordValue = |
| 480 | ((status_word::VOUT_FAULT) | (status_word::VOUT_OV_FAULT)); |
| 481 | // Turn on STATUS_VOUT fault bit(s) |
| 482 | expectations.statusVOUTValue = 0xA0; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 483 | // STATUS_TEMPERATURE don't care (default) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 484 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 485 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 486 | .Times(1) |
| 487 | .WillOnce(Return("217000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 488 | psu2.analyze(); |
| 489 | EXPECT_EQ(psu2.isPresent(), true); |
| 490 | EXPECT_EQ(psu2.isFaulted(), true); |
| 491 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 492 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 493 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 494 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 495 | EXPECT_EQ(psu2.hasVoutOVFault(), true); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 496 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 497 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 498 | EXPECT_EQ(psu2.hasFanFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 499 | EXPECT_EQ(psu2.hasTempFault(), false); |
| 500 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 501 | EXPECT_EQ(psu2.hasPSKillFault(), false); |
| 502 | EXPECT_EQ(psu2.hasPS12VcsFault(), false); |
| 503 | EXPECT_EQ(psu2.hasPSCS12VFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | // IOUT_OC_FAULT fault |
| 507 | { |
| 508 | // First STATUS_WORD with no bits set, then with IOUT_OC fault. |
| 509 | PMBusExpectations expectations; |
| 510 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 511 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 512 | .Times(1) |
| 513 | .WillOnce(Return("218000")); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 514 | psu2.analyze(); |
| 515 | // STATUS_WORD with IOUT_OC fault. |
| 516 | expectations.statusWordValue = status_word::IOUT_OC_FAULT; |
| 517 | // Turn on STATUS_IOUT fault bit(s) |
| 518 | expectations.statusIOUTValue = 0x88; |
| 519 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 520 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 521 | .Times(1) |
| 522 | .WillOnce(Return("219000")); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 523 | psu2.analyze(); |
| 524 | EXPECT_EQ(psu2.isPresent(), true); |
| 525 | EXPECT_EQ(psu2.isFaulted(), true); |
| 526 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 527 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 528 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 529 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 530 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
| 531 | EXPECT_EQ(psu2.hasIoutOCFault(), true); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 532 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 533 | EXPECT_EQ(psu2.hasFanFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 534 | EXPECT_EQ(psu2.hasTempFault(), false); |
| 535 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 536 | EXPECT_EQ(psu2.hasPSKillFault(), false); |
| 537 | EXPECT_EQ(psu2.hasPS12VcsFault(), false); |
| 538 | EXPECT_EQ(psu2.hasPSCS12VFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | // VOUT_UV_FAULT |
| 542 | { |
| 543 | // First STATUS_WORD with no bits set, then with VOUT fault. |
| 544 | PMBusExpectations expectations; |
| 545 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 546 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 547 | .Times(1) |
| 548 | .WillOnce(Return("220000")); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 549 | psu2.analyze(); |
| 550 | // Change STATUS_WORD to indicate VOUT fault. |
| 551 | expectations.statusWordValue = (status_word::VOUT_FAULT); |
| 552 | // Turn on STATUS_VOUT fault bit(s) |
| 553 | expectations.statusVOUTValue = 0x30; |
| 554 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 555 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 556 | .Times(1) |
| 557 | .WillOnce(Return("221000")); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 558 | psu2.analyze(); |
| 559 | EXPECT_EQ(psu2.isPresent(), true); |
| 560 | EXPECT_EQ(psu2.isFaulted(), true); |
| 561 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 562 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 563 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 564 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 565 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
| 566 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
| 567 | EXPECT_EQ(psu2.hasVoutUVFault(), true); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 568 | EXPECT_EQ(psu2.hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 569 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 570 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 571 | EXPECT_EQ(psu2.hasPSKillFault(), false); |
| 572 | EXPECT_EQ(psu2.hasPS12VcsFault(), false); |
| 573 | EXPECT_EQ(psu2.hasPSCS12VFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 574 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 575 | |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 576 | // Fan fault |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 577 | { |
| 578 | // First STATUS_WORD with no bits set, then with fan fault. |
| 579 | PMBusExpectations expectations; |
| 580 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 581 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 582 | .Times(1) |
| 583 | .WillOnce(Return("222000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 584 | psu2.analyze(); |
| 585 | expectations.statusWordValue = (status_word::FAN_FAULT); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 586 | // STATUS_FANS_1_2 with fan 1 warning & fault bits on. |
| 587 | expectations.statusFans12Value = 0xA0; |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 588 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 589 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 590 | .Times(1) |
| 591 | .WillOnce(Return("223000")); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 592 | psu2.analyze(); |
| 593 | EXPECT_EQ(psu2.isPresent(), true); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 594 | EXPECT_EQ(psu2.isFaulted(), true); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 595 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 596 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 597 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 598 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 599 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 600 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 601 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 602 | EXPECT_EQ(psu2.hasFanFault(), true); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 603 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 604 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 605 | EXPECT_EQ(psu2.hasPSKillFault(), false); |
| 606 | EXPECT_EQ(psu2.hasPS12VcsFault(), false); |
| 607 | EXPECT_EQ(psu2.hasPSCS12VFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 608 | } |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 609 | |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 610 | // PGOOD/OFF fault. Deglitched, needs to reach DEGLITCH_LIMIT. |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 611 | { |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 612 | // First STATUS_WORD with no bits set. |
| 613 | PMBusExpectations expectations; |
| 614 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 615 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 616 | .Times(1) |
| 617 | .WillOnce(Return("123000")); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 618 | psu2.analyze(); |
| 619 | EXPECT_EQ(psu2.isFaulted(), false); |
| 620 | // POWER_GOOD# inactive, and OFF bit on. |
| 621 | expectations.statusWordValue = |
| 622 | ((status_word::POWER_GOOD_NEGATED) | (status_word::UNIT_IS_OFF)); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 623 | for (auto x = 1; x <= DEGLITCH_LIMIT; x++) |
| 624 | { |
| 625 | // STATUS_INPUT, STATUS_MFR, STATUS_CML, STATUS_VOUT, and |
| 626 | // STATUS_TEMPERATURE: Don't care if bits set or not (defaults). |
| 627 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 628 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 629 | .Times(1) |
| 630 | .WillOnce(Return("124000")); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 631 | psu2.analyze(); |
| 632 | EXPECT_EQ(psu2.isPresent(), true); |
| 633 | if (x < DEGLITCH_LIMIT) |
| 634 | { |
| 635 | EXPECT_EQ(psu2.isFaulted(), false); |
| 636 | } |
| 637 | else |
| 638 | { |
| 639 | EXPECT_EQ(psu2.isFaulted(), true); |
| 640 | } |
| 641 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 642 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 643 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 644 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 645 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
| 646 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
| 647 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
| 648 | EXPECT_EQ(psu2.hasFanFault(), false); |
| 649 | EXPECT_EQ(psu2.hasTempFault(), false); |
| 650 | if (x < DEGLITCH_LIMIT) |
| 651 | { |
| 652 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
| 653 | } |
| 654 | else |
| 655 | { |
| 656 | EXPECT_EQ(psu2.hasPgoodFault(), true); |
| 657 | } |
| 658 | } |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 661 | // TODO: ReadFailure |
| 662 | } |
| 663 | |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 664 | TEST_F(PowerSupplyTests, OnOffConfig) |
| 665 | { |
| 666 | auto bus = sdbusplus::bus::new_default(); |
| 667 | uint8_t data = 0x15; |
| 668 | |
| 669 | // Test where PSU is NOT present |
| 670 | try |
| 671 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 672 | // Assume GPIO presence, not inventory presence? |
| 673 | PowerSupply psu{bus, PSUInventoryPath, 4, 0x69, PSUGPIOLineName}; |
| 674 | |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 675 | MockedGPIOInterface* mockPresenceGPIO = |
| 676 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 677 | ON_CALL(*mockPresenceGPIO, read()).WillByDefault(Return(0)); |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 678 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 679 | // Constructor should set initial presence, default read returns 0. |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 680 | // If it is not present, I should not be trying to write to it. |
| 681 | EXPECT_CALL(mockPMBus, writeBinary(_, _, _)).Times(0); |
| 682 | psu.onOffConfig(data); |
| 683 | } |
| 684 | catch (...) |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 685 | {} |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 686 | |
| 687 | // Test where PSU is present |
| 688 | try |
| 689 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 690 | // Assume GPIO presence, not inventory presence? |
| 691 | PowerSupply psu{bus, PSUInventoryPath, 5, 0x6a, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 692 | MockedGPIOInterface* mockPresenceGPIO = |
| 693 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 694 | // There will potentially be multiple calls, we want it to continue |
| 695 | // returning 1 for the GPIO read to keep the power supply present. |
| 696 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 697 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 698 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
| 699 | // If I am calling analyze(), I should probably give it good data. |
| 700 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 701 | PMBusExpectations expectations; |
| 702 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 703 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 704 | .Times(1) |
| 705 | .WillOnce(Return("205000")); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 706 | psu.analyze(); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 707 | // I definitely should be writting ON_OFF_CONFIG if I call the function |
| 708 | EXPECT_CALL(mockPMBus, writeBinary(ON_OFF_CONFIG, ElementsAre(0x15), |
| 709 | Type::HwmonDeviceDebug)) |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 710 | .Times(1); |
| 711 | psu.onOffConfig(data); |
| 712 | } |
| 713 | catch (...) |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 714 | {} |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 715 | } |
| 716 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 717 | TEST_F(PowerSupplyTests, ClearFaults) |
| 718 | { |
| 719 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 720 | PowerSupply psu{bus, PSUInventoryPath, 13, 0x68, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 721 | MockedGPIOInterface* mockPresenceGPIO = |
| 722 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 723 | // Always return 1 to indicate present. |
| 724 | // Each analyze() call will trigger a read of the presence GPIO. |
| 725 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 726 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 727 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 728 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 729 | PMBusExpectations expectations; |
| 730 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 731 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 732 | .Times(1) |
| 733 | .WillOnce(Return("207000")); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 734 | psu.analyze(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 735 | EXPECT_EQ(psu.isPresent(), true); |
| 736 | EXPECT_EQ(psu.isFaulted(), false); |
| 737 | EXPECT_EQ(psu.hasInputFault(), false); |
| 738 | EXPECT_EQ(psu.hasMFRFault(), false); |
| 739 | EXPECT_EQ(psu.hasVINUVFault(), false); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 740 | EXPECT_EQ(psu.hasCommFault(), false); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 741 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 742 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 743 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 744 | EXPECT_EQ(psu.hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 745 | EXPECT_EQ(psu.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 746 | EXPECT_EQ(psu.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 747 | EXPECT_EQ(psu.hasPSKillFault(), false); |
| 748 | EXPECT_EQ(psu.hasPS12VcsFault(), false); |
| 749 | EXPECT_EQ(psu.hasPSCS12VFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 750 | |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 751 | // STATUS_WORD with fault bits galore! |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 752 | expectations.statusWordValue = 0xFFFF; |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 753 | // STATUS_INPUT with fault bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 754 | expectations.statusInputValue = 0xFF; |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 755 | // STATUS_MFR_SPEFIC with bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 756 | expectations.statusMFRValue = 0xFF; |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 757 | // STATUS_CML with bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 758 | expectations.statusCMLValue = 0xFF; |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 759 | // STATUS_VOUT with bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 760 | expectations.statusVOUTValue = 0xFF; |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 761 | // STATUS_IOUT with bits on. |
| 762 | expectations.statusIOUTValue = 0xFF; |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 763 | // STATUS_FANS_1_2 with bits on. |
| 764 | expectations.statusFans12Value = 0xFF; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 765 | // STATUS_TEMPERATURE with bits on. |
| 766 | expectations.statusTempValue = 0xFF; |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 767 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 768 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 769 | .Times(1) |
| 770 | .WillOnce(Return("0")); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 771 | psu.analyze(); |
| 772 | EXPECT_EQ(psu.isPresent(), true); |
| 773 | EXPECT_EQ(psu.isFaulted(), true); |
| 774 | EXPECT_EQ(psu.hasInputFault(), true); |
| 775 | EXPECT_EQ(psu.hasMFRFault(), true); |
| 776 | EXPECT_EQ(psu.hasVINUVFault(), true); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 777 | EXPECT_EQ(psu.hasCommFault(), true); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 778 | EXPECT_EQ(psu.hasVoutOVFault(), true); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 779 | EXPECT_EQ(psu.hasIoutOCFault(), true); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 780 | // Cannot have VOUT_OV_FAULT and VOUT_UV_FAULT. |
| 781 | // Rely on HasVoutUVFault() to verify this sets and clears. |
| 782 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 783 | EXPECT_EQ(psu.hasFanFault(), true); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 784 | EXPECT_EQ(psu.hasTempFault(), true); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 785 | // pgoodFault is deglitched up to DEGLITCH_LIMIT |
| 786 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 787 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 788 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 789 | .Times(1) |
| 790 | .WillOnce(Return("0")); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 791 | psu.analyze(); |
| 792 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 793 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 794 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 795 | .Times(1) |
| 796 | .WillOnce(Return("0")); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 797 | psu.analyze(); |
| 798 | // DEGLITCH_LIMIT reached for pgoodFault |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 799 | EXPECT_EQ(psu.hasPgoodFault(), true); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 800 | EXPECT_EQ(psu.hasPSKillFault(), true); |
| 801 | EXPECT_EQ(psu.hasPS12VcsFault(), true); |
| 802 | EXPECT_EQ(psu.hasPSCS12VFault(), true); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 803 | // This is the CLEAR_FAULTS read that does not check the return value. |
| 804 | EXPECT_CALL(mockPMBus, read(READ_VIN, _)).Times(1).WillOnce(Return(3)); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 805 | psu.clearFaults(); |
| 806 | EXPECT_EQ(psu.isPresent(), true); |
| 807 | EXPECT_EQ(psu.isFaulted(), false); |
| 808 | EXPECT_EQ(psu.hasInputFault(), false); |
| 809 | EXPECT_EQ(psu.hasMFRFault(), false); |
| 810 | EXPECT_EQ(psu.hasVINUVFault(), false); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 811 | EXPECT_EQ(psu.hasCommFault(), false); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 812 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 813 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 814 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 815 | EXPECT_EQ(psu.hasFanFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 816 | EXPECT_EQ(psu.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 817 | EXPECT_EQ(psu.hasPgoodFault(), false); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 818 | EXPECT_EQ(psu.hasPSKillFault(), false); |
| 819 | EXPECT_EQ(psu.hasPS12VcsFault(), false); |
| 820 | EXPECT_EQ(psu.hasPSCS12VFault(), false); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 821 | |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 822 | // Faults clear on READ_VIN 0 -> !0 |
| 823 | // STATUS_WORD with fault bits galore! |
| 824 | expectations.statusWordValue = 0xFFFF; |
| 825 | // STATUS_INPUT with fault bits on. |
| 826 | expectations.statusInputValue = 0xFF; |
| 827 | // STATUS_MFR_SPEFIC with bits on. |
| 828 | expectations.statusMFRValue = 0xFF; |
| 829 | // STATUS_CML with bits on. |
| 830 | expectations.statusCMLValue = 0xFF; |
| 831 | // STATUS_VOUT with bits on. |
| 832 | expectations.statusVOUTValue = 0xFF; |
| 833 | // STATUS_IOUT with bits on. |
| 834 | expectations.statusIOUTValue = 0xFF; |
| 835 | // STATUS_FANS_1_2 with bits on. |
| 836 | expectations.statusFans12Value = 0xFF; |
| 837 | // STATUS_TEMPERATURE with bits on. |
| 838 | expectations.statusTempValue = 0xFF; |
| 839 | setPMBusExpectations(mockPMBus, expectations); |
| 840 | EXPECT_CALL(mockPMBus, read(READ_VIN, _)).Times(1).WillOnce(Return(0)); |
| 841 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 842 | .Times(1) |
| 843 | .WillOnce(Return("0")); |
| 844 | psu.analyze(); |
| 845 | EXPECT_EQ(psu.isPresent(), true); |
| 846 | EXPECT_EQ(psu.isFaulted(), true); |
| 847 | EXPECT_EQ(psu.hasInputFault(), true); |
| 848 | EXPECT_EQ(psu.hasMFRFault(), true); |
| 849 | EXPECT_EQ(psu.hasVINUVFault(), true); |
| 850 | // True due to CML fault bits on |
| 851 | EXPECT_EQ(psu.hasCommFault(), true); |
| 852 | EXPECT_EQ(psu.hasVoutOVFault(), true); |
| 853 | EXPECT_EQ(psu.hasIoutOCFault(), true); |
| 854 | // Cannot have VOUT_OV_FAULT and VOUT_UV_FAULT. |
| 855 | // Rely on HasVoutUVFault() to verify this sets and clears. |
| 856 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
| 857 | EXPECT_EQ(psu.hasFanFault(), true); |
| 858 | EXPECT_EQ(psu.hasTempFault(), true); |
| 859 | // PGOOD fault is deglitched before hasPgoodFault() returns true. |
| 860 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 861 | EXPECT_EQ(psu.hasPSKillFault(), true); |
| 862 | EXPECT_EQ(psu.hasPS12VcsFault(), true); |
| 863 | EXPECT_EQ(psu.hasPSCS12VFault(), true); |
| 864 | // STATUS_WORD with INPUT/VIN_UV fault bits off. |
| 865 | expectations.statusWordValue = 0xDFF7; |
| 866 | // STATUS_INPUT with VIN_UV_WARNING, VIN_UV_FAULT, and Unit Off For |
| 867 | // Insufficient Input Voltage bits off. |
| 868 | expectations.statusInputValue = 0xC7; |
| 869 | setPMBusExpectations(mockPMBus, expectations); |
| 870 | // READ_VIN back in range. |
| 871 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 872 | .Times(1) |
| 873 | .WillOnce(Return("206000")); |
| 874 | psu.analyze(); |
| 875 | EXPECT_EQ(psu.isPresent(), true); |
| 876 | EXPECT_EQ(psu.isFaulted(), false); |
| 877 | EXPECT_EQ(psu.hasInputFault(), false); |
| 878 | EXPECT_EQ(psu.hasMFRFault(), false); |
| 879 | EXPECT_EQ(psu.hasVINUVFault(), false); |
| 880 | EXPECT_EQ(psu.hasCommFault(), false); |
| 881 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
| 882 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
| 883 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
| 884 | EXPECT_EQ(psu.hasFanFault(), false); |
| 885 | EXPECT_EQ(psu.hasTempFault(), false); |
| 886 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 887 | EXPECT_EQ(psu.hasPSKillFault(), false); |
| 888 | EXPECT_EQ(psu.hasPS12VcsFault(), false); |
| 889 | EXPECT_EQ(psu.hasPSCS12VFault(), false); |
| 890 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 891 | // TODO: Faults clear on missing/present? |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | TEST_F(PowerSupplyTests, UpdateInventory) |
| 895 | { |
| 896 | auto bus = sdbusplus::bus::new_default(); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 897 | |
| 898 | try |
| 899 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 900 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x68, PSUGPIOLineName}; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 901 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 902 | // If it is not present, I should not be trying to read a string |
| 903 | EXPECT_CALL(mockPMBus, readString(_, _)).Times(0); |
| 904 | psu.updateInventory(); |
| 905 | } |
| 906 | catch (...) |
| 907 | { |
| 908 | ADD_FAILURE() << "Should not have caught exception."; |
| 909 | } |
| 910 | |
| 911 | try |
| 912 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 913 | PowerSupply psu{bus, PSUInventoryPath, 13, 0x69, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 914 | MockedGPIOInterface* mockPresenceGPIO = |
| 915 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 916 | // GPIO read return 1 to indicate present. |
| 917 | EXPECT_CALL(*mockPresenceGPIO, read()).Times(1).WillOnce(Return(1)); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 918 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 919 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
| 920 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 921 | PMBusExpectations expectations; |
| 922 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 923 | // Call to analyze will read voltage, trigger clear faults for 0 to |
| 924 | // within range. |
| 925 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 926 | .Times(1) |
| 927 | .WillOnce(Return("123456")); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 928 | psu.analyze(); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 929 | EXPECT_CALL(mockPMBus, readString(_, _)).WillRepeatedly(Return("")); |
| 930 | psu.updateInventory(); |
| 931 | |
Brandon Wyman | 3c530fb | 2021-04-13 13:13:22 -0500 | [diff] [blame] | 932 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 933 | EXPECT_CALL(mockPMBus, readString(_, _)) |
| 934 | .WillOnce(Return("CCIN")) |
| 935 | .WillOnce(Return("PN3456")) |
| 936 | .WillOnce(Return("FN3456")) |
| 937 | .WillOnce(Return("HEADER")) |
| 938 | .WillOnce(Return("SN3456")) |
| 939 | .WillOnce(Return("FW3456")); |
Brandon Wyman | 3c530fb | 2021-04-13 13:13:22 -0500 | [diff] [blame] | 940 | #endif |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 941 | psu.updateInventory(); |
| 942 | // TODO: D-Bus mocking to verify values stored on D-Bus (???) |
| 943 | } |
| 944 | catch (...) |
| 945 | { |
| 946 | ADD_FAILURE() << "Should not have caught exception."; |
| 947 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | TEST_F(PowerSupplyTests, IsPresent) |
| 951 | { |
| 952 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 953 | |
| 954 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x68, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 955 | MockedGPIOInterface* mockPresenceGPIO = |
| 956 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 957 | EXPECT_EQ(psu.isPresent(), false); |
| 958 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 959 | // Change GPIO read to return 1 to indicate present. |
| 960 | EXPECT_CALL(*mockPresenceGPIO, read()).Times(1).WillOnce(Return(1)); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 961 | // Call to analyze() will update to present, that will trigger updating |
| 962 | // to the correct/latest HWMON directory, in case it changes. |
| 963 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 964 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
| 965 | // Call to analyze things will trigger read of STATUS_WORD and READ_VIN. |
| 966 | // Default expectations will be on, no faults. |
| 967 | PMBusExpectations expectations; |
| 968 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 969 | // Give it an input voltage in the 100-volt range. |
| 970 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 971 | .Times(1) |
| 972 | .WillOnce(Return("123456")); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 973 | psu.analyze(); |
| 974 | EXPECT_EQ(psu.isPresent(), true); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | TEST_F(PowerSupplyTests, IsFaulted) |
| 978 | { |
| 979 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 980 | |
| 981 | PowerSupply psu{bus, PSUInventoryPath, 11, 0x6f, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 982 | MockedGPIOInterface* mockPresenceGPIO = |
| 983 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 984 | // Always return 1 to indicate present. |
| 985 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 986 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 987 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
| 988 | // Call to analyze things will trigger read of STATUS_WORD and READ_VIN. |
| 989 | // Default expectations will be on, no faults. |
| 990 | PMBusExpectations expectations; |
| 991 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 992 | // Give it an input voltage in the 100-volt range. |
| 993 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 994 | .Times(1) |
| 995 | .WillOnce(Return("124680")); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 996 | psu.analyze(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 997 | EXPECT_EQ(psu.isFaulted(), false); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 998 | // STATUS_WORD with fault bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 999 | expectations.statusWordValue = 0xFFFF; |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1000 | // STATUS_INPUT with fault bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1001 | expectations.statusInputValue = 0xFF; |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1002 | // STATUS_MFR_SPECIFIC with faults bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1003 | expectations.statusMFRValue = 0xFF; |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 1004 | // STATUS_CML with faults bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1005 | expectations.statusCMLValue = 0xFF; |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 1006 | // STATUS_VOUT with fault bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1007 | expectations.statusVOUTValue = 0xFF; |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 1008 | // STATUS_IOUT with fault bits on. |
| 1009 | expectations.statusIOUTValue = 0xFF; |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 1010 | // STATUS_FANS_1_2 with bits on. |
| 1011 | expectations.statusFans12Value = 0xFF; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 1012 | // STATUS_TEMPERATURE with fault bits on. |
| 1013 | expectations.statusTempValue = 0xFF; |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1014 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1015 | // Also get another read of READ_VIN. |
| 1016 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1017 | .Times(1) |
| 1018 | .WillOnce(Return("125790")); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1019 | psu.analyze(); |
| 1020 | EXPECT_EQ(psu.isFaulted(), true); |
| 1021 | } |
| 1022 | |
| 1023 | TEST_F(PowerSupplyTests, HasInputFault) |
| 1024 | { |
| 1025 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 1026 | |
| 1027 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x68, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 1028 | MockedGPIOInterface* mockPresenceGPIO = |
| 1029 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 1030 | // Always return 1 to indicate present. |
| 1031 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1032 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1033 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 1034 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1035 | PMBusExpectations expectations; |
| 1036 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1037 | // Analyze call will also need good READ_VIN value to check. |
| 1038 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1039 | .Times(1) |
| 1040 | .WillOnce(Return("201100")); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1041 | psu.analyze(); |
| 1042 | EXPECT_EQ(psu.hasInputFault(), false); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1043 | // STATUS_WORD with input fault/warn on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1044 | expectations.statusWordValue = (status_word::INPUT_FAULT_WARN); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1045 | // STATUS_INPUT with an input fault bit on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1046 | expectations.statusInputValue = 0x80; |
| 1047 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1048 | // Analyze call will also need good READ_VIN value to check. |
| 1049 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1050 | .Times(1) |
| 1051 | .WillOnce(Return("201200")); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1052 | psu.analyze(); |
| 1053 | EXPECT_EQ(psu.hasInputFault(), true); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1054 | // STATUS_WORD with no bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1055 | expectations.statusWordValue = 0; |
| 1056 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1057 | // Analyze call will also need good READ_VIN value to check. |
| 1058 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1059 | .Times(1) |
| 1060 | .WillOnce(Return("201300")); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1061 | psu.analyze(); |
| 1062 | EXPECT_EQ(psu.hasInputFault(), false); |
| 1063 | } |
| 1064 | |
| 1065 | TEST_F(PowerSupplyTests, HasMFRFault) |
| 1066 | { |
| 1067 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 1068 | |
| 1069 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x68, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 1070 | MockedGPIOInterface* mockPresenceGPIO = |
| 1071 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 1072 | // Always return 1 to indicate present. |
| 1073 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1074 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1075 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1076 | // First return STATUS_WORD with no bits on. |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 1077 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1078 | PMBusExpectations expectations; |
| 1079 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1080 | // Analyze call will also need good READ_VIN value to check. |
| 1081 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1082 | .Times(1) |
| 1083 | .WillOnce(Return("202100")); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1084 | psu.analyze(); |
| 1085 | EXPECT_EQ(psu.hasMFRFault(), false); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1086 | // Next return STATUS_WORD with MFR fault bit on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1087 | expectations.statusWordValue = (status_word::MFR_SPECIFIC_FAULT); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1088 | // STATUS_MFR_SPEFIC with bit(s) on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1089 | expectations.statusMFRValue = 0xFF; |
| 1090 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1091 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1092 | .Times(1) |
| 1093 | .WillOnce(Return("202200")); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1094 | psu.analyze(); |
| 1095 | EXPECT_EQ(psu.hasMFRFault(), true); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1096 | // Back to no bits on in STATUS_WORD |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1097 | expectations.statusWordValue = 0; |
| 1098 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1099 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1100 | .Times(1) |
| 1101 | .WillOnce(Return("202300")); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1102 | psu.analyze(); |
| 1103 | EXPECT_EQ(psu.hasMFRFault(), false); |
| 1104 | } |
| 1105 | |
| 1106 | TEST_F(PowerSupplyTests, HasVINUVFault) |
| 1107 | { |
| 1108 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 1109 | |
| 1110 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x68, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 1111 | MockedGPIOInterface* mockPresenceGPIO = |
| 1112 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 1113 | // Always return 1 to indicate present. |
| 1114 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1115 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1116 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1117 | |
| 1118 | // Presence change from missing to present will trigger in1_input read in |
| 1119 | // an attempt to get CLEAR_FAULTS called. Return value ignored. |
| 1120 | // Zero to non-zero voltage, for missing/present change, triggers clear |
| 1121 | // faults call again. Return value ignored. |
| 1122 | // Fault (low voltage) to not faulted (voltage in range) triggers clear |
| 1123 | // faults call a third time. |
| 1124 | |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 1125 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1126 | PMBusExpectations expectations; |
| 1127 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1128 | // Analyze call will also need good READ_VIN value to check. |
| 1129 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1130 | .Times(1) |
| 1131 | .WillOnce(Return("201100")); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1132 | psu.analyze(); |
| 1133 | EXPECT_EQ(psu.hasVINUVFault(), false); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1134 | // Turn fault on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1135 | expectations.statusWordValue = (status_word::VIN_UV_FAULT); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 1136 | // Curious disagreement between PMBus Spec. Part II Figure 16 and 33. Go by |
| 1137 | // Figure 16, and assume bits on in STATUS_INPUT. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1138 | expectations.statusInputValue = 0x18; |
| 1139 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1140 | // If there is a VIN_UV fault, fake reading voltage of less than 20V |
| 1141 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1142 | .Times(1) |
| 1143 | .WillOnce(Return("19876")); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1144 | psu.analyze(); |
| 1145 | EXPECT_EQ(psu.hasVINUVFault(), true); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 1146 | // Back to no fault bits on in STATUS_WORD |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1147 | expectations.statusWordValue = 0; |
| 1148 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1149 | // Updates now result in clearing faults if read voltage goes from below the |
| 1150 | // minimum, to within a valid range. |
| 1151 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1152 | .Times(1) |
| 1153 | .WillOnce(Return("201300")); |
| 1154 | // Went from below minimum to within range, expect CLEAR_FAULTS. |
| 1155 | EXPECT_CALL(mockPMBus, read(READ_VIN, _)).Times(1).WillOnce(Return(3)); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 1156 | psu.analyze(); |
| 1157 | EXPECT_EQ(psu.hasVINUVFault(), false); |
| 1158 | } |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 1159 | |
| 1160 | TEST_F(PowerSupplyTests, HasVoutOVFault) |
| 1161 | { |
| 1162 | auto bus = sdbusplus::bus::new_default(); |
| 1163 | |
| 1164 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x69, PSUGPIOLineName}; |
| 1165 | MockedGPIOInterface* mockPresenceGPIO = |
| 1166 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 1167 | // Always return 1 to indicate present. |
| 1168 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 1169 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1170 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 1171 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1172 | PMBusExpectations expectations; |
| 1173 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1174 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1175 | // Initial value would be 0, so this read updates it to non-zero. |
| 1176 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1177 | .Times(1) |
| 1178 | .WillOnce(Return("202100")); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 1179 | psu.analyze(); |
| 1180 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
| 1181 | // Turn fault on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1182 | expectations.statusWordValue = (status_word::VOUT_OV_FAULT); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 1183 | // STATUS_VOUT fault bit(s) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1184 | expectations.statusVOUTValue = 0x80; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 1185 | // STATUS_TEMPERATURE default. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1186 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1187 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1188 | .Times(1) |
| 1189 | .WillOnce(Return("202200")); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 1190 | psu.analyze(); |
| 1191 | EXPECT_EQ(psu.hasVoutOVFault(), true); |
| 1192 | // Back to no fault bits on in STATUS_WORD |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 1193 | expectations.statusWordValue = 0; |
| 1194 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1195 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1196 | .Times(1) |
| 1197 | .WillOnce(Return("202300")); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 1198 | psu.analyze(); |
| 1199 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
| 1200 | } |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 1201 | |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 1202 | TEST_F(PowerSupplyTests, HasIoutOCFault) |
| 1203 | { |
| 1204 | auto bus = sdbusplus::bus::new_default(); |
| 1205 | |
| 1206 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x6d, PSUGPIOLineName}; |
| 1207 | MockedGPIOInterface* mockPresenceGPIO = |
| 1208 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 1209 | // Always return 1 to indicate present. |
| 1210 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 1211 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1212 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 1213 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 1214 | PMBusExpectations expectations; |
| 1215 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1216 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1217 | // Initial value would be 0, so this read updates it to non-zero. |
| 1218 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1219 | .Times(1) |
| 1220 | .WillOnce(Return("203100")); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 1221 | psu.analyze(); |
| 1222 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
| 1223 | // Turn fault on. |
| 1224 | expectations.statusWordValue = status_word::IOUT_OC_FAULT; |
| 1225 | // STATUS_IOUT fault bit(s) |
| 1226 | expectations.statusIOUTValue = 0x88; |
| 1227 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1228 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1229 | .Times(1) |
| 1230 | .WillOnce(Return("203200")); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 1231 | psu.analyze(); |
| 1232 | EXPECT_EQ(psu.hasIoutOCFault(), true); |
| 1233 | // Back to no fault bits on in STATUS_WORD |
| 1234 | expectations.statusWordValue = 0; |
| 1235 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1236 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1237 | .Times(1) |
| 1238 | .WillOnce(Return("203300")); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 1239 | psu.analyze(); |
| 1240 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
| 1241 | } |
| 1242 | |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 1243 | TEST_F(PowerSupplyTests, HasVoutUVFault) |
| 1244 | { |
| 1245 | auto bus = sdbusplus::bus::new_default(); |
| 1246 | |
| 1247 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x6a, PSUGPIOLineName}; |
| 1248 | MockedGPIOInterface* mockPresenceGPIO = |
| 1249 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 1250 | // Always return 1 to indicate present. |
| 1251 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 1252 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1253 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
| 1254 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 1255 | PMBusExpectations expectations; |
| 1256 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1257 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1258 | // Initial value would be 0, so this read updates it to non-zero. |
| 1259 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1260 | .Times(1) |
| 1261 | .WillOnce(Return("204100")); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 1262 | psu.analyze(); |
| 1263 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
| 1264 | // Turn fault on. |
| 1265 | expectations.statusWordValue = (status_word::VOUT_FAULT); |
| 1266 | // STATUS_VOUT fault bit(s) |
| 1267 | expectations.statusVOUTValue = 0x30; |
| 1268 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1269 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1270 | .Times(1) |
| 1271 | .WillOnce(Return("204200")); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 1272 | psu.analyze(); |
| 1273 | EXPECT_EQ(psu.hasVoutUVFault(), true); |
| 1274 | // Back to no fault bits on in STATUS_WORD |
| 1275 | expectations.statusWordValue = 0; |
| 1276 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1277 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1278 | .Times(1) |
| 1279 | .WillOnce(Return("204300")); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 1280 | psu.analyze(); |
| 1281 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
| 1282 | } |
| 1283 | |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 1284 | TEST_F(PowerSupplyTests, HasFanFault) |
| 1285 | { |
| 1286 | auto bus = sdbusplus::bus::new_default(); |
| 1287 | |
| 1288 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x6d, PSUGPIOLineName}; |
| 1289 | MockedGPIOInterface* mockPresenceGPIO = |
| 1290 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 1291 | // Always return 1 to indicate present. |
| 1292 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 1293 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1294 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 1295 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 1296 | PMBusExpectations expectations; |
| 1297 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1298 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1299 | // Initial value would be 0, so this read updates it to non-zero. |
| 1300 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1301 | .Times(1) |
| 1302 | .WillOnce(Return("205100")); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 1303 | psu.analyze(); |
| 1304 | EXPECT_EQ(psu.hasFanFault(), false); |
| 1305 | // Turn fault on. |
| 1306 | expectations.statusWordValue = (status_word::FAN_FAULT); |
| 1307 | // STATUS_FANS_1_2 fault bit on (Fan 1 Fault) |
| 1308 | expectations.statusFans12Value = 0x80; |
| 1309 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1310 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1311 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1312 | .Times(1) |
| 1313 | .WillOnce(Return("205200")); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 1314 | psu.analyze(); |
| 1315 | EXPECT_EQ(psu.hasFanFault(), true); |
| 1316 | // Back to no fault bits on in STATUS_WORD |
| 1317 | expectations.statusWordValue = 0; |
| 1318 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1319 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1320 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1321 | .Times(1) |
| 1322 | .WillOnce(Return("205300")); |
Brandon Wyman | 7ee4d7e | 2021-11-19 20:48:23 +0000 | [diff] [blame] | 1323 | psu.analyze(); |
| 1324 | EXPECT_EQ(psu.hasFanFault(), false); |
| 1325 | } |
| 1326 | |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 1327 | TEST_F(PowerSupplyTests, HasTempFault) |
| 1328 | { |
| 1329 | auto bus = sdbusplus::bus::new_default(); |
| 1330 | |
| 1331 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x6a, PSUGPIOLineName}; |
| 1332 | MockedGPIOInterface* mockPresenceGPIO = |
| 1333 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 1334 | // Always return 1 to indicate present. |
| 1335 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 1336 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1337 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 1338 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 1339 | PMBusExpectations expectations; |
| 1340 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1341 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1342 | // Initial value would be 0, so this read updates it to non-zero. |
| 1343 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1344 | .Times(1) |
| 1345 | .WillOnce(Return("206100")); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 1346 | psu.analyze(); |
| 1347 | EXPECT_EQ(psu.hasTempFault(), false); |
| 1348 | // Turn fault on. |
| 1349 | expectations.statusWordValue = (status_word::TEMPERATURE_FAULT_WARN); |
| 1350 | // STATUS_TEMPERATURE fault bit on (OT Fault) |
| 1351 | expectations.statusTempValue = 0x80; |
| 1352 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1353 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1354 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1355 | .Times(1) |
| 1356 | .WillOnce(Return("206200")); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 1357 | psu.analyze(); |
| 1358 | EXPECT_EQ(psu.hasTempFault(), true); |
| 1359 | // Back to no fault bits on in STATUS_WORD |
| 1360 | expectations.statusWordValue = 0; |
| 1361 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1362 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1363 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1364 | .Times(1) |
| 1365 | .WillOnce(Return("206300")); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 1366 | psu.analyze(); |
| 1367 | EXPECT_EQ(psu.hasTempFault(), false); |
| 1368 | } |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1369 | |
| 1370 | TEST_F(PowerSupplyTests, HasPgoodFault) |
| 1371 | { |
| 1372 | auto bus = sdbusplus::bus::new_default(); |
| 1373 | |
| 1374 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x6b, PSUGPIOLineName}; |
| 1375 | MockedGPIOInterface* mockPresenceGPIO = |
| 1376 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 1377 | // Always return 1 to indicate present. |
| 1378 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1379 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1380 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1381 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 1382 | PMBusExpectations expectations; |
| 1383 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1384 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1385 | // Initial value would be 0, so this read updates it to non-zero. |
| 1386 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1387 | .Times(1) |
| 1388 | .WillOnce(Return("207100")); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1389 | psu.analyze(); |
| 1390 | EXPECT_EQ(psu.hasPgoodFault(), false); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1391 | // Setup another expectation of no faults. |
| 1392 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1393 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1394 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1395 | .Times(1) |
| 1396 | .WillOnce(Return("207200")); |
| 1397 | psu.analyze(); |
| 1398 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 1399 | // Setup another expectation of no faults. |
| 1400 | setPMBusExpectations(mockPMBus, expectations); |
| 1401 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1402 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1403 | .Times(1) |
| 1404 | .WillOnce(Return("207300")); |
Brandon Wyman | 391a069 | 2021-12-08 23:28:18 +0000 | [diff] [blame] | 1405 | psu.analyze(); |
| 1406 | EXPECT_EQ(psu.hasPgoodFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1407 | // Turn PGOOD# off (fault on). |
| 1408 | expectations.statusWordValue = (status_word::POWER_GOOD_NEGATED); |
| 1409 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1410 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1411 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1412 | .Times(1) |
| 1413 | .WillOnce(Return("207400")); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1414 | psu.analyze(); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 1415 | // Expect false until reaches DEGLITCH_LIMIT |
| 1416 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 1417 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1418 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1419 | .Times(1) |
| 1420 | .WillOnce(Return("207500")); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 1421 | psu.analyze(); |
| 1422 | // Expect false until reaches DEGLITCH_LIMIT |
| 1423 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 1424 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1425 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1426 | .Times(1) |
| 1427 | .WillOnce(Return("207600")); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 1428 | psu.analyze(); |
| 1429 | // DEGLITCH_LIMIT reached, expect true. |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1430 | EXPECT_EQ(psu.hasPgoodFault(), true); |
| 1431 | // Back to no fault bits on in STATUS_WORD |
| 1432 | expectations.statusWordValue = 0; |
| 1433 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1434 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1435 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1436 | .Times(1) |
| 1437 | .WillOnce(Return("207700")); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1438 | psu.analyze(); |
| 1439 | EXPECT_EQ(psu.hasPgoodFault(), false); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1440 | |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1441 | // Turn OFF bit on |
| 1442 | expectations.statusWordValue = (status_word::UNIT_IS_OFF); |
| 1443 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1444 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1445 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1446 | .Times(1) |
| 1447 | .WillOnce(Return("208100")); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1448 | psu.analyze(); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 1449 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 1450 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1451 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1452 | .Times(1) |
| 1453 | .WillOnce(Return("208200")); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 1454 | psu.analyze(); |
| 1455 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 1456 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1457 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1458 | .Times(1) |
| 1459 | .WillOnce(Return("208300")); |
Brandon Wyman | 06ca459 | 2021-12-06 22:52:23 +0000 | [diff] [blame] | 1460 | psu.analyze(); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1461 | EXPECT_EQ(psu.hasPgoodFault(), true); |
| 1462 | // Back to no fault bits on in STATUS_WORD |
| 1463 | expectations.statusWordValue = 0; |
| 1464 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1465 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1466 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1467 | .Times(1) |
| 1468 | .WillOnce(Return("208400")); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 1469 | psu.analyze(); |
| 1470 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 1471 | } |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1472 | |
| 1473 | TEST_F(PowerSupplyTests, HasPSKillFault) |
| 1474 | { |
| 1475 | auto bus = sdbusplus::bus::new_default(); |
| 1476 | PowerSupply psu{bus, PSUInventoryPath, 4, 0x6d, PSUGPIOLineName}; |
| 1477 | MockedGPIOInterface* mockPresenceGPIO = |
| 1478 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 1479 | // Always return 1 to indicate present. |
| 1480 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1481 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1482 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1483 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 1484 | PMBusExpectations expectations; |
| 1485 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1486 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1487 | // Initial value would be 0, so this read updates it to non-zero. |
| 1488 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1489 | .Times(1) |
| 1490 | .WillOnce(Return("208100")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1491 | psu.analyze(); |
| 1492 | EXPECT_EQ(psu.hasPSKillFault(), false); |
| 1493 | // Next return STATUS_WORD with MFR fault bit on. |
| 1494 | expectations.statusWordValue = (status_word::MFR_SPECIFIC_FAULT); |
| 1495 | // STATUS_MFR_SPEFIC with bit(s) on. |
| 1496 | expectations.statusMFRValue = 0xFF; |
| 1497 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1498 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1499 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1500 | .Times(1) |
| 1501 | .WillOnce(Return("208200")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1502 | psu.analyze(); |
| 1503 | EXPECT_EQ(psu.hasPSKillFault(), true); |
| 1504 | // Back to no bits on in STATUS_WORD |
| 1505 | expectations.statusWordValue = 0; |
| 1506 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1507 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1508 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1509 | .Times(1) |
| 1510 | .WillOnce(Return("208300")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1511 | psu.analyze(); |
| 1512 | EXPECT_EQ(psu.hasPSKillFault(), false); |
| 1513 | // Next return STATUS_WORD with MFR fault bit on. |
| 1514 | expectations.statusWordValue = (status_word::MFR_SPECIFIC_FAULT); |
| 1515 | // STATUS_MFR_SPEFIC with bit 4 on. |
| 1516 | expectations.statusMFRValue = 0x10; |
| 1517 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1518 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1519 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1520 | .Times(1) |
| 1521 | .WillOnce(Return("208400")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1522 | psu.analyze(); |
| 1523 | EXPECT_EQ(psu.hasPSKillFault(), true); |
| 1524 | // Back to no bits on in STATUS_WORD |
| 1525 | expectations.statusWordValue = 0; |
| 1526 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1527 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1528 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1529 | .Times(1) |
| 1530 | .WillOnce(Return("208500")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1531 | psu.analyze(); |
| 1532 | EXPECT_EQ(psu.hasPSKillFault(), false); |
| 1533 | } |
| 1534 | |
| 1535 | TEST_F(PowerSupplyTests, HasPS12VcsFault) |
| 1536 | { |
| 1537 | auto bus = sdbusplus::bus::new_default(); |
| 1538 | PowerSupply psu{bus, PSUInventoryPath, 5, 0x6e, PSUGPIOLineName}; |
| 1539 | MockedGPIOInterface* mockPresenceGPIO = |
| 1540 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 1541 | // Always return 1 to indicate present. |
| 1542 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1543 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1544 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1545 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 1546 | PMBusExpectations expectations; |
| 1547 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1548 | // Call to analyze will trigger read of "in1_input" to check voltage. |
| 1549 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1550 | .Times(1) |
| 1551 | .WillOnce(Return("209100")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1552 | psu.analyze(); |
| 1553 | EXPECT_EQ(psu.hasPS12VcsFault(), false); |
| 1554 | // Next return STATUS_WORD with MFR fault bit on. |
| 1555 | expectations.statusWordValue = (status_word::MFR_SPECIFIC_FAULT); |
| 1556 | // STATUS_MFR_SPEFIC with bit(s) on. |
| 1557 | expectations.statusMFRValue = 0xFF; |
| 1558 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1559 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1560 | .Times(1) |
| 1561 | .WillOnce(Return("209200")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1562 | psu.analyze(); |
| 1563 | EXPECT_EQ(psu.hasPS12VcsFault(), true); |
| 1564 | // Back to no bits on in STATUS_WORD |
| 1565 | expectations.statusWordValue = 0; |
| 1566 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1567 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1568 | .Times(1) |
| 1569 | .WillOnce(Return("209300")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1570 | psu.analyze(); |
| 1571 | EXPECT_EQ(psu.hasPS12VcsFault(), false); |
| 1572 | // Next return STATUS_WORD with MFR fault bit on. |
| 1573 | expectations.statusWordValue = (status_word::MFR_SPECIFIC_FAULT); |
| 1574 | // STATUS_MFR_SPEFIC with bit 6 on. |
| 1575 | expectations.statusMFRValue = 0x40; |
| 1576 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1577 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1578 | .Times(1) |
| 1579 | .WillOnce(Return("209400")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1580 | psu.analyze(); |
| 1581 | EXPECT_EQ(psu.hasPS12VcsFault(), true); |
| 1582 | // Back to no bits on in STATUS_WORD |
| 1583 | expectations.statusWordValue = 0; |
| 1584 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1585 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1586 | .Times(1) |
| 1587 | .WillOnce(Return("209500")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1588 | psu.analyze(); |
| 1589 | EXPECT_EQ(psu.hasPS12VcsFault(), false); |
| 1590 | } |
| 1591 | |
| 1592 | TEST_F(PowerSupplyTests, HasPSCS12VFault) |
| 1593 | { |
| 1594 | auto bus = sdbusplus::bus::new_default(); |
| 1595 | PowerSupply psu{bus, PSUInventoryPath, 6, 0x6f, PSUGPIOLineName}; |
| 1596 | MockedGPIOInterface* mockPresenceGPIO = |
| 1597 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 1598 | // Always return 1 to indicate present. |
| 1599 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1600 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1601 | setMissingToPresentExpects(mockPMBus, mockedUtil); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1602 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 1603 | PMBusExpectations expectations; |
| 1604 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1605 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1606 | .Times(1) |
| 1607 | .WillOnce(Return("209100")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1608 | psu.analyze(); |
| 1609 | EXPECT_EQ(psu.hasPSCS12VFault(), false); |
| 1610 | // Next return STATUS_WORD with MFR fault bit on. |
| 1611 | expectations.statusWordValue = (status_word::MFR_SPECIFIC_FAULT); |
| 1612 | // STATUS_MFR_SPEFIC with bit(s) on. |
| 1613 | expectations.statusMFRValue = 0xFF; |
| 1614 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1615 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1616 | .Times(1) |
| 1617 | .WillOnce(Return("209200")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1618 | psu.analyze(); |
| 1619 | EXPECT_EQ(psu.hasPSCS12VFault(), true); |
| 1620 | // Back to no bits on in STATUS_WORD |
| 1621 | expectations.statusWordValue = 0; |
| 1622 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1623 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1624 | .Times(1) |
| 1625 | .WillOnce(Return("209300")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1626 | psu.analyze(); |
| 1627 | EXPECT_EQ(psu.hasPSCS12VFault(), false); |
| 1628 | // Next return STATUS_WORD with MFR fault bit on. |
| 1629 | expectations.statusWordValue = (status_word::MFR_SPECIFIC_FAULT); |
| 1630 | // STATUS_MFR_SPEFIC with bit 7 on. |
| 1631 | expectations.statusMFRValue = 0x80; |
| 1632 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1633 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1634 | .Times(1) |
| 1635 | .WillOnce(Return("209400")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1636 | psu.analyze(); |
| 1637 | EXPECT_EQ(psu.hasPSCS12VFault(), true); |
| 1638 | // Back to no bits on in STATUS_WORD |
| 1639 | expectations.statusWordValue = 0; |
| 1640 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 82affd9 | 2021-11-24 19:12:49 +0000 | [diff] [blame] | 1641 | EXPECT_CALL(mockPMBus, readString(READ_VIN, _)) |
| 1642 | .Times(1) |
| 1643 | .WillOnce(Return("209500")); |
Brandon Wyman | 39ea02b | 2021-11-23 23:22:23 +0000 | [diff] [blame] | 1644 | psu.analyze(); |
| 1645 | EXPECT_EQ(psu.hasPSCS12VFault(), false); |
| 1646 | } |