blob: 313d9f7c299b410f71f132a7d0fe98a21e74b9b4 [file] [log] [blame]
Shawn McCarney8a3afd72020-03-12 14:28:44 -05001/**
2 * Copyright © 2020 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 */
Shawn McCarneydb0b8332020-04-06 14:13:04 -050016#include "action.hpp"
17#include "chassis.hpp"
18#include "configuration.hpp"
19#include "device.hpp"
Shawn McCarney8a3afd72020-03-12 14:28:44 -050020#include "i2c_interface.hpp"
Shawn McCarneydb0b8332020-04-06 14:13:04 -050021#include "mock_action.hpp"
22#include "presence_detection.hpp"
23#include "rail.hpp"
24#include "rule.hpp"
Shawn McCarney8a3afd72020-03-12 14:28:44 -050025
26#include <memory>
Shawn McCarneydb0b8332020-04-06 14:13:04 -050027#include <string>
28#include <utility>
29#include <vector>
Shawn McCarney8a3afd72020-03-12 14:28:44 -050030
31namespace phosphor::power::regulators::test_utils
32{
33
34/**
35 * Create an I2CInterface object with hard-coded bus and address values.
36 *
37 * @return I2CInterface object wrapped in a unique_ptr
38 */
39inline std::unique_ptr<i2c::I2CInterface> createI2CInterface()
40{
41 return i2c::create(1, 0x70, i2c::I2CInterface::InitialState::CLOSED);
42}
43
Shawn McCarneydb0b8332020-04-06 14:13:04 -050044/**
45 * Creates a Device object with the specified ID.
46 *
47 * Creates Rail objects within the Device if railIDs is specified.
48 *
49 * @param id device ID
50 * @param railIDs rail IDs (optional)
51 * @return Device object
52 */
53inline std::unique_ptr<Device>
54 createDevice(const std::string& id,
55 const std::vector<std::string>& railIDs = {})
56{
57 // Create Rails (if any)
58 std::vector<std::unique_ptr<Rail>> rails{};
59 for (const std::string& railID : railIDs)
60 {
61 rails.emplace_back(std::make_unique<Rail>(railID));
62 }
63
64 // Create Device
65 bool isRegulator = true;
66 std::string fru = "/system/chassis/motherboard/reg1";
67 std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
68 std::unique_ptr<PresenceDetection> presenceDetection{};
69 std::unique_ptr<Configuration> configuration{};
70 return std::make_unique<Device>(id, isRegulator, fru,
71 std::move(i2cInterface),
72 std::move(presenceDetection),
73 std::move(configuration), std::move(rails));
74}
75
76/**
77 * Creates a Rule object with the specified ID.
78 *
79 * @param id rule ID
80 * @return Rule object
81 */
82inline std::unique_ptr<Rule> createRule(const std::string& id)
83{
84 // Create actions
85 std::vector<std::unique_ptr<Action>> actions{};
86 actions.emplace_back(std::make_unique<MockAction>());
87
88 // Create Rule
89 return std::make_unique<Rule>(id, std::move(actions));
90}
91
Shawn McCarney8a3afd72020-03-12 14:28:44 -050092} // namespace phosphor::power::regulators::test_utils