/** * Copyright © 2025 IBM Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "chassis.hpp" #include "mock_services.hpp" #include "power_sequencer_device.hpp" #include "rail.hpp" #include "services.hpp" #include "ucd90160_device.hpp" #include // for size_t #include #include #include #include #include #include using namespace phosphor::power::sequencer; /** * Creates a PowerSequencerDevice instance. * * PowerSequencerDevice is an abstract base class. The actual object type * created is a UCD90160Device. * * @param bus I2C bus for the device * @param address I2C address for the device * @param services System services like hardware presence and the journal * @return PowerSequencerDevice instance */ std::unique_ptr createPowerSequencer( uint8_t bus, uint16_t address, Services& services) { std::string powerControlGPIOName{"power-chassis-control"}; std::string powerGoodGPIOName{"power-chassis-good"}; std::vector> rails; return std::make_unique( bus, address, powerControlGPIOName, powerGoodGPIOName, std::move(rails), services); } TEST(ChassisTests, Constructor) { MockServices services; size_t number{1}; std::string inventoryPath{"/xyz/openbmc_project/inventory/system/chassis"}; std::vector> powerSequencers; powerSequencers.emplace_back(createPowerSequencer(3, 0x70, services)); Chassis chassis{number, inventoryPath, std::move(powerSequencers)}; EXPECT_EQ(chassis.getNumber(), number); EXPECT_EQ(chassis.getInventoryPath(), inventoryPath); EXPECT_EQ(chassis.getPowerSequencers().size(), 1); EXPECT_EQ(chassis.getPowerSequencers()[0]->getBus(), 3); EXPECT_EQ(chassis.getPowerSequencers()[0]->getAddress(), 0x70); } TEST(ChassisTests, GetNumber) { MockServices services; size_t number{2}; std::string inventoryPath{"/xyz/openbmc_project/inventory/system/chassis2"}; std::vector> powerSequencers; Chassis chassis{number, inventoryPath, std::move(powerSequencers)}; EXPECT_EQ(chassis.getNumber(), number); } TEST(ChassisTests, GetInventoryPath) { MockServices services; size_t number{3}; std::string inventoryPath{ "/xyz/openbmc_project/inventory/system/chassis_3"}; std::vector> powerSequencers; Chassis chassis{number, inventoryPath, std::move(powerSequencers)}; EXPECT_EQ(chassis.getInventoryPath(), inventoryPath); } TEST(ChassisTests, GetPowerSequencers) { MockServices services; size_t number{2}; std::string inventoryPath{"/xyz/openbmc_project/inventory/system/chassis2"}; std::vector> powerSequencers; powerSequencers.emplace_back(createPowerSequencer(3, 0x70, services)); powerSequencers.emplace_back(createPowerSequencer(4, 0x32, services)); powerSequencers.emplace_back(createPowerSequencer(10, 0x16, services)); Chassis chassis{number, inventoryPath, std::move(powerSequencers)}; EXPECT_EQ(chassis.getPowerSequencers().size(), 3); EXPECT_EQ(chassis.getPowerSequencers()[0]->getBus(), 3); EXPECT_EQ(chassis.getPowerSequencers()[0]->getAddress(), 0x70); EXPECT_EQ(chassis.getPowerSequencers()[1]->getBus(), 4); EXPECT_EQ(chassis.getPowerSequencers()[1]->getAddress(), 0x32); EXPECT_EQ(chassis.getPowerSequencers()[2]->getBus(), 10); EXPECT_EQ(chassis.getPowerSequencers()[2]->getAddress(), 0x16); }