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