psu-ng: gtest cleanup expectation warnings
A number of the tests are missing various EXPECT_CALL statements that
result in very verbose testlog.txt output. This becomes especially
problematic when a test fails, as there are pages of output to look for
to narrow down what failed where and why.
Adding in the EXPECT_CALL statements that should be there, such as
findHwmonDir, the reading of "in1_input" as part of the fault clearing,
etc.
Change-Id: I9f2f88622ad7b682461069df980a50b0b13c44a6
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/phosphor-power-supply/test/power_supply_tests.cpp b/phosphor-power-supply/test/power_supply_tests.cpp
index a762ecb..539f2fb 100644
--- a/phosphor-power-supply/test/power_supply_tests.cpp
+++ b/phosphor-power-supply/test/power_supply_tests.cpp
@@ -92,6 +92,23 @@
const MockedUtil& mockedUtil;
};
+// Helper function for when a power supply goes from missing to present.
+void setMissingToPresentExpects(MockedPMBus& pmbus, const MockedUtil& util)
+{
+ // Call to analyze() will update to present, that will trigger updating
+ // to the correct/latest HWMON directory, in case it changes.
+ EXPECT_CALL(pmbus, findHwmonDir());
+ // Presence change from missing to present will trigger write to
+ // ON_OFF_CONFIG.
+ EXPECT_CALL(pmbus, writeBinary(ON_OFF_CONFIG, _, _));
+ // Presence change from missing to present will trigger in1_input read
+ // in an attempt to get CLEAR_FAULTS called.
+ EXPECT_CALL(pmbus, read(READ_VIN, _)).Times(1).WillOnce(Return(1));
+ // Missing/present call will update Presence in inventory.
+ // EXPECT_CALL(mockedUtil, setPresence(_, _, true, _));
+ EXPECT_CALL(util, setPresence(_, _, true, _));
+}
+
TEST_F(PowerSupplyTests, Constructor)
{
/**
@@ -228,18 +245,7 @@
EXPECT_EQ(psu2.isPresent(), false);
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu2.getPMBus());
- // First analyze() call will trigger missing to present, requiring update
- // to find the new HWMON directory.
- EXPECT_CALL(mockPMBus, findHwmonDir());
- // Presence change from missing to present will trigger write to
- // ON_OFF_CONFIG.
- EXPECT_CALL(mockPMBus, writeBinary(ON_OFF_CONFIG, _, _));
- // Presence change from missing to present will trigger in1_input read
- // in an attempt to get CLEAR_FAULTS called.
- EXPECT_CALL(mockPMBus, read(READ_VIN, _)).Times(1).WillOnce(Return(206000));
- // Change from missing to present will trigger call to update Present
- // property in the inventory
- EXPECT_CALL(mockedUtil, setPresence(_, _, true, _));
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
// STATUS_WORD INPUT fault.
{
@@ -599,14 +605,19 @@
PowerSupply psu{bus, PSUInventoryPath, 5, 0x6a, PSUGPIOLineName};
MockedGPIOInterface* mockPresenceGPIO =
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
- ON_CALL(*mockPresenceGPIO, read()).WillByDefault(Return(1));
+ // There will potentially be multiple calls, we want it to continue
+ // returning 1 for the GPIO read to keep the power supply present.
+ EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- // TODO: expect setPresence call?
- // updatePresence() private function reads gpio, called by analyze().
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
+ // If I am calling analyze(), I should probably give it good data.
+ // STATUS_WORD 0x0000 is powered on, no faults.
+ PMBusExpectations expectations;
+ setPMBusExpectations(mockPMBus, expectations);
psu.analyze();
- // TODO: ???should I check the filename?
- EXPECT_CALL(mockPMBus,
- writeBinary(_, ElementsAre(0x15), Type::HwmonDeviceDebug))
+ // I definitely should be writting ON_OFF_CONFIG if I call the function
+ EXPECT_CALL(mockPMBus, writeBinary(ON_OFF_CONFIG, ElementsAre(0x15),
+ Type::HwmonDeviceDebug))
.Times(1);
psu.onOffConfig(data);
}
@@ -624,15 +635,7 @@
// Each analyze() call will trigger a read of the presence GPIO.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- // Change from missing to present will trigger HWMON directory update.
- EXPECT_CALL(mockPMBus, findHwmonDir());
- // Change from missing to present will trigger ON_OFF_CONFIG write.
- EXPECT_CALL(mockPMBus, writeBinary(ON_OFF_CONFIG, _, _));
- // Presence change from missing to present will trigger in1_input read in
- // an attempt to get CLEAR_FAULTS called.
- EXPECT_CALL(mockPMBus, read(READ_VIN, _)).Times(1).WillOnce(Return(206000));
- // Missing/present call will update Presence in inventory.
- EXPECT_CALL(mockedUtil, setPresence(_, _, true, _));
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
// STATUS_WORD 0x0000 is powered on, no faults.
PMBusExpectations expectations;
setPMBusExpectations(mockPMBus, expectations);
@@ -697,9 +700,7 @@
EXPECT_EQ(psu.hasPS12VcsFault(), true);
EXPECT_EQ(psu.hasPSCS12VFault(), true);
- EXPECT_CALL(mockPMBus, read("in1_input", _))
- .Times(1)
- .WillOnce(Return(209000));
+ EXPECT_CALL(mockPMBus, read(READ_VIN, _)).Times(1).WillOnce(Return(207000));
psu.clearFaults();
EXPECT_EQ(psu.isPresent(), true);
EXPECT_EQ(psu.isFaulted(), false);
@@ -744,8 +745,13 @@
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
// GPIO read return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).Times(1).WillOnce(Return(1));
- psu.analyze();
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
+ // STATUS_WORD 0x0000 is powered on, no faults.
+ PMBusExpectations expectations;
+ setPMBusExpectations(mockPMBus, expectations);
+ // Need analyze call to update power supply from missing to present.
+ psu.analyze();
EXPECT_CALL(mockPMBus, readString(_, _)).WillRepeatedly(Return(""));
psu.updateInventory();
@@ -778,6 +784,14 @@
// Change GPIO read to return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).Times(1).WillOnce(Return(1));
+ // Call to analyze() will update to present, that will trigger updating
+ // to the correct/latest HWMON directory, in case it changes.
+ MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
+ // Call to analyze things will trigger read of STATUS_WORD and READ_VIN.
+ // Default expectations will be on, no faults.
+ PMBusExpectations expectations;
+ setPMBusExpectations(mockPMBus, expectations);
psu.analyze();
EXPECT_EQ(psu.isPresent(), true);
}
@@ -791,10 +805,14 @@
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
// Always return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
+ MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
+ // Call to analyze things will trigger read of STATUS_WORD and READ_VIN.
+ // Default expectations will be on, no faults.
+ PMBusExpectations expectations;
+ setPMBusExpectations(mockPMBus, expectations);
psu.analyze();
EXPECT_EQ(psu.isFaulted(), false);
- MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- PMBusExpectations expectations;
// STATUS_WORD with fault bits on.
expectations.statusWordValue = 0xFFFF;
// STATUS_INPUT with fault bits on.
@@ -825,9 +843,8 @@
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
// Always return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
- psu.analyze();
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- EXPECT_EQ(psu.hasInputFault(), false);
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
// STATUS_WORD 0x0000 is powered on, no faults.
PMBusExpectations expectations;
setPMBusExpectations(mockPMBus, expectations);
@@ -856,9 +873,8 @@
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
// Always return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
- psu.analyze();
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- EXPECT_EQ(psu.hasMFRFault(), false);
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
// First return STATUS_WORD with no bits on.
// STATUS_WORD 0x0000 is powered on, no faults.
PMBusExpectations expectations;
@@ -888,9 +904,8 @@
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
// Always return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
- psu.analyze();
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- EXPECT_EQ(psu.hasVINUVFault(), false);
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
// STATUS_WORD 0x0000 is powered on, no faults.
PMBusExpectations expectations;
setPMBusExpectations(mockPMBus, expectations);
@@ -920,9 +935,8 @@
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
// Always return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
- psu.analyze();
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- EXPECT_EQ(psu.hasVoutOVFault(), false);
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
// STATUS_WORD 0x0000 is powered on, no faults.
PMBusExpectations expectations;
setPMBusExpectations(mockPMBus, expectations);
@@ -952,9 +966,8 @@
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
// Always return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
- psu.analyze();
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- EXPECT_EQ(psu.hasIoutOCFault(), false);
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
// STATUS_WORD 0x0000 is powered on, no faults.
PMBusExpectations expectations;
setPMBusExpectations(mockPMBus, expectations);
@@ -983,9 +996,9 @@
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
// Always return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
- psu.analyze();
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- EXPECT_EQ(psu.hasVoutUVFault(), false);
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
+ // STATUS_WORD 0x0000 is powered on, no faults.
PMBusExpectations expectations;
setPMBusExpectations(mockPMBus, expectations);
psu.analyze();
@@ -1013,9 +1026,8 @@
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
// Always return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
- psu.analyze();
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- EXPECT_EQ(psu.hasFanFault(), false);
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
// STATUS_WORD 0x0000 is powered on, no faults.
PMBusExpectations expectations;
setPMBusExpectations(mockPMBus, expectations);
@@ -1044,9 +1056,8 @@
static_cast<MockedGPIOInterface*>(psu.getPresenceGPIO());
// Always return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
- psu.analyze();
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- EXPECT_EQ(psu.hasTempFault(), false);
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
// STATUS_WORD 0x0000 is powered on, no faults.
PMBusExpectations expectations;
setPMBusExpectations(mockPMBus, expectations);
@@ -1076,21 +1087,16 @@
// Always return 1 to indicate present.
EXPECT_CALL(*mockPresenceGPIO, read()).WillRepeatedly(Return(1));
MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
- EXPECT_CALL(mockPMBus, findHwmonDir());
- // Presence change from missing to present will trigger write to
- // ON_OFF_CONFIG.
- EXPECT_CALL(mockPMBus, writeBinary(ON_OFF_CONFIG, _, _));
- // Missing/present will trigger read of "in1_input" to try CLEAR_FAULTS.
- EXPECT_CALL(mockPMBus, read("in1_input", _))
- .Times(1)
- .WillOnce(Return(207000));
- // Missing/present call will update Presence in inventory.
- EXPECT_CALL(mockedUtil, setPresence(_, _, true, _));
+ setMissingToPresentExpects(mockPMBus, mockedUtil);
// STATUS_WORD 0x0000 is powered on, no faults.
PMBusExpectations expectations;
setPMBusExpectations(mockPMBus, expectations);
psu.analyze();
EXPECT_EQ(psu.hasPgoodFault(), false);
+ // Setup another expectation of no faults.
+ setPMBusExpectations(mockPMBus, expectations);
+ psu.analyze();
+ EXPECT_EQ(psu.hasPgoodFault(), false);
// Turn PGOOD# off (fault on).
expectations.statusWordValue = (status_word::POWER_GOOD_NEGATED);
setPMBusExpectations(mockPMBus, expectations);