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 | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 33 | uint8_t statusTempValue{0x00}; |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 36 | // Helper function to setup expectations for various STATUS_* commands |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 37 | void setPMBusExpectations(MockedPMBus& mockPMBus, |
| 38 | const PMBusExpectations& expectations) |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 39 | { |
| 40 | EXPECT_CALL(mockPMBus, read(STATUS_WORD, _)) |
| 41 | .Times(1) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 42 | .WillOnce(Return(expectations.statusWordValue)); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 43 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 44 | if (expectations.statusWordValue != 0) |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 45 | { |
| 46 | // 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] | 47 | // STATUS_INPUT, STATUS_MFR, STATUS_CML, STATUS_VOUT (page 0), and |
| 48 | // STATUS_TEMPERATURE. |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 49 | EXPECT_CALL(mockPMBus, read(STATUS_INPUT, _)) |
| 50 | .Times(1) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 51 | .WillOnce(Return(expectations.statusInputValue)); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 52 | EXPECT_CALL(mockPMBus, read(STATUS_MFR, _)) |
| 53 | .Times(1) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 54 | .WillOnce(Return(expectations.statusMFRValue)); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 55 | EXPECT_CALL(mockPMBus, read(STATUS_CML, _)) |
| 56 | .Times(1) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 57 | .WillOnce(Return(expectations.statusCMLValue)); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 58 | // Page will need to be set to 0 to read STATUS_VOUT. |
| 59 | EXPECT_CALL(mockPMBus, insertPageNum(STATUS_VOUT, 0)) |
| 60 | .Times(1) |
| 61 | .WillOnce(Return("status0_vout")); |
| 62 | EXPECT_CALL(mockPMBus, read("status0_vout", _)) |
| 63 | .Times(1) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 64 | .WillOnce(Return(expectations.statusVOUTValue)); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 65 | EXPECT_CALL(mockPMBus, read(STATUS_IOUT, _)) |
| 66 | .Times(1) |
| 67 | .WillOnce(Return(expectations.statusIOUTValue)); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 68 | EXPECT_CALL(mockPMBus, read(STATUS_TEMPERATURE, _)) |
| 69 | .Times(1) |
| 70 | .WillOnce(Return(expectations.statusTempValue)); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 74 | class PowerSupplyTests : public ::testing::Test |
| 75 | { |
| 76 | public: |
| 77 | PowerSupplyTests() : |
| 78 | mockedUtil(reinterpret_cast<const MockedUtil&>(getUtils())) |
| 79 | { |
| 80 | ON_CALL(mockedUtil, getPresence(_, _)).WillByDefault(Return(false)); |
| 81 | } |
| 82 | |
| 83 | ~PowerSupplyTests() override |
| 84 | { |
| 85 | freeUtils(); |
| 86 | } |
| 87 | |
| 88 | const MockedUtil& mockedUtil; |
| 89 | }; |
| 90 | |
| 91 | TEST_F(PowerSupplyTests, Constructor) |
| 92 | { |
| 93 | /** |
| 94 | * @param[in] invpath - String for inventory path to use |
| 95 | * @param[in] i2cbus - The bus number this power supply is on |
| 96 | * @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] | 97 | * @param[in] gpioLineName - The string for the gpio-line-name to read for |
| 98 | * presence. |
| 99 | * @param[in] bindDelay - Time in milliseconds to delay binding the device |
| 100 | * driver after seeing the presence line go active. |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 101 | */ |
| 102 | auto bus = sdbusplus::bus::new_default(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 103 | |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 104 | // Try where inventory path is empty, constructor should fail. |
| 105 | try |
| 106 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 107 | auto psu = |
| 108 | std::make_unique<PowerSupply>(bus, "", 3, 0x68, PSUGPIOLineName); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 109 | ADD_FAILURE() << "Should not have reached this line."; |
| 110 | } |
| 111 | catch (const std::invalid_argument& e) |
| 112 | { |
| 113 | EXPECT_STREQ(e.what(), "Invalid empty inventoryPath"); |
| 114 | } |
| 115 | catch (...) |
| 116 | { |
| 117 | ADD_FAILURE() << "Should not have caught exception."; |
| 118 | } |
| 119 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 120 | // TODO: Try invalid i2c address? |
| 121 | |
| 122 | // Try where gpioLineName is empty. |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 123 | try |
| 124 | { |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 125 | auto psu = |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 126 | std::make_unique<PowerSupply>(bus, PSUInventoryPath, 3, 0x68, ""); |
| 127 | ADD_FAILURE() |
| 128 | << "Should not have reached this line. Invalid gpioLineName."; |
| 129 | } |
| 130 | catch (const std::invalid_argument& e) |
| 131 | { |
| 132 | EXPECT_STREQ(e.what(), "Invalid empty gpioLineName"); |
| 133 | } |
| 134 | catch (...) |
| 135 | { |
| 136 | ADD_FAILURE() << "Should not have caught exception."; |
| 137 | } |
| 138 | |
| 139 | // Test with valid arguments |
| 140 | // NOT using D-Bus inventory path for presence. |
| 141 | try |
| 142 | { |
| 143 | auto psu = std::make_unique<PowerSupply>(bus, PSUInventoryPath, 3, 0x68, |
| 144 | PSUGPIOLineName); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 145 | |
| 146 | EXPECT_EQ(psu->isPresent(), false); |
| 147 | EXPECT_EQ(psu->isFaulted(), false); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 148 | EXPECT_EQ(psu->hasCommFault(), false); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 149 | EXPECT_EQ(psu->hasInputFault(), false); |
| 150 | EXPECT_EQ(psu->hasMFRFault(), false); |
| 151 | EXPECT_EQ(psu->hasVINUVFault(), false); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 152 | EXPECT_EQ(psu->hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 153 | EXPECT_EQ(psu->hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 154 | EXPECT_EQ(psu->hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 155 | EXPECT_EQ(psu->hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 156 | EXPECT_EQ(psu->hasPgoodFault(), false); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 157 | } |
| 158 | catch (...) |
| 159 | { |
| 160 | ADD_FAILURE() << "Should not have caught exception."; |
| 161 | } |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 162 | |
| 163 | // Test with valid arguments |
| 164 | // TODO: Using D-Bus inventory path for presence. |
| 165 | try |
| 166 | { |
| 167 | // FIXME: How do I get that presenceGPIO.read() in the startup to throw |
| 168 | // an exception? |
| 169 | |
| 170 | // EXPECT_CALL(mockedUtil, getPresence(_, |
| 171 | // StrEq(PSUInventoryPath))) |
| 172 | // .Times(1); |
| 173 | } |
| 174 | catch (...) |
| 175 | { |
| 176 | ADD_FAILURE() << "Should not have caught exception."; |
| 177 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | TEST_F(PowerSupplyTests, Analyze) |
| 181 | { |
| 182 | auto bus = sdbusplus::bus::new_default(); |
| 183 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 184 | { |
| 185 | // If I default to reading the GPIO, I will NOT expect a call to |
| 186 | // getPresence(). |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 187 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 188 | PowerSupply psu{bus, PSUInventoryPath, 4, 0x69, PSUGPIOLineName}; |
| 189 | MockedGPIOInterface* mockPresenceGPIO = |
| 190 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 191 | EXPECT_CALL(*mockPresenceGPIO, read()).Times(1).WillOnce(Return(0)); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 192 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 193 | psu.analyze(); |
| 194 | // By default, nothing should change. |
| 195 | EXPECT_EQ(psu.isPresent(), false); |
| 196 | EXPECT_EQ(psu.isFaulted(), false); |
| 197 | EXPECT_EQ(psu.hasInputFault(), false); |
| 198 | EXPECT_EQ(psu.hasMFRFault(), false); |
| 199 | EXPECT_EQ(psu.hasVINUVFault(), false); |
| 200 | EXPECT_EQ(psu.hasCommFault(), false); |
| 201 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 202 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 203 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 204 | EXPECT_EQ(psu.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 205 | EXPECT_EQ(psu.hasPgoodFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 206 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 207 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 208 | PowerSupply psu2{bus, PSUInventoryPath, 5, 0x6a, PSUGPIOLineName}; |
| 209 | // In order to get the various faults tested, the power supply needs to |
| 210 | // be present in order to read from the PMBus device(s). |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 211 | MockedGPIOInterface* mockPresenceGPIO2 = |
| 212 | static_cast<MockedGPIOInterface*>(psu2.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 213 | ON_CALL(*mockPresenceGPIO2, read()).WillByDefault(Return(1)); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 214 | EXPECT_EQ(psu2.isPresent(), false); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 215 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 216 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu2.getPMBus()); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 217 | // Presence change from missing to present will trigger write to |
| 218 | // ON_OFF_CONFIG. |
| 219 | EXPECT_CALL(mockPMBus, writeBinary(ON_OFF_CONFIG, _, _)); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 220 | // Presence change from missing to present will trigger in1_input read |
| 221 | // in an attempt to get CLEAR_FAULTS called. |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 222 | EXPECT_CALL(mockPMBus, read(READ_VIN, _)).Times(1).WillOnce(Return(206000)); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 223 | |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 224 | // STATUS_WORD INPUT fault. |
| 225 | { |
| 226 | // Start with STATUS_WORD 0x0000. Powered on, no faults. |
| 227 | // Set expectations for a no fault |
| 228 | PMBusExpectations expectations; |
| 229 | setPMBusExpectations(mockPMBus, expectations); |
| 230 | psu2.analyze(); |
| 231 | EXPECT_EQ(psu2.isPresent(), true); |
| 232 | EXPECT_EQ(psu2.isFaulted(), false); |
| 233 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 234 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 235 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 236 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 237 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 238 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 239 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 240 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 241 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 242 | |
| 243 | // Update expectations for STATUS_WORD input fault/warn |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 244 | // STATUS_INPUT fault bits ... on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 245 | expectations.statusWordValue = (status_word::INPUT_FAULT_WARN); |
| 246 | expectations.statusInputValue = 0x38; |
| 247 | setPMBusExpectations(mockPMBus, expectations); |
| 248 | psu2.analyze(); |
| 249 | EXPECT_EQ(psu2.isPresent(), true); |
| 250 | EXPECT_EQ(psu2.isFaulted(), true); |
| 251 | EXPECT_EQ(psu2.hasInputFault(), true); |
| 252 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 253 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 254 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 255 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 256 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 257 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 258 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 259 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 260 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 261 | |
| 262 | // STATUS_WORD INPUT/UV fault. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 263 | { |
| 264 | // First need it to return good status, then the fault |
| 265 | PMBusExpectations expectations; |
| 266 | setPMBusExpectations(mockPMBus, expectations); |
| 267 | psu2.analyze(); |
| 268 | // Now set fault bits in STATUS_WORD |
| 269 | expectations.statusWordValue = |
| 270 | (status_word::INPUT_FAULT_WARN | status_word::VIN_UV_FAULT); |
| 271 | // STATUS_INPUT fault bits ... on. |
| 272 | expectations.statusInputValue = 0x38; |
| 273 | setPMBusExpectations(mockPMBus, expectations); |
| 274 | psu2.analyze(); |
| 275 | EXPECT_EQ(psu2.isPresent(), true); |
| 276 | EXPECT_EQ(psu2.isFaulted(), true); |
| 277 | EXPECT_EQ(psu2.hasInputFault(), true); |
| 278 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 279 | EXPECT_EQ(psu2.hasVINUVFault(), true); |
| 280 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 281 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 282 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 283 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 284 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 285 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 286 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 287 | |
| 288 | // STATUS_WORD MFR fault. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 289 | { |
| 290 | // First need it to return good status, then the fault |
| 291 | PMBusExpectations expectations; |
| 292 | setPMBusExpectations(mockPMBus, expectations); |
| 293 | psu2.analyze(); |
| 294 | // Now STATUS_WORD with MFR fault bit on. |
| 295 | expectations.statusWordValue = (status_word::MFR_SPECIFIC_FAULT); |
| 296 | // STATUS_MFR bits on. |
| 297 | expectations.statusMFRValue = 0xFF; |
| 298 | setPMBusExpectations(mockPMBus, expectations); |
| 299 | psu2.analyze(); |
| 300 | EXPECT_EQ(psu2.isPresent(), true); |
| 301 | EXPECT_EQ(psu2.isFaulted(), true); |
| 302 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 303 | EXPECT_EQ(psu2.hasMFRFault(), true); |
| 304 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 305 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 306 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 307 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 308 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 309 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 310 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 311 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 312 | |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 313 | // Temperature fault. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 314 | { |
| 315 | // First STATUS_WORD with no bits set, then with temperature fault. |
| 316 | PMBusExpectations expectations; |
| 317 | setPMBusExpectations(mockPMBus, expectations); |
| 318 | psu2.analyze(); |
| 319 | // STATUS_WORD with temperature fault bit on. |
| 320 | expectations.statusWordValue = (status_word::TEMPERATURE_FAULT_WARN); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 321 | // STATUS_TEMPERATURE with fault bit(s) on. |
| 322 | expectations.statusTempValue = 0x10; |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 323 | setPMBusExpectations(mockPMBus, expectations); |
| 324 | psu2.analyze(); |
| 325 | EXPECT_EQ(psu2.isPresent(), true); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 326 | EXPECT_EQ(psu2.isFaulted(), true); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 327 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 328 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 329 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 330 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 331 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 332 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 333 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 334 | EXPECT_EQ(psu2.hasTempFault(), true); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 335 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 336 | } |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 337 | |
| 338 | // CML fault |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 339 | { |
| 340 | // First STATUS_WORD wit no bits set, then with CML fault. |
| 341 | PMBusExpectations expectations; |
| 342 | setPMBusExpectations(mockPMBus, expectations); |
| 343 | psu2.analyze(); |
| 344 | // STATUS_WORD with CML fault bit on. |
| 345 | expectations.statusWordValue = (status_word::CML_FAULT); |
| 346 | // Turn on STATUS_CML fault bit(s) |
| 347 | expectations.statusCMLValue = 0xFF; |
| 348 | setPMBusExpectations(mockPMBus, expectations); |
| 349 | psu2.analyze(); |
| 350 | EXPECT_EQ(psu2.isPresent(), true); |
| 351 | EXPECT_EQ(psu2.isFaulted(), true); |
| 352 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 353 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 354 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 355 | EXPECT_EQ(psu2.hasCommFault(), true); |
| 356 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 357 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 358 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 359 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 360 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 361 | } |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 362 | |
| 363 | // VOUT_OV_FAULT fault |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 364 | { |
| 365 | // First STATUS_WORD with no bits set, then with VOUT/VOUT_OV fault. |
| 366 | PMBusExpectations expectations; |
| 367 | setPMBusExpectations(mockPMBus, expectations); |
| 368 | psu2.analyze(); |
| 369 | // STATUS_WORD with VOUT/VOUT_OV fault. |
| 370 | expectations.statusWordValue = |
| 371 | ((status_word::VOUT_FAULT) | (status_word::VOUT_OV_FAULT)); |
| 372 | // Turn on STATUS_VOUT fault bit(s) |
| 373 | expectations.statusVOUTValue = 0xA0; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 374 | // STATUS_TEMPERATURE don't care (default) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 375 | setPMBusExpectations(mockPMBus, expectations); |
| 376 | psu2.analyze(); |
| 377 | EXPECT_EQ(psu2.isPresent(), true); |
| 378 | EXPECT_EQ(psu2.isFaulted(), true); |
| 379 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 380 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 381 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 382 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 383 | EXPECT_EQ(psu2.hasVoutOVFault(), true); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 384 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 385 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
| 386 | EXPECT_EQ(psu2.hasTempFault(), false); |
| 387 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
| 388 | } |
| 389 | |
| 390 | // IOUT_OC_FAULT fault |
| 391 | { |
| 392 | // First STATUS_WORD with no bits set, then with IOUT_OC fault. |
| 393 | PMBusExpectations expectations; |
| 394 | setPMBusExpectations(mockPMBus, expectations); |
| 395 | psu2.analyze(); |
| 396 | // STATUS_WORD with IOUT_OC fault. |
| 397 | expectations.statusWordValue = status_word::IOUT_OC_FAULT; |
| 398 | // Turn on STATUS_IOUT fault bit(s) |
| 399 | expectations.statusIOUTValue = 0x88; |
| 400 | setPMBusExpectations(mockPMBus, expectations); |
| 401 | psu2.analyze(); |
| 402 | EXPECT_EQ(psu2.isPresent(), true); |
| 403 | EXPECT_EQ(psu2.isFaulted(), true); |
| 404 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 405 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 406 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 407 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 408 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
| 409 | EXPECT_EQ(psu2.hasIoutOCFault(), true); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 410 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
| 411 | EXPECT_EQ(psu2.hasTempFault(), false); |
| 412 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
| 413 | } |
| 414 | |
| 415 | // VOUT_UV_FAULT |
| 416 | { |
| 417 | // First STATUS_WORD with no bits set, then with VOUT fault. |
| 418 | PMBusExpectations expectations; |
| 419 | setPMBusExpectations(mockPMBus, expectations); |
| 420 | psu2.analyze(); |
| 421 | // Change STATUS_WORD to indicate VOUT fault. |
| 422 | expectations.statusWordValue = (status_word::VOUT_FAULT); |
| 423 | // Turn on STATUS_VOUT fault bit(s) |
| 424 | expectations.statusVOUTValue = 0x30; |
| 425 | setPMBusExpectations(mockPMBus, expectations); |
| 426 | psu2.analyze(); |
| 427 | EXPECT_EQ(psu2.isPresent(), true); |
| 428 | EXPECT_EQ(psu2.isFaulted(), true); |
| 429 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 430 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 431 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 432 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 433 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
| 434 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
| 435 | EXPECT_EQ(psu2.hasVoutUVFault(), true); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 436 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 437 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 438 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 439 | |
| 440 | // Ignore fan fault |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 441 | { |
| 442 | // First STATUS_WORD with no bits set, then with fan fault. |
| 443 | PMBusExpectations expectations; |
| 444 | setPMBusExpectations(mockPMBus, expectations); |
| 445 | psu2.analyze(); |
| 446 | expectations.statusWordValue = (status_word::FAN_FAULT); |
| 447 | setPMBusExpectations(mockPMBus, expectations); |
| 448 | psu2.analyze(); |
| 449 | EXPECT_EQ(psu2.isPresent(), true); |
| 450 | EXPECT_EQ(psu2.isFaulted(), false); |
| 451 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 452 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 453 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 454 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 455 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 456 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 457 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 458 | EXPECT_EQ(psu2.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 459 | EXPECT_EQ(psu2.hasPgoodFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 460 | } |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 461 | |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 462 | // PGOOD/OFF fault. |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 463 | { |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 464 | // First STATUS_WORD with no bits set. |
| 465 | PMBusExpectations expectations; |
| 466 | setPMBusExpectations(mockPMBus, expectations); |
| 467 | psu2.analyze(); |
| 468 | EXPECT_EQ(psu2.isFaulted(), false); |
| 469 | // POWER_GOOD# inactive, and OFF bit on. |
| 470 | expectations.statusWordValue = |
| 471 | ((status_word::POWER_GOOD_NEGATED) | (status_word::UNIT_IS_OFF)); |
| 472 | // STATUS_INPUT, STATUS_MFR, STATUS_CML, STATUS_VOUT, and |
| 473 | // STATUS_TEMPERATURE: Don't care if bits set or not (defaults). |
| 474 | setPMBusExpectations(mockPMBus, expectations); |
| 475 | psu2.analyze(); |
| 476 | EXPECT_EQ(psu2.isPresent(), true); |
| 477 | EXPECT_EQ(psu2.isFaulted(), true); |
| 478 | EXPECT_EQ(psu2.hasInputFault(), false); |
| 479 | EXPECT_EQ(psu2.hasMFRFault(), false); |
| 480 | EXPECT_EQ(psu2.hasVINUVFault(), false); |
| 481 | EXPECT_EQ(psu2.hasCommFault(), false); |
| 482 | EXPECT_EQ(psu2.hasVoutOVFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 483 | EXPECT_EQ(psu2.hasVoutUVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 484 | EXPECT_EQ(psu2.hasIoutOCFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 485 | EXPECT_EQ(psu2.hasTempFault(), false); |
| 486 | EXPECT_EQ(psu2.hasPgoodFault(), true); |
| 487 | } |
| 488 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 489 | // TODO: ReadFailure |
| 490 | } |
| 491 | |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 492 | TEST_F(PowerSupplyTests, OnOffConfig) |
| 493 | { |
| 494 | auto bus = sdbusplus::bus::new_default(); |
| 495 | uint8_t data = 0x15; |
| 496 | |
| 497 | // Test where PSU is NOT present |
| 498 | try |
| 499 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 500 | // Assume GPIO presence, not inventory presence? |
| 501 | PowerSupply psu{bus, PSUInventoryPath, 4, 0x69, PSUGPIOLineName}; |
| 502 | |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 503 | MockedGPIOInterface* mockPresenceGPIO = |
| 504 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 505 | ON_CALL(*mockPresenceGPIO, read()).WillByDefault(Return(0)); |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 506 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 507 | // Constructor should set initial presence, default read returns 0. |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 508 | // If it is not present, I should not be trying to write to it. |
| 509 | EXPECT_CALL(mockPMBus, writeBinary(_, _, _)).Times(0); |
| 510 | psu.onOffConfig(data); |
| 511 | } |
| 512 | catch (...) |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 513 | {} |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 514 | |
| 515 | // Test where PSU is present |
| 516 | try |
| 517 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 518 | // Assume GPIO presence, not inventory presence? |
| 519 | PowerSupply psu{bus, PSUInventoryPath, 5, 0x6a, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 520 | MockedGPIOInterface* mockPresenceGPIO = |
| 521 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 522 | ON_CALL(*mockPresenceGPIO, read()).WillByDefault(Return(1)); |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 523 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 524 | // TODO: expect setPresence call? |
| 525 | // updatePresence() private function reads gpio, called by analyze(). |
| 526 | psu.analyze(); |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 527 | // TODO: ???should I check the filename? |
| 528 | EXPECT_CALL(mockPMBus, |
| 529 | writeBinary(_, ElementsAre(0x15), Type::HwmonDeviceDebug)) |
| 530 | .Times(1); |
| 531 | psu.onOffConfig(data); |
| 532 | } |
| 533 | catch (...) |
Adriana Kobylak | 0c9a33d | 2021-09-13 18:05:09 +0000 | [diff] [blame] | 534 | {} |
Brandon Wyman | 59a3579 | 2020-06-04 12:37:40 -0500 | [diff] [blame] | 535 | } |
| 536 | |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 537 | TEST_F(PowerSupplyTests, ClearFaults) |
| 538 | { |
| 539 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 540 | PowerSupply psu{bus, PSUInventoryPath, 13, 0x68, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 541 | MockedGPIOInterface* mockPresenceGPIO = |
| 542 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 543 | // GPIO read return 1 to indicate present. |
| 544 | ON_CALL(*mockPresenceGPIO, read()).WillByDefault(Return(1)); |
| 545 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 546 | // Presence change from missing to present will trigger in1_input read in |
| 547 | // an attempt to get CLEAR_FAULTS called. |
| 548 | EXPECT_CALL(mockPMBus, read(READ_VIN, _)).Times(1).WillOnce(Return(206000)); |
| 549 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 550 | PMBusExpectations expectations; |
| 551 | setPMBusExpectations(mockPMBus, expectations); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 552 | psu.analyze(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 553 | EXPECT_EQ(psu.isPresent(), true); |
| 554 | EXPECT_EQ(psu.isFaulted(), false); |
| 555 | EXPECT_EQ(psu.hasInputFault(), false); |
| 556 | EXPECT_EQ(psu.hasMFRFault(), false); |
| 557 | EXPECT_EQ(psu.hasVINUVFault(), false); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 558 | EXPECT_EQ(psu.hasCommFault(), false); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 559 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 560 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 561 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 562 | EXPECT_EQ(psu.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 563 | EXPECT_EQ(psu.hasPgoodFault(), false); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 564 | |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 565 | // STATUS_WORD with fault bits galore! |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 566 | expectations.statusWordValue = 0xFFFF; |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 567 | // STATUS_INPUT with fault bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 568 | expectations.statusInputValue = 0xFF; |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 569 | // STATUS_MFR_SPEFIC with bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 570 | expectations.statusMFRValue = 0xFF; |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 571 | // STATUS_CML with bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 572 | expectations.statusCMLValue = 0xFF; |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 573 | // STATUS_VOUT with bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 574 | expectations.statusVOUTValue = 0xFF; |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 575 | // STATUS_IOUT with bits on. |
| 576 | expectations.statusIOUTValue = 0xFF; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 577 | // STATUS_TEMPERATURE with bits on. |
| 578 | expectations.statusTempValue = 0xFF; |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 579 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 580 | psu.analyze(); |
| 581 | EXPECT_EQ(psu.isPresent(), true); |
| 582 | EXPECT_EQ(psu.isFaulted(), true); |
| 583 | EXPECT_EQ(psu.hasInputFault(), true); |
| 584 | EXPECT_EQ(psu.hasMFRFault(), true); |
| 585 | EXPECT_EQ(psu.hasVINUVFault(), true); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 586 | EXPECT_EQ(psu.hasCommFault(), true); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 587 | EXPECT_EQ(psu.hasVoutOVFault(), true); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 588 | EXPECT_EQ(psu.hasIoutOCFault(), true); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 589 | // Cannot have VOUT_OV_FAULT and VOUT_UV_FAULT. |
| 590 | // Rely on HasVoutUVFault() to verify this sets and clears. |
| 591 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 592 | EXPECT_EQ(psu.hasTempFault(), true); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 593 | EXPECT_EQ(psu.hasPgoodFault(), true); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 594 | |
Brandon Wyman | 3c20846 | 2020-05-13 16:25:58 -0500 | [diff] [blame] | 595 | EXPECT_CALL(mockPMBus, read("in1_input", _)) |
| 596 | .Times(1) |
| 597 | .WillOnce(Return(209000)); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 598 | psu.clearFaults(); |
| 599 | EXPECT_EQ(psu.isPresent(), true); |
| 600 | EXPECT_EQ(psu.isFaulted(), false); |
| 601 | EXPECT_EQ(psu.hasInputFault(), false); |
| 602 | EXPECT_EQ(psu.hasMFRFault(), false); |
| 603 | EXPECT_EQ(psu.hasVINUVFault(), false); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 604 | EXPECT_EQ(psu.hasCommFault(), false); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 605 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 606 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 607 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 608 | EXPECT_EQ(psu.hasTempFault(), false); |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 609 | EXPECT_EQ(psu.hasPgoodFault(), false); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 610 | |
| 611 | // TODO: Faults clear on missing/present? |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | TEST_F(PowerSupplyTests, UpdateInventory) |
| 615 | { |
| 616 | auto bus = sdbusplus::bus::new_default(); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 617 | |
| 618 | try |
| 619 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 620 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x68, PSUGPIOLineName}; |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 621 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 622 | // If it is not present, I should not be trying to read a string |
| 623 | EXPECT_CALL(mockPMBus, readString(_, _)).Times(0); |
| 624 | psu.updateInventory(); |
| 625 | } |
| 626 | catch (...) |
| 627 | { |
| 628 | ADD_FAILURE() << "Should not have caught exception."; |
| 629 | } |
| 630 | |
| 631 | try |
| 632 | { |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 633 | PowerSupply psu{bus, PSUInventoryPath, 13, 0x69, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 634 | MockedGPIOInterface* mockPresenceGPIO = |
| 635 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 636 | // GPIO read return 1 to indicate present. |
| 637 | EXPECT_CALL(*mockPresenceGPIO, read()).Times(1).WillOnce(Return(1)); |
| 638 | psu.analyze(); |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 639 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 640 | EXPECT_CALL(mockPMBus, readString(_, _)).WillRepeatedly(Return("")); |
| 641 | psu.updateInventory(); |
| 642 | |
Brandon Wyman | 3c530fb | 2021-04-13 13:13:22 -0500 | [diff] [blame] | 643 | #if IBM_VPD |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 644 | EXPECT_CALL(mockPMBus, readString(_, _)) |
| 645 | .WillOnce(Return("CCIN")) |
| 646 | .WillOnce(Return("PN3456")) |
| 647 | .WillOnce(Return("FN3456")) |
| 648 | .WillOnce(Return("HEADER")) |
| 649 | .WillOnce(Return("SN3456")) |
| 650 | .WillOnce(Return("FW3456")); |
Brandon Wyman | 3c530fb | 2021-04-13 13:13:22 -0500 | [diff] [blame] | 651 | #endif |
Brandon Wyman | 1d7a7df | 2020-03-26 10:14:05 -0500 | [diff] [blame] | 652 | psu.updateInventory(); |
| 653 | // TODO: D-Bus mocking to verify values stored on D-Bus (???) |
| 654 | } |
| 655 | catch (...) |
| 656 | { |
| 657 | ADD_FAILURE() << "Should not have caught exception."; |
| 658 | } |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | TEST_F(PowerSupplyTests, IsPresent) |
| 662 | { |
| 663 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 664 | |
| 665 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x68, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 666 | MockedGPIOInterface* mockPresenceGPIO = |
| 667 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 668 | EXPECT_EQ(psu.isPresent(), false); |
| 669 | |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 670 | // Change GPIO read to return 1 to indicate present. |
| 671 | EXPECT_CALL(*mockPresenceGPIO, read()).Times(1).WillOnce(Return(1)); |
| 672 | psu.analyze(); |
| 673 | EXPECT_EQ(psu.isPresent(), true); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | TEST_F(PowerSupplyTests, IsFaulted) |
| 677 | { |
| 678 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 679 | |
| 680 | PowerSupply psu{bus, PSUInventoryPath, 11, 0x6f, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 681 | MockedGPIOInterface* mockPresenceGPIO = |
| 682 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 683 | // Always return 1 to indicate present. |
| 684 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
| 685 | psu.analyze(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 686 | EXPECT_EQ(psu.isFaulted(), false); |
| 687 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 688 | PMBusExpectations expectations; |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 689 | // STATUS_WORD with fault bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 690 | expectations.statusWordValue = 0xFFFF; |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 691 | // STATUS_INPUT with fault bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 692 | expectations.statusInputValue = 0xFF; |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 693 | // STATUS_MFR_SPECIFIC with faults bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 694 | expectations.statusMFRValue = 0xFF; |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 695 | // STATUS_CML with faults bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 696 | expectations.statusCMLValue = 0xFF; |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 697 | // STATUS_VOUT with fault bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 698 | expectations.statusVOUTValue = 0xFF; |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 699 | // STATUS_IOUT with fault bits on. |
| 700 | expectations.statusIOUTValue = 0xFF; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 701 | // STATUS_TEMPERATURE with fault bits on. |
| 702 | expectations.statusTempValue = 0xFF; |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 703 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 704 | psu.analyze(); |
| 705 | EXPECT_EQ(psu.isFaulted(), true); |
| 706 | } |
| 707 | |
| 708 | TEST_F(PowerSupplyTests, HasInputFault) |
| 709 | { |
| 710 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 711 | |
| 712 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x68, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 713 | MockedGPIOInterface* mockPresenceGPIO = |
| 714 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 715 | // Always return 1 to indicate present. |
| 716 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
| 717 | psu.analyze(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 718 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 719 | EXPECT_EQ(psu.hasInputFault(), false); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 720 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 721 | PMBusExpectations expectations; |
| 722 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 723 | psu.analyze(); |
| 724 | EXPECT_EQ(psu.hasInputFault(), false); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 725 | // STATUS_WORD with input fault/warn on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 726 | expectations.statusWordValue = (status_word::INPUT_FAULT_WARN); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 727 | // STATUS_INPUT with an input fault bit on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 728 | expectations.statusInputValue = 0x80; |
| 729 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 730 | psu.analyze(); |
| 731 | EXPECT_EQ(psu.hasInputFault(), true); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 732 | // STATUS_WORD with no bits on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 733 | expectations.statusWordValue = 0; |
| 734 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 735 | psu.analyze(); |
| 736 | EXPECT_EQ(psu.hasInputFault(), false); |
| 737 | } |
| 738 | |
| 739 | TEST_F(PowerSupplyTests, HasMFRFault) |
| 740 | { |
| 741 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 742 | |
| 743 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x68, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 744 | MockedGPIOInterface* mockPresenceGPIO = |
| 745 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 746 | // Always return 1 to indicate present. |
| 747 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
| 748 | psu.analyze(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 749 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 750 | EXPECT_EQ(psu.hasMFRFault(), false); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 751 | // First return STATUS_WORD with no bits on. |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 752 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 753 | PMBusExpectations expectations; |
| 754 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 755 | psu.analyze(); |
| 756 | EXPECT_EQ(psu.hasMFRFault(), false); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 757 | // Next return STATUS_WORD with MFR fault bit on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 758 | expectations.statusWordValue = (status_word::MFR_SPECIFIC_FAULT); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 759 | // STATUS_MFR_SPEFIC with bit(s) on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 760 | expectations.statusMFRValue = 0xFF; |
| 761 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 762 | psu.analyze(); |
| 763 | EXPECT_EQ(psu.hasMFRFault(), true); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 764 | // Back to no bits on in STATUS_WORD |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 765 | expectations.statusWordValue = 0; |
| 766 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 767 | psu.analyze(); |
| 768 | EXPECT_EQ(psu.hasMFRFault(), false); |
| 769 | } |
| 770 | |
| 771 | TEST_F(PowerSupplyTests, HasVINUVFault) |
| 772 | { |
| 773 | auto bus = sdbusplus::bus::new_default(); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 774 | |
| 775 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x68, PSUGPIOLineName}; |
Adriana Kobylak | 3ca062a | 2021-10-20 15:27:23 +0000 | [diff] [blame] | 776 | MockedGPIOInterface* mockPresenceGPIO = |
| 777 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
B. J. Wyman | 681b2a3 | 2021-04-20 22:31:22 +0000 | [diff] [blame] | 778 | // Always return 1 to indicate present. |
| 779 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
| 780 | psu.analyze(); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 781 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 782 | EXPECT_EQ(psu.hasVINUVFault(), false); |
Brandon Wyman | 8da35c5 | 2021-10-28 22:45:08 +0000 | [diff] [blame] | 783 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 784 | PMBusExpectations expectations; |
| 785 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 786 | psu.analyze(); |
| 787 | EXPECT_EQ(psu.hasVINUVFault(), false); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 788 | // Turn fault on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 789 | expectations.statusWordValue = (status_word::VIN_UV_FAULT); |
Brandon Wyman | 85c7bf4 | 2021-10-19 22:28:48 +0000 | [diff] [blame] | 790 | // Curious disagreement between PMBus Spec. Part II Figure 16 and 33. Go by |
| 791 | // Figure 16, and assume bits on in STATUS_INPUT. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 792 | expectations.statusInputValue = 0x18; |
| 793 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 794 | psu.analyze(); |
| 795 | EXPECT_EQ(psu.hasVINUVFault(), true); |
Brandon Wyman | f07bc79 | 2021-10-12 19:00:35 +0000 | [diff] [blame] | 796 | // Back to no fault bits on in STATUS_WORD |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 797 | expectations.statusWordValue = 0; |
| 798 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 3f1242f | 2020-01-28 13:11:25 -0600 | [diff] [blame] | 799 | psu.analyze(); |
| 800 | EXPECT_EQ(psu.hasVINUVFault(), false); |
| 801 | } |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 802 | |
| 803 | TEST_F(PowerSupplyTests, HasVoutOVFault) |
| 804 | { |
| 805 | auto bus = sdbusplus::bus::new_default(); |
| 806 | |
| 807 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x69, PSUGPIOLineName}; |
| 808 | MockedGPIOInterface* mockPresenceGPIO = |
| 809 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 810 | // Always return 1 to indicate present. |
| 811 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
| 812 | psu.analyze(); |
| 813 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 814 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
| 815 | // STATUS_WORD 0x0000 is powered on, no faults. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 816 | PMBusExpectations expectations; |
| 817 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 818 | psu.analyze(); |
| 819 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
| 820 | // Turn fault on. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 821 | expectations.statusWordValue = (status_word::VOUT_OV_FAULT); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 822 | // STATUS_VOUT fault bit(s) |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 823 | expectations.statusVOUTValue = 0x80; |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 824 | // STATUS_TEMPERATURE default. |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 825 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 826 | psu.analyze(); |
| 827 | EXPECT_EQ(psu.hasVoutOVFault(), true); |
| 828 | // Back to no fault bits on in STATUS_WORD |
Brandon Wyman | b654c61 | 2021-11-05 23:24:51 +0000 | [diff] [blame] | 829 | expectations.statusWordValue = 0; |
| 830 | setPMBusExpectations(mockPMBus, expectations); |
Brandon Wyman | 6710ba2 | 2021-10-27 17:39:31 +0000 | [diff] [blame] | 831 | psu.analyze(); |
| 832 | EXPECT_EQ(psu.hasVoutOVFault(), false); |
| 833 | } |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 834 | |
Brandon Wyman | b10b3be | 2021-11-09 22:12:15 +0000 | [diff] [blame] | 835 | TEST_F(PowerSupplyTests, HasIoutOCFault) |
| 836 | { |
| 837 | auto bus = sdbusplus::bus::new_default(); |
| 838 | |
| 839 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x6d, PSUGPIOLineName}; |
| 840 | MockedGPIOInterface* mockPresenceGPIO = |
| 841 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 842 | // Always return 1 to indicate present. |
| 843 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
| 844 | psu.analyze(); |
| 845 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 846 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
| 847 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 848 | PMBusExpectations expectations; |
| 849 | setPMBusExpectations(mockPMBus, expectations); |
| 850 | psu.analyze(); |
| 851 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
| 852 | // Turn fault on. |
| 853 | expectations.statusWordValue = status_word::IOUT_OC_FAULT; |
| 854 | // STATUS_IOUT fault bit(s) |
| 855 | expectations.statusIOUTValue = 0x88; |
| 856 | setPMBusExpectations(mockPMBus, expectations); |
| 857 | psu.analyze(); |
| 858 | EXPECT_EQ(psu.hasIoutOCFault(), true); |
| 859 | // Back to no fault bits on in STATUS_WORD |
| 860 | expectations.statusWordValue = 0; |
| 861 | setPMBusExpectations(mockPMBus, expectations); |
| 862 | psu.analyze(); |
| 863 | EXPECT_EQ(psu.hasIoutOCFault(), false); |
| 864 | } |
| 865 | |
Brandon Wyman | 2cf4694 | 2021-10-28 19:09:16 +0000 | [diff] [blame] | 866 | TEST_F(PowerSupplyTests, HasVoutUVFault) |
| 867 | { |
| 868 | auto bus = sdbusplus::bus::new_default(); |
| 869 | |
| 870 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x6a, PSUGPIOLineName}; |
| 871 | MockedGPIOInterface* mockPresenceGPIO = |
| 872 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 873 | // Always return 1 to indicate present. |
| 874 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
| 875 | psu.analyze(); |
| 876 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 877 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
| 878 | PMBusExpectations expectations; |
| 879 | setPMBusExpectations(mockPMBus, expectations); |
| 880 | psu.analyze(); |
| 881 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
| 882 | // Turn fault on. |
| 883 | expectations.statusWordValue = (status_word::VOUT_FAULT); |
| 884 | // STATUS_VOUT fault bit(s) |
| 885 | expectations.statusVOUTValue = 0x30; |
| 886 | setPMBusExpectations(mockPMBus, expectations); |
| 887 | psu.analyze(); |
| 888 | EXPECT_EQ(psu.hasVoutUVFault(), true); |
| 889 | // Back to no fault bits on in STATUS_WORD |
| 890 | expectations.statusWordValue = 0; |
| 891 | setPMBusExpectations(mockPMBus, expectations); |
| 892 | psu.analyze(); |
| 893 | EXPECT_EQ(psu.hasVoutUVFault(), false); |
| 894 | } |
| 895 | |
Brandon Wyman | 96893a4 | 2021-11-05 19:56:57 +0000 | [diff] [blame] | 896 | TEST_F(PowerSupplyTests, HasTempFault) |
| 897 | { |
| 898 | auto bus = sdbusplus::bus::new_default(); |
| 899 | |
| 900 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x6a, PSUGPIOLineName}; |
| 901 | MockedGPIOInterface* mockPresenceGPIO = |
| 902 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 903 | // Always return 1 to indicate present. |
| 904 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
| 905 | psu.analyze(); |
| 906 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 907 | EXPECT_EQ(psu.hasTempFault(), false); |
| 908 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 909 | PMBusExpectations expectations; |
| 910 | setPMBusExpectations(mockPMBus, expectations); |
| 911 | psu.analyze(); |
| 912 | EXPECT_EQ(psu.hasTempFault(), false); |
| 913 | // Turn fault on. |
| 914 | expectations.statusWordValue = (status_word::TEMPERATURE_FAULT_WARN); |
| 915 | // STATUS_TEMPERATURE fault bit on (OT Fault) |
| 916 | expectations.statusTempValue = 0x80; |
| 917 | setPMBusExpectations(mockPMBus, expectations); |
| 918 | psu.analyze(); |
| 919 | EXPECT_EQ(psu.hasTempFault(), true); |
| 920 | // Back to no fault bits on in STATUS_WORD |
| 921 | expectations.statusWordValue = 0; |
| 922 | setPMBusExpectations(mockPMBus, expectations); |
| 923 | psu.analyze(); |
| 924 | EXPECT_EQ(psu.hasTempFault(), false); |
| 925 | } |
Brandon Wyman | 2916ea5 | 2021-11-06 03:31:18 +0000 | [diff] [blame] | 926 | |
| 927 | TEST_F(PowerSupplyTests, HasPgoodFault) |
| 928 | { |
| 929 | auto bus = sdbusplus::bus::new_default(); |
| 930 | |
| 931 | PowerSupply psu{bus, PSUInventoryPath, 3, 0x6b, PSUGPIOLineName}; |
| 932 | MockedGPIOInterface* mockPresenceGPIO = |
| 933 | static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO()); |
| 934 | // Always return 1 to indicate present. |
| 935 | EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1)); |
| 936 | psu.analyze(); |
| 937 | MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus()); |
| 938 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 939 | // STATUS_WORD 0x0000 is powered on, no faults. |
| 940 | PMBusExpectations expectations; |
| 941 | setPMBusExpectations(mockPMBus, expectations); |
| 942 | psu.analyze(); |
| 943 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 944 | // Turn PGOOD# off (fault on). |
| 945 | expectations.statusWordValue = (status_word::POWER_GOOD_NEGATED); |
| 946 | setPMBusExpectations(mockPMBus, expectations); |
| 947 | psu.analyze(); |
| 948 | EXPECT_EQ(psu.hasPgoodFault(), true); |
| 949 | // Back to no fault bits on in STATUS_WORD |
| 950 | expectations.statusWordValue = 0; |
| 951 | setPMBusExpectations(mockPMBus, expectations); |
| 952 | psu.analyze(); |
| 953 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 954 | // Turn OFF bit on |
| 955 | expectations.statusWordValue = (status_word::UNIT_IS_OFF); |
| 956 | setPMBusExpectations(mockPMBus, expectations); |
| 957 | psu.analyze(); |
| 958 | EXPECT_EQ(psu.hasPgoodFault(), true); |
| 959 | // Back to no fault bits on in STATUS_WORD |
| 960 | expectations.statusWordValue = 0; |
| 961 | setPMBusExpectations(mockPMBus, expectations); |
| 962 | psu.analyze(); |
| 963 | EXPECT_EQ(psu.hasPgoodFault(), false); |
| 964 | } |