1b0f94e07SShawn McCarney /** 2b0f94e07SShawn McCarney * Copyright © 2025 IBM Corporation 3b0f94e07SShawn McCarney * 4b0f94e07SShawn McCarney * Licensed under the Apache License, Version 2.0 (the "License"); 5b0f94e07SShawn McCarney * you may not use this file except in compliance with the License. 6b0f94e07SShawn McCarney * You may obtain a copy of the License at 7b0f94e07SShawn McCarney * 8b0f94e07SShawn McCarney * http://www.apache.org/licenses/LICENSE-2.0 9b0f94e07SShawn McCarney * 10b0f94e07SShawn McCarney * Unless required by applicable law or agreed to in writing, software 11b0f94e07SShawn McCarney * distributed under the License is distributed on an "AS IS" BASIS, 12b0f94e07SShawn McCarney * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b0f94e07SShawn McCarney * See the License for the specific language governing permissions and 14b0f94e07SShawn McCarney * limitations under the License. 15b0f94e07SShawn McCarney */ 16b0f94e07SShawn McCarney 17b0f94e07SShawn McCarney #include "chassis_status_monitor.hpp" 18b0f94e07SShawn McCarney 19b0f94e07SShawn McCarney #include <stddef.h> // for size_t 20b0f94e07SShawn McCarney 21b0f94e07SShawn McCarney #include <sdbusplus/bus.hpp> 22b0f94e07SShawn McCarney 23b0f94e07SShawn McCarney #include <string> 24b0f94e07SShawn McCarney 25b0f94e07SShawn McCarney #include <gtest/gtest.h> 26b0f94e07SShawn McCarney 27b0f94e07SShawn McCarney namespace phosphor::power::util 28b0f94e07SShawn McCarney { 29b0f94e07SShawn McCarney bool operator==(const ChassisStatusMonitorOptions& lhs, 30b0f94e07SShawn McCarney const ChassisStatusMonitorOptions& rhs) 31b0f94e07SShawn McCarney { 32b0f94e07SShawn McCarney return ( 33b0f94e07SShawn McCarney (lhs.isPresentMonitored == rhs.isPresentMonitored) && 34b0f94e07SShawn McCarney (lhs.isAvailableMonitored == rhs.isAvailableMonitored) && 35b0f94e07SShawn McCarney (lhs.isEnabledMonitored == rhs.isEnabledMonitored) && 36b0f94e07SShawn McCarney (lhs.isPowerStateMonitored == rhs.isPowerStateMonitored) && 37b0f94e07SShawn McCarney (lhs.isPowerGoodMonitored == rhs.isPowerGoodMonitored) && 38b0f94e07SShawn McCarney (lhs.isInputPowerStatusMonitored == rhs.isInputPowerStatusMonitored) && 39b0f94e07SShawn McCarney (lhs.isPowerSuppliesStatusMonitored == 40b0f94e07SShawn McCarney rhs.isPowerSuppliesStatusMonitored)); 41b0f94e07SShawn McCarney } 42b0f94e07SShawn McCarney } // namespace phosphor::power::util 43b0f94e07SShawn McCarney 44b0f94e07SShawn McCarney using namespace phosphor::power::util; 45b0f94e07SShawn McCarney 46*68345d13SShawn McCarney TEST(ChassisStatusMonitorOptionsTests, DefaultConstructor) 47*68345d13SShawn McCarney { 48*68345d13SShawn McCarney ChassisStatusMonitorOptions options; 49*68345d13SShawn McCarney EXPECT_FALSE(options.isPresentMonitored); 50*68345d13SShawn McCarney EXPECT_FALSE(options.isAvailableMonitored); 51*68345d13SShawn McCarney EXPECT_FALSE(options.isEnabledMonitored); 52*68345d13SShawn McCarney EXPECT_FALSE(options.isPowerStateMonitored); 53*68345d13SShawn McCarney EXPECT_FALSE(options.isPowerGoodMonitored); 54*68345d13SShawn McCarney EXPECT_FALSE(options.isInputPowerStatusMonitored); 55*68345d13SShawn McCarney EXPECT_FALSE(options.isPowerSuppliesStatusMonitored); 56*68345d13SShawn McCarney } 57*68345d13SShawn McCarney 58b0f94e07SShawn McCarney TEST(BMCChassisStatusMonitorTests, Constructor) 59b0f94e07SShawn McCarney { 60b0f94e07SShawn McCarney auto bus = sdbusplus::bus::new_default(); 61b0f94e07SShawn McCarney size_t number{2}; 62b0f94e07SShawn McCarney std::string inventoryPath{ 63b0f94e07SShawn McCarney "/xyz/openbmc_project/inventory/system/chassis_two"}; 64b0f94e07SShawn McCarney ChassisStatusMonitorOptions options; 65b0f94e07SShawn McCarney options.isPresentMonitored = true; 66b0f94e07SShawn McCarney options.isAvailableMonitored = false; 67b0f94e07SShawn McCarney options.isEnabledMonitored = true; 68b0f94e07SShawn McCarney options.isPowerStateMonitored = true; 69b0f94e07SShawn McCarney options.isPowerGoodMonitored = true; 70b0f94e07SShawn McCarney options.isInputPowerStatusMonitored = false; 71b0f94e07SShawn McCarney options.isPowerSuppliesStatusMonitored = true; 72b0f94e07SShawn McCarney BMCChassisStatusMonitor monitor{bus, number, inventoryPath, options}; 73b0f94e07SShawn McCarney 74b0f94e07SShawn McCarney EXPECT_EQ(monitor.getNumber(), number); 75b0f94e07SShawn McCarney EXPECT_EQ(monitor.getInventoryPath(), inventoryPath); 76b0f94e07SShawn McCarney EXPECT_EQ(monitor.getOptions(), options); 77b0f94e07SShawn McCarney } 78b0f94e07SShawn McCarney 79b0f94e07SShawn McCarney TEST(BMCChassisStatusMonitorTests, GetNumber) 80b0f94e07SShawn McCarney { 81b0f94e07SShawn McCarney auto bus = sdbusplus::bus::new_default(); 82b0f94e07SShawn McCarney size_t number{3}; 83b0f94e07SShawn McCarney std::string inventoryPath{"/xyz/openbmc_project/inventory/system/chassis3"}; 84b0f94e07SShawn McCarney ChassisStatusMonitorOptions options; 85b0f94e07SShawn McCarney BMCChassisStatusMonitor monitor{bus, number, inventoryPath, options}; 86b0f94e07SShawn McCarney 87b0f94e07SShawn McCarney EXPECT_EQ(monitor.getNumber(), number); 88b0f94e07SShawn McCarney } 89b0f94e07SShawn McCarney 90b0f94e07SShawn McCarney TEST(BMCChassisStatusMonitorTests, GetInventoryPath) 91b0f94e07SShawn McCarney { 92b0f94e07SShawn McCarney auto bus = sdbusplus::bus::new_default(); 93b0f94e07SShawn McCarney size_t number{3}; 94b0f94e07SShawn McCarney std::string inventoryPath{"/xyz/openbmc_project/inventory/system/chassis3"}; 95b0f94e07SShawn McCarney ChassisStatusMonitorOptions options; 96b0f94e07SShawn McCarney BMCChassisStatusMonitor monitor{bus, number, inventoryPath, options}; 97b0f94e07SShawn McCarney 98b0f94e07SShawn McCarney EXPECT_EQ(monitor.getInventoryPath(), inventoryPath); 99b0f94e07SShawn McCarney } 100b0f94e07SShawn McCarney 101b0f94e07SShawn McCarney TEST(BMCChassisStatusMonitorTests, GetOptions) 102b0f94e07SShawn McCarney { 103b0f94e07SShawn McCarney auto bus = sdbusplus::bus::new_default(); 104b0f94e07SShawn McCarney size_t number{1}; 105b0f94e07SShawn McCarney std::string inventoryPath{"/xyz/openbmc_project/inventory/system/chassis"}; 106b0f94e07SShawn McCarney ChassisStatusMonitorOptions options; 107b0f94e07SShawn McCarney options.isPresentMonitored = false; 108b0f94e07SShawn McCarney options.isAvailableMonitored = true; 109b0f94e07SShawn McCarney options.isEnabledMonitored = false; 110b0f94e07SShawn McCarney options.isPowerStateMonitored = false; 111b0f94e07SShawn McCarney options.isPowerGoodMonitored = false; 112b0f94e07SShawn McCarney options.isInputPowerStatusMonitored = true; 113b0f94e07SShawn McCarney options.isPowerSuppliesStatusMonitored = false; 114b0f94e07SShawn McCarney BMCChassisStatusMonitor monitor{bus, number, inventoryPath, options}; 115b0f94e07SShawn McCarney 116b0f94e07SShawn McCarney EXPECT_EQ(monitor.getOptions(), options); 117b0f94e07SShawn McCarney } 118