Shawn McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 1 | /** |
| 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 McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 16 | #include "action.hpp" |
| 17 | #include "chassis.hpp" |
| 18 | #include "configuration.hpp" |
| 19 | #include "device.hpp" |
Shawn McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 20 | #include "i2c_interface.hpp" |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 21 | #include "mock_action.hpp" |
| 22 | #include "presence_detection.hpp" |
| 23 | #include "rail.hpp" |
| 24 | #include "rule.hpp" |
Shawn McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 25 | |
| 26 | #include <memory> |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 27 | #include <string> |
| 28 | #include <utility> |
| 29 | #include <vector> |
Shawn McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 30 | |
| 31 | namespace 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 | */ |
| 39 | inline std::unique_ptr<i2c::I2CInterface> createI2CInterface() |
| 40 | { |
| 41 | return i2c::create(1, 0x70, i2c::I2CInterface::InitialState::CLOSED); |
| 42 | } |
| 43 | |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 44 | /** |
| 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 | */ |
| 53 | inline 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 | */ |
| 82 | inline 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 McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 92 | } // namespace phosphor::power::regulators::test_utils |